From b65e3ebdb6b8a5f68e830799f89fc22f3f25d9a0 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Tue, 18 Nov 2014 00:07:50 +0000 Subject: [PATCH] [trunk] fixed a bug leading to jpwl build failure & add related odd width/height sYCC tests (fixes issue 422) --- src/bin/common/color.c | 86 +++++++++++-------------- tests/nonregression/md5refs.txt | 9 +++ tests/nonregression/test_suite.ctest.in | 4 ++ 3 files changed, 51 insertions(+), 48 deletions(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index afb244a5..598a080d 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -91,12 +91,13 @@ static void sycc444_to_rgb(opj_image_t *img) { int *d0, *d1, *d2, *r, *g, *b; const int *y, *cb, *cr; - int maxw, maxh, max, i, offset, upb; + unsigned int maxw, maxh, max, i; + int offset, upb; - i = (int)img->comps[0].prec; - offset = 1<<(i - 1); upb = (1<comps[0].prec; + offset = 1<<(upb - 1); upb = (1<comps[0].w; maxh = (int)img->comps[0].h; + maxw = (unsigned int)img->comps[0].w; maxh = (unsigned int)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; @@ -107,12 +108,11 @@ static void sycc444_to_rgb(opj_image_t *img) d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max); - for(i = 0; i < max; ++i) - { - sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); - - ++y; ++cb; ++cr; ++r; ++g; ++b; - } + for(i = 0U; i < max; ++i) + { + sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); + ++y; ++cb; ++cr; ++r; ++g; ++b; + } free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; @@ -123,13 +123,14 @@ static void sycc422_to_rgb(opj_image_t *img) { int *d0, *d1, *d2, *r, *g, *b; const int *y, *cb, *cr; - int maxw, maxh, max, offset, upb; - int i, j; + unsigned int maxw, maxh, max; + int offset, upb; + unsigned int i, j; - i = (int)img->comps[0].prec; - offset = 1<<(i - 1); upb = (1<comps[0].prec; + offset = 1<<(upb - 1); upb = (1<comps[0].w; maxh = (int)img->comps[0].h; + maxw = (unsigned int)img->comps[0].w; maxh = (unsigned int)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; @@ -140,16 +141,13 @@ static void sycc422_to_rgb(opj_image_t *img) d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max); - for(i=0; i < maxh; ++i) + for(i=0U; i < maxh; ++i) { - for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2) + for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); - ++y; ++r; ++g; ++b; - sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); - ++y; ++r; ++g; ++b; ++cb; ++cr; } if (j < maxw) { @@ -179,13 +177,14 @@ static void sycc420_to_rgb(opj_image_t *img) { int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb; const int *y, *cb, *cr, *ny; - int maxw, maxh, max, offset, upb; - int i, j; + unsigned int maxw, maxh, max; + int offset, upb; + unsigned int i, j; - i = (int)img->comps[0].prec; - offset = 1<<(i - 1); upb = (1<comps[0].prec; + offset = 1<<(upb - 1); upb = (1<comps[0].w; maxh = (int)img->comps[0].h; + maxw = (unsigned int)img->comps[0].w; maxh = (unsigned int)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; @@ -196,44 +195,36 @@ static void sycc420_to_rgb(opj_image_t *img) d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max); - for(i=0; (OPJ_UINT32)i < (maxh & ~(OPJ_UINT32)1); i += 2) + for(i=0U; i < (maxh & ~(unsigned int)1U); i += 2U) { ny = y + maxw; nr = r + maxw; ng = g + maxw; nb = b + maxw; - for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2) + for(j=0; j < (maxw & ~(unsigned int)1U); j += 2U) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); - ++y; ++r; ++g; ++b; - sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); - ++y; ++r; ++g; ++b; sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); - ++ny; ++nr; ++ng; ++nb; - sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); - ++ny; ++nr; ++ng; ++nb; ++cb; ++cr; } if(j < maxw) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); - ++y; ++r; ++g; ++b; sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); - ++ny; ++nr; ++ng; ++nb; ++cb; ++cr; } y += maxw; r += maxw; g += maxw; b += maxw; } if(i < maxh) - { - for(j=0; (OPJ_UINT32)j < (maxw & ~(OPJ_UINT32)1); j += 2) + { + for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); @@ -269,11 +260,11 @@ static void sycc420_to_rgb(opj_image_t *img) void color_sycc_to_rgb(opj_image_t *img) { - if(img->numcomps < 3) - { - img->color_space = OPJ_CLRSPC_GRAY; - return; - } + if(img->numcomps < 3) + { + img->color_space = OPJ_CLRSPC_GRAY; + return; + } if((img->comps[0].dx == 1) && (img->comps[1].dx == 2) @@ -282,7 +273,7 @@ void color_sycc_to_rgb(opj_image_t *img) && (img->comps[1].dy == 2) && (img->comps[2].dy == 2))/* horizontal and vertical sub-sample */ { - sycc420_to_rgb(img); + sycc420_to_rgb(img); } else if((img->comps[0].dx == 1) @@ -292,7 +283,7 @@ void color_sycc_to_rgb(opj_image_t *img) && (img->comps[1].dy == 1) && (img->comps[2].dy == 1))/* horizontal sub-sample only */ { - sycc422_to_rgb(img); + sycc422_to_rgb(img); } else if((img->comps[0].dx == 1) @@ -302,13 +293,12 @@ void color_sycc_to_rgb(opj_image_t *img) && (img->comps[1].dy == 1) && (img->comps[2].dy == 1))/* no sub-sample */ { - sycc444_to_rgb(img); + sycc444_to_rgb(img); } else { - fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", - __FILE__,__LINE__); - return; + fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__); + return; } img->color_space = OPJ_CLRSPC_SRGB; diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 14a6b9c9..3e4dc8b4 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -163,3 +163,12 @@ a73bec4d6d82c8a64203e8fdf893b86d issue428.jp2_0.pgx ec6886229ffaeaddfe22ce02b7a75e15 issue414.jp2_3.pgx 6aa5c69c83d6f4d5d65968f34f9bc2a3 issue414.jp2_4.pgx 00f34217ad2f88f4d4e1c5cd0d2c4329 issue399.j2k_0.pgx +d8fb69def2a48a3686483c4353544f4b issue411-ycc444.jp2_0.pgx +d2911f75ed1758057f9b1bf26bcb2400 issue411-ycc444.jp2_1.pgx +f7c23ee589ceda07ffb77a83018606cc issue411-ycc444.jp2_2.pgx +7e5e5546ae7ab4e9257ec30185ff9155 issue411-ycc422.jp2_0.pgx +d5ecef537edf294af83826763c0cf860 issue411-ycc422.jp2_1.pgx +3a8d91d7cf3e8887dd0d29beac030620 issue411-ycc422.jp2_2.pgx +07480962d25b3d8cce18096648963c8a issue411-ycc420.jp2_0.pgx +149a69831b42401f20b8f7492ef99d97 issue411-ycc420.jp2_1.pgx +ec8d1c99db9763a8ba489df4f41dda53 issue411-ycc420.jp2_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 1e660520..c580cf95 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -219,6 +219,10 @@ opj_decompress -i @INPUT_NR_PATH@/issue414.jp2 -o @TEMP_PATH@/issue414.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/issue418.jp2 -o @TEMP_PATH@/issue418.jp2.pgx # issue 420 (from pdfium fuzz engine) Illegal custom precinct exponent. !opj_decompress -i @INPUT_NR_PATH@/issue420.jp2 -o @TEMP_PATH@/issue420.jp2.pgx +# issue 422 (rework of issue 411). ycc with odd width/height +opj_decompress -i @INPUT_NR_PATH@/issue411-ycc444.jp2 -o @TEMP_PATH@/issue411-ycc444.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/issue411-ycc422.jp2 -o @TEMP_PATH@/issue411-ycc422.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/issue411-ycc420.jp2 -o @TEMP_PATH@/issue411-ycc420.jp2.pgx # decode with specific area # prec=12; nb_c=1