diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-05-16 13:26:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-05-16 13:26:37 +0400 |
commit | e34a1fc1a5d856c42313b4e5e3be0308460b6d98 (patch) | |
tree | 4c1e0ce32c7db66c6355e02fd8efe32e58e4a7ca /source/blender/imbuf/intern/jp2.c | |
parent | a7e6d3872757780b3fce06ee9a238379cfce7ab0 (diff) |
style cleanup: imbuf
Diffstat (limited to 'source/blender/imbuf/intern/jp2.c')
-rw-r--r-- | source/blender/imbuf/intern/jp2.c | 494 |
1 files changed, 247 insertions, 247 deletions
diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index c71763b245d..4f71f296caa 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -40,7 +40,7 @@ #define JP2_FILEHEADER_SIZE 14 -static char JP2_HEAD[]= {0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A}; +static char JP2_HEAD[] = {0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A}; /* We only need this because of how the presets are set */ typedef struct img_folder { @@ -72,7 +72,7 @@ int imb_is_a_jp2(unsigned char *buf) */ static void error_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; + FILE *stream = (FILE *)client_data; fprintf(stream, "[ERROR] %s", msg); } /** @@ -80,7 +80,7 @@ static void error_callback(const char *msg, void *client_data) */ static void warning_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; + FILE *stream = (FILE *)client_data; fprintf(stream, "[WARNING] %s", msg); } /** @@ -99,21 +99,21 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) struct ImBuf *ibuf = NULL; int use_float = 0; /* for precision higher then 8 use float */ - long signed_offsets[4]= {0, 0, 0, 0}; - int float_divs[4]= {1, 1, 1, 1}; + long signed_offsets[4] = {0, 0, 0, 0}; + int float_divs[4] = {1, 1, 1, 1}; int index; int w, h, planes; - opj_dparameters_t parameters; /* decompression parameters */ + opj_dparameters_t parameters; /* decompression parameters */ - opj_event_mgr_t event_mgr; /* event manager */ + opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; int i; - opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ + opj_dinfo_t *dinfo = NULL; /* handle to a decompressor */ opj_cio_t *cio = NULL; if (check_jp2(mem) == 0) return(NULL); @@ -166,18 +166,18 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) h = image->comps[0].h; switch (image->numcomps) { - case 1: /* Greyscale */ - case 3: /* Color */ - planes= 24; - break; - default: /* 2 or 4 - Greyscale or Color + alpha */ - planes= 32; /* greyscale + alpha */ - break; + case 1: /* Greyscale */ + case 3: /* Color */ + planes = 24; + break; + default: /* 2 or 4 - Greyscale or Color + alpha */ + planes = 32; /* greyscale + alpha */ + break; } i = image->numcomps; - if (i>4) i= 4; + if (i > 4) i = 4; while (i) { i--; @@ -186,15 +186,15 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) use_float = 1; if (image->comps[i].sgnd) - signed_offsets[i]= 1 << (image->comps[i].prec - 1); + signed_offsets[i] = 1 << (image->comps[i].prec - 1); /* only needed for float images but dosnt hurt to calc this */ - float_divs[i]= (1<<image->comps[i].prec)-1; + float_divs[i] = (1 << image->comps[i].prec) - 1; } - ibuf= IMB_allocImBuf(w, h, planes, use_float ? IB_rectfloat : IB_rect); + ibuf = IMB_allocImBuf(w, h, planes, use_float ? IB_rectfloat : IB_rect); - if (ibuf==NULL) { + if (ibuf == NULL) { if (dinfo) opj_destroy_decompress(dinfo); return NULL; @@ -203,67 +203,67 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) ibuf->ftype = JP2; if (use_float) { - float *rect_float= ibuf->rect_float; + float *rect_float = ibuf->rect_float; if (image->numcomps < 3) { /* greyscale 12bits+ */ - for (i = 0; i < w * h; i++, rect_float+=4) { + for (i = 0; i < w * h; i++, rect_float += 4) { index = w * h - ((i) / (w) + 1) * w + (i) % (w); - rect_float[0]= rect_float[1]= rect_float[2]= (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0]; + rect_float[0] = rect_float[1] = rect_float[2] = (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0]; if (image->numcomps == 2) - rect_float[3]= (image->comps[1].data[index] + signed_offsets[1]) / float_divs[1]; + rect_float[3] = (image->comps[1].data[index] + signed_offsets[1]) / float_divs[1]; else - rect_float[3]= 1.0f; + rect_float[3] = 1.0f; } } else { /* rgb or rgba 12bits+ */ - for (i = 0; i < w * h; i++, rect_float+=4) { + for (i = 0; i < w * h; i++, rect_float += 4) { index = w * h - ((i) / (w) + 1) * w + (i) % (w); - rect_float[0]= (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0]; - rect_float[1]= (float)(image->comps[1].data[index] + signed_offsets[1]) / float_divs[1]; - rect_float[2]= (float)(image->comps[2].data[index] + signed_offsets[2]) / float_divs[2]; + rect_float[0] = (float)(image->comps[0].data[index] + signed_offsets[0]) / float_divs[0]; + rect_float[1] = (float)(image->comps[1].data[index] + signed_offsets[1]) / float_divs[1]; + rect_float[2] = (float)(image->comps[2].data[index] + signed_offsets[2]) / float_divs[2]; if (image->numcomps >= 4) - rect_float[3]= (float)(image->comps[3].data[index] + signed_offsets[3]) / float_divs[3]; + rect_float[3] = (float)(image->comps[3].data[index] + signed_offsets[3]) / float_divs[3]; else - rect_float[3]= 1.0f; + rect_float[3] = 1.0f; } } } else { - unsigned char *rect= (unsigned char *)ibuf->rect; + unsigned char *rect = (unsigned char *)ibuf->rect; if (image->numcomps < 3) { /* greyscale */ - for (i = 0; i < w * h; i++, rect+=4) { + for (i = 0; i < w * h; i++, rect += 4) { index = w * h - ((i) / (w) + 1) * w + (i) % (w); - rect[0]= rect[1]= rect[2]= (image->comps[0].data[index] + signed_offsets[0]); + rect[0] = rect[1] = rect[2] = (image->comps[0].data[index] + signed_offsets[0]); if (image->numcomps == 2) - rect[3]= image->comps[1].data[index] + signed_offsets[1]; + rect[3] = image->comps[1].data[index] + signed_offsets[1]; else - rect[3]= 255; + rect[3] = 255; } } else { /* 8bit rgb or rgba */ - for (i = 0; i < w * h; i++, rect+=4) { + for (i = 0; i < w * h; i++, rect += 4) { int index = w * h - ((i) / (w) + 1) * w + (i) % (w); - rect[0]= image->comps[0].data[index] + signed_offsets[0]; - rect[1]= image->comps[1].data[index] + signed_offsets[1]; - rect[2]= image->comps[2].data[index] + signed_offsets[2]; + rect[0] = image->comps[0].data[index] + signed_offsets[0]; + rect[1] = image->comps[1].data[index] + signed_offsets[1]; + rect[2] = image->comps[2].data[index] + signed_offsets[2]; if (image->numcomps >= 4) - rect[3]= image->comps[3].data[index] + signed_offsets[3]; + rect[3] = image->comps[3].data[index] + signed_offsets[3]; else - rect[3]= 255; + rect[3] = 255; } } } @@ -286,12 +286,12 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) //static opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp) { /* prec can be 8, 12, 16 */ -#define UPSAMPLE_8_TO_12(_val) ((_val<<4) | (_val & ((1<<4)-1))) -#define UPSAMPLE_8_TO_16(_val) ((_val<<8)+_val) +#define UPSAMPLE_8_TO_12(_val) ((_val << 4) | (_val & ((1 << 4) - 1))) +#define UPSAMPLE_8_TO_16(_val) ((_val << 8) + _val) -#define DOWNSAMPLE_FLOAT_TO_8BIT(_val) (_val)<=0.0f?0: ((_val)>=1.0f?255: (int)(255.0f*(_val))) -#define DOWNSAMPLE_FLOAT_TO_12BIT(_val) (_val)<=0.0f?0: ((_val)>=1.0f?4095: (int)(4095.0f*(_val))) -#define DOWNSAMPLE_FLOAT_TO_16BIT(_val) (_val)<=0.0f?0: ((_val)>=1.0f?65535: (int)(65535.0f*(_val))) +#define DOWNSAMPLE_FLOAT_TO_8BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 255 : (int)(255.0f * (_val))) +#define DOWNSAMPLE_FLOAT_TO_12BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 4095 : (int)(4095.0f * (_val))) +#define DOWNSAMPLE_FLOAT_TO_16BIT(_val) (_val) <= 0.0f ? 0 : ((_val) >= 1.0f ? 65535 : (int)(65535.0f * (_val))) /* @@ -304,10 +304,10 @@ struct ImBuf *imb_jp2_decode(unsigned char *mem, size_t size, int flags) /* ****************************** COPIED FROM image_to_j2k.c */ /* ----------------------------------------------------------------------- */ -#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/ -#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/ -#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ -#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ +#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/ +#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/ +#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ +#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ static int initialise_4K_poc(opj_poc_t *POC, int numres) @@ -316,11 +316,11 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres) POC[0].resno0 = 0; POC[0].compno0 = 0; POC[0].layno1 = 1; - POC[0].resno1 = numres-1; + POC[0].resno1 = numres - 1; POC[0].compno1 = 3; POC[0].prg1 = CPRL; POC[1].tile = 1; - POC[1].resno0 = numres-1; + POC[1].resno0 = numres - 1; POC[1].compno0 = 0; POC[1].layno1 = 1; POC[1].resno1 = numres; @@ -332,8 +332,8 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres) static void cinema_parameters(opj_cparameters_t *parameters) { parameters->tile_size_on = 0; /* FALSE */ - parameters->cp_tdx=1; - parameters->cp_tdy=1; + parameters->cp_tdx = 1; + parameters->cp_tdy = 1; /*Tile part*/ parameters->tp_flag = 'C'; @@ -356,7 +356,7 @@ static void cinema_parameters(opj_cparameters_t *parameters) /* No ROI */ parameters->roi_compno = -1; - parameters->subsampling_dx = 1; parameters->subsampling_dy = 1; + parameters->subsampling_dx = 1; parameters->subsampling_dy = 1; /* 9-7 transform */ parameters->irreversible = 1; @@ -369,93 +369,93 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima float temp_rate; switch (parameters->cp_cinema) { - case CINEMA2K_24: - case CINEMA2K_48: - if (parameters->numresolution > 6) { - parameters->numresolution = 6; - } - if (!((image->comps[0].w == 2048) || (image->comps[0].h == 1080))) { - fprintf(stdout, "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " - "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", - image->comps[0].w, image->comps[0].h); - parameters->cp_rsiz = STD_RSIZ; - } - break; + case CINEMA2K_24: + case CINEMA2K_48: + if (parameters->numresolution > 6) { + parameters->numresolution = 6; + } + if (!((image->comps[0].w == 2048) || (image->comps[0].h == 1080))) { + fprintf(stdout, "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " + "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", + image->comps[0].w, image->comps[0].h); + parameters->cp_rsiz = STD_RSIZ; + } + break; - case CINEMA4K_24: - if (parameters->numresolution < 1) { - parameters->numresolution = 1; - } - else if (parameters->numresolution > 7) { - parameters->numresolution = 7; - } - if (!((image->comps[0].w == 4096) || (image->comps[0].h == 2160))) { - fprintf(stdout, "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" - "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", - image->comps[0].w, image->comps[0].h); - parameters->cp_rsiz = STD_RSIZ; - } - parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution); - break; - case OFF: - /* do nothing */ - break; + case CINEMA4K_24: + if (parameters->numresolution < 1) { + parameters->numresolution = 1; + } + else if (parameters->numresolution > 7) { + parameters->numresolution = 7; + } + if (!((image->comps[0].w == 4096) || (image->comps[0].h == 2160))) { + fprintf(stdout, "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" + "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", + image->comps[0].w, image->comps[0].h); + parameters->cp_rsiz = STD_RSIZ; + } + parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution); + break; + case OFF: + /* do nothing */ + break; } switch (parameters->cp_cinema) { - case CINEMA2K_24: - case CINEMA4K_24: - for (i=0 ; i<parameters->tcp_numlayers ; i++) { - temp_rate = 0; - if (img_fol->rates[i]== 0) { - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - } - else { - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_24_CS ) { - parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + case CINEMA2K_24: + case CINEMA4K_24: + for (i = 0; i < parameters->tcp_numlayers; i++) { + temp_rate = 0; + if (img_fol->rates[i] == 0) { + parameters->tcp_rates[0] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) / + (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); } else { - parameters->tcp_rates[i]= img_fol->rates[i]; + temp_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) / + (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_24_CS) { + parameters->tcp_rates[i] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) / + (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + } + else { + parameters->tcp_rates[i] = img_fol->rates[i]; + } } } - } - parameters->max_comp_size = COMP_24_CS; - break; + parameters->max_comp_size = COMP_24_CS; + break; - case CINEMA2K_48: - for (i=0 ; i<parameters->tcp_numlayers ; i++) { - temp_rate = 0; - if (img_fol->rates[i]== 0) { - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - } - else { - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_48_CS ) { - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + case CINEMA2K_48: + for (i = 0; i < parameters->tcp_numlayers; i++) { + temp_rate = 0; + if (img_fol->rates[i] == 0) { + parameters->tcp_rates[0] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) / + (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); } else { - parameters->tcp_rates[i]= img_fol->rates[i]; + temp_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) / + (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_48_CS) { + parameters->tcp_rates[0] = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)) / + (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + } + else { + parameters->tcp_rates[i] = img_fol->rates[i]; + } } } - } - parameters->max_comp_size = COMP_48_CS; - break; - case OFF: - /* do nothing */ - break; + parameters->max_comp_size = COMP_48_CS; + break; + case OFF: + /* do nothing */ + break; } parameters->cp_disto_alloc = 1; } -static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) +static opj_image_t *ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) { unsigned char *rect; float *rect_float; @@ -467,51 +467,51 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) int i, numcomps, w, h, prec; int x, y, y_row; OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */ - opj_image_t * image = NULL; + opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */ + opj_image_t *image = NULL; img_fol_t img_fol; /* only needed for cinema presets */ memset(&img_fol, 0, sizeof(img_fol_t)); if (ibuf->ftype & JP2_CINE) { - if (ibuf->x==4096 || ibuf->y==2160) - parameters->cp_cinema= CINEMA4K_24; + if (ibuf->x == 4096 || ibuf->y == 2160) + parameters->cp_cinema = CINEMA4K_24; else { if (ibuf->ftype & JP2_CINE_48FPS) { - parameters->cp_cinema= CINEMA2K_48; + parameters->cp_cinema = CINEMA2K_48; } else { - parameters->cp_cinema= CINEMA2K_24; + parameters->cp_cinema = CINEMA2K_24; } } if (parameters->cp_cinema) { - img_fol.rates = (float*)MEM_mallocN(parameters->tcp_numlayers * sizeof(float), "jp2_rates"); - for (i=0; i< parameters->tcp_numlayers; i++) { + img_fol.rates = (float *)MEM_mallocN(parameters->tcp_numlayers * sizeof(float), "jp2_rates"); + for (i = 0; i < parameters->tcp_numlayers; i++) { img_fol.rates[i] = parameters->tcp_rates[i]; } cinema_parameters(parameters); } - color_space= CLRSPC_SYCC; - prec= 12; - numcomps= 3; + color_space = CLRSPC_SYCC; + prec = 12; + numcomps = 3; } else { /* Get settings from the imbuf */ color_space = (ibuf->ftype & JP2_YCC) ? CLRSPC_SYCC : CLRSPC_SRGB; - if (ibuf->ftype & JP2_16BIT) prec= 16; - else if (ibuf->ftype & JP2_12BIT) prec= 12; - else prec= 8; + if (ibuf->ftype & JP2_16BIT) prec = 16; + else if (ibuf->ftype & JP2_12BIT) prec = 12; + else prec = 8; /* 32bit images == alpha channel */ /* grayscale not supported yet */ - numcomps= (ibuf->planes==32) ? 4 : 3; + numcomps = (ibuf->planes == 32) ? 4 : 3; } - w= ibuf->x; - h= ibuf->y; + w = ibuf->x; + h = ibuf->y; /* initialize image components */ @@ -535,16 +535,16 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) /* set image offset and reference grid */ image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; + image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; + image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; /* set image data */ - rect = (unsigned char*) ibuf->rect; - rect_float= ibuf->rect_float; + rect = (unsigned char *) ibuf->rect; + rect_float = ibuf->rect_float; - if (rect_float && rect && prec==8) { + if (rect_float && rect && prec == 8) { /* No need to use the floating point buffer, just write the 8 bits from the char buffer */ - rect_float= NULL; + rect_float = NULL; } @@ -552,112 +552,112 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) float rgb[3]; switch (prec) { - case 8: /* Convert blenders float color channels to 8, 12 or 16bit ints */ - for (y=h-1; y>=0; y--) { - y_row = y*w; - for (x=0; x<w; x++, rect_float+=4) { - i = y_row + x; - - if (ibuf->profile == IB_PROFILE_LINEAR_RGB) - linearrgb_to_srgb_v3_v3(rgb, rect_float); - else - copy_v3_v3(rgb, rect_float); - - image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[0]); - image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[1]); - image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[2]); - if (numcomps>3) - image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]); + case 8: /* Convert blenders float color channels to 8, 12 or 16bit ints */ + for (y = h - 1; y >= 0; y--) { + y_row = y * w; + for (x = 0; x < w; x++, rect_float += 4) { + i = y_row + x; + + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) + linearrgb_to_srgb_v3_v3(rgb, rect_float); + else + copy_v3_v3(rgb, rect_float); + + image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[0]); + image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[1]); + image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rgb[2]); + if (numcomps > 3) + image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[3]); + } } - } - break; + break; - case 12: - for (y=h-1; y>=0; y--) { - y_row = y*w; - for (x=0; x<w; x++, rect_float+=4) { - i = y_row + x; - - if (ibuf->profile == IB_PROFILE_LINEAR_RGB) - linearrgb_to_srgb_v3_v3(rgb, rect_float); - else - copy_v3_v3(rgb, rect_float); - - image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[0]); - image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[1]); - image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[2]); - if (numcomps>3) - image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]); + case 12: + for (y = h - 1; y >= 0; y--) { + y_row = y * w; + for (x = 0; x < w; x++, rect_float += 4) { + i = y_row + x; + + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) + linearrgb_to_srgb_v3_v3(rgb, rect_float); + else + copy_v3_v3(rgb, rect_float); + + image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[0]); + image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[1]); + image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rgb[2]); + if (numcomps > 3) + image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[3]); + } } - } - break; - case 16: - for (y=h-1; y>=0; y--) { - y_row = y*w; - for (x=0; x<w; x++, rect_float+=4) { - i = y_row + x; - - if (ibuf->profile == IB_PROFILE_LINEAR_RGB) - linearrgb_to_srgb_v3_v3(rgb, rect_float); - else - copy_v3_v3(rgb, rect_float); - - image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[0]); - image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[1]); - image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[2]); - if (numcomps>3) - image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]); + break; + case 16: + for (y = h - 1; y >= 0; y--) { + y_row = y * w; + for (x = 0; x < w; x++, rect_float += 4) { + i = y_row + x; + + if (ibuf->profile == IB_PROFILE_LINEAR_RGB) + linearrgb_to_srgb_v3_v3(rgb, rect_float); + else + copy_v3_v3(rgb, rect_float); + + image->comps[0].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[0]); + image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[1]); + image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rgb[2]); + if (numcomps > 3) + image->comps[3].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[3]); + } } - } - break; + break; } } else { /* just use rect*/ switch (prec) { - case 8: - for (y=h-1; y>=0; y--) { - y_row = y*w; - for (x=0; x<w; x++, rect+=4) { - i = y_row + x; - - image->comps[0].data[i] = rect[0]; - image->comps[1].data[i] = rect[1]; - image->comps[2].data[i] = rect[2]; - if (numcomps>3) - image->comps[3].data[i] = rect[3]; + case 8: + for (y = h - 1; y >= 0; y--) { + y_row = y * w; + for (x = 0; x < w; x++, rect += 4) { + i = y_row + x; + + image->comps[0].data[i] = rect[0]; + image->comps[1].data[i] = rect[1]; + image->comps[2].data[i] = rect[2]; + if (numcomps > 3) + image->comps[3].data[i] = rect[3]; + } } - } - break; + break; - case 12: /* Up Sampling, a bit pointless but best write the bit depth requested */ - for (y=h-1; y>=0; y--) { - y_row = y*w; - for (x=0; x<w; x++, rect+=4) { - i = y_row + x; - - image->comps[0].data[i]= UPSAMPLE_8_TO_12(rect[0]); - image->comps[1].data[i]= UPSAMPLE_8_TO_12(rect[1]); - image->comps[2].data[i]= UPSAMPLE_8_TO_12(rect[2]); - if (numcomps>3) - image->comps[3].data[i]= UPSAMPLE_8_TO_12(rect[3]); + case 12: /* Up Sampling, a bit pointless but best write the bit depth requested */ + for (y = h - 1; y >= 0; y--) { + y_row = y * w; + for (x = 0; x < w; x++, rect += 4) { + i = y_row + x; + + image->comps[0].data[i] = UPSAMPLE_8_TO_12(rect[0]); + image->comps[1].data[i] = UPSAMPLE_8_TO_12(rect[1]); + image->comps[2].data[i] = UPSAMPLE_8_TO_12(rect[2]); + if (numcomps > 3) + image->comps[3].data[i] = UPSAMPLE_8_TO_12(rect[3]); + } } - } - break; - case 16: - for (y=h-1; y>=0; y--) { - y_row = y*w; - for (x=0; x<w; x++, rect+=4) { - i = y_row + x; - - image->comps[0].data[i]= UPSAMPLE_8_TO_16(rect[0]); - image->comps[1].data[i]= UPSAMPLE_8_TO_16(rect[1]); - image->comps[2].data[i]= UPSAMPLE_8_TO_16(rect[2]); - if (numcomps>3) - image->comps[3].data[i]= UPSAMPLE_8_TO_16(rect[3]); + break; + case 16: + for (y = h - 1; y >= 0; y--) { + y_row = y * w; + for (x = 0; x < w; x++, rect += 4) { + i = y_row + x; + + image->comps[0].data[i] = UPSAMPLE_8_TO_16(rect[0]); + image->comps[1].data[i] = UPSAMPLE_8_TO_16(rect[1]); + image->comps[2].data[i] = UPSAMPLE_8_TO_16(rect[2]); + if (numcomps > 3) + image->comps[3].data[i] = UPSAMPLE_8_TO_16(rect[3]); + } } - } - break; + break; } } @@ -681,8 +681,8 @@ int imb_savejp2(struct ImBuf *ibuf, const char *name, int flags) int quality = ibuf->ftype & 0xff; int bSuccess; - opj_cparameters_t parameters; /* compression parameters */ - opj_event_mgr_t event_mgr; /* event manager */ + opj_cparameters_t parameters; /* compression parameters */ + opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; (void)flags; /* unused */ @@ -702,22 +702,22 @@ int imb_savejp2(struct ImBuf *ibuf, const char *name, int flags) /* compression ratio */ /* invert range, from 10-100, 100-1 * where jpeg see's 1 and highest quality (lossless) and 100 is very low quality*/ - parameters.tcp_rates[0]= ((100-quality)/90.0f*99.0f) + 1; + parameters.tcp_rates[0] = ((100 - quality) / 90.0f * 99.0f) + 1; parameters.tcp_numlayers = 1; // only one resolution parameters.cp_disto_alloc = 1; - image= ibuftoimage(ibuf, ¶meters); + image = ibuftoimage(ibuf, ¶meters); - { /* JP2 format output */ + { /* JP2 format output */ int codestream_length; opj_cio_t *cio = NULL; FILE *f = NULL; /* get a JP2 compressor handle */ - opj_cinfo_t* cinfo = opj_create_compress(CODEC_JP2); + opj_cinfo_t *cinfo = opj_create_compress(CODEC_JP2); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr); |