Several bugs fixed when dealing with pgx-files with more than 8 bpp and the fixed_qua...
authorAntonin Descampe <antonin@gmail.com>
Mon, 18 Jul 2005 15:21:56 +0000 (15:21 +0000)
committerAntonin Descampe <antonin@gmail.com>
Mon, 18 Jul 2005 15:21:56 +0000 (15:21 +0000)
codec/image_to_j2k.c
codec/j2k_to_image.c
libopenjpeg/tcd.c

index 132f8f88f0082a6d24c8ecabda2b763d9d13552a..e64616abf99cb8875955b05a4b45a3c47f8c9082 100644 (file)
@@ -659,13 +659,13 @@ int main(int argc, char **argv)
   if ((cp.disto_alloc || cp.fixed_alloc || cp.fixed_quality)
       && (!(cp.disto_alloc ^ cp.fixed_alloc ^ cp.fixed_quality))) {
     fprintf(stderr,
-           "Error: options -r -q and -f can not be used together !!\n");
+           "Error: options -r -q and -f cannot be used together !!\n");
     return 1;
   }                            // mod fixed_quality
 
   /* if no rate entered, lossless by default */
   if (tcp_init->numlayers == 0) {
-    tcp_init->rates[tcp_init->numlayers] = 0;  //MOD antonin : losslessbug
+    tcp_init->rates[0] = 0;    //MOD antonin : losslessbug
     tcp_init->numlayers++;
     cp.disto_alloc = 1;
   }
index 00fca99c586d4809161345209ac5a4b5857e1e0e..3a6dcce1b1f62620926d321007cde67fa60301b4 100644 (file)
@@ -366,25 +366,24 @@ int main(int argc, char **argv)
        img.comps[0].factor);
       
       
-      fprintf(fdest, "P6\n# %d %d %d %d %d\n%d %d\n%d\n",
-       cp.tcps[cp.tileno[0]].tccps[0].numresolutions, w, h,
-       img.comps[0].x0, img.comps[0].y0, wrr, hrr, max);
+      fprintf(fdest, "P6\n%d %d\n%d\n", wrr, hrr, max);
       adjust = img.comps[0].prec > 8 ? img.comps[0].prec - 8 : 0;
       for (i = 0; i < wrr * hrr; i++) {
-       char r, g, b;
+       int r, g, b;
+        unsigned char rc,gc,bc;
        r = img.comps[0].data[i / wrr * wr + i % wrr];
        r += (img.comps[0].sgnd ? 1 << (img.comps[0].prec - 1) : 0);
-       r = r >> adjust;
+       rc = (unsigned char) ((r >> adjust)+((r >> (adjust-1))%2));
        
        g = img.comps[1].data[i / wrr * wr + i % wrr];
        g += (img.comps[1].sgnd ? 1 << (img.comps[1].prec - 1) : 0);
-       g = g >> adjust;
+       gc = (unsigned char) ((g >> adjust)+((g >> (adjust-1))%2));
        
        b = img.comps[2].data[i / wrr * wr + i % wrr];
        b += (img.comps[2].sgnd ? 1 << (img.comps[2].prec - 1) : 0);
-       b = b >> adjust;
+       bc = (unsigned char) ((b >> adjust)+((b >> (adjust-1))%2));
        
-       fprintf(fdest, "%c%c%c", r, g, b);
+       fprintf(fdest, "%c%c%c", rc, gc, bc);
       }
       free(img.comps[0].data);
       free(img.comps[1].data);
@@ -438,19 +437,17 @@ int main(int argc, char **argv)
                                      img.comps[compno].dy),
                                      img.comps[compno].factor);
        
-       fprintf(fdest, "P5\n# %d %d %d %d %d\n%d %d\n%d\n",
-         cp.tcps[cp.tileno[0]].tccps[compno].
-         numresolutions, w, h, img.comps[compno].x0,
-         img.comps[compno].y0, wrr, hrr, max);
+       fprintf(fdest, "P5\n%d %d\n%d\n", wrr, hrr, max);
        adjust =
          img.comps[compno].prec > 8 ? img.comps[compno].prec - 8 : 0;
        for (i = 0; i < wrr * hrr; i++) {
-         char l;
+         int l;
+          unsigned char lc;
          l = img.comps[compno].data[i / wrr * wr + i % wrr];
          l += (img.comps[compno].
            sgnd ? 1 << (img.comps[compno].prec - 1) : 0);
-         l = l >> adjust;
-         fprintf(fdest, "%c", l);
+         lc = (unsigned char) ((l >> adjust)+((l >> (adjust-1))%2));
+         fprintf(fdest, "%c", lc);
        }
        fclose(fdest);
        free(img.comps[compno].data);
@@ -476,12 +473,11 @@ int main(int argc, char **argv)
        tmp--;
       }
       *tmp='\0';
-      //if (img.numcomps > 1)
-      sprintf(name, "%s-%d.pgx", outfile, compno);
       
-      //else
-      
-      //sprintf(name, "%s.pgx", outfile);
+      if (img.numcomps > 1)
+        sprintf(name, "%s-%d.pgx", outfile, compno);
+      else
+        sprintf(name, "%s.pgx", outfile);
       
       fdest = fopen(name, "wb");
       if (!fdest) {
index 017b638efbdbed967296fbea0d567ef09ae12340..f39d34030962c3c79e79aa6de40d872ea579fa32 100644 (file)
@@ -1076,11 +1076,7 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
        }                       /* precno */
       }                                /* bandno */
     }                          /* resno */
-
-    maxSE +=
-      (double) (((1 << tcd_img->comps[compno].prec) -
-                1) * ((1 << tcd_img->comps[compno].prec) -
-                      1)) * (tilec->nbpix);
+    maxSE += (((double)(1 << tcd_img->comps[compno].prec) - 1.0) * ((double)(1 << tcd_img->comps[compno].prec) -1.0)) * ((double)(tilec->nbpix));
   }                            /* compno */
 
   /* add antonin index */
@@ -1103,8 +1099,8 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
     double distotarget;                //add fixed_quality
 
     distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10));      // add fixed_quality
-
-    if (tcd_tcp->rates[layno]) {
+    
+    if ((tcd_tcp->rates[layno]) || (tcd_cp->disto_alloc==0)) {
       for (i = 0; i < 32; i++) {
        volatile double thresh = (lo + hi) / 2;
        int l = 0;