Modified the way raw images with more that 8bpp are read and written
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Fri, 8 Aug 2008 13:15:36 +0000 (13:15 +0000)
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Fri, 8 Aug 2008 13:15:36 +0000 (13:15 +0000)
ChangeLog
codec/convert.c

index 3565e425a13357af89c767203cbb71ef842ebdac..4ffce3a60d38d4d6f1b70395394b85468d1ce06b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+August 8, 2008
+! [FOD] Modified the way raw images with more that 8bpp are read and written
+
 July 9, 2008
 + [Parvatha] Added the default lossless parameter to opj_set_default_encoder_parameters in openjpeg.c.
 
index e56d1311cf0cf3d3268c297e8f9d0a136dc15ed0..3f3384df007ce155967d5ef6a3cd25f09d928603 100644 (file)
@@ -2013,19 +2013,30 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw
                        }
                }
        }
-       else
+       else if(raw_cp->rawBitDepth <= 16)
        {
-               unsigned short value = 0;
+               unsigned short value;
                for(compno = 0; compno < numcomps; compno++) {
                        for (i = 0; i < w * h; i++) {
-                               if (!fread(&value, 2, 1, f)) {
+                               unsigned char temp;
+                               if (!fread(&temp, 1, 1, f)) {
                                        fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
                                        return NULL;
                                }
+                               value = temp << 8;
+                               if (!fread(&temp, 1, 1, f)) {
+                                       fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
+                                       return NULL;
+                               }
+                               value += temp;
                                image->comps[compno].data[i] = raw_cp->rawSigned?(short)value:value;
                        }
                }
        }
+       else {
+               fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n");
+               return NULL;
+       }
 
        if (fread(&ch, 1, 1, f)) {
                fprintf(stderr,"Warning. End of raw file not reached... processing anyway\n");
@@ -2103,8 +2114,12 @@ int imagetoraw(opj_image_t * image, const char *outfile)
                                ptr = image->comps[compno].data;
                                for (line = 0; line < h; line++) {
                                        for(row = 0; row < w; row++)    {                                       
-                                               curr = (signed short int) (*ptr & mask);
-                                               fwrite(&curr, sizeof(signed short int), 1, rawFile);
+                                               unsigned char temp;
+                                               curr = (signed short int) (*ptr & mask);                                                
+                                               temp = curr >> 8;
+                                               fwrite(&temp, 1, 1, rawFile);
+                                               temp = curr;
+                                               fwrite(&temp, 1, 1, rawFile);
                                                ptr++;
                                        }
                                }
@@ -2116,8 +2131,12 @@ int imagetoraw(opj_image_t * image, const char *outfile)
                                ptr = image->comps[compno].data;
                                for (line = 0; line < h; line++) {
                                        for(row = 0; row < w; row++)    {                               
-                                               curr = (unsigned short int) (*ptr & mask);
-                                               fwrite(&curr, sizeof(unsigned short int), 1, rawFile);
+                                               unsigned char temp;
+                                               curr = (unsigned short int) (*ptr & mask);                                              
+                                               temp = curr >> 8;
+                                               fwrite(&temp, 1, 1, rawFile);
+                                               temp = curr;
+                                               fwrite(&temp, 1, 1, rawFile);
                                                ptr++;
                                        }
                                }