Fix formatting
This commit is contained in:
parent
fa9142b7e4
commit
d4ac2f613d
|
@ -566,181 +566,171 @@ void color_apply_conversion(opj_image_t *image)
|
||||||
{
|
{
|
||||||
int *row;
|
int *row;
|
||||||
int enumcs, numcomps;
|
int enumcs, numcomps;
|
||||||
|
|
||||||
image->color_space = OPJ_CLRSPC_SRGB;
|
image->color_space = OPJ_CLRSPC_SRGB;
|
||||||
|
|
||||||
numcomps = image->numcomps;
|
numcomps = image->numcomps;
|
||||||
|
|
||||||
if(numcomps != 3)
|
if(numcomps != 3)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n",
|
fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n",
|
||||||
__FILE__,__LINE__,numcomps);
|
__FILE__,__LINE__,numcomps);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = (int*)image->icc_profile_buf;
|
row = (int*)image->icc_profile_buf;
|
||||||
enumcs = row[0];
|
enumcs = row[0];
|
||||||
|
|
||||||
if(enumcs == 14)// CIELab
|
if(enumcs == 14)// CIELab
|
||||||
{
|
{
|
||||||
int *L, *a, *b, *red, *green, *blue;
|
int *L, *a, *b, *red, *green, *blue;
|
||||||
int *src0, *src1, *src2, *dst0, *dst1, *dst2;
|
int *src0, *src1, *src2, *dst0, *dst1, *dst2;
|
||||||
double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2;
|
double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2;
|
||||||
double minL, maxL, mina, maxa, minb, maxb;
|
double minL, maxL, mina, maxa, minb, maxb;
|
||||||
unsigned int default_type;
|
unsigned int default_type;
|
||||||
unsigned int i, max;
|
unsigned int i, max;
|
||||||
cmsHPROFILE in, out;
|
cmsHPROFILE in, out;
|
||||||
cmsHTRANSFORM transform;
|
cmsHTRANSFORM transform;
|
||||||
cmsUInt16Number RGB[3];
|
cmsUInt16Number RGB[3];
|
||||||
cmsCIELab Lab;
|
cmsCIELab Lab;
|
||||||
|
|
||||||
in = cmsCreateLab4Profile(NULL);
|
in = cmsCreateLab4Profile(NULL);
|
||||||
out = cmsCreate_sRGBProfile();
|
out = cmsCreate_sRGBProfile();
|
||||||
|
|
||||||
transform =
|
transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, INTENT_PERCEPTUAL, 0);
|
||||||
cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16,
|
|
||||||
INTENT_PERCEPTUAL, 0);
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBLCMS2
|
#ifdef HAVE_LIBLCMS2
|
||||||
cmsCloseProfile(in);
|
cmsCloseProfile(in);
|
||||||
cmsCloseProfile(out);
|
cmsCloseProfile(out);
|
||||||
#endif
|
#endif
|
||||||
if(transform == NULL)
|
if(transform == NULL)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBLCMS1
|
#ifdef HAVE_LIBLCMS1
|
||||||
cmsCloseProfile(in);
|
cmsCloseProfile(in);
|
||||||
cmsCloseProfile(out);
|
cmsCloseProfile(out);
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prec0 = (double)image->comps[0].prec;
|
prec0 = (double)image->comps[0].prec;
|
||||||
prec1 = (double)image->comps[1].prec;
|
prec1 = (double)image->comps[1].prec;
|
||||||
prec2 = (double)image->comps[2].prec;
|
prec2 = (double)image->comps[2].prec;
|
||||||
|
|
||||||
default_type = row[1];
|
default_type = row[1];
|
||||||
|
|
||||||
if(default_type == 0x44454600)// DEF : default
|
if(default_type == 0x44454600)// DEF : default
|
||||||
{
|
{
|
||||||
rl = 100; ra = 170; rb = 200;
|
rl = 100; ra = 170; rb = 200;
|
||||||
ol = 0;
|
ol = 0;
|
||||||
oa = pow(2, prec1 - 1);
|
oa = pow(2, prec1 - 1);
|
||||||
ob = pow(2, prec2 - 2) + pow(2, prec2 - 3);
|
ob = pow(2, prec2 - 2) + pow(2, prec2 - 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rl = row[2]; ra = row[4]; rb = row[6];
|
rl = row[2]; ra = row[4]; rb = row[6];
|
||||||
ol = row[3]; oa = row[5]; ob = row[7];
|
ol = row[3]; oa = row[5]; ob = row[7];
|
||||||
}
|
}
|
||||||
L = src0 = image->comps[0].data;
|
|
||||||
a = src1 = image->comps[1].data;
|
L = src0 = image->comps[0].data;
|
||||||
b = src2 = image->comps[2].data;
|
a = src1 = image->comps[1].data;
|
||||||
|
b = src2 = image->comps[2].data;
|
||||||
max = image->comps[0].w * image->comps[0].h;
|
|
||||||
|
max = image->comps[0].w * image->comps[0].h;
|
||||||
red = dst0 = (int*)malloc(max * sizeof(int));
|
|
||||||
green = dst1 = (int*)malloc(max * sizeof(int));
|
red = dst0 = (int*)malloc(max * sizeof(int));
|
||||||
blue = dst2 = (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;
|
minL = -(rl * ol)/(pow(2, prec0)-1);
|
||||||
|
maxL = minL + rl;
|
||||||
mina = -(ra * oa)/(pow(2, prec1)-1);
|
|
||||||
maxa = mina + ra;
|
mina = -(ra * oa)/(pow(2, prec1)-1);
|
||||||
|
maxa = mina + ra;
|
||||||
minb = -(rb * ob)/(pow(2, prec2)-1);
|
|
||||||
maxb = minb + rb;
|
minb = -(rb * ob)/(pow(2, prec2)-1);
|
||||||
|
maxb = minb + rb;
|
||||||
for(i = 0; i < max; ++i)
|
|
||||||
{
|
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.L = minL + (double)(*L) * (maxL - minL)/(pow(2, prec0)-1); ++L;
|
||||||
Lab.b = minb + (double)(*b) * (maxb - minb)/(pow(2, prec2)-1); ++b;
|
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);
|
|
||||||
|
cmsDoTransform(transform, &Lab, RGB, 1);
|
||||||
*red++ = RGB[0];
|
|
||||||
*green++ = RGB[1];
|
*red++ = RGB[0];
|
||||||
*blue++ = RGB[2];
|
*green++ = RGB[1];
|
||||||
}
|
*blue++ = RGB[2];
|
||||||
cmsDeleteTransform(transform);
|
}
|
||||||
|
cmsDeleteTransform(transform);
|
||||||
#ifdef HAVE_LIBLCMS1
|
#ifdef HAVE_LIBLCMS1
|
||||||
cmsCloseProfile(in);
|
cmsCloseProfile(in);
|
||||||
cmsCloseProfile(out);
|
cmsCloseProfile(out);
|
||||||
#endif
|
#endif
|
||||||
free(src0); image->comps[0].data = dst0;
|
free(src0); image->comps[0].data = dst0;
|
||||||
free(src1); image->comps[1].data = dst1;
|
free(src1); image->comps[1].data = dst1;
|
||||||
free(src2); image->comps[2].data = dst2;
|
free(src2); image->comps[2].data = dst2;
|
||||||
|
|
||||||
image->color_space = OPJ_CLRSPC_SRGB;
|
image->color_space = OPJ_CLRSPC_SRGB;
|
||||||
image->comps[0].prec = 16;
|
image->comps[0].prec = 16;
|
||||||
image->comps[1].prec = 16;
|
image->comps[1].prec = 16;
|
||||||
image->comps[2].prec = 16;
|
image->comps[2].prec = 16;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n",
|
fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n", __FILE__,__LINE__, enumcs);
|
||||||
__FILE__,__LINE__, enumcs);
|
|
||||||
|
|
||||||
}// color_apply_conversion()
|
}// color_apply_conversion()
|
||||||
|
|
||||||
#endif // HAVE_LIBLCMS2 || HAVE_LIBLCMS1
|
#endif // HAVE_LIBLCMS2 || HAVE_LIBLCMS1
|
||||||
|
|
||||||
void color_cmyk_to_rgb(opj_image_t *image)
|
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;
|
float C, M, Y, K;
|
||||||
unsigned int w, h, max, prec, len, i;
|
float sC, sM, sY, sK;
|
||||||
|
unsigned int w, h, max, i;
|
||||||
|
|
||||||
w = image->comps[0].w;
|
w = image->comps[0].w;
|
||||||
h = image->comps[0].h;
|
h = image->comps[0].h;
|
||||||
prec = image->comps[0].prec;
|
|
||||||
|
|
||||||
if(prec != 8) return;
|
if(image->numcomps < 4) return;
|
||||||
if(image->numcomps != 4) return;
|
|
||||||
|
|
||||||
max = w * h;
|
max = w * h;
|
||||||
len = max * sizeof(int);
|
|
||||||
|
sC = 1.0F / (float)((1 << image->comps[0].prec) - 1);
|
||||||
R = dst0 = (int*)malloc(len);
|
sM = 1.0F / (float)((1 << image->comps[1].prec) - 1);
|
||||||
G = dst1 = (int*)malloc(len);
|
sY = 1.0F / (float)((1 << image->comps[2].prec) - 1);
|
||||||
B = dst2 = (int*)malloc(len);
|
sK = 1.0F / (float)((1 << image->comps[3].prec) - 1);
|
||||||
|
|
||||||
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)
|
for(i = 0; i < max; ++i)
|
||||||
{
|
{
|
||||||
// CMYK and CMY values from 0 to 1
|
/* CMYK values from 0 to 1 */
|
||||||
//
|
C = (float)(image->comps[0].data[i]) * sC;
|
||||||
C = (float)(*sc++)/(float)255.;
|
M = (float)(image->comps[1].data[i]) * sM;
|
||||||
M = (float)(*sm++)/(float)255;
|
Y = (float)(image->comps[2].data[i]) * sY;
|
||||||
Y = (float)(*sy++)/(float)255;
|
K = (float)(image->comps[3].data[i]) * sK;
|
||||||
K = (float)(*sk++)/(float)255;
|
|
||||||
|
/* Invert all CMYK values */
|
||||||
|
C = 1.0F - C;
|
||||||
|
M = 1.0F - M;
|
||||||
|
Y = 1.0F - Y;
|
||||||
|
K = 1.0F - K;
|
||||||
|
|
||||||
// CMYK -> CMY
|
/* CMYK -> RGB : RGB results from 0 to 255 */
|
||||||
//
|
image->comps[0].data[i] = (int)(255.0F * C * K); /* R */
|
||||||
C = ( C * ( (float)1. - K ) + K );
|
image->comps[1].data[i] = (int)(255.0F * M * K); /* G */
|
||||||
M = ( M * ( (float)1. - K ) + K );
|
image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */
|
||||||
Y = ( Y * ( (float)1. - K ) + K );
|
}
|
||||||
|
|
||||||
// CMY -> RGB : RGB results from 0 to 255
|
free(image->comps[3].data); image->comps[3].data = NULL;
|
||||||
//
|
image->comps[0].prec = 8;
|
||||||
*R++ = (int)(unsigned char)(( (float)1. - C ) * (float)255.);
|
image->comps[1].prec = 8;
|
||||||
*G++ = (int)(unsigned char)(( (float)1. - M ) * (float)255.);
|
image->comps[2].prec = 8;
|
||||||
*B++ = (int)(unsigned char)(( (float)1. - Y ) * (float)255.);
|
image->numcomps -= 1;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
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()
|
}// color_cmyk_to_rgb()
|
||||||
|
|
||||||
|
@ -749,66 +739,50 @@ void color_cmyk_to_rgb(opj_image_t *image)
|
||||||
//
|
//
|
||||||
void color_esycc_to_rgb(opj_image_t *image)
|
void color_esycc_to_rgb(opj_image_t *image)
|
||||||
{
|
{
|
||||||
int *s0, *s1, *s2, *src0, *src1, *src2;
|
int y, cb, cr, sign1, sign2, val;
|
||||||
int *r, *g, *b, *dst0, *dst1, *dst2;
|
unsigned int w, h, max, i;
|
||||||
int y, cb, cr, sign1, sign2, val;
|
int flip_value = (1 << (image->comps[0].prec-1));
|
||||||
unsigned int w, h, max, i;
|
|
||||||
int flip_value = (1 << (image->comps[0].prec-1));
|
|
||||||
int max_value = (~(-1 << image->comps[0].prec));
|
int max_value = (~(-1 << image->comps[0].prec));
|
||||||
|
|
||||||
if(image->numcomps != 3) return;
|
if(image->numcomps < 3) return;
|
||||||
|
|
||||||
w = image->comps[0].w;
|
w = image->comps[0].w;
|
||||||
h = image->comps[0].h;
|
h = image->comps[0].h;
|
||||||
|
|
||||||
s0 = src0 = image->comps[0].data;
|
sign1 = image->comps[1].sgnd;
|
||||||
s1 = src1 = image->comps[1].data;
|
sign2 = image->comps[2].sgnd;
|
||||||
s2 = src2 = image->comps[2].data;
|
|
||||||
|
max = w * h;
|
||||||
sign1 = image->comps[1].sgnd;
|
|
||||||
sign2 = image->comps[2].sgnd;
|
for(i = 0; i < max; ++i)
|
||||||
|
{
|
||||||
max = w * h;
|
|
||||||
|
y = image->comps[0].data[i]; cb = image->comps[1].data[i]; cr = image->comps[2].data[i];
|
||||||
r = dst0 = (int*)malloc(max * sizeof(int));
|
|
||||||
g = dst1 = (int*)malloc(max * sizeof(int));
|
if( !sign1) cb -= flip_value;
|
||||||
b = dst2 = (int*)malloc(max * sizeof(int));
|
if( !sign2) cr -= flip_value;
|
||||||
|
|
||||||
for(i = 0; i < max; ++i)
|
val = (int)
|
||||||
{
|
((float)y - (float)0.0000368 * (float)cb
|
||||||
|
+ (float)1.40199 * (float)cr + (float)0.5);
|
||||||
y = *s0++; cb = *s1++; cr = *s2++;
|
|
||||||
|
if(val > max_value) val = max_value; else if(val < 0) val = 0;
|
||||||
if( !sign1) cb -= flip_value;
|
image->comps[0].data[i] = val;
|
||||||
if( !sign2) cr -= flip_value;
|
|
||||||
|
val = (int)
|
||||||
val = (int)
|
((float)1.0003 * (float)y - (float)0.344125 * (float)cb
|
||||||
((float)y - (float)0.0000368 * (float)cb
|
- (float)0.7141128 * (float)cr + (float)0.5);
|
||||||
+ (float)1.40199 * (float)cr + (float)0.5);
|
|
||||||
|
if(val > max_value) val = max_value; else if(val < 0) val = 0;
|
||||||
if(val > max_value) val = max_value; else if(val < 0) val = 0;
|
image->comps[1].data[i] = val;
|
||||||
*r++ = val;
|
|
||||||
|
val = (int)
|
||||||
val = (int)
|
((float)0.999823 * (float)y + (float)1.77204 * (float)cb
|
||||||
((float)1.0003 * (float)y - (float)0.344125 * (float)cb
|
- (float)0.000008 *(float)cr + (float)0.5);
|
||||||
- (float)0.7141128 * (float)cr + (float)0.5);
|
|
||||||
|
if(val > max_value) val = max_value; else if(val < 0) val = 0;
|
||||||
if(val > max_value) val = max_value; else if(val < 0) val = 0;
|
image->comps[2].data[i] = val;
|
||||||
*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;
|
image->color_space = OPJ_CLRSPC_SRGB;
|
||||||
|
|
||||||
}// color_esycc_to_rgb()
|
}// color_esycc_to_rgb()
|
||||||
|
|
Loading…
Reference in New Issue