Fix formatting

This commit is contained in:
mayeut 2015-08-21 20:17:55 +02:00
parent fa9142b7e4
commit d4ac2f613d
1 changed files with 178 additions and 204 deletions

View File

@ -597,9 +597,7 @@ void color_apply_conversion(opj_image_t *image)
in = cmsCreateLab4Profile(NULL);
out = cmsCreate_sRGBProfile();
transform =
cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16,
INTENT_PERCEPTUAL, 0);
transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, INTENT_PERCEPTUAL, 0);
#ifdef HAVE_LIBLCMS2
cmsCloseProfile(in);
@ -631,6 +629,7 @@ void color_apply_conversion(opj_image_t *image)
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;
@ -679,69 +678,60 @@ void color_apply_conversion(opj_image_t *image)
return;
}
fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n",
__FILE__,__LINE__, enumcs);
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;
float sC, sM, sY, sK;
unsigned int w, h, max, 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;
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;
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 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 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;
// CMYK -> CMY
//
C = ( C * ( (float)1. - K ) + K );
M = ( M * ( (float)1. - K ) + K );
Y = ( Y * ( (float)1. - K ) + K );
/* Invert all CMYK values */
C = 1.0F - C;
M = 1.0F - M;
Y = 1.0F - Y;
K = 1.0F - 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.);
/* 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(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;
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()
//
@ -749,35 +739,25 @@ void color_cmyk_to_rgb(opj_image_t *image)
//
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;
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++;
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;
@ -787,28 +767,22 @@ void color_esycc_to_rgb(opj_image_t *image)
+ (float)1.40199 * (float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0;
*r++ = val;
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;
*g++ = val;
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;
*b++ = val;
image->comps[2].data[i] = 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()