[trunk] Fix issue with & vs &&
[openjpeg.git] / src / bin / jp2 / convert.c
index f99cd169b5f9f34c02fdbbac8b8b67bd6cf10930..3588700b75e89bebf76ab517e8c5ec8f7624f59a 100644 (file)
@@ -183,7 +183,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
 
 #if WORDS_BIGENDIAN == 1
 
-static inline int16_t swap16(int16_t x)
+static INLINE int16_t swap16(int16_t x)
 {
     return((((u_int16_t)x & 0x00ffU) <<  8) |
            (((u_int16_t)x & 0xff00U) >>  8));
@@ -416,6 +416,7 @@ int imagetotga(opj_image_t * image, const char *outfile) {
     float scale;
     FILE *fdest;
     size_t res;
+    fails = 1;
 
     fdest = fopen(outfile, "wb");
     if (!fdest) {
@@ -573,7 +574,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
     unsigned char *table_R, *table_G, *table_B;
     unsigned int j, PAD = 0;
 
-    int x, y, index;
+    unsigned int x, y;
+    int index;
     int gray_scale = 1;
     int has_color;
     DWORD W, H;
@@ -710,7 +712,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
 
         /* Place the cursor at the beginning of the image information */
         fseek(IN, 0, SEEK_SET);
-        fseek(IN, File_h.bfOffBits, SEEK_SET);
+        fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
 
         W = Info_h.biWidth;
         H = Info_h.biHeight;
@@ -732,10 +734,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
 
         index = 0;
 
-        for(y = 0; y < (int)H; y++)
+        for(y = 0; y < H; y++)
         {
             unsigned char *scanline = RGB + (3 * (unsigned int)W + PAD) * ((unsigned int)H - 1 - (unsigned int)y);
-            for(x = 0; x < (int)W; x++)
+            for(x = 0; x < W; x++)
             {
                 unsigned char *pixel = &scanline[3 * x];
                 image->comps[0].data[index] = pixel[2];        /* R */
@@ -771,7 +773,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
 
             /* Place the cursor at the beginning of the image information */
             fseek(IN, 0, SEEK_SET);
-            fseek(IN, File_h.bfOffBits, SEEK_SET);
+            fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
 
             W = Info_h.biWidth;
             H = Info_h.biHeight;
@@ -862,8 +864,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
             {
                 unsigned char *pix, *beyond;
                 int *gray, *red, *green, *blue;
-                unsigned int x, y, max;
-                int i, c, c1;
+                unsigned int max;
+                int c, c1;
                 unsigned char uc;
 
                 if (Info_h.biClrUsed == 0)
@@ -923,7 +925,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
 
                 /* Place the cursor at the beginning of the image information */
                 fseek(IN, 0, SEEK_SET);
-                fseek(IN, File_h.bfOffBits, SEEK_SET);
+                fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
 
                 W = Info_h.biWidth;
                 H = Info_h.biHeight;
@@ -1419,7 +1421,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
 
 #define CLAMP(x,a,b) x < a ? a : (x > b ? b : x)
 
-static inline int clamp( const int value, const int prec, const int sgnd )
+static INLINE int clamp( const int value, const int prec, const int sgnd )
 {
   if( sgnd )
     {
@@ -1714,7 +1716,7 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph)
         }
         if(ph->depth < 1 || ph->depth > 4) return;
 
-        if(ph->width && ph->height && ph->depth & ph->maxval && ttype)
+        if(ph->width && ph->height && ph->depth && ph->maxval && ttype)
             ph->ok = 1;
     }
     else
@@ -2098,8 +2100,15 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0;
 
     for (compno = 0; compno < ncomp; compno++)
     {
-        if (ncomp > 1)
-            sprintf(destname, "%d.%s", compno, outfile);
+    if (ncomp > 1)
+      {
+      /*sprintf(destname, "%d.%s", compno, outfile);*/
+      const size_t olen = strlen(outfile);
+      const size_t dotpos = olen - 4;
+
+      strncpy(destname, outfile, dotpos);
+      sprintf(destname+dotpos, "_%d.pgm", compno);
+      }
         else
             sprintf(destname, "%s", outfile);
 
@@ -3120,15 +3129,15 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL
         {
             if(image->comps[compno].sgnd == 1)
             {
-                union { signed short val; signed char vals[2]; } uc;
+                union { signed short val; signed char vals[2]; } uc16;
                 mask = (1 << image->comps[compno].prec) - 1;
                 ptr = image->comps[compno].data;
                 for (line = 0; line < h; line++) {
                     for(row = 0; row < w; row++)       {
                         curr = *ptr;
                         if(curr > 32767 ) curr = 32767; else if( curr < -32768) curr = -32768;
-                        uc.val = (signed short)(curr & mask);
-                        res = fwrite(uc.vals, 1, 2, rawFile);
+                        uc16.val = (signed short)(curr & mask);
+                        res = fwrite(uc16.vals, 1, 2, rawFile);
                         if( res < 2 ) {
                             fprintf(stderr, "failed to write 2 byte for %s\n", outfile);
                             goto fin;
@@ -3139,15 +3148,15 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL
             }
             else if(image->comps[compno].sgnd == 0)
             {
-                union { unsigned short val; unsigned char vals[2]; } uc;
+                union { unsigned short val; unsigned char vals[2]; } uc16;
                 mask = (1 << image->comps[compno].prec) - 1;
                 ptr = image->comps[compno].data;
                 for (line = 0; line < h; line++) {
                     for(row = 0; row < w; row++)       {
                         curr = *ptr;
                         if(curr > 65536 ) curr = 65536; else if( curr < 0) curr = 0;
-                        uc.val = (unsigned short)(curr & mask);
-                        res = fwrite(uc.vals, 1, 2, rawFile);
+                        uc16.val = (unsigned short)(curr & mask);
+                        res = fwrite(uc16.vals, 1, 2, rawFile);
                         if( res < 2 ) {
                             fprintf(stderr, "failed to write 2 byte for %s\n", outfile);
                             goto fin;