Fix [#22304] Tiff 16bit gives darker images

Also fixed similar issue for jpeg2000
This commit is contained in:
Matt Ebb
2010-05-18 07:28:44 +00:00
parent cf4f5c4497
commit e3587f9e9f
3 changed files with 47 additions and 13 deletions

View File

@@ -105,6 +105,7 @@
#define AVG2(x, y) ( 0.5 * ((x) + (y)) )
#define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 : (char)((255.0f*(val))+0.5f))
#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f))
#define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);}
#define VECCOPY2D(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1);}

View File

@@ -24,6 +24,7 @@
#ifdef WITH_OPENJPEG
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "imbuf.h"
@@ -532,16 +533,23 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
if (rect_float) {
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(rect_float[0]);
image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[1]);
image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_8BIT(rect_float[2]);
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]);
}
@@ -553,10 +561,15 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
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(rect_float[0]);
image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[1]);
image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_12BIT(rect_float[2]);
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]);
}
@@ -567,10 +580,15 @@ static opj_image_t* ibuftoimage(ImBuf *ibuf, opj_cparameters_t *parameters) {
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(rect_float[0]);
image->comps[1].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[1]);
image->comps[2].data[i] = DOWNSAMPLE_FLOAT_TO_16BIT(rect_float[2]);
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]);
}

View File

@@ -45,7 +45,9 @@
#include "imbuf.h"
#include "BKE_global.h"
#include "BKE_utildefines.h"
#include "BLI_math.h"
#include "BLI_string.h"
#include "IMB_imbuf_types.h"
@@ -501,8 +503,6 @@ void imb_loadtiletiff(ImBuf *ibuf, unsigned char *mem, int size, int tx, int ty,
* @return: 1 if the function is successful, 0 on failure.
*/
#define FTOUSHORT(val) ((val >= 1.0f-0.5f/65535)? 65535: (val <= 0.0f)? 0: (unsigned short)(val*65535.0f + 0.5f))
int imb_savetiff(ImBuf *ibuf, char *name, int flags)
{
TIFF *image = NULL;
@@ -609,8 +609,23 @@ int imb_savetiff(ImBuf *ibuf, char *name, int flags)
to_i = samplesperpixel*((ibuf->y-y-1)*ibuf->x+x);
if(pixels16) {
for(i = 0; i < samplesperpixel; i++, to_i++, from_i++)
to16[to_i] = FTOUSHORT(fromf[from_i]);
/* convert from float source */
float rgb[3];
if (ibuf->profile == IB_PROFILE_LINEAR_RGB)
linearrgb_to_srgb_v3_v3(rgb, &fromf[from_i]);
else
copy_v3_v3(rgb, &fromf[from_i]);
to16[to_i+0] = FTOUSHORT(rgb[0]);
to16[to_i+1] = FTOUSHORT(rgb[1]);
to16[to_i+2] = FTOUSHORT(rgb[2]);
to_i += 3; from_i+=3;
if (samplesperpixel == 4) {
to16[to_i+3] = FTOUSHORT(fromf[from_i+3]);
to_i++; from_i++;
}
}
else {
for(i = 0; i < samplesperpixel; i++, to_i++, from_i++)