diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 20aba2ba..944df73b 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -378,16 +378,15 @@ void color_apply_icc_profile(opj_image_t *image) cmsColorSpaceSignature in_space, out_space; cmsUInt32Number intent, in_type, out_type; int *r, *g, *b; - size_t nr_samples; - int prec, i, max, max_w, max_h, ok = 0; + size_t nr_samples, i, max, max_w, max_h; + int prec, ok = 0; OPJ_COLOR_SPACE new_space; - in_prof = - cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); + in_prof = cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); #ifdef DEBUG_PROFILE - FILE *icm = fopen("debug.icm","wb"); - fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm); - fclose(icm); + FILE *icm = fopen("debug.icm","wb"); + fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm); + fclose(icm); #endif if(in_prof == NULL) return; @@ -397,87 +396,83 @@ void color_apply_icc_profile(opj_image_t *image) intent = cmsGetHeaderRenderingIntent(in_prof); - max_w = (int)image->comps[0].w; - max_h = (int)image->comps[0].h; + max_w = image->comps[0].w; + max_h = image->comps[0].h; prec = (int)image->comps[0].prec; if(out_space == cmsSigRgbData) /* enumCS 16 */ - { - if( prec <= 8 ) - { - in_type = TYPE_RGB_8; - out_type = TYPE_RGB_8; - } + { + if( prec <= 8 ) + { + in_type = TYPE_RGB_8; + out_type = TYPE_RGB_8; + } + else + { + in_type = TYPE_RGB_16; + out_type = TYPE_RGB_16; + } + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } + else if(out_space == cmsSigGrayData) /* enumCS 17 */ + { + in_type = TYPE_GRAY_8; + out_type = TYPE_RGB_8; + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } + else if(out_space == cmsSigYCbCrData) /* enumCS 18 */ + { + in_type = TYPE_YCbCr_16; + out_type = TYPE_RGB_16; + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } else - { - in_type = TYPE_RGB_16; - out_type = TYPE_RGB_16; - } - out_prof = cmsCreate_sRGBProfile(); - new_space = OPJ_CLRSPC_SRGB; - } - else - if(out_space == cmsSigGrayData) /* enumCS 17 */ - { - in_type = TYPE_GRAY_8; - out_type = TYPE_RGB_8; - out_prof = cmsCreate_sRGBProfile(); - new_space = OPJ_CLRSPC_SRGB; - } - else - if(out_space == cmsSigYCbCrData) /* enumCS 18 */ - { - in_type = TYPE_YCbCr_16; - out_type = TYPE_RGB_16; - out_prof = cmsCreate_sRGBProfile(); - new_space = OPJ_CLRSPC_SRGB; - } - else - { + { #ifdef DEBUG_PROFILE -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); + 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); #endif - cmsCloseProfile(in_prof); + cmsCloseProfile(in_prof); - return; - } + return; + } if(out_prof == NULL) - { - cmsCloseProfile(in_prof); - - return; - } + { + cmsCloseProfile(in_prof); + return; + } #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); + 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); -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, + 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, - 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; (void)in_space; #endif /* DEBUG_PROFILE */ - transform = cmsCreateTransform(in_prof, in_type, - out_prof, out_type, intent, 0); + transform = cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); #ifdef OPJ_HAVE_LIBLCMS2 /* Possible for: LCMS_VERSION >= 2000 :*/ @@ -486,219 +481,217 @@ fprintf(stderr,"\trender_intent (%u)\n\t" #endif if(transform == NULL) - { + { #ifdef DEBUG_PROFILE -fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " -"ICC Profile ignored.\n",__FILE__,__LINE__); + fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " + "ICC Profile ignored.\n",__FILE__,__LINE__); #endif #ifdef OPJ_HAVE_LIBLCMS1 - cmsCloseProfile(in_prof); - cmsCloseProfile(out_prof); + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); #endif - return; - } + return; + } if(image->numcomps > 2)/* RGB, RGBA */ - { - if( prec <= 8 ) - { - unsigned char *inbuf, *outbuf, *in, *out; + { + if( prec <= 8 ) + { + unsigned char *inbuf, *outbuf, *in, *out; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); - in = inbuf = (unsigned char*)malloc(nr_samples); - out = outbuf = (unsigned char*)malloc(nr_samples); + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned char)); + in = inbuf = (unsigned char*)malloc(nr_samples); + out = outbuf = (unsigned char*)malloc(nr_samples); - if(inbuf == NULL || outbuf == NULL) goto fails0; + if(inbuf == NULL || outbuf == NULL) goto fails0; - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned char)*r++; - *in++ = (unsigned char)*g++; - *in++ = (unsigned char)*b++; - } + for(i = 0U; i < max; ++i) + { + *in++ = (unsigned char)*r++; + *in++ = (unsigned char)*g++; + *in++ = (unsigned char)*b++; + } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - ok = 1; + for(i = 0U; i < max; ++i) + { + *r++ = (int)*out++; + *g++ = (int)*out++; + *b++ = (int)*out++; + } + ok = 1; fails0: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - } - else /* prec > 8 */ - { - unsigned short *inbuf, *outbuf, *in, *out; + free(inbuf); + free(outbuf); + } + else /* prec > 8 */ + { + unsigned short *inbuf, *outbuf, *in, *out; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned short)); - in = inbuf = (unsigned short*)malloc(nr_samples); - out = outbuf = (unsigned short*)malloc(nr_samples); + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned short)); + in = inbuf = (unsigned short*)malloc(nr_samples); + out = outbuf = (unsigned short*)malloc(nr_samples); - if(inbuf == NULL || outbuf == NULL) goto fails1; + if(inbuf == NULL || outbuf == NULL) goto fails1; - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned short)*r++; - *in++ = (unsigned short)*g++; - *in++ = (unsigned short)*b++; - } + for(i = 0U ; i < max; ++i) + { + *in++ = (unsigned short)*r++; + *in++ = (unsigned short)*g++; + *in++ = (unsigned short)*b++; + } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - ok = 1; + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; + *g++ = (int)*out++; + *b++ = (int)*out++; + } + ok = 1; fails1: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - } - } + free(inbuf); + free(outbuf); + } + } else /* image->numcomps <= 2 : GRAY, GRAYA */ - { - if(prec <= 8) - { - unsigned char *in, *inbuf, *out, *outbuf; - opj_image_comp_t *new_comps; + { + if(prec <= 8) + { + unsigned char *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); - in = inbuf = (unsigned char*)malloc(nr_samples); - out = outbuf = (unsigned char*)malloc(nr_samples); - g = (int*)calloc((size_t)max, sizeof(int)); - b = (int*)calloc((size_t)max, sizeof(int)); + max = max_w * max_h; + nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); + in = inbuf = (unsigned char*)malloc(nr_samples); + out = outbuf = (unsigned char*)malloc(nr_samples); + g = (int*)calloc((size_t)max, sizeof(int)); + b = (int*)calloc((size_t)max, sizeof(int)); - if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails2; + if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails2; - new_comps = (opj_image_comp_t*) - realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + new_comps = (opj_image_comp_t*)realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); - if(new_comps == NULL) goto fails2; + if(new_comps == NULL) goto fails2; - image->comps = new_comps; + image->comps = new_comps; - if(image->numcomps == 2) - image->comps[3] = image->comps[1]; + if(image->numcomps == 2) + image->comps[3] = image->comps[1]; - image->comps[1] = image->comps[0]; - image->comps[2] = image->comps[0]; + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; - image->comps[1].data = g; - image->comps[2].data = b; + image->comps[1].data = g; + image->comps[2].data = b; - image->numcomps += 2; + image->numcomps += 2; - r = image->comps[0].data; + r = image->comps[0].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned char)*r++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + for(i = 0U; i < max; ++i) + { + *in++ = (unsigned char)*r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } - r = g = b = NULL; - ok = 1; + for(i = 0U; i < max; ++i) + { + *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; + } + r = g = b = NULL; + ok = 1; fails2: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - if(g) free(g); - if(b) free(b); - } - else /* prec > 8 */ - { - unsigned short *in, *inbuf, *out, *outbuf; - opj_image_comp_t *new_comps; + free(inbuf); + free(outbuf); + free(g); + free(b); + } + else /* prec > 8 */ + { + unsigned short *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned short)); - in = inbuf = (unsigned short*)malloc(nr_samples); - out = outbuf = (unsigned short*)malloc(nr_samples); - g = (int*)calloc((size_t)max, sizeof(int)); - b = (int*)calloc((size_t)max, sizeof(int)); + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned short)); + in = inbuf = (unsigned short*)malloc(nr_samples); + out = outbuf = (unsigned short*)malloc(nr_samples); + g = (int*)calloc((size_t)max, sizeof(int)); + b = (int*)calloc((size_t)max, sizeof(int)); - if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails3; + if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails3; - new_comps = (opj_image_comp_t*) - realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + new_comps = (opj_image_comp_t*)realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); - if(new_comps == NULL) goto fails3; + if(new_comps == NULL) goto fails3; - image->comps = new_comps; + image->comps = new_comps; - if(image->numcomps == 2) - image->comps[3] = image->comps[1]; + if(image->numcomps == 2) + image->comps[3] = image->comps[1]; - image->comps[1] = image->comps[0]; - image->comps[2] = image->comps[0]; + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; - image->comps[1].data = g; - image->comps[2].data = b; + image->comps[1].data = g; + image->comps[2].data = b; - image->numcomps += 2; + image->numcomps += 2; - r = image->comps[0].data; + r = image->comps[0].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned short)*r++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + for(i = 0U; i < max; ++i) + { + *in++ = (unsigned short)*r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } - r = g = b = NULL; - ok = 1; + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; + } + r = g = b = NULL; + ok = 1; fails3: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - if(g) free(g); - if(b) free(b); - } - }/* if(image->numcomps > 2) */ + free(inbuf); + free(outbuf); + free(g); + free(b); + } + }/* if(image->numcomps > 2) */ cmsDeleteTransform(transform); @@ -707,9 +700,9 @@ fails3: cmsCloseProfile(out_prof); #endif if(ok) - { - image->color_space = new_space; - } + { + image->color_space = new_space; + } }/* color_apply_icc_profile() */ void color_cielab_to_rgb(opj_image_t *image) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 4dc69773..323a3b80 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2442,22 +2442,22 @@ static OPJ_BOOL opj_j2k_write_cod( opj_j2k_t *p_j2k, l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data; - opj_write_bytes(l_current_data,J2K_MS_COD,2); /* COD */ + opj_write_bytes(l_current_data,J2K_MS_COD,2); /* COD */ l_current_data += 2; - opj_write_bytes(l_current_data,l_code_size-2,2); /* L_COD */ + opj_write_bytes(l_current_data,l_code_size-2,2); /* L_COD */ l_current_data += 2; - opj_write_bytes(l_current_data,l_tcp->csty,1); /* Scod */ + opj_write_bytes(l_current_data,l_tcp->csty,1); /* Scod */ ++l_current_data; - opj_write_bytes(l_current_data,l_tcp->prg,1); /* SGcod (A) */ + opj_write_bytes(l_current_data,(OPJ_UINT32)l_tcp->prg,1); /* SGcod (A) */ ++l_current_data; - opj_write_bytes(l_current_data,l_tcp->numlayers,2); /* SGcod (B) */ + opj_write_bytes(l_current_data,l_tcp->numlayers,2); /* SGcod (B) */ l_current_data+=2; - opj_write_bytes(l_current_data,l_tcp->mct,1); /* SGcod (C) */ + opj_write_bytes(l_current_data,l_tcp->mct,1); /* SGcod (C) */ ++l_current_data; l_remaining_size -= 9; @@ -3174,7 +3174,7 @@ static void opj_j2k_write_poc_in_memory( opj_j2k_t *p_j2k, opj_write_bytes(l_current_data,l_current_poc->compno1,l_poc_room); /* CEpoc_i */ l_current_data+=l_poc_room; - opj_write_bytes(l_current_data,l_current_poc->prg,1); /* Ppoc_i */ + opj_write_bytes(l_current_data, (OPJ_UINT32)l_current_poc->prg,1); /* Ppoc_i */ ++l_current_data; /* change the value of the max layer according to the actual number of layers in the file, components and resolutions*/ @@ -5371,7 +5371,7 @@ static OPJ_BOOL opj_j2k_write_mcc_record( opj_j2k_t *p_j2k, l_current_data+=l_nb_bytes_for_comp; } - l_tmcc = ((!p_mcc_record->m_is_irreversible)&1)<<16; + l_tmcc = ((!p_mcc_record->m_is_irreversible) & 1U) << 16; if (p_mcc_record->m_decorrelation_array) { l_tmcc |= p_mcc_record->m_decorrelation_array->m_index; diff --git a/src/lib/openjp2/raw.c b/src/lib/openjp2/raw.c index 2498761c..d3581d1a 100644 --- a/src/lib/openjp2/raw.c +++ b/src/lib/openjp2/raw.c @@ -88,7 +88,7 @@ OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) { } } raw->ct--; - d = (raw->c >> raw->ct) & 0x01; + d = ((OPJ_UINT32)raw->c >> raw->ct) & 0x01U; return d; }