Add option to force component splitting in imagetopnm 531/head
authormayeut <mayeut@users.noreply.github.com>
Sat, 11 Jul 2015 09:35:21 +0000 (11:35 +0200)
committermayeut <mayeut@users.noreply.github.com>
Sat, 11 Jul 2015 09:35:21 +0000 (11:35 +0200)
Update uclouvain/openjpeg#289

src/bin/jp2/convert.c
src/bin/jp2/convert.h
src/bin/jp2/opj_decompress.c
src/lib/openjp2/j2k.c
tests/conformance/CMakeLists.txt

index 92e043b6d0aed7f71d266e65c084c74cdaf48252..5cde4fbd33a1001c31e173f8cde5e70041adcc6b 100644 (file)
@@ -1350,7 +1350,7 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
     return image;
 }/* pnmtoimage() */
 
-int imagetopnm(opj_image_t * image, const char *outfile
+int imagetopnm(opj_image_t * image, const char *outfile, int force_split)
 {
     int *red, *green, *blue, *alpha;
     int wr, hr, max;
@@ -1380,7 +1380,8 @@ int imagetopnm(opj_image_t * image, const char *outfile)
 
     if(want_gray) ncomp = 1;
 
-    if (ncomp == 2 /* GRAYA */
+    if ((force_split == 0) &&
+                               (ncomp == 2 /* GRAYA */
             || (ncomp > 2 /* RGB, RGBA */
                 && image->comps[0].dx == image->comps[1].dx
                 && image->comps[1].dx == image->comps[2].dx
@@ -1388,8 +1389,8 @@ int imagetopnm(opj_image_t * image, const char *outfile)
                 && image->comps[1].dy == image->comps[2].dy
                 && image->comps[0].prec == image->comps[1].prec
                 && image->comps[1].prec == image->comps[2].prec
-                ))
-    {
+                )))
+               {
         fdest = fopen(outfile, "wb");
 
         if (!fdest)
index d375e86bfc134df7f517975195883c34b6195dcf..51018c0b3bbfa1d86d390c995b7feb782fa9eba2 100644 (file)
@@ -91,7 +91,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters);
 int imagetopgx(opj_image_t *image, const char *outfile);
 
 opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters);
-int imagetopnm(opj_image_t *image, const char *outfile);
+int imagetopnm(opj_image_t *image, const char *outfile, int force_split);
 
 /* RAW conversion */
 int imagetoraw(opj_image_t * image, const char *outfile);
index c6e5cff8d22fe4c60bff42ee8bc562cfc99af829..7479097bd8a730f79de3bbc3f313d2b489ca805a 100644 (file)
@@ -145,6 +145,8 @@ typedef struct opj_decompress_params
        int force_rgb;
        /* upsample components according to their dx/dy values */
        int upsample;
+       /* split output components to different files */
+       int split_pnm;
 }opj_decompress_parameters;
 
 /* -------------------------------------------------------------------------- */
@@ -218,6 +220,8 @@ static void decode_help_display(void) {
                       "    Force output image colorspace to RGB\n"
                       "  -upsample\n"
                       "    Downsampled components will be upsampled to image size\n"
+                      "  -split-pnm\n"
+                      "    Split output components to different files when writing to PNM\n"
                       "\n");
 /* UniPG>> */
 #ifdef USE_JPWL
@@ -506,7 +510,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
                {"ImgDir",    REQ_ARG, NULL ,'y'},
                {"OutFor",    REQ_ARG, NULL ,'O'},
                {"force-rgb", NO_ARG,  &(parameters->force_rgb), 1},
-               {"upsample",  NO_ARG,  &(parameters->upsample),  1}
+               {"upsample",  NO_ARG,  &(parameters->upsample),  1},
+               {"split-pnm", NO_ARG,  &(parameters->split_pnm), 1}
        };
 
        const char optlist[] = "i:o:r:l:x:d:t:p:"
@@ -1433,7 +1438,7 @@ int main(int argc, char **argv)
                /* ------------------- */
                switch (parameters.cod_format) {
                case PXM_DFMT:                  /* PNM PGM PPM */
-                       if (imagetopnm(image, parameters.outfile)) {
+                       if (imagetopnm(image, parameters.outfile, parameters.split_pnm)) {
                 fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
         failed = 1;
                        }
index 6730154704924bb2068f89544699e42721f25a24..5892d579c0f9e785e176e2f0376544374f0700aa 100644 (file)
@@ -2031,14 +2031,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
         }
 
         /* testcase issue427-illegal-tile-offset.jp2 */
-        l_tx1 = l_cp->tx0 + l_cp->tdx;
-        if (l_tx1 < l_cp->tx0) { /* manage overflow */
-                l_tx1 = 0xFFFFFFFFU;
-        }
-        l_ty1 = l_cp->ty0 + l_cp->tdy;
-        if (l_ty1 < l_cp->ty0) { /* manage overflow */
-                l_ty1 = 0xFFFFFFFFU;
-        }
+        l_tx1 = opj_uint_adds(l_cp->tx0, l_cp->tdx); /* manage overflow */
+        l_ty1 = opj_uint_adds(l_cp->ty0, l_cp->tdy); /* manage overflow */
         if ((l_cp->tx0 > l_image->x0) || (l_cp->ty0 > l_image->y0) || (l_tx1 <= l_image->x0) || (l_ty1 <= l_image->y0) ) {
                 opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: illegal tile offset\n");
                 return OPJ_FALSE;
index c4d1bb6636169c994dbd8934c84b2d8f3ac95499..3a07dbc494e02f09a4a5fd9adafc2bf809c22140 100644 (file)
@@ -510,11 +510,17 @@ foreach(kdu_file ${kdu_j2k_conf_files})
   set( filenameInput "${kdu_file}.j2c" )
   set( filenameRef   "${kdu_file}.ppm" )
 
+       if("${kdu_file}" STREQUAL "a6_mono_colr")
+    set(kdu_test_args -upsample -split-pnm )
+  else()
+    set(kdu_test_args -upsample )
+  endif()
+
   add_test(NAME ETS-KDU-${filenameInput}-decode
     COMMAND opj_decompress
     -i ${INPUT_CONF}/${filenameInput}
     -o ${TEMP}/${filenameInput}.ppm
-    -upsample
+    ${kdu_test_args}
   )
 
   if("${kdu_file}" STREQUAL "a6_mono_colr")