[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28815] trunk/blender/source/blender: Fix [#22304] Tiff 16bit gives darker images

Matt Ebb matt at mke3.net
Tue May 18 09:28:47 CEST 2010


Revision: 28815
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28815
Author:   broken
Date:     2010-05-18 09:28:44 +0200 (Tue, 18 May 2010)

Log Message:
-----------
Fix [#22304] Tiff 16bit gives darker images

Also fixed similar issue for jpeg2000

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_utildefines.h
    trunk/blender/source/blender/imbuf/intern/jp2.c
    trunk/blender/source/blender/imbuf/intern/tiff.c

Modified: trunk/blender/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_utildefines.h	2010-05-18 05:40:30 UTC (rev 28814)
+++ trunk/blender/source/blender/blenkernel/BKE_utildefines.h	2010-05-18 07:28:44 UTC (rev 28815)
@@ -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);}

Modified: trunk/blender/source/blender/imbuf/intern/jp2.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/jp2.c	2010-05-18 05:40:30 UTC (rev 28814)
+++ trunk/blender/source/blender/imbuf/intern/jp2.c	2010-05-18 07:28:44 UTC (rev 28815)
@@ -24,6 +24,7 @@
 #ifdef WITH_OPENJPEG
 
 #include "BLI_blenlib.h"
+#include "BLI_math.h"
 
 #include "imbuf.h"
 
@@ -532,16 +533,23 @@
 	
 	
 	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 @@
 				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 @@
 				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]);
 				}

Modified: trunk/blender/source/blender/imbuf/intern/tiff.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/tiff.c	2010-05-18 05:40:30 UTC (rev 28814)
+++ trunk/blender/source/blender/imbuf/intern/tiff.c	2010-05-18 07:28:44 UTC (rev 28815)
@@ -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 @@
  * @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 @@
 			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++)





More information about the Bf-blender-cvs mailing list