git commit -a
This commit is contained in:
parent
c6c49865fe
commit
5828201df4
|
@ -0,0 +1,44 @@
|
||||||
|
####Library patch for CMYK, CIELAB, eSYCC images
|
||||||
|
|
||||||
|
1. opj_decompress.c
|
||||||
|
|
||||||
|
calls the new functions defined in color.c; see 3.
|
||||||
|
|
||||||
|
2. color.h
|
||||||
|
|
||||||
|
declares the new functions defined in color.c; see 3.
|
||||||
|
|
||||||
|
3. color.c
|
||||||
|
|
||||||
|
defines the new functions:
|
||||||
|
|
||||||
|
**color_apply_conversion(opj_image_t*)**:
|
||||||
|
|
||||||
|
uses icc_profile_buf with icc_profile_len == 0.
|
||||||
|
This allows entensions without changing the structures of opj_image_t:
|
||||||
|
the structure change should have been done before but has not been done.
|
||||||
|
There has not been introduced a color_space for CIELAB, etc.
|
||||||
|
The first extension is with CIELab.
|
||||||
|
|
||||||
|
**color_cmyk_to_rgb(opj_image_t*)**
|
||||||
|
|
||||||
|
**color_esycc_to_rgb(opj_image_t*)**
|
||||||
|
|
||||||
|
4. jp2.c
|
||||||
|
|
||||||
|
collects data for CIELab
|
||||||
|
sets the color_space for EYCC and CMYK
|
||||||
|
|
||||||
|
5. CMakeLists.txt
|
||||||
|
|
||||||
|
With THIRDPARTY the libraries are static. LINUX needs '-fPIC' or fails,
|
||||||
|
if static libraries without '-fPIC' AND dynamic libraries are linked:
|
||||||
|
LINUX reports an error.
|
||||||
|
|
||||||
|
Her Highness KDU shows CIELab and CMYK images.
|
||||||
|
|
||||||
|
OPENJPEG now can opj_decompress (and flviewer can show) CIELAB, CMYK and
|
||||||
|
sEYCC images.
|
||||||
|
|
||||||
|
|
||||||
|
winfried
|
|
@ -192,7 +192,9 @@ if(CMAKE_COMPILER_IS_GNUCC)
|
||||||
# Do not use ffast-math for all build, it would produce incorrect results, only set for release:
|
# Do not use ffast-math for all build, it would produce incorrect results, only set for release:
|
||||||
set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
|
set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
|
||||||
endif()
|
endif()
|
||||||
|
if(UNIX)
|
||||||
|
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
|
||||||
|
endif()
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# opj_config.h generation (1/2)
|
# opj_config.h generation (1/2)
|
||||||
|
|
||||||
|
|
|
@ -305,6 +305,7 @@ void color_sycc_to_rgb(opj_image_t *img)
|
||||||
}/* color_sycc_to_rgb() */
|
}/* color_sycc_to_rgb() */
|
||||||
|
|
||||||
#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1)
|
#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1)
|
||||||
|
|
||||||
#ifdef OPJ_HAVE_LIBLCMS1
|
#ifdef OPJ_HAVE_LIBLCMS1
|
||||||
/* Bob Friesenhahn proposed:*/
|
/* Bob Friesenhahn proposed:*/
|
||||||
#define cmsSigXYZData icSigXYZData
|
#define cmsSigXYZData icSigXYZData
|
||||||
|
@ -354,16 +355,16 @@ void color_apply_icc_profile(opj_image_t *image)
|
||||||
|
|
||||||
if(out_space == cmsSigRgbData) /* enumCS 16 */
|
if(out_space == cmsSigRgbData) /* enumCS 16 */
|
||||||
{
|
{
|
||||||
if( prec <= 8 )
|
if( prec <= 8 )
|
||||||
{
|
{
|
||||||
in_type = TYPE_RGB_8;
|
in_type = TYPE_RGB_8;
|
||||||
out_type = TYPE_RGB_8;
|
out_type = TYPE_RGB_8;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
in_type = TYPE_RGB_16;
|
in_type = TYPE_RGB_16;
|
||||||
out_type = TYPE_RGB_16;
|
out_type = TYPE_RGB_16;
|
||||||
}
|
}
|
||||||
out_prof = cmsCreate_sRGBProfile();
|
out_prof = cmsCreate_sRGBProfile();
|
||||||
image->color_space = OPJ_CLRSPC_SRGB;
|
image->color_space = OPJ_CLRSPC_SRGB;
|
||||||
}
|
}
|
||||||
|
@ -389,8 +390,8 @@ else
|
||||||
fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown "
|
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",
|
"output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n",
|
||||||
__FILE__,__LINE__,out_space,
|
__FILE__,__LINE__,out_space,
|
||||||
(out_space>>24) & 0xff,(out_space>>16) & 0xff,
|
(out_space>>24) & 0xff,(out_space>>16) & 0xff,
|
||||||
(out_space>>8) & 0xff, out_space & 0xff);
|
(out_space>>8) & 0xff, out_space & 0xff);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -398,21 +399,21 @@ __FILE__,__LINE__,out_space,
|
||||||
#ifdef DEBUG_PROFILE
|
#ifdef DEBUG_PROFILE
|
||||||
fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)"
|
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,
|
"\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"
|
fprintf(stderr,"\trender_intent (%u)\n\t"
|
||||||
"color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t"
|
"color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t"
|
||||||
" type: in(%u) out:(%u)\n",
|
" type: in(%u) out:(%u)\n",
|
||||||
intent,
|
intent,
|
||||||
in_space,
|
in_space,
|
||||||
(in_space>>24) & 0xff,(in_space>>16) & 0xff,
|
(in_space>>24) & 0xff,(in_space>>16) & 0xff,
|
||||||
(in_space>>8) & 0xff, in_space & 0xff,
|
(in_space>>8) & 0xff, in_space & 0xff,
|
||||||
|
|
||||||
out_space,
|
out_space,
|
||||||
(out_space>>24) & 0xff,(out_space>>16) & 0xff,
|
(out_space>>24) & 0xff,(out_space>>16) & 0xff,
|
||||||
(out_space>>8) & 0xff, out_space & 0xff,
|
(out_space>>8) & 0xff, out_space & 0xff,
|
||||||
|
|
||||||
in_type,out_type
|
in_type,out_type
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
(void)prec;
|
(void)prec;
|
||||||
|
@ -444,11 +445,11 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
|
||||||
|
|
||||||
if(image->numcomps > 2)/* RGB, RGBA */
|
if(image->numcomps > 2)/* RGB, RGBA */
|
||||||
{
|
{
|
||||||
if( prec <= 8 )
|
if( prec <= 8 )
|
||||||
{
|
{
|
||||||
unsigned char *inbuf, *outbuf, *in, *out;
|
unsigned char *inbuf, *outbuf, *in, *out;
|
||||||
max = max_w * max_h;
|
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);
|
in = inbuf = (unsigned char*)malloc(nr_samples);
|
||||||
out = outbuf = (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;
|
b = image->comps[2].data;
|
||||||
|
|
||||||
for(i = 0; i < max; ++i)
|
for(i = 0; i < max; ++i)
|
||||||
{
|
{
|
||||||
*in++ = (unsigned char)*r++;
|
*in++ = (unsigned char)*r++;
|
||||||
*in++ = (unsigned char)*g++;
|
*in++ = (unsigned char)*g++;
|
||||||
*in++ = (unsigned char)*b++;
|
*in++ = (unsigned char)*b++;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
|
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;
|
b = image->comps[2].data;
|
||||||
|
|
||||||
for(i = 0; i < max; ++i)
|
for(i = 0; i < max; ++i)
|
||||||
{
|
{
|
||||||
*r++ = (int)*out++;
|
*r++ = (int)*out++;
|
||||||
*g++ = (int)*out++;
|
*g++ = (int)*out++;
|
||||||
*b++ = (int)*out++;
|
*b++ = (int)*out++;
|
||||||
}
|
}
|
||||||
free(inbuf); free(outbuf);
|
free(inbuf); free(outbuf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned short *inbuf, *outbuf, *in, *out;
|
unsigned short *inbuf, *outbuf, *in, *out;
|
||||||
max = max_w * max_h;
|
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);
|
in = inbuf = (unsigned short*)malloc(nr_samples);
|
||||||
out = outbuf = (unsigned short*)malloc(nr_samples);
|
out = outbuf = (unsigned short*)malloc(nr_samples);
|
||||||
|
|
||||||
|
@ -490,11 +491,11 @@ else
|
||||||
b = image->comps[2].data;
|
b = image->comps[2].data;
|
||||||
|
|
||||||
for(i = 0; i < max; ++i)
|
for(i = 0; i < max; ++i)
|
||||||
{
|
{
|
||||||
*in++ = (unsigned short)*r++;
|
*in++ = (unsigned short)*r++;
|
||||||
*in++ = (unsigned short)*g++;
|
*in++ = (unsigned short)*g++;
|
||||||
*in++ = (unsigned short)*b++;
|
*in++ = (unsigned short)*b++;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
|
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
|
||||||
|
|
||||||
|
@ -503,19 +504,19 @@ else
|
||||||
b = image->comps[2].data;
|
b = image->comps[2].data;
|
||||||
|
|
||||||
for(i = 0; i < max; ++i)
|
for(i = 0; i < max; ++i)
|
||||||
{
|
{
|
||||||
*r++ = (int)*out++;
|
*r++ = (int)*out++;
|
||||||
*g++ = (int)*out++;
|
*g++ = (int)*out++;
|
||||||
*b++ = (int)*out++;
|
*b++ = (int)*out++;
|
||||||
}
|
}
|
||||||
free(inbuf); free(outbuf);
|
free(inbuf); free(outbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* GRAY, GRAYA */
|
else /* GRAY, GRAYA */
|
||||||
{
|
{
|
||||||
unsigned char *in, *inbuf, *out, *outbuf;
|
unsigned char *in, *inbuf, *out, *outbuf;
|
||||||
max = max_w * max_h;
|
max = max_w * max_h;
|
||||||
nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char);
|
nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char);
|
||||||
in = inbuf = (unsigned char*)malloc(nr_samples);
|
in = inbuf = (unsigned char*)malloc(nr_samples);
|
||||||
out = outbuf = (unsigned char*)malloc(nr_samples);
|
out = outbuf = (unsigned char*)malloc(nr_samples);
|
||||||
|
|
||||||
|
@ -561,5 +562,253 @@ else
|
||||||
#endif
|
#endif
|
||||||
}/* color_apply_icc_profile() */
|
}/* 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 = 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 = 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)
|
||||||
|
{
|
||||||
|
int *R, *G, *B, *dst0, *dst1, *dst2;
|
||||||
|
int *sc, *sm, *sy, *sk, *src0, *src1, *src2, *src3;
|
||||||
|
float C, M, Y, K;
|
||||||
|
unsigned int w, h, max, prec, len, i;
|
||||||
|
|
||||||
|
w = image->comps[0].w;
|
||||||
|
h = image->comps[0].h;
|
||||||
|
prec = image->comps[0].prec;
|
||||||
|
|
||||||
|
if(prec != 8) return;
|
||||||
|
if(image->numcomps != 4) return;
|
||||||
|
|
||||||
|
max = w * h;
|
||||||
|
len = max * sizeof(int);
|
||||||
|
|
||||||
|
R = dst0 = (int*)malloc(len);
|
||||||
|
G = dst1 = (int*)malloc(len);
|
||||||
|
B = dst2 = (int*)malloc(len);
|
||||||
|
|
||||||
|
sc = src0 = image->comps[0].data;
|
||||||
|
sm = src1 = image->comps[1].data;
|
||||||
|
sy = src2 = image->comps[2].data;
|
||||||
|
sk = src3 = image->comps[3].data;
|
||||||
|
|
||||||
|
for(i = 0; i < max; ++i)
|
||||||
|
{
|
||||||
|
// CMYK and CMY values from 0 to 1
|
||||||
|
//
|
||||||
|
C = (float)(*sc++)/(float)255.;
|
||||||
|
M = (float)(*sm++)/(float)255;
|
||||||
|
Y = (float)(*sy++)/(float)255;
|
||||||
|
K = (float)(*sk++)/(float)255;
|
||||||
|
|
||||||
|
// CMYK -> CMY
|
||||||
|
//
|
||||||
|
C = ( C * ( (float)1. - K ) + K );
|
||||||
|
M = ( M * ( (float)1. - K ) + K );
|
||||||
|
Y = ( Y * ( (float)1. - K ) + K );
|
||||||
|
|
||||||
|
// CMY -> RGB : RGB results from 0 to 255
|
||||||
|
//
|
||||||
|
*R++ = (int)(unsigned char)(( (float)1. - C ) * (float)255.);
|
||||||
|
*G++ = (int)(unsigned char)(( (float)1. - M ) * (float)255.);
|
||||||
|
*B++ = (int)(unsigned char)(( (float)1. - Y ) * (float)255.);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(src0); image->comps[0].data = dst0;
|
||||||
|
free(src1); image->comps[1].data = dst1;
|
||||||
|
free(src2); image->comps[2].data = dst2;
|
||||||
|
free(src3); image->comps[3].data = NULL;
|
||||||
|
|
||||||
|
image->numcomps = 3;
|
||||||
|
image->color_space = OPJ_CLRSPC_SRGB;
|
||||||
|
|
||||||
|
}// 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 *s0, *s1, *s2, *src0, *src1, *src2;
|
||||||
|
int *r, *g, *b, *dst0, *dst1, *dst2;
|
||||||
|
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));
|
||||||
|
|
||||||
|
if(image->numcomps != 3) return;
|
||||||
|
|
||||||
|
w = image->comps[0].w;
|
||||||
|
h = image->comps[0].h;
|
||||||
|
|
||||||
|
s0 = src0 = image->comps[0].data;
|
||||||
|
s1 = src1 = image->comps[1].data;
|
||||||
|
s2 = src2 = image->comps[2].data;
|
||||||
|
|
||||||
|
sign1 = image->comps[1].sgnd;
|
||||||
|
sign2 = image->comps[2].sgnd;
|
||||||
|
|
||||||
|
max = w * h;
|
||||||
|
|
||||||
|
r = dst0 = (int*)malloc(max * sizeof(int));
|
||||||
|
g = dst1 = (int*)malloc(max * sizeof(int));
|
||||||
|
b = dst2 = (int*)malloc(max * sizeof(int));
|
||||||
|
|
||||||
|
for(i = 0; i < max; ++i)
|
||||||
|
{
|
||||||
|
|
||||||
|
y = *s0++; cb = *s1++; cr = *s2++;
|
||||||
|
|
||||||
|
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;
|
||||||
|
*r++ = 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;
|
||||||
|
*g++ = 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;
|
||||||
|
*b++ = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(src0); image->comps[0].data = dst0;
|
||||||
|
free(src1); image->comps[1].data = dst1;
|
||||||
|
free(src2); image->comps[2].data = dst2;
|
||||||
|
|
||||||
|
image->numcomps = 3;
|
||||||
|
image->color_space = OPJ_CLRSPC_SRGB;
|
||||||
|
|
||||||
|
}// color_esycc_to_rgb()
|
||||||
|
|
|
@ -40,5 +40,8 @@
|
||||||
|
|
||||||
extern void color_sycc_to_rgb(opj_image_t *img);
|
extern void color_sycc_to_rgb(opj_image_t *img);
|
||||||
extern void color_apply_icc_profile(opj_image_t *image);
|
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_ */
|
#endif /* _OPJ_COLOR_H_ */
|
||||||
|
|
|
@ -1306,10 +1306,6 @@ int main(int argc, char **argv)
|
||||||
/* Close the byte stream */
|
/* Close the byte stream */
|
||||||
opj_stream_destroy(l_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
|
if( image->color_space != OPJ_CLRSPC_SYCC
|
||||||
&& image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy
|
&& image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy
|
||||||
&& image->comps[1].dx != 1 )
|
&& image->comps[1].dx != 1 )
|
||||||
|
@ -1317,9 +1313,24 @@ int main(int argc, char **argv)
|
||||||
else if (image->numcomps <= 2)
|
else if (image->numcomps <= 2)
|
||||||
image->color_space = OPJ_CLRSPC_GRAY;
|
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){
|
||||||
|
color_cmyk_to_rgb(image);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(image->color_space == OPJ_CLRSPC_EYCC){
|
||||||
|
color_esycc_to_rgb(image);
|
||||||
|
}
|
||||||
|
|
||||||
if(image->icc_profile_buf) {
|
if(image->icc_profile_buf) {
|
||||||
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
|
#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
|
#endif
|
||||||
free(image->icc_profile_buf);
|
free(image->icc_profile_buf);
|
||||||
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
|
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
|
||||||
|
|
|
@ -836,6 +836,8 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, nr_channels);
|
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, nr_channels);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
if (info[i].asoc > 65534) continue;
|
||||||
|
|
||||||
if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= nr_channels) {
|
if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= nr_channels) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, nr_channels);
|
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, nr_channels);
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
|
@ -936,7 +938,7 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
|
||||||
|
|
||||||
old_comps = image->comps;
|
old_comps = image->comps;
|
||||||
new_comps = (opj_image_comp_t*)
|
new_comps = (opj_image_comp_t*)
|
||||||
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
|
opj_calloc(nr_channels, sizeof(opj_image_comp_t));
|
||||||
if (!new_comps) {
|
if (!new_comps) {
|
||||||
/* FIXME no error code for opj_jp2_apply_pclr */
|
/* FIXME no error code for opj_jp2_apply_pclr */
|
||||||
/* FIXME event manager error callback */
|
/* FIXME event manager error callback */
|
||||||
|
@ -1182,65 +1184,67 @@ OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2,
|
||||||
|
|
||||||
void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
|
void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
|
||||||
{
|
{
|
||||||
opj_jp2_cdef_info_t *info;
|
opj_jp2_cdef_info_t *info;
|
||||||
OPJ_UINT16 i, n, cn, asoc, acn;
|
OPJ_UINT16 i, j, n, cn, asoc, acn, last, typ, nr_typ0 = 0;
|
||||||
|
|
||||||
info = color->jp2_cdef->info;
|
info = color->jp2_cdef->info;
|
||||||
n = color->jp2_cdef->n;
|
n = color->jp2_cdef->n;
|
||||||
|
|
||||||
for(i = 0; i < n; ++i)
|
for(i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
/* WATCH: acn = asoc - 1 ! */
|
if(info[i].asoc != 65535 && info[i].typ != 65535) continue;
|
||||||
asoc = info[i].asoc;
|
|
||||||
cn = info[i].cn;
|
opj_free(image->comps[i].data);
|
||||||
|
image->comps[i].data = NULL;
|
||||||
if( cn >= image->numcomps)
|
|
||||||
{
|
last = n - 1;
|
||||||
fprintf(stderr, "cn=%d, numcomps=%d\n", cn, image->numcomps);
|
|
||||||
continue;
|
for(j = i; j < last; ++j)
|
||||||
}
|
{
|
||||||
if(asoc == 0 || asoc == 65535)
|
image->comps[j] = image->comps[j+1];
|
||||||
{
|
info[j] = info[j+1];
|
||||||
image->comps[cn].alpha = info[i].typ;
|
}
|
||||||
continue;
|
--n; --color->jp2_cdef->n;
|
||||||
}
|
--image->numcomps;
|
||||||
|
}
|
||||||
acn = (OPJ_UINT16)(asoc - 1);
|
|
||||||
if( acn >= image->numcomps )
|
for(i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "acn=%d, numcomps=%d\n", acn, image->numcomps);
|
/* WATCH: acn = asoc - 1 ! */
|
||||||
continue;
|
asoc = info[i].asoc;
|
||||||
}
|
typ = info[i].typ;
|
||||||
|
|
||||||
/* Swap only if color channel */
|
image->comps[i].alpha = (typ == 1);
|
||||||
if((cn != acn) && (info[i].typ == 0))
|
|
||||||
{
|
if(typ == 1) continue;
|
||||||
opj_image_comp_t saved;
|
if(asoc == 0) continue;
|
||||||
OPJ_UINT16 j;
|
|
||||||
|
cn = info[i].cn;
|
||||||
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
|
acn = (OPJ_UINT16)(asoc - 1);
|
||||||
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
|
if( cn >= image->numcomps || acn >= image->numcomps )
|
||||||
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
|
{
|
||||||
|
fprintf(stderr, "\tINFO[%d]cn=%d, acn=%d, numcomps=%d: SKIP.\n",
|
||||||
/* Swap channels in following channel definitions, don't bother with j <= i that are already processed */
|
i,cn, acn, image->numcomps);
|
||||||
for (j = (OPJ_UINT16)(i + 1U); j < n ; ++j)
|
continue;
|
||||||
{
|
}
|
||||||
if (info[j].cn == cn) {
|
|
||||||
info[j].cn = acn;
|
if(cn != acn && typ == 0)
|
||||||
}
|
{
|
||||||
else if (info[j].cn == acn) {
|
opj_image_comp_t saved;
|
||||||
info[j].cn = cn;
|
|
||||||
}
|
++nr_typ0;
|
||||||
/* asoc is related to color index. Do not update. */
|
|
||||||
}
|
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
|
||||||
}
|
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
|
||||||
|
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
|
||||||
image->comps[cn].alpha = info[i].typ;
|
|
||||||
}
|
info[i].asoc = (OPJ_UINT16)(cn + 1);
|
||||||
|
info[acn].asoc = (OPJ_UINT16)(info[acn].cn + 1);
|
||||||
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
|
}
|
||||||
|
}
|
||||||
opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
|
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
|
||||||
|
|
||||||
|
opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
|
||||||
|
|
||||||
}/* jp2_apply_cdef() */
|
}/* jp2_apply_cdef() */
|
||||||
|
|
||||||
|
@ -1359,7 +1363,51 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
|
||||||
}
|
}
|
||||||
|
|
||||||
opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */
|
opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */
|
||||||
|
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
|
||||||
|
if(jp2->enumcs == 14)/* CIELab */
|
||||||
|
{
|
||||||
|
OPJ_UINT32 *cielab;
|
||||||
|
OPJ_UINT32 rl, ol, ra, oa, rb, ob, il;
|
||||||
|
|
||||||
|
cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32));
|
||||||
|
cielab[0] = 14; /* enumcs */
|
||||||
|
|
||||||
|
if(p_colr_header_size == 7)/* default values */
|
||||||
|
{
|
||||||
|
rl = ra = rb = ol = oa = ob = 0;
|
||||||
|
il = 0x00443530; /* D50 */
|
||||||
|
cielab[1] = 0x44454600;/* DEF */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(p_colr_header_size == 35)
|
||||||
|
{
|
||||||
|
opj_read_bytes(p_colr_header_data, &rl, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
opj_read_bytes(p_colr_header_data, &ol, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
opj_read_bytes(p_colr_header_data, &ra, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
opj_read_bytes(p_colr_header_data, &oa, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
opj_read_bytes(p_colr_header_data, &rb, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
opj_read_bytes(p_colr_header_data, &ob, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
opj_read_bytes(p_colr_header_data, &il, 4);
|
||||||
|
p_colr_header_data += 4;
|
||||||
|
|
||||||
|
cielab[1] = 0;
|
||||||
|
}
|
||||||
|
cielab[2] = rl; cielab[4] = ra; cielab[6] = rb;
|
||||||
|
cielab[3] = ol; cielab[5] = oa; cielab[7] = ob;
|
||||||
|
cielab[8] = il;
|
||||||
|
|
||||||
|
jp2->color.icc_profile_buf = (unsigned char*)cielab;
|
||||||
|
jp2->color.icc_profile_len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
jp2->color.jp2_has_colr = 1;
|
jp2->color.jp2_has_colr = 1;
|
||||||
}
|
}
|
||||||
else if (jp2->meth == 2) {
|
else if (jp2->meth == 2) {
|
||||||
|
@ -1422,6 +1470,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
|
||||||
p_image->color_space = OPJ_CLRSPC_SYCC;
|
p_image->color_space = OPJ_CLRSPC_SYCC;
|
||||||
else if (jp2->enumcs == 24)
|
else if (jp2->enumcs == 24)
|
||||||
p_image->color_space = OPJ_CLRSPC_EYCC;
|
p_image->color_space = OPJ_CLRSPC_EYCC;
|
||||||
|
else
|
||||||
|
if (jp2->enumcs == 12)
|
||||||
|
p_image->color_space = OPJ_CLRSPC_CMYK;
|
||||||
else
|
else
|
||||||
p_image->color_space = OPJ_CLRSPC_UNKNOWN;
|
p_image->color_space = OPJ_CLRSPC_UNKNOWN;
|
||||||
|
|
||||||
|
@ -2719,6 +2770,12 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
|
||||||
p_image->color_space = OPJ_CLRSPC_GRAY;
|
p_image->color_space = OPJ_CLRSPC_GRAY;
|
||||||
else if (p_jp2->enumcs == 18)
|
else if (p_jp2->enumcs == 18)
|
||||||
p_image->color_space = OPJ_CLRSPC_SYCC;
|
p_image->color_space = OPJ_CLRSPC_SYCC;
|
||||||
|
else
|
||||||
|
if (p_jp2->enumcs == 24)
|
||||||
|
p_image->color_space = OPJ_CLRSPC_EYCC;
|
||||||
|
else
|
||||||
|
if (p_jp2->enumcs == 12)
|
||||||
|
p_image->color_space = OPJ_CLRSPC_CMYK;
|
||||||
else
|
else
|
||||||
p_image->color_space = OPJ_CLRSPC_UNKNOWN;
|
p_image->color_space = OPJ_CLRSPC_UNKNOWN;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue