]> granicus.if.org Git - openjpeg/commitdiff
Fixed save capabilities in OPJViewer due to recent code upgrade
authorGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Fri, 31 Aug 2007 10:55:15 +0000 (10:55 +0000)
committerGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Fri, 31 Aug 2007 10:55:15 +0000 (10:55 +0000)
ChangeLog
OPJViewer/OPJViewer.dsp
OPJViewer/source/build.h
OPJViewer/source/imagj2k.cpp
OPJViewer/source/imagj2k.h

index 111a60e79b7ef057f6c3388245860a7e914a321b..98275da3af826acfc31870b2d51326403cbad864 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+August 31, 2007
+* [GB] Fixed save capabilities in OPJViewer due to recent code upgrade
+
 August 30, 2007
 * [FOD] Changed the OpenJPEG library interface to enable users to access information regarding the codestream (also called codestream index).
                This index is usefull for all applications requiring to have a scalable acces to the codestream (like JPIP applications, ...)
index 899127698b8f51cde5b2ba8c6b7295cb25c87c72..c7f33354c104f79b37f8fbf9c41373a8485b11b3 100644 (file)
@@ -42,15 +42,15 @@ 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 /G6 /MD /W3 /GX /O2 /I "c:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "c:\programmi\wxWidgets-2.8.0\include" /I ".." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c\r
+# ADD CPP /nologo /G6 /MD /W3 /GX /O2 /I "d:\programmi\wxWidgets-2.8.0\lib\vc_lib\msw" /I "d:\programmi\wxWidgets-2.8.0\include" /I ".." /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_WINDOWS" /D WINVER=0x400 /D "_MT" /D wxUSE_GUI=1 /D "wxUSE_LIBOPENJPEG" /D "OPJ_STATIC" /D "USE_JPWL" /D "OPJ_HTMLABOUT" /D "OPJ_MANYFORMATS" /D "OPJ_INICONFIG" /FR /FD /c\r
 # ADD BASE RSC /l 0x410 /d "NDEBUG"\r
-# ADD RSC /l 0x409 /i "c:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG"\r
+# ADD RSC /l 0x409 /i "d:\programmi\wxWidgets-2.8.0\include" /d "NDEBUG"\r
 BSC32=bscmake.exe\r
 # ADD BASE BSC32 /nologo\r
 # ADD BSC32 /nologo\r
 LINK32=link.exe\r
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib wxzlib.lib wxregex.lib wxpng.lib wxjpeg.lib wxbase28.lib wxmsw28_core.lib wxmsw28_html.lib wxmsw28_adv.lib wxmsw28_core.lib wxbase28.lib wxtiff.lib wxjpeg.lib wxpng.lib wxzlib.lib wxregex.lib wxexpat.lib LibOpenJPEG_JPWL.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libcmt.lib" /libpath:"c:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Release" /IGNORE:4089\r
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib rpcrt4.lib wsock32.lib wxzlib.lib wxregex.lib wxpng.lib wxjpeg.lib wxbase28.lib wxmsw28_core.lib wxmsw28_html.lib wxmsw28_adv.lib wxmsw28_core.lib wxbase28.lib wxtiff.lib wxjpeg.lib wxpng.lib wxzlib.lib wxregex.lib wxexpat.lib LibOpenJPEG_JPWL.lib /nologo /subsystem:windows /machine:I386 /nodefaultlib:"libcmt.lib" /libpath:"d:\programmi\wxWidgets-2.8.0\lib\vc_lib" /libpath:"..\jpwl\Release" /IGNORE:4089\r
 # SUBTRACT LINK32 /pdb:none\r
 # Begin Special Build Tool\r
 SOURCE="$(InputPath)"\r
index fce4f83bfc08f8ee2a2c2653fdfaa817b97f2857..cfbcdd1dda90433214eb39486d167116e24c4717 100644 (file)
@@ -1 +1 @@
-wxT("200") \r
+wxT("204") \r
index 6dc57fac0ace84c11beb2114063e4fc7b5bff134..64c051fff75f939aed3b00cf077e3bead2087180 100644 (file)
@@ -238,6 +238,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
        opj_image_t *oimage = NULL;\r
        opj_image_cmptparm_t *cmptparm; \r
        opj_cio_t *cio = NULL;\r
+       opj_codestream_info_t cstr_info;\r
        int codestream_length;\r
        bool bSuccess;\r
        int i;\r
@@ -255,6 +256,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
        opj_set_default_encoder_parameters(&parameters);\r
 \r
        /* load parameters */\r
+       parameters.cp_cinema = OFF;\r
 \r
        /* subsampling */\r
        if (sscanf(m_subsampling.c_str(), wxT("%d,%d"), &(parameters.subsampling_dx), &(parameters.subsampling_dy)) != 2) {\r
@@ -442,7 +444,7 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
        cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);\r
 \r
        /* encode the image */\r
-       bSuccess = opj_encode(cinfo, cio, oimage, parameters.index);\r
+       bSuccess = opj_encode(cinfo, cio, oimage, &cstr_info);\r
        if (!bSuccess) {\r
 \r
                opj_cio_close(cio);\r
@@ -476,6 +478,14 @@ bool wxJ2KHandler::SaveFile( wxImage *wimage, wxOutputStream& stream, bool verbo
        /* close and free the byte stream */\r
        opj_cio_close(cio);\r
 \r
+       /* Write the index to disk */\r
+       if (parameters.index_on) {\r
+               bSuccess = write_index_file(&cstr_info, parameters.index);\r
+               if (bSuccess) {\r
+                       wxLogError(wxT("Failed to output index file"));\r
+               }\r
+       }\r
+\r
        /* free remaining compression structures */\r
        opj_destroy_compress(cinfo);\r
 \r
@@ -517,6 +527,236 @@ bool wxJ2KHandler::DoCanRead( wxInputStream& stream )
     return hdr[0] == 0xFF && hdr[1] == 0x4F;\r
 }\r
 \r
+/**\r
+Create an index and write it to a file\r
+@param cstr_info Codestream information \r
+@param index Index filename\r
+@return Returns 0 if successful, returns 1 otherwise\r
+*/\r
+bool wxJ2KHandler::write_index_file(opj_codestream_info_t *cstr_info, char *index) {\r
+       int tileno, compno, layno, resno, precno, pack_nb, x, y;\r
+       FILE *stream = NULL;\r
+       double total_disto = 0;\r
+\r
+       if (!cstr_info)         \r
+               return false;\r
+\r
+       stream = fopen(index, "w");\r
+       if (!stream) {\r
+               wxLogError(wxT("failed to open index file [%s] for writing"), index);\r
+               return false;\r
+       }\r
+       \r
+       fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);\r
+       fprintf(stream, "%d\n", cstr_info->prog);\r
+       fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);\r
+       fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);\r
+       fprintf(stream, "%d\n", cstr_info->comp);\r
+       fprintf(stream, "%d\n", cstr_info->layer);\r
+       fprintf(stream, "%d\n", cstr_info->decomposition);\r
+       \r
+       for (resno = cstr_info->decomposition; resno >= 0; resno--) {\r
+               fprintf(stream, "[%d,%d] ", \r
+                       (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno]));    /* based on tile 0 */\r
+       }\r
+       fprintf(stream, "\n");\r
+       fprintf(stream, "%d\n", cstr_info->main_head_end);\r
+       fprintf(stream, "%d\n", cstr_info->codestream_size);\r
+       \r
+       fprintf(stream, "\nINFO ON TILES\n");\r
+       fprintf(stream, "tileno start_pos  end_hd  end_tile         disto     nbpix   disto/nbpix\n");\r
+       for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {\r
+               fprintf(stream, "%4d %9d %9d %9d %9e %9d %9e\n",\r
+                       cstr_info->tile[tileno].num_tile,\r
+                       cstr_info->tile[tileno].start_pos,\r
+                       cstr_info->tile[tileno].end_header,\r
+                       cstr_info->tile[tileno].end_pos,\r
+                       cstr_info->tile[tileno].distotile, cstr_info->tile[tileno].nbpix,\r
+                       cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].nbpix);\r
+       }\r
+               \r
+       for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {\r
+               int start_pos, end_ph_pos, end_pos;\r
+               double disto = 0;\r
+               pack_nb = 0;\r
+\r
+               fprintf(stream, "\nTILE %d DETAILS\n", tileno);                         \r
+               if (cstr_info->prog == LRCP) {  /* LRCP */\r
+\r
+                       fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos disto\n");\r
+\r
+                       for (layno = 0; layno < cstr_info->layer; layno++) {\r
+                               for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {\r
+                                       for (compno = 0; compno < cstr_info->comp; compno++) {\r
+                                               int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                               for (precno = 0; precno < prec_max; precno++) {\r
+                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                       fprintf(stream, "%4d %6d %7d %5d %6d  %6d    %6d     %6d %7d %8e\n",\r
+                                                               pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos, disto);\r
+                                                       total_disto += disto;\r
+                                                       pack_nb++;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               } /* LRCP */\r
+               else if (cstr_info->prog == RLCP) {     /* RLCP */\r
+\r
+                       fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos disto\n");\r
+\r
+                       for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {\r
+                               for (layno = 0; layno < cstr_info->layer; layno++) {\r
+                                       for (compno = 0; compno < cstr_info->comp; compno++) {\r
+                                               int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                               for (precno = 0; precno < prec_max; precno++) {\r
+                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                       fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d   %9d %7d %8e\n",\r
+                                                               pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos, disto);\r
+                                                       total_disto += disto;\r
+                                                       pack_nb++;\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               } /* RLCP */\r
+               else if (cstr_info->prog == RPCL) {     /* RPCL */\r
+\r
+                       fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos disto\n"); \r
+\r
+                       for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {\r
+                               /* I suppose components have same XRsiz, YRsiz */\r
+                               int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;\r
+                               int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;\r
+                               int x1 = x0 + cstr_info->tile_x;\r
+                               int y1 = y0 + cstr_info->tile_y;\r
+                               for (compno = 0; compno < cstr_info->comp; compno++) {\r
+                                       int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                       for (precno = 0; precno < prec_max; precno++) {\r
+                                               int pcnx = cstr_info->tile[tileno].pw[resno];\r
+                                               int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno );\r
+                                               int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno );\r
+                                               int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;\r
+                                               int precno_y = (int) floor( (float)precno/(float)pcnx );\r
+                                               for(y = y0; y < y1; y++) {                                                      \r
+                                                       if (precno_y*pcy == y ) {\r
+                                                               for (x = x0; x < x1; x++) {                                                                     \r
+                                                                       if (precno_x*pcx == x ) {\r
+                                                                               for (layno = 0; layno < cstr_info->layer; layno++) {\r
+                                                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                                                       fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d   %9d %7d %8e\n",\r
+                                                                                               pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos, disto); \r
+                                                                                       total_disto += disto;\r
+                                                                                       pack_nb++; \r
+                                                                               }\r
+                                                                       }\r
+                                                               }/* x = x0..x1 */\r
+                                                       } \r
+                                               }  /* y = y0..y1 */\r
+                                       } /* precno */\r
+                               } /* compno */\r
+                       } /* resno */\r
+               } /* RPCL */\r
+               else if (cstr_info->prog == PCRL) {     /* PCRL */\r
+                       /* I suppose components have same XRsiz, YRsiz */\r
+                       int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;\r
+                       int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;\r
+                       int x1 = x0 + cstr_info->tile_x;\r
+                       int y1 = y0 + cstr_info->tile_y;\r
+\r
+                       fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos disto\n"); \r
+\r
+                       for (compno = 0; compno < cstr_info->comp; compno++) {\r
+                               for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {\r
+                                       int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                       for (precno = 0; precno < prec_max; precno++) {\r
+                                               int pcnx = cstr_info->tile[tileno].pw[resno];\r
+                                               int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno );\r
+                                               int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno );\r
+                                               int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;\r
+                                               int precno_y = (int) floor( (float)precno/(float)pcnx );\r
+                                               for(y = y0; y < y1; y++) {                                                      \r
+                                                       if (precno_y*pcy == y ) {\r
+                                                               for (x = x0; x < x1; x++) {                                                                     \r
+                                                                       if (precno_x*pcx == x ) {\r
+                                                                               for (layno = 0; layno < cstr_info->layer; layno++) {\r
+                                                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                                                       fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d   %9d %7d %8e\n",\r
+                                                                                               pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos, disto); \r
+                                                                                       total_disto += disto;\r
+                                                                                       pack_nb++; \r
+                                                                               }\r
+                                                                       }\r
+                                                               }/* x = x0..x1 */\r
+                                                       } \r
+                                               }  /* y = y0..y1 */\r
+                                       } /* precno */\r
+                               } /* resno */\r
+                       } /* compno */\r
+               } /* PCRL */\r
+               else {  /* CPRL */\r
+\r
+                       fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos disto\n"); \r
+\r
+                       for (compno = 0; compno < cstr_info->comp; compno++) {\r
+                               /* I suppose components have same XRsiz, YRsiz */\r
+                               int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;\r
+                               int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;\r
+                               int x1 = x0 + cstr_info->tile_x;\r
+                               int y1 = y0 + cstr_info->tile_y;\r
+                               \r
+                               for (resno = 0; resno < cstr_info->decomposition + 1; resno++) {\r
+                                       int prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];\r
+                                       for (precno = 0; precno < prec_max; precno++) {\r
+                                               int pcnx = cstr_info->tile[tileno].pw[resno];\r
+                                               int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->decomposition - resno );\r
+                                               int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->decomposition - resno );\r
+                                               int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;\r
+                                               int precno_y = (int) floor( (float)precno/(float)pcnx );\r
+                                               for(y = y0; y < y1; y++) {\r
+                                                       if (precno_y*pcy == y ) {\r
+                                                               for (x = x0; x < x1; x++) {\r
+                                                                       if (precno_x*pcx == x ) {\r
+                                                                               for (layno = 0; layno < cstr_info->layer; layno++) {\r
+                                                                                       start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;\r
+                                                                                       end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;\r
+                                                                                       end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;\r
+                                                                                       disto = cstr_info->tile[tileno].packet[pack_nb].disto;\r
+                                                                                       fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d   %9d %7d %8e\n",\r
+                                                                                               pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos, disto); \r
+                                                                                       total_disto += disto;\r
+                                                                                       pack_nb++; \r
+                                                                               }\r
+                                                                       }\r
+                                                               }/* x = x0..x1 */\r
+                                                       }\r
+                                               } /* y = y0..y1 */\r
+                                       } /* precno */\r
+                               } /* resno */\r
+                       } /* compno */\r
+               } /* CPRL */   \r
+       } /* tileno */\r
+       \r
+       fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */\r
+       fprintf(stream, "%.8e\n", total_disto); /* SE totale */\r
+       fclose(stream);\r
+\r
+       wxLogError(wxT("Generated index file %s"), index);\r
+\r
+       return true;\r
+}\r
+\r
 #endif   // wxUSE_STREAMS\r
 \r
 #endif   // wxUSE_LIBOPENJPEG\r
index 9b6f63a91b41e511c0e282ce494cf1db0937a136..898eeaf3e6574f7d29eaa732d1d6561f1f4895dd 100644 (file)
@@ -145,6 +145,8 @@ public:
        bool m_enablecomm;\r
        wxString m_comment;\r
 \r
+       bool write_index_file(opj_codestream_info_t *cstr_info, char *index);\r
+\r
 #if wxUSE_STREAMS\r
     virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );\r
     virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );\r