Fixed issues with generation of SOP marker.
authorParvatha Elangovan <p.elangovan@intopix.com>
Wed, 19 Sep 2007 14:56:19 +0000 (14:56 +0000)
committerParvatha Elangovan <p.elangovan@intopix.com>
Wed, 19 Sep 2007 14:56:19 +0000 (14:56 +0000)
ChangeLog
codec/convert.c
libopenjpeg/j2k.c
libopenjpeg/t2.c
libopenjpeg/tcd.h

index 11584840facdbec5b46dd2d51079b21d382cefae..5b0484434c2579380589b345278b848446433b5a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+September 19, 2007
+* [Parvatha] Fixed issues with generation of SOP marker. 
+
 September 18, 2007
 * [Parvatha] Fixed issues with Reading and Writing TIF images in convert.c to avoid segmentation fault. 
 * [Parvatha] Fixed issues relating to using user specified rates for CINEMA option for multiple images.
index 5e9f49693f9520ee3171b2eb5326915f34de427d..ff95001f1c593b06a60d1d7d022d03f941d68275 100644 (file)
@@ -1423,7 +1423,7 @@ typedef struct tiff_infoheader{
 }tiff_infoheader_t;
 
 int imagetotif(opj_image_t * image, const char *outfile) {
-       int width, height, imgsize;
+       int width, height, imgsize ;
        int bps,index,adjust = 0;
        int last_i=0;
        TIFF *tif;
@@ -1646,7 +1646,8 @@ int imagetotif(opj_image_t * image, const char *outfile) {
                        }
 
                        width   = image->comps[0].w;
-                       height= image->comps[0].h;
+                       height  = image->comps[0].h;
+                       imgsize = image->comps[0].w * image->comps[0].h ;
                        bps             = image->comps[0].prec;
 
                        /* Set tags */
@@ -1670,38 +1671,47 @@ int imagetotif(opj_image_t * image, const char *outfile) {
                                dat8 = buf;
                                if (image->comps[0].prec == 8){
                                        for (i=0; i<TIFFStripSize(tif); i+=1) { // 8 bits per pixel 
-                                               int r = 0;
-                                               r = image->comps[0].data[index];
-                                               if (image->comps[0].sgnd){
-                                                       r  += adjust;
-                                               }
-                                               dat8[i+0] = r;
-                                               index++;
+                                               if(index < imgsize){
+                                                       int r = 0;
+                                                       r = image->comps[0].data[index];
+                                                       if (image->comps[0].sgnd){
+                                                               r  += adjust;
+                                                       }
+                                                       dat8[i+0] = r;
+                                                       index++;
+                                               }else
+                                                       break; 
                                        }
                                }else if (image->comps[0].prec == 12){
                                        for (i = 0; i<TIFFStripSize(tif); i+=3) {       // 12 bits per pixel 
-                                               int r = 0, r1 = 0;
-                                               r  = image->comps[0].data[index];
-                                               r1 = image->comps[0].data[index+1];
-                                               if (image->comps[0].sgnd){
-                                                       r  += adjust;
-                                                       r1 += adjust;
-                                               }
-                                               dat8[i+0] = (r >> 4);
-                                               dat8[i+1] = ((r & 0x0f) << 4 )|((r1 >> 8)& 0x0f);
-                                               dat8[i+2] = r1 ;
-                                               index+=2;
+                                               if(index < imgsize){
+                                                       int r = 0, r1 = 0;
+                                                       r  = image->comps[0].data[index];
+                                                       r1 = image->comps[0].data[index+1];
+                                                       if (image->comps[0].sgnd){
+                                                               r  += adjust;
+                                                               r1 += adjust;
+                                                       }
+                                                       dat8[i+0] = (r >> 4);
+                                                       dat8[i+1] = ((r & 0x0f) << 4 )|((r1 >> 8)& 0x0f);
+                                                       dat8[i+2] = r1 ;
+                                                       index+=2;
+                                               }else
+                                                       break; 
                                        }
                                }else if (image->comps[0].prec == 16){
                                        for (i=0; i<TIFFStripSize(tif); i+=2) { // 16 bits per pixel 
-                                               int r = 0;
-                                               r = image->comps[0].data[index];
-                                               if (image->comps[0].sgnd){
-                                                       r  += adjust;
-                                               }
-                                               dat8[i+0] = r;
-                                               dat8[i+1] = r >> 8;
-                                               index++;
+                                               if(index < imgsize){
+                                                       int r = 0;
+                                                       r = image->comps[0].data[index];
+                                                       if (image->comps[0].sgnd){
+                                                               r  += adjust;
+                                                       }
+                                                       dat8[i+0] = r;
+                                                       dat8[i+1] = r >> 8;
+                                                       index++;
+                                               }else
+                                                       break; 
                                        }
                                }else{
                                        fprintf(stderr,"Bits=%d, Only 8,12,16 bits implemented\n",image->comps[0].prec);
@@ -1733,7 +1743,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
        OPJ_COLOR_SPACE color_space;
        opj_image_cmptparm_t cmptparm[3];
        opj_image_t * image = NULL;
-       int imgsize;
+       int imgsize = 0;
 
        tif = TIFFOpen(filename, "r");
 
@@ -1889,6 +1899,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
                strip_size = 0;
                strip_size = TIFFStripSize(tif);
                index = 0;
+               imgsize = image->comps[0].w * image->comps[0].h ;
                /* Read the Image components*/
                for (strip = 0; strip < TIFFNumberOfStrips(tif); strip++) {
                        unsigned char *dat8;
index a58ab6c39cc0b50109564ea6391146fe98501dfa..01c6bfdfc069c8c5deaf18c4db194d79db00a725 100644 (file)
@@ -1444,8 +1444,10 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
        for (layno = 0; layno < tcp->numlayers; layno++) {
                tcp->rates[layno] -= tcp->rates[layno] ? (j2k->sod_start / (cp->th * cp->tw)) : 0;
        }
-       if(cstr_info && (j2k->cur_tp_num == 0)) {
-               cstr_info->packno = 0;
+       if(j2k->cur_tp_num == 0){
+               tcd->tcd_image->tiles->packno = 0;
+               if(cstr_info)
+                       cstr_info->packno = 0;
        }
        
        l = tcd_encode_tile(tcd, j2k->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, cstr_info);
index 84d8bee7f3abfa67ac7aefb79250cf26e96e381e..a30bb53af7a00e8e227c4fcc60e51a4f0dfe4af5 100644 (file)
@@ -147,8 +147,8 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
                c[1] = 145;
                c[2] = 0;
                c[3] = 4;
-               c[4] = (cstr_info->packno % 65536) / 256;
-               c[5] = (cstr_info->packno % 65536) % 256;
+               c[4] = (tile->packno % 65536) / 256;
+               c[5] = (tile->packno % 65536) % 256;
                c += 6;
        }
        /* </SOP> */
@@ -656,6 +656,7 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
                                        cstr_info->packno++;
                                }
                                /* << INDEX */
+                               tile->packno++;
                        }
                }
        }
index f7c64e4d2a051b5f0ec30bb6a51bb86d471bb7d9..787cb8fabb441e2ce155a48480ca7da761fa8fd5 100644 (file)
@@ -144,6 +144,8 @@ typedef struct opj_tcd_tile {
   int numpix;                  /* add fixed_quality */
   double distotile;            /* add fixed_quality */
   double distolayer[100];      /* add fixed_quality */
+  /** packet number */
+  int packno;
 } opj_tcd_tile_t;
 
 /**