diff options
| author | mayeut <mayeut@users.noreply.github.com> | 2015-09-08 22:33:07 +0200 |
|---|---|---|
| committer | mayeut <mayeut@users.noreply.github.com> | 2015-09-08 22:33:07 +0200 |
| commit | 66d890bf225a4edc49658803b4aa6a65031479e4 (patch) | |
| tree | a52c7bb60ab709ff4e7deff1e1b159bea5ddec30 /src/bin | |
| parent | 0a4ac0852afe7a43e52c48dc33bae126171f5f1e (diff) | |
| parent | e71247bb90085155559fafaf088d4e573add7156 (diff) | |
Merge remote-tracking branch 'uclouvain/master' into coc-qcc
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/common/color.c | 295 | ||||
| -rw-r--r-- | src/bin/common/color.h | 3 | ||||
| -rw-r--r-- | src/bin/jp2/convertbmp.c | 148 | ||||
| -rw-r--r-- | src/bin/jp2/converttif.c | 14 | ||||
| -rw-r--r-- | src/bin/jp2/opj_decompress.c | 19 | ||||
| -rw-r--r-- | src/bin/jpwl/convert.c | 4 | ||||
| -rw-r--r-- | src/bin/wx/OPJViewer/source/OPJThreads.cpp | 2 |
7 files changed, 368 insertions, 117 deletions
diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 598a080d..98a4cec8 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -305,6 +305,7 @@ void color_sycc_to_rgb(opj_image_t *img) }/* color_sycc_to_rgb() */ #if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1) + #ifdef OPJ_HAVE_LIBLCMS1 /* Bob Friesenhahn proposed:*/ #define cmsSigXYZData icSigXYZData @@ -354,16 +355,16 @@ void color_apply_icc_profile(opj_image_t *image) if(out_space == cmsSigRgbData) /* enumCS 16 */ { - if( prec <= 8 ) -{ + if( prec <= 8 ) + { in_type = TYPE_RGB_8; out_type = TYPE_RGB_8; -} -else -{ + } + else + { in_type = TYPE_RGB_16; out_type = TYPE_RGB_16; -} + } out_prof = cmsCreate_sRGBProfile(); image->color_space = OPJ_CLRSPC_SRGB; } @@ -389,8 +390,8 @@ else fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown " "output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n", __FILE__,__LINE__,out_space, -(out_space>>24) & 0xff,(out_space>>16) & 0xff, -(out_space>>8) & 0xff, out_space & 0xff); + (out_space>>24) & 0xff,(out_space>>16) & 0xff, + (out_space>>8) & 0xff, out_space & 0xff); #endif return; } @@ -398,21 +399,21 @@ __FILE__,__LINE__,out_space, #ifdef DEBUG_PROFILE fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)" "\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec, -max_w,max_h, (void*)in_prof,(void*)out_prof); + max_w,max_h, (void*)in_prof,(void*)out_prof); fprintf(stderr,"\trender_intent (%u)\n\t" "color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t" " type: in(%u) out:(%u)\n", -intent, -in_space, -(in_space>>24) & 0xff,(in_space>>16) & 0xff, -(in_space>>8) & 0xff, in_space & 0xff, + intent, + in_space, + (in_space>>24) & 0xff,(in_space>>16) & 0xff, + (in_space>>8) & 0xff, in_space & 0xff, -out_space, -(out_space>>24) & 0xff,(out_space>>16) & 0xff, -(out_space>>8) & 0xff, out_space & 0xff, + out_space, + (out_space>>24) & 0xff,(out_space>>16) & 0xff, + (out_space>>8) & 0xff, out_space & 0xff, -in_type,out_type + in_type,out_type ); #else (void)prec; @@ -444,11 +445,11 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " if(image->numcomps > 2)/* RGB, RGBA */ { - if( prec <= 8 ) -{ + if( prec <= 8 ) + { unsigned char *inbuf, *outbuf, *in, *out; max = max_w * max_h; - nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char); + nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char); in = inbuf = (unsigned char*)malloc(nr_samples); out = outbuf = (unsigned char*)malloc(nr_samples); @@ -457,11 +458,11 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " b = image->comps[2].data; for(i = 0; i < max; ++i) - { + { *in++ = (unsigned char)*r++; *in++ = (unsigned char)*g++; *in++ = (unsigned char)*b++; - } + } cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); @@ -470,18 +471,18 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " b = image->comps[2].data; for(i = 0; i < max; ++i) - { + { *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } + } free(inbuf); free(outbuf); -} -else -{ + } + else + { unsigned short *inbuf, *outbuf, *in, *out; max = max_w * max_h; - nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short); + nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short); in = inbuf = (unsigned short*)malloc(nr_samples); out = outbuf = (unsigned short*)malloc(nr_samples); @@ -490,11 +491,11 @@ else b = image->comps[2].data; for(i = 0; i < max; ++i) - { + { *in++ = (unsigned short)*r++; *in++ = (unsigned short)*g++; *in++ = (unsigned short)*b++; - } + } cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); @@ -503,19 +504,19 @@ else b = image->comps[2].data; for(i = 0; i < max; ++i) - { + { *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } + } free(inbuf); free(outbuf); -} + } } else /* GRAY, GRAYA */ { unsigned char *in, *inbuf, *out, *outbuf; - max = max_w * max_h; - nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char); + max = max_w * max_h; + nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char); in = inbuf = (unsigned char*)malloc(nr_samples); out = outbuf = (unsigned char*)malloc(nr_samples); @@ -561,5 +562,227 @@ else #endif }/* color_apply_icc_profile() */ -#endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */ +void color_apply_conversion(opj_image_t *image) +{ + int *row; + int enumcs, numcomps; + + image->color_space = OPJ_CLRSPC_SRGB; + + numcomps = (int)image->numcomps; + + if(numcomps != 3) + { + fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n", + __FILE__,__LINE__,numcomps); + return; + } + + row = (int*)image->icc_profile_buf; + enumcs = row[0]; + + if(enumcs == 14)// CIELab + { + int *L, *a, *b, *red, *green, *blue; + int *src0, *src1, *src2, *dst0, *dst1, *dst2; + double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; + double minL, maxL, mina, maxa, minb, maxb; + unsigned int default_type; + unsigned int i, max; + cmsHPROFILE in, out; + cmsHTRANSFORM transform; + cmsUInt16Number RGB[3]; + cmsCIELab Lab; + + in = cmsCreateLab4Profile(NULL); + out = cmsCreate_sRGBProfile(); + + transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, INTENT_PERCEPTUAL, 0); + +#ifdef HAVE_LIBLCMS2 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + if(transform == NULL) + { +#ifdef HAVE_LIBLCMS1 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + return; + } + prec0 = (double)image->comps[0].prec; + prec1 = (double)image->comps[1].prec; + prec2 = (double)image->comps[2].prec; + + default_type = (unsigned int)row[1]; + + if(default_type == 0x44454600)// DEF : default + { + rl = 100; ra = 170; rb = 200; + ol = 0; + oa = pow(2, prec1 - 1); + ob = pow(2, prec2 - 2) + pow(2, prec2 - 3); + } + else + { + rl = row[2]; ra = row[4]; rb = row[6]; + ol = row[3]; oa = row[5]; ob = row[7]; + } + + L = src0 = image->comps[0].data; + a = src1 = image->comps[1].data; + b = src2 = image->comps[2].data; + + max = image->comps[0].w * image->comps[0].h; + + red = dst0 = (int*)malloc(max * sizeof(int)); + green = dst1 = (int*)malloc(max * sizeof(int)); + blue = dst2 = (int*)malloc(max * sizeof(int)); + + minL = -(rl * ol)/(pow(2, prec0)-1); + maxL = minL + rl; + + mina = -(ra * oa)/(pow(2, prec1)-1); + maxa = mina + ra; + + minb = -(rb * ob)/(pow(2, prec2)-1); + maxb = minb + rb; + + for(i = 0; i < max; ++i) + { + Lab.L = minL + (double)(*L) * (maxL - minL)/(pow(2, prec0)-1); ++L; + Lab.a = mina + (double)(*a) * (maxa - mina)/(pow(2, prec1)-1); ++a; + Lab.b = minb + (double)(*b) * (maxb - minb)/(pow(2, prec2)-1); ++b; + + cmsDoTransform(transform, &Lab, RGB, 1); + + *red++ = RGB[0]; + *green++ = RGB[1]; + *blue++ = RGB[2]; + } + cmsDeleteTransform(transform); +#ifdef HAVE_LIBLCMS1 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + free(src0); image->comps[0].data = dst0; + free(src1); image->comps[1].data = dst1; + free(src2); image->comps[2].data = dst2; + + image->color_space = OPJ_CLRSPC_SRGB; + image->comps[0].prec = 16; + image->comps[1].prec = 16; + image->comps[2].prec = 16; + + return; + } + + fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n", __FILE__,__LINE__, enumcs); +}// color_apply_conversion() + +#endif // HAVE_LIBLCMS2 || HAVE_LIBLCMS1 + +void color_cmyk_to_rgb(opj_image_t *image) +{ + float C, M, Y, K; + float sC, sM, sY, sK; + unsigned int w, h, max, i; + + w = image->comps[0].w; + h = image->comps[0].h; + + if(image->numcomps < 4) return; + + max = w * h; + + sC = 1.0F / (float)((1 << image->comps[0].prec) - 1); + sM = 1.0F / (float)((1 << image->comps[1].prec) - 1); + sY = 1.0F / (float)((1 << image->comps[2].prec) - 1); + sK = 1.0F / (float)((1 << image->comps[3].prec) - 1); + + for(i = 0; i < max; ++i) + { + /* CMYK values from 0 to 1 */ + C = (float)(image->comps[0].data[i]) * sC; + M = (float)(image->comps[1].data[i]) * sM; + Y = (float)(image->comps[2].data[i]) * sY; + K = (float)(image->comps[3].data[i]) * sK; + + /* Invert all CMYK values */ + C = 1.0F - C; + M = 1.0F - M; + Y = 1.0F - Y; + K = 1.0F - K; + + /* CMYK -> RGB : RGB results from 0 to 255 */ + image->comps[0].data[i] = (int)(255.0F * C * K); /* R */ + image->comps[1].data[i] = (int)(255.0F * M * K); /* G */ + image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */ + } + + free(image->comps[3].data); image->comps[3].data = NULL; + image->comps[0].prec = 8; + image->comps[1].prec = 8; + image->comps[2].prec = 8; + image->numcomps -= 1; + image->color_space = OPJ_CLRSPC_SRGB; + + for (i = 3; i < image->numcomps; ++i) { + memcpy(&(image->comps[i]), &(image->comps[i+1]), sizeof(image->comps[i])); + } + +}// color_cmyk_to_rgb() + +// +// This code has been adopted from sjpx_openjpeg.c of ghostscript +// +void color_esycc_to_rgb(opj_image_t *image) +{ + int y, cb, cr, sign1, sign2, val; + unsigned int w, h, max, i; + int flip_value = (1 << (image->comps[0].prec-1)); + int max_value = (1 << image->comps[0].prec) - 1; + + if(image->numcomps < 3) return; + + w = image->comps[0].w; + h = image->comps[0].h; + + sign1 = (int)image->comps[1].sgnd; + sign2 = (int)image->comps[2].sgnd; + + max = w * h; + + for(i = 0; i < max; ++i) + { + + y = image->comps[0].data[i]; cb = image->comps[1].data[i]; cr = image->comps[2].data[i]; + + if( !sign1) cb -= flip_value; + if( !sign2) cr -= flip_value; + + val = (int) + ((float)y - (float)0.0000368 * (float)cb + + (float)1.40199 * (float)cr + (float)0.5); + + if(val > max_value) val = max_value; else if(val < 0) val = 0; + image->comps[0].data[i] = val; + + val = (int) + ((float)1.0003 * (float)y - (float)0.344125 * (float)cb + - (float)0.7141128 * (float)cr + (float)0.5); + + if(val > max_value) val = max_value; else if(val < 0) val = 0; + image->comps[1].data[i] = val; + + val = (int) + ((float)0.999823 * (float)y + (float)1.77204 * (float)cb + - (float)0.000008 *(float)cr + (float)0.5); + + if(val > max_value) val = max_value; else if(val < 0) val = 0; + image->comps[2].data[i] = val; + } + image->color_space = OPJ_CLRSPC_SRGB; +}// color_esycc_to_rgb() diff --git a/src/bin/common/color.h b/src/bin/common/color.h index da8c6e7b..c329f87f 100644 --- a/src/bin/common/color.h +++ b/src/bin/common/color.h @@ -40,5 +40,8 @@ extern void color_sycc_to_rgb(opj_image_t *img); extern void color_apply_icc_profile(opj_image_t *image); +extern void color_apply_conversion(opj_image_t *image); +extern void color_cmyk_to_rgb(opj_image_t *image); +extern void color_esycc_to_rgb(opj_image_t *image); #endif /* _OPJ_COLOR_H_ */ diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index 9d779b39..1131a599 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -315,7 +315,7 @@ static opj_image_t* bmp8toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_i static OPJ_BOOL bmp_read_file_header(FILE* IN, OPJ_BITMAPFILEHEADER* header) { header->bfType = (OPJ_UINT16)getc(IN); - header->bfType |= (OPJ_UINT16)((OPJ_UINT32)(getc(IN) << 8)); + header->bfType |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); if (header->bfType != 19778) { fprintf(stderr,"Error, not a BMP file!\n"); @@ -325,20 +325,20 @@ static OPJ_BOOL bmp_read_file_header(FILE* IN, OPJ_BITMAPFILEHEADER* header) /* FILE HEADER */ /* ------------- */ header->bfSize = (OPJ_UINT32)getc(IN); - header->bfSize |= (OPJ_UINT32)(getc(IN) << 8); - header->bfSize |= (OPJ_UINT32)(getc(IN) << 16); - header->bfSize |= (OPJ_UINT32)(getc(IN) << 24); + header->bfSize |= (OPJ_UINT32)getc(IN) << 8; + header->bfSize |= (OPJ_UINT32)getc(IN) << 16; + header->bfSize |= (OPJ_UINT32)getc(IN) << 24; header->bfReserved1 = (OPJ_UINT16)getc(IN); - header->bfReserved1 |= (OPJ_UINT16)((OPJ_UINT32)(getc(IN) << 8)); + header->bfReserved1 |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); header->bfReserved2 = (OPJ_UINT16)getc(IN); - header->bfReserved2 |= (OPJ_UINT16)((OPJ_UINT32)(getc(IN) << 8)); + header->bfReserved2 |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); header->bfOffBits = (OPJ_UINT32)getc(IN); - header->bfOffBits |= (OPJ_UINT32)(getc(IN) << 8); - header->bfOffBits |= (OPJ_UINT32)(getc(IN) << 16); - header->bfOffBits |= (OPJ_UINT32)(getc(IN) << 24); + header->bfOffBits |= (OPJ_UINT32)getc(IN) << 8; + header->bfOffBits |= (OPJ_UINT32)getc(IN) << 16; + header->bfOffBits |= (OPJ_UINT32)getc(IN) << 24; return OPJ_TRUE; } static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header) @@ -347,9 +347,9 @@ static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header) /* INFO HEADER */ /* ------------- */ header->biSize = (OPJ_UINT32)getc(IN); - header->biSize |= (OPJ_UINT32)(getc(IN) << 8); - header->biSize |= (OPJ_UINT32)(getc(IN) << 16); - header->biSize |= (OPJ_UINT32)(getc(IN) << 24); + header->biSize |= (OPJ_UINT32)getc(IN) << 8; + header->biSize |= (OPJ_UINT32)getc(IN) << 16; + header->biSize |= (OPJ_UINT32)getc(IN) << 24; switch (header->biSize) { case 12U: /* BITMAPCOREHEADER */ @@ -365,80 +365,80 @@ static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header) } header->biWidth = (OPJ_UINT32)getc(IN); - header->biWidth |= (OPJ_UINT32)(getc(IN) << 8); - header->biWidth |= (OPJ_UINT32)(getc(IN) << 16); - header->biWidth |= (OPJ_UINT32)(getc(IN) << 24); + header->biWidth |= (OPJ_UINT32)getc(IN) << 8; + header->biWidth |= (OPJ_UINT32)getc(IN) << 16; + header->biWidth |= (OPJ_UINT32)getc(IN) << 24; header->biHeight = (OPJ_UINT32)getc(IN); - header->biHeight |= (OPJ_UINT32)(getc(IN) << 8); - header->biHeight |= (OPJ_UINT32)(getc(IN) << 16); - header->biHeight |= (OPJ_UINT32)(getc(IN) << 24); + header->biHeight |= (OPJ_UINT32)getc(IN) << 8; + header->biHeight |= (OPJ_UINT32)getc(IN) << 16; + header->biHeight |= (OPJ_UINT32)getc(IN) << 24; header->biPlanes = (OPJ_UINT16)getc(IN); - header->biPlanes |= (OPJ_UINT16)((OPJ_UINT32)(getc(IN) << 8)); + header->biPlanes |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); header->biBitCount = (OPJ_UINT16)getc(IN); - header->biBitCount |= (OPJ_UINT16)((OPJ_UINT32)(getc(IN) << 8)); + header->biBitCount |= (OPJ_UINT16)((OPJ_UINT32)getc(IN) << 8); if(header->biSize >= 40U) { header->biCompression = (OPJ_UINT32)getc(IN); - header->biCompression |= (OPJ_UINT32)(getc(IN) << 8); - header->biCompression |= (OPJ_UINT32)(getc(IN) << 16); - header->biCompression |= (OPJ_UINT32)(getc(IN) << 24); + header->biCompression |= (OPJ_UINT32)getc(IN) << 8; + header->biCompression |= (OPJ_UINT32)getc(IN) << 16; + header->biCompression |= (OPJ_UINT32)getc(IN) << 24; header->biSizeImage = (OPJ_UINT32)getc(IN); - header->biSizeImage |= (OPJ_UINT32)(getc(IN) << 8); - header->biSizeImage |= (OPJ_UINT32)(getc(IN) << 16); - header->biSizeImage |= (OPJ_UINT32)(getc(IN) << 24); + header->biSizeImage |= (OPJ_UINT32)getc(IN) << 8; + header->biSizeImage |= (OPJ_UINT32)getc(IN) << 16; + header->biSizeImage |= (OPJ_UINT32)getc(IN) << 24; header->biXpelsPerMeter = (OPJ_UINT32)getc(IN); - header->biXpelsPerMeter |= (OPJ_UINT32)(getc(IN) << 8); - header->biXpelsPerMeter |= (OPJ_UINT32)(getc(IN) << 16); - header->biXpelsPerMeter |= (OPJ_UINT32)(getc(IN) << 24); + header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 8; + header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 16; + header->biXpelsPerMeter |= (OPJ_UINT32)getc(IN) << 24; header->biYpelsPerMeter = (OPJ_UINT32)getc(IN); - header->biYpelsPerMeter |= (OPJ_UINT32)(getc(IN) << 8); - header->biYpelsPerMeter |= (OPJ_UINT32)(getc(IN) << 16); - header->biYpelsPerMeter |= (OPJ_UINT32)(getc(IN) << 24); + header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 8; + header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 16; + header->biYpelsPerMeter |= (OPJ_UINT32)getc(IN) << 24; header->biClrUsed = (OPJ_UINT32)getc(IN); - header->biClrUsed |= (OPJ_UINT32)(getc(IN) << 8); - header->biClrUsed |= (OPJ_UINT32)(getc(IN) << 16); - header->biClrUsed |= (OPJ_UINT32)(getc(IN) << 24); + header->biClrUsed |= (OPJ_UINT32)getc(IN) << 8; + header->biClrUsed |= (OPJ_UINT32)getc(IN) << 16; + header->biClrUsed |= (OPJ_UINT32)getc(IN) << 24; header->biClrImportant = (OPJ_UINT32)getc(IN); - header->biClrImportant |= (OPJ_UINT32)(getc(IN) << 8); - header->biClrImportant |= (OPJ_UINT32)(getc(IN) << 16); - header->biClrImportant |= (OPJ_UINT32)(getc(IN) << 24); + header->biClrImportant |= (OPJ_UINT32)getc(IN) << 8; + header->biClrImportant |= (OPJ_UINT32)getc(IN) << 16; + header->biClrImportant |= (OPJ_UINT32)getc(IN) << 24; } if(header->biSize >= 56U) { header->biRedMask = (OPJ_UINT32)getc(IN); - header->biRedMask |= (OPJ_UINT32)(getc(IN) << 8); - header->biRedMask |= (OPJ_UINT32)(getc(IN) << 16); - header->biRedMask |= (OPJ_UINT32)(getc(IN) << 24); + header->biRedMask |= (OPJ_UINT32)getc(IN) << 8; + header->biRedMask |= (OPJ_UINT32)getc(IN) << 16; + header->biRedMask |= (OPJ_UINT32)getc(IN) << 24; header->biGreenMask = (OPJ_UINT32)getc(IN); - header->biGreenMask |= (OPJ_UINT32)(getc(IN) << 8); - header->biGreenMask |= (OPJ_UINT32)(getc(IN) << 16); - header->biGreenMask |= (OPJ_UINT32)(getc(IN) << 24); + header->biGreenMask |= (OPJ_UINT32)getc(IN) << 8; + header->biGreenMask |= (OPJ_UINT32)getc(IN) << 16; + header->biGreenMask |= (OPJ_UINT32)getc(IN) << 24; header->biBlueMask = (OPJ_UINT32)getc(IN); - header->biBlueMask |= (OPJ_UINT32)(getc(IN) << 8); - header->biBlueMask |= (OPJ_UINT32)(getc(IN) << 16); - header->biBlueMask |= (OPJ_UINT32)(getc(IN) << 24); + header->biBlueMask |= (OPJ_UINT32)getc(IN) << 8; + header->biBlueMask |= (OPJ_UINT32)getc(IN) << 16; + header->biBlueMask |= (OPJ_UINT32)getc(IN) << 24; header->biAlphaMask = (OPJ_UINT32)getc(IN); - header->biAlphaMask |= (OPJ_UINT32)(getc(IN) << 8); - header->biAlphaMask |= (OPJ_UINT32)(getc(IN) << 16); - header->biAlphaMask |= (OPJ_UINT32)(getc(IN) << 24); + header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 8; + header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 16; + header->biAlphaMask |= (OPJ_UINT32)getc(IN) << 24; } if(header->biSize >= 108U) { header->biColorSpaceType = (OPJ_UINT32)getc(IN); - header->biColorSpaceType |= (OPJ_UINT32)(getc(IN) << 8); - header->biColorSpaceType |= (OPJ_UINT32)(getc(IN) << 16); - header->biColorSpaceType |= (OPJ_UINT32)(getc(IN) << 24); + header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 8; + header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 16; + header->biColorSpaceType |= (OPJ_UINT32)getc(IN) << 24; if (fread(&(header->biColorSpaceEP), 1U, sizeof(header->biColorSpaceEP), IN) != sizeof(header->biColorSpaceEP)) { fprintf(stderr,"Error, can't read BMP header\n"); @@ -446,41 +446,41 @@ static OPJ_BOOL bmp_read_info_header(FILE* IN, OPJ_BITMAPINFOHEADER* header) } header->biRedGamma = (OPJ_UINT32)getc(IN); - header->biRedGamma |= (OPJ_UINT32)(getc(IN) << 8); - header->biRedGamma |= (OPJ_UINT32)(getc(IN) << 16); - header->biRedGamma |= (OPJ_UINT32)(getc(IN) << 24); + header->biRedGamma |= (OPJ_UINT32)getc(IN) << 8; + header->biRedGamma |= (OPJ_UINT32)getc(IN) << 16; + header->biRedGamma |= (OPJ_UINT32)getc(IN) << 24; header->biGreenGamma = (OPJ_UINT32)getc(IN); - header->biGreenGamma |= (OPJ_UINT32)(getc(IN) << 8); - header->biGreenGamma |= (OPJ_UINT32)(getc(IN) << 16); - header->biGreenGamma |= (OPJ_UINT32)(getc(IN) << 24); + header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 8; + header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 16; + header->biGreenGamma |= (OPJ_UINT32)getc(IN) << 24; header->biBlueGamma = (OPJ_UINT32)getc(IN); - header->biBlueGamma |= (OPJ_UINT32)(getc(IN) << 8); - header->biBlueGamma |= (OPJ_UINT32)(getc(IN) << 16); - header->biBlueGamma |= (OPJ_UINT32)(getc(IN) << 24); + header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 8; + header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 16; + header->biBlueGamma |= (OPJ_UINT32)getc(IN) << 24; } if(header->biSize >= 124U) { header->biIntent = (OPJ_UINT32)getc(IN); - header->biIntent |= (OPJ_UINT32)(getc(IN) << 8); - header->biIntent |= (OPJ_UINT32)(getc(IN) << 16); - header->biIntent |= (OPJ_UINT32)(getc(IN) << 24); + header->biIntent |= (OPJ_UINT32)getc(IN) << 8; + header->biIntent |= (OPJ_UINT32)getc(IN) << 16; + header->biIntent |= (OPJ_UINT32)getc(IN) << 24; header->biIccProfileData = (OPJ_UINT32)getc(IN); - header->biIccProfileData |= (OPJ_UINT32)(getc(IN) << 8); - header->biIccProfileData |= (OPJ_UINT32)(getc(IN) << 16); - header->biIccProfileData |= (OPJ_UINT32)(getc(IN) << 24); + header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 8; + header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 16; + header->biIccProfileData |= (OPJ_UINT32)getc(IN) << 24; header->biIccProfileSize = (OPJ_UINT32)getc(IN); - header->biIccProfileSize |= (OPJ_UINT32)(getc(IN) << 8); - header->biIccProfileSize |= (OPJ_UINT32)(getc(IN) << 16); - header->biIccProfileSize |= (OPJ_UINT32)(getc(IN) << 24); + header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 8; + header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 16; + header->biIccProfileSize |= (OPJ_UINT32)getc(IN) << 24; header->biReserved = (OPJ_UINT32)getc(IN); - header->biReserved |= (OPJ_UINT32)(getc(IN) << 8); - header->biReserved |= (OPJ_UINT32)(getc(IN) << 16); - header->biReserved |= (OPJ_UINT32)(getc(IN) << 24); + header->biReserved |= (OPJ_UINT32)getc(IN) << 8; + header->biReserved |= (OPJ_UINT32)getc(IN) << 16; + header->biReserved |= (OPJ_UINT32)getc(IN) << 24; } return OPJ_TRUE; } diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index daddbfee..f164989f 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -183,7 +183,18 @@ int imagetotif(opj_image_t * image, const char *outfile) numcomps = image->numcomps; - if (numcomps > 2U) { + if (image->color_space == OPJ_CLRSPC_CMYK) { + if (numcomps < 4U) { + fprintf(stderr,"imagetotif: CMYK images shall be composed of at least 4 planes.\n"); + fprintf(stderr,"\tAborting\n"); + return 1; + } + tiPhoto = PHOTOMETRIC_SEPARATED; + if (numcomps > 4U) { + numcomps = 4U; /* Alpha not supported */ + } + } + else if (numcomps > 2U) { tiPhoto = PHOTOMETRIC_RGB; if (numcomps > 4U) { numcomps = 4U; @@ -266,6 +277,7 @@ int imagetotif(opj_image_t * image, const char *outfile) TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, tiPhoto); TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); + strip_size = TIFFStripSize(tif); rowStride = ((OPJ_SIZE_T)width * numcomps * (OPJ_SIZE_T)bps + 7U) / 8U; if (rowStride != (OPJ_SIZE_T)strip_size) { diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 6630e2ef..ac17b69d 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -1349,10 +1349,6 @@ int main(int argc, char **argv) /* Close the byte stream */ opj_stream_destroy(l_stream); - if(image->color_space == OPJ_CLRSPC_SYCC){ - color_sycc_to_rgb(image); /* FIXME */ - } - if( image->color_space != OPJ_CLRSPC_SYCC && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy && image->comps[1].dx != 1 ) @@ -1360,9 +1356,22 @@ int main(int argc, char **argv) else if (image->numcomps <= 2) image->color_space = OPJ_CLRSPC_GRAY; + if(image->color_space == OPJ_CLRSPC_SYCC){ + color_sycc_to_rgb(image); + } + else if((image->color_space == OPJ_CLRSPC_CMYK) && (parameters.cod_format != TIF_DFMT)){ + color_cmyk_to_rgb(image); + } + else if(image->color_space == OPJ_CLRSPC_EYCC){ + color_esycc_to_rgb(image); + } + if(image->icc_profile_buf) { #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) - color_apply_icc_profile(image); /* FIXME */ + if(image->icc_profile_len) + color_apply_icc_profile(image); + else + color_apply_conversion(image); #endif free(image->icc_profile_buf); image->icc_profile_buf = NULL; image->icc_profile_len = 0; diff --git a/src/bin/jpwl/convert.c b/src/bin/jpwl/convert.c index 5d9219b3..de04e22f 100644 --- a/src/bin/jpwl/convert.c +++ b/src/bin/jpwl/convert.c @@ -2858,6 +2858,7 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw for (i = 0; i < w * h; i++) { if (!fread(&value, 1, 1, f)) { fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + fclose(f); return NULL; } image->comps[compno].data[i] = raw_cp->rawSigned?(char)value:value; @@ -2872,11 +2873,13 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw unsigned char temp; if (!fread(&temp, 1, 1, f)) { fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + fclose(f); return NULL; } value = temp << 8; if (!fread(&temp, 1, 1, f)) { fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + fclose(f); return NULL; } value += temp; @@ -2886,6 +2889,7 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw } else { fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n"); + fclose(f); return NULL; } diff --git a/src/bin/wx/OPJViewer/source/OPJThreads.cpp b/src/bin/wx/OPJViewer/source/OPJThreads.cpp index e3533a72..c9859860 100644 --- a/src/bin/wx/OPJViewer/source/OPJThreads.cpp +++ b/src/bin/wx/OPJViewer/source/OPJThreads.cpp @@ -889,7 +889,7 @@ void OPJMarkerTree::OnSelChanged(wxTreeEvent& event) m_peektextCtrl->WriteText(text); - delete buffer; + delete [] buffer; } /*void LogKeyEvent(const wxChar *name, const wxKeyEvent& event) |
