]> granicus.if.org Git - openjpeg/commitdiff
[trunk] Follow up to r1691. Handle signed case.
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Tue, 29 May 2012 09:33:28 +0000 (09:33 +0000)
committerMathieu Malaterre <mathieu.malaterre@gmail.com>
Tue, 29 May 2012 09:33:28 +0000 (09:33 +0000)
applications/codec/convert.c

index 19518dd03d9725aefb3d8aa478d302aa69bde29d..dee780d4a70b0827e0ee827a27a22840fab0601f 100644 (file)
@@ -3001,9 +3001,17 @@ int imagetoraw_common(opj_image_t * image, const char *outfile, opj_bool big_end
                                                unsigned char temp1;
                                                unsigned char temp2;
                                                curr = (signed short int) (*ptr & mask);
-                                               temp1 = (unsigned char) (curr >> 8);
-                                               temp2 = (unsigned char) curr;
-                                               res = fwrite(&temp1, 1, 1, rawFile);
+            if( big_endian )
+              {
+              temp1 = (unsigned char) (curr >> 8);
+              temp2 = (unsigned char) curr;
+              }
+            else
+              {
+              temp2 = (unsigned char) (curr >> 8);
+              temp1 = (unsigned char) curr;
+              }
+            res = fwrite(&temp1, 1, 1, rawFile);
             if( res < 1 ) {
               fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
               return 1;