JPWL encoding is finalized correctly into the JP2 file format; added an additional...
authorGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Tue, 11 Sep 2007 15:21:12 +0000 (15:21 +0000)
committerGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Tue, 11 Sep 2007 15:21:12 +0000 (15:21 +0000)
ChangeLog
codec/image_to_j2k.c
jpwl/JPWL_image_to_j2k.dsp
jpwl/jpwl.c
jpwl/jpwl.h
libopenjpeg/j2k.c
libopenjpeg/openjpeg.h

index 183d8628ea65cec6e3b5e4d19426d676b18e85c4..ddb8977c4aaa86e8b3a88f1277978b7acf354da0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+September 11, 2007
+* [GB] JPWL encoding is finalized correctly into the JP2 file format; added an additional structure in opj_codestream_info, to keep a record of the written markers
+
 September 8, 2007
 * [GB] Adapted the JPWL and OPJViewer code to new interface; fixed a samll bug in JPWL which created large EPBs even when null protection was specified
 
index 576c0ee9ead6be2bcfa2a1b970aa1cc2ecc660aa..9c579193bd5e6a197c39316423d1b5758e6dbd62 100644 (file)
@@ -287,12 +287,22 @@ void encode_help_display() {
        fprintf(stdout,"decomposition_levels\n");
        fprintf(stdout,"[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n");
        fprintf(stdout,"   [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n");
+       fprintf(stdout,"Main_header_start_position\n");
        fprintf(stdout,"Main_header_end_position\n");
        fprintf(stdout,"Codestream_size\n");
-       fprintf(stdout,"Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n");
-       fprintf(stdout,"Tile_1   ''           ''        ''        ''       ''    ''\n");
+       fprintf(stdout,"\n");
+       fprintf(stdout,"INFO ON TILES\n");
+       fprintf(stdout,"tileno start_pos end_hd end_tile nbparts disto nbpix disto/nbpix\n");
+       fprintf(stdout,"Tile_0 start_pos end_Theader end_pos NumParts TotalDisto NumPix MaxMSE\n");
+       fprintf(stdout,"Tile_1   ''           ''        ''        ''       ''    ''      ''\n");
+       fprintf(stdout,"...\n");
+       fprintf(stdout,"Tile_Nt   ''           ''        ''        ''       ''    ''     ''\n");
+       fprintf(stdout,"...\n");
+       fprintf(stdout,"TILE 0 DETAILS\n");
+       fprintf(stdout,"part_nb tileno num_packs start_pos end_tph_pos end_pos\n");
        fprintf(stdout,"...\n");
-       fprintf(stdout,"Tile_Nt   ''           ''        ''        ''       ''    ''\n");
+       fprintf(stdout,"Progression_string\n");
+       fprintf(stdout,"pack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos disto\n");
        fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
        fprintf(stdout,"...\n");
        fprintf(stdout,"Tpacket_Np ''   ''    ''   ''    ''       ''       ''     ''\n");
index f7c4e35c0f6900eb9cc4ca7445a4e06a78bd027e..52d5e9aa1df0080089d5e3cde7377b8ba7d2e55e 100644 (file)
@@ -42,7 +42,8 @@ RSC=rc.exe
 # PROP Ignore_Export_Lib 0\r
 # PROP Target_Dir ""\r
 # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FR /YX /FD /c\r
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "OPJ_STATIC" /D "USE_JPWL" /D "USE_JPSEC" /FR /FD /c\r
+# SUBTRACT CPP /YX\r
 # ADD BASE RSC /l 0x80c /d "NDEBUG"\r
 # ADD RSC /l 0x80c /d "NDEBUG"\r
 BSC32=bscmake.exe\r
index 7a307839976dbba24a4eac6bb7d7976f468948d1..894e7d3fd2c7f11f345c4f9acf372d95af134d9e 100644 (file)
 /** @name Local static variables */\r
 /*@{*/\r
 \r
-/** position of markers to insert */\r
-static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS]; \r
-/** number of prepared markers */\r
+/** number of JPWL prepared markers */\r
 static int jwmarker_num;\r
+/** properties of JPWL markers to insert */\r
+static jpwl_marker_t jwmarker[JPWL_MAX_NO_MARKERS]; \r
 \r
 /*@}*/\r
 \r
@@ -107,6 +107,57 @@ void jpwl_esd_write(jpwl_esd_ms_t *esdmark, unsigned char *buf);
 \r
 /*-----------------------------------------------------------------*/\r
 \r
+void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {\r
+\r
+       int mm;\r
+\r
+       /* let's reset some settings */\r
+\r
+       /* clear the existing markers */\r
+       for (mm = 0; mm < jwmarker_num; mm++) {\r
+\r
+               switch (jwmarker[mm].id) {\r
+\r
+               case J2K_MS_EPB:\r
+                       free(jwmarker[mm].epbmark);\r
+                       break;\r
+\r
+               case J2K_MS_EPC:\r
+                       free(jwmarker[mm].epcmark);\r
+                       break;\r
+\r
+               case J2K_MS_ESD:\r
+                       free(jwmarker[mm].esdmark);\r
+                       break;\r
+\r
+               case J2K_MS_RED:\r
+                       free(jwmarker[mm].redmark);\r
+                       break;\r
+\r
+               default:\r
+                       break;\r
+               }\r
+       }\r
+\r
+       /* clear the marker structure array */\r
+       memset(jwmarker, 0, sizeof(jpwl_marker_t) * JPWL_MAX_NO_MARKERS);\r
+\r
+       /* no more markers in the list */\r
+       jwmarker_num = 0;\r
+\r
+       /* let's begin creating a marker list, according to user wishes */\r
+       jpwl_prepare_marks(j2k, cio, image);\r
+\r
+       /* now we dump the JPWL markers on the codestream */\r
+       jpwl_dump_marks(j2k, cio, image);\r
+\r
+       /* do not know exactly what is this for,\r
+       but it gets called during index creation */\r
+       j2k->pos_correction = 0;\r
+\r
+}\r
+\r
+\r
 void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {\r
 \r
        unsigned short int socsiz_len = 0;\r
@@ -282,7 +333,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
                                                jwmarker[jwmarker_num].id = J2K_MS_ESD; /* its type */\r
                                                jwmarker[jwmarker_num].esdmark = esd_mark; /* the EPB */\r
                                                /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */\r
-                                               jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
+                                               jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
                                                jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos + 0.2; /* not first at all! */\r
                                                jwmarker[jwmarker_num].len = esd_mark->Lesd; /* its length */\r
                                                jwmarker[jwmarker_num].len_ready = true; /* ready, yet */\r
@@ -458,7 +509,7 @@ void jpwl_prepare_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
                                                jwmarker[jwmarker_num].id = J2K_MS_EPB; /* its type */\r
                                                jwmarker[jwmarker_num].epbmark = epb_mark; /* the EPB */\r
                                                /****** jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].start_pos + sot_len + 2; */ /* after SOT */\r
-                                               jwmarker[jwmarker_num].pos = soc_pos + j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
+                                               jwmarker[jwmarker_num].pos = j2k->cstr_info->tile[tileno].tp[tpno].tp_start_pos + sot_len + 2; /* after SOT */\r
                                                jwmarker[jwmarker_num].dpos = (double) jwmarker[jwmarker_num].pos; /* first first first! */\r
                                                jwmarker[jwmarker_num].len = epb_mark->Lepb; /* its length */\r
                                                jwmarker[jwmarker_num].len_ready = true; /* ready */\r
@@ -647,23 +698,23 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
        /* Order JPWL markers according to their wishlist position */\r
        qsort((void *) jwmarker, (size_t) jwmarker_num, sizeof (jpwl_marker_t), jpwl_markcomp);\r
 \r
-       /* compute markers total size */\r
+       /* compute markers total size */ \r
        for (mm = 0; mm < jwmarker_num; mm++) {\r
                /*printf("%x, %d, %.10f, %d long\n", jwmarker[mm].id, jwmarker[mm].pos,\r
                        jwmarker[mm].dpos, jwmarker[mm].len);*/\r
                new_size += jwmarker[mm].len + 2;\r
        }\r
 \r
-       /* allocate a temporary buffer of proper size */\r
+       /* allocate a new buffer of proper size */\r
        if (!(jpwl_buf = (unsigned char *) opj_malloc((size_t) new_size * sizeof (unsigned char)))) {\r
-               opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL temp codestream buffer\n");\r
+               opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not allocate room for JPWL codestream buffer\n");\r
                exit(1);\r
        };\r
 \r
        /* copy the jp2 part, if any */\r
-       memcpy(jpwl_buf, cio->buffer, soc_pos);\r
-\r
        orig_buf = jpwl_buf;\r
+       memcpy(jpwl_buf, cio->buffer, soc_pos);\r
+       jpwl_buf += soc_pos;\r
 \r
        /* cycle through markers */\r
        orig_pos = soc_pos + 0; /* start from the beginning */\r
@@ -713,8 +764,8 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
        }\r
 \r
        /* finish remaining original codestream */\r
-       memcpy(jpwl_buf, cio_getbp(cio), soc_pos + old_size - orig_pos);\r
-       jpwl_buf += soc_pos + old_size - orig_pos;\r
+       memcpy(jpwl_buf, cio_getbp(cio), old_size - (orig_pos - soc_pos));\r
+       jpwl_buf += old_size - (orig_pos - soc_pos);\r
        cio_seek(cio, soc_pos + old_size);\r
        \r
        /*\r
@@ -814,7 +865,8 @@ void jpwl_dump_marks(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image) {
        opj_free(cio->buffer);\r
        /*cio->cinfo;*/ /* no change */\r
        /*cio->openmode;*/ /* no change */\r
-       cio->buffer = jpwl_buf - new_size - soc_pos;\r
+       /*cio->buffer = jpwl_buf - new_size - soc_pos;*/\r
+       cio->buffer = orig_buf;\r
        cio->length = new_size + soc_pos;\r
        cio->start = jpwl_buf - new_size - soc_pos;\r
        cio->end = jpwl_buf - 1;\r
index a18c148093e036b0b6d0337d545bf003c12660c4..65edce777f141cf5a2fa49b521d8006a6b30f33b 100644 (file)
@@ -205,6 +205,14 @@ typedef struct jpwl_marker {
        bool data_ready;
 }      jpwl_marker_t;
 
+/**
+Encode according to JPWL specs
+@param j2k J2K handle
+@param cio codestream handle
+@param image image handle
+*/
+void jpwl_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image);
+
 /**
 Prepare the list of JPWL markers, after the Part 1 codestream
 has been finalized (index struct is full)
@@ -227,6 +235,7 @@ Read the EPC marker (Error Protection Capability)
 @param j2k J2K handle
 */
 void j2k_read_epc(opj_j2k_t *j2k);
+
 /**
 Write the EPC marker (Error Protection Capability), BUT the DL field is always set to 0
 (this simplifies the management of EPBs and it is openly stated in the standard
@@ -235,21 +244,25 @@ are not yet implemented
 @param j2k J2K handle
 */
 void j2k_write_epc(opj_j2k_t *j2k);
+
 /**
 Read the EPB marker (Error Protection Block)
 @param j2k J2K handle
 */
 void j2k_read_epb(opj_j2k_t *j2k);
+
 /**
 Write the EPB marker (Error Protection Block)
 @param j2k J2K handle
 */
 void j2k_write_epb(opj_j2k_t *j2k);
+
 /**
 Read the ESD marker (Error Sensitivity Descriptor)
 @param j2k J2K handle
 */
 void j2k_read_esd(opj_j2k_t *j2k);
+
 /**
 Read the RED marker (Residual Error Descriptor)
 @param j2k J2K handle
index 727391eff2ad004720a0da2fc82a2593ca3c89ba..651ef215b2d90cd47d8b746f6bf5947c921a9017 100644 (file)
@@ -2454,20 +2454,12 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestre
 
 #ifdef USE_JPWL
        /*
-       preparation of JPWL marker segments: can be finalized only when the whole
-       codestream is known
+       preparation of JPWL marker segments
        */
        if(cp->epc_on) {
 
-               /* let's begin creating a marker list, according to user wishes */
-               jpwl_prepare_marks(j2k, cio, image);
-
-               /* now we dump the JPWL markers on the codestream */
-               jpwl_dump_marks(j2k, cio, image);
-
-               /* do not know exactly what is this for,
-               but it gets called during index creation */
-               j2k->pos_correction = 0;
+               /* encode according to JPWL */
+               jpwl_encode(j2k, cio, image);
 
        }
 #endif /* USE_JPWL */
index 7021bb540956307d8aefe72f702cb060ef41dfa3..876c0ab1229bdca70c2422aa246f2306f942500e 100644 (file)
@@ -644,6 +644,20 @@ typedef struct opj_tile_info {
        opj_tp_info_t *tp;
 } opj_tile_info_t;
 
+/* UniPG>> */
+/**
+Marker structure
+*/
+typedef struct opj_marker_info_t {
+       /** marker type */
+       unsigned short int type;
+       /** position in codestream */
+       int pos;
+       /** length, marker val included */
+       int len;
+} opj_marker_info_t;
+/* <<UniPG */
+
 /**
 Index structure of the codestream
 */
@@ -678,6 +692,12 @@ typedef struct opj_codestream_info {
        int numlayers;
        /** number of decomposition of first component */
        int numdecompos;
+/* UniPG>> */
+       /** number of markers */
+       int marknum;
+       /** list of markers */
+       opj_marker_info_t *marker;
+/* <<UniPG */
        /** main header position */
        int main_head_start;
        /** main header position */