[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54937] trunk/blender/source/blender/imbuf /intern: Changed a way how RGB images are saving from RGBA

Sergey Sharybin sergey.vfx at gmail.com
Thu Feb 28 15:25:26 CET 2013


Revision: 54937
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54937
Author:   nazgul
Date:     2013-02-28 14:25:26 +0000 (Thu, 28 Feb 2013)
Log Message:
-----------
Changed a way how RGB images are saving from RGBA

Before alpha channel was simply ignored causing bad looking
straight colors which is pretty much useless.

Now saving RGB would alpha-over image on top of black color,
which makes final image look really nice. It's also very
such the same what other graphics software does this.

In the future we could easily support configurable backdrop
color, which would be really the same as other SW does it.

Also, it'll probably worth adding the same mode to RGB
display of image editor.

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

Modified: trunk/blender/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/colormanagement.c	2013-02-28 14:25:18 UTC (rev 54936)
+++ trunk/blender/source/blender/imbuf/intern/colormanagement.c	2013-02-28 14:25:26 UTC (rev 54937)
@@ -1702,13 +1702,11 @@
 	int do_colormanagement;
 	int is_movie = BKE_imtype_is_movie(image_format_data->imtype);
 	int requires_linear_float = BKE_imtype_requires_linear_float(image_format_data->imtype);
+	int do_alpha_under = image_format_data->planes != R_IMF_PLANES_RGBA;
 
 	do_colormanagement = save_as_render && (is_movie || !requires_linear_float);
 
-	if (do_colormanagement) {
-		int make_byte = FALSE;
-		ImFileType *type;
-
+	if (do_colormanagement || do_alpha_under) {
 		if (allocate_result) {
 			colormanaged_ibuf = IMB_dupImBuf(ibuf);
 		}
@@ -1727,7 +1725,42 @@
 				ibuf->mall |= IB_rectfloat;
 			}
 		}
+	}
 
+	/* If we're saving from RGBA to RGB buffer then it's not
+	 * so much useful to just ignore alpha -- it leads to bad
+	 * artifacts especially when saving byte images.
+	 *
+	 * What we do here is we're overing our image on top of
+	 * background color (which is currently black).
+	 *
+	 * This is quite much the same as what Gimp does and it
+	 * seems to be what artists expects from saving.
+	 *
+	 * Do a conversion here, so image format writers could
+	 * happily assume all the alpha tricks were made already.
+	 * helps keep things locally here, not spreading it to
+	 * all possible image writers we've got.
+	 */
+	if (do_alpha_under) {
+		float color[3] = {0, 0, 0};
+
+		if (colormanaged_ibuf->rect_float && colormanaged_ibuf->channels == 4) {
+			IMB_alpha_under_color_float(colormanaged_ibuf->rect_float, colormanaged_ibuf->x,
+			                            colormanaged_ibuf->y, color);
+		}
+
+		if (colormanaged_ibuf->rect) {
+			IMB_alpha_under_color_byte((unsigned char *)colormanaged_ibuf->rect,
+			                           colormanaged_ibuf->x, colormanaged_ibuf->y,
+			                           color);
+		}
+	}
+
+	if (do_colormanagement) {
+		int make_byte = FALSE;
+		ImFileType *type;
+
 		/* for proper check whether byte buffer is required by a format or not
 		 * should be pretty safe since this image buffer is supposed to be used for
 		 * saving only and ftype would be overwritten a bit later by BKE_imbuf_write

Modified: trunk/blender/source/blender/imbuf/intern/imageprocess.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imageprocess.c	2013-02-28 14:25:18 UTC (rev 54936)
+++ trunk/blender/source/blender/imbuf/intern/imageprocess.c	2013-02-28 14:25:26 UTC (rev 54937)
@@ -367,9 +367,9 @@
 		else {
 			int mul = 255 - cp[3];
 
-			cp[0] += mul * backcol[0] / 255;
-			cp[1] += mul * backcol[1] / 255;
-			cp[2] += mul * backcol[2] / 255;
+			cp[0] = (cp[0] * cp[3] >> 8) + mul * backcol[0] / 255;
+			cp[1] = (cp[1] * cp[3] >> 8) + mul * backcol[1] / 255;
+			cp[2] = (cp[2] * cp[3] >> 8) + mul * backcol[2] / 255;
 		}
 
 		cp[3] = 255;




More information about the Bf-blender-cvs mailing list