[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53807] trunk/blender/source/blender/imbuf /intern/png.c: fix [#33781] Confusing units in displacement modifier parameters

Campbell Barton ideasman42 at gmail.com
Tue Jan 15 09:10:06 CET 2013


Revision: 53807
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53807
Author:   campbellbarton
Date:     2013-01-15 08:10:02 +0000 (Tue, 15 Jan 2013)
Log Message:
-----------
fix [#33781] Confusing units in displacement modifier parameters

16bit PNG images were not doing any conversions when saving linear float buffers, but would always load them as SRGB.
apply the same method used for 16bit images from floats as used in jpeg2000.

Modified Paths:
--------------
    trunk/blender/source/blender/imbuf/intern/png.c

Modified: trunk/blender/source/blender/imbuf/intern/png.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/png.c	2013-01-15 07:56:50 UTC (rev 53806)
+++ trunk/blender/source/blender/imbuf/intern/png.c	2013-01-15 08:10:02 UTC (rev 53807)
@@ -107,6 +107,17 @@
 	longjmp(png_jmpbuf(png_ptr), 1);
 }
 
+static float channel_colormanage_noop(float value)
+{
+	return value;
+}
+
+/* wrap to avoid macro calling functions multiple times */
+BLI_INLINE unsigned short ftoshort(float val)
+{
+	return FTOUSHORT(val);
+}
+
 int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
 {
 	png_structp png_ptr;
@@ -123,11 +134,22 @@
 	bool is_16bit  = (ibuf->ftype & PNG_16BIT);
 	bool has_float = (ibuf->rect_float != NULL);
 
+	float (*chanel_colormanage_cb)(float);
+
 	/* use the jpeg quality setting for compression */
 	int compression;
 	compression = (int)(((float)(ibuf->ftype & 0xff) / 11.1111f));
 	compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression);
 
+	if (ibuf->float_colorspace) {
+		/* float buffer was managed already, no need in color space conversion */
+		chanel_colormanage_cb = channel_colormanage_noop;
+	}
+	else {
+		/* standard linear-to-srgb conversion if float buffer wasn't managed */
+		chanel_colormanage_cb = linearrgb_to_srgb;
+	}
+
 	/* for prints */
 	if (flags & IB_mem)
 		name = "<memory>";
@@ -183,10 +205,10 @@
 				if (has_float) {
 					for (i = ibuf->x * ibuf->y; i > 0; i--) {
 						premul_to_straight_v4(from_straight, from_float);
-						to16[0] = FTOUSHORT(from_straight[0]);
-						to16[1] = FTOUSHORT(from_straight[1]);
-						to16[2] = FTOUSHORT(from_straight[2]);
-						to16[3] = FTOUSHORT(from_straight[3]);
+						to16[0] = ftoshort(chanel_colormanage_cb(from_straight[0]));
+						to16[1] = ftoshort(chanel_colormanage_cb(from_straight[1]));
+						to16[2] = ftoshort(chanel_colormanage_cb(from_straight[2]));
+						to16[3] = ftoshort(chanel_colormanage_cb(from_straight[3]));
 						to16 += 4; from_float += 4;
 					}
 				}
@@ -216,9 +238,9 @@
 				if (has_float) {
 					for (i = ibuf->x * ibuf->y; i > 0; i--) {
 						premul_to_straight_v4(from_straight, from_float);
-						to16[0] = FTOUSHORT(from_straight[0]);
-						to16[1] = FTOUSHORT(from_straight[1]);
-						to16[2] = FTOUSHORT(from_straight[2]);
+						to16[0] = ftoshort(chanel_colormanage_cb(from_straight[0]));
+						to16[1] = ftoshort(chanel_colormanage_cb(from_straight[1]));
+						to16[2] = ftoshort(chanel_colormanage_cb(from_straight[2]));
 						to16 += 3; from_float += 4;
 					}
 				}
@@ -246,7 +268,7 @@
 				if (has_float) {
 					for (i = ibuf->x * ibuf->y; i > 0; i--) {
 						premul_to_straight_v4(from_straight, from_float);
-						to16[0] = FTOUSHORT(from_straight[0]);
+						to16[0] = ftoshort(chanel_colormanage_cb(from_straight[0]));
 						to16++; from_float += 4;
 					}
 				}




More information about the Bf-blender-cvs mailing list