[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57639] branches/soc-2013-paint/source/ blender: Applying patch by Fredrik Hansson: Extra blend modes.

Antony Riakiotakis kalast at gmail.com
Fri Jun 21 19:04:03 CEST 2013


Revision: 57639
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57639
Author:   psy-fi
Date:     2013-06-21 17:04:02 +0000 (Fri, 21 Jun 2013)
Log Message:
-----------
Applying patch by Fredrik Hansson: Extra blend modes.

Actually should be called the blend mode imperialism commit, this commit
adds no more no less about 15 new blend modes.

The catch is that the float versions will probably have to work in
display colour spaces, but seeing how the rest of the blending code is I
think this can go in right now.

Thanks to Fredrik for the original patch and to Campbell for writing
uncrustify. A solid weapon in the war against the non-blender-style-

To painters out there: Test this extensively!

Modified Paths:
--------------
    branches/soc-2013-paint/source/blender/blenlib/BLI_math_color_blend.h
    branches/soc-2013-paint/source/blender/blenlib/intern/math_color_blend_inline.c
    branches/soc-2013-paint/source/blender/imbuf/IMB_imbuf.h
    branches/soc-2013-paint/source/blender/imbuf/intern/rectop.c
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2013-paint/source/blender/blenlib/BLI_math_color_blend.h
===================================================================
--- branches/soc-2013-paint/source/blender/blenlib/BLI_math_color_blend.h	2013-06-21 14:26:33 UTC (rev 57638)
+++ branches/soc-2013-paint/source/blender/blenlib/BLI_math_color_blend.h	2013-06-21 17:04:02 UTC (rev 57639)
@@ -49,8 +49,27 @@
 MINLINE void blend_color_darken_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
 MINLINE void blend_color_erase_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
 MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
+
+MINLINE void blend_color_overlay_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_hardlight_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_burn_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_linearburn_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_dodge_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_screen_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_softlight_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_pinlight_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_linearlight_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_vividlight_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_difference_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_exclusion_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_color_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_hue_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_saturation_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+MINLINE void blend_color_luminosity_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4]);
+
 MINLINE void blend_color_interpolate_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4], float t);
 
+
 MINLINE void blend_color_mix_float(float dst[4], const float src1[4], const float src2[4]);
 MINLINE void blend_color_add_float(float dst[4], const float src1[4], const float src2[4]);
 MINLINE void blend_color_sub_float(float dst[4], const float src1[4], const float src2[4]);
@@ -59,6 +78,24 @@
 MINLINE void blend_color_darken_float(float dst[4], const float src1[4], const float src2[4]);
 MINLINE void blend_color_erase_alpha_float(float dst[4], const float src1[4], const float src2[4]);
 MINLINE void blend_color_add_alpha_float(float dst[4], const float src1[4], const float src2[4]);
+
+MINLINE void blend_color_overlay_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_hardlight_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_burn_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_linearburn_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_dodge_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_screen_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_softlight_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_pinlight_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_linearlight_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_vividlight_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_difference_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_exclusion_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_color_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_hue_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_saturation_float(float dst[4], const float src1[4], const float src2[2]);
+MINLINE void blend_color_luminosity_float(float dst[4], const float src1[4], const float src2[2]);
+
 MINLINE void blend_color_interpolate_float(float dst[4], const float src1[4], const float src2[4], float t);
 
 #if BLI_MATH_DO_INLINE

Modified: branches/soc-2013-paint/source/blender/blenlib/intern/math_color_blend_inline.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenlib/intern/math_color_blend_inline.c	2013-06-21 14:26:33 UTC (rev 57638)
+++ branches/soc-2013-paint/source/blender/blenlib/intern/math_color_blend_inline.c	2013-06-21 17:04:02 UTC (rev 57639)
@@ -242,6 +242,592 @@
 	}
 }
 
+MINLINE void blend_color_overlay_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4])
+{
+	const unsigned char fac = src2[3];
+	if (fac != 0) {
+		int temp;
+		int mfac = 255 - fac;
+		if (src1[0] > 127)
+			temp = 255 - ((255 - 2 * (src1[0] - 127)) * (255 - src2[0]) / 255);
+		else
+			temp = (2 * src1[0] * src2[0]) >> 8;
+		temp = (temp * fac + src1[0] * mfac) / 255;
+		if (temp < 255)
+			dst[0] = temp;
+		else
+			dst[0] = 255;
+		if (src1[1] > 127)
+			temp = 255 - ((255 - 2 * (src1[1] - 127)) * (255 - src2[1]) / 255);
+		else
+			temp = (2 * src1[1] * src2[1]) / 255;
+
+		temp = (temp * fac + src1[1] * mfac) / 255;
+		if (temp < 255)
+			dst[1] = temp;
+		else
+			dst[1] = 255;
+
+		if (src1[2] > 127)
+			temp = 255 - ((255 - 2 * (src1[2] - 127)) * (255 - src2[2]) / 255);
+		else
+			temp = (2 * src1[2] * src2[2]) / 255;
+
+		temp = (temp * fac + src1[2] * mfac) / 255;
+		if (temp < 255)
+			dst[2] = temp;
+		else
+			dst[2] = 255;
+	}
+	else {
+		/* no op */
+		dst[0] = src1[0];
+		dst[1] = src1[1];
+		dst[2] = src1[2];
+		dst[3] = src1[3];
+	}
+}
+
+
+MINLINE void blend_color_hardlight_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4])
+{
+	const unsigned char fac = src2[3];
+	if (fac != 0) {
+		int temp;
+		int mfac = 255 - fac;
+		if (src2[0] > 127)
+			temp = 255 - ((255 - 2 * (src2[0] - 127)) * (255 - src1[0]) / 255);
+		else
+			temp = (2 * src2[0] * src1[0]) >> 8;
+		temp = (temp * fac + src1[0] * mfac) / 255;
+		if (temp < 255) dst[0] = temp; else dst[0] = 255;
+
+
+		if (src2[1] > 127)
+			temp = 255 - ((255 - 2 * (src2[1] - 127)) * (255 - src1[1]) / 255);
+		else
+			temp = (2 * src2[1] * src1[1]) / 255;
+		temp = (temp * fac + src1[1] * mfac) / 255;
+		if (temp < 255) dst[1] = temp; else dst[1] = 255;
+
+
+		if (src2[2] > 127)
+			temp = 255 - ((255 - 2 * (src2[2] - 127)) * (255 - src1[2]) / 255);
+		else
+			temp = (2 * src2[2] * src1[2]) / 255;
+
+		temp = (temp * fac + src1[2] * mfac) / 255;
+		if (temp < 255) dst[2] = temp; else dst[2] = 255;
+	}
+	else {
+		/* no op */
+		dst[0] = src1[0];
+		dst[1] = src1[1];
+		dst[2] = src1[2];
+		dst[3] = src1[3];
+	}
+}
+
+
+MINLINE void blend_color_burn_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4])
+{
+	const unsigned char fac = src2[3];
+	if (fac != 0) {
+		int temp;
+		int mfac = 255 - fac;
+
+
+		if (src2[0] == 0)
+			temp = 0;
+		else
+			temp = 255 - ((255 - src1[0]) * 255) / src2[0];
+		if (temp < 0)
+			temp = 0;
+		dst[0] = (temp * fac + src1[0] * mfac) / 255;
+
+
+		if (src2[1] == 0)
+			temp = 0;
+		else
+			temp = 255 - ((255 - src1[1]) * 255) / src2[1];
+		if (temp < 0)
+			temp = 0;
+		dst[1] = (temp * fac + src1[1] * mfac) / 255;
+
+
+		if (src2[2] == 0)
+			temp = 0;
+		else
+			temp = 255 - ((255 - src1[2]) * 255) / src2[2];
+		if (temp < 0)
+			temp = 0;
+		dst[2] = (temp * fac + src1[2] * mfac) / 255;
+
+	}
+	else {
+		/* no op */
+		dst[0] = src1[0];
+		dst[1] = src1[1];
+		dst[2] = src1[2];
+		dst[3] = src1[3];
+	}
+}
+
+
+MINLINE void blend_color_linearburn_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4])
+{
+	const unsigned char fac = src2[3];
+	if (fac != 0) {
+		int temp;
+		int mfac = 255 - fac;
+
+		temp = src1[0] + src2[0] - 255;
+		if (temp < 0) temp = 0;
+		dst[0] = (temp * fac + src1[0] * mfac) / 255;
+
+		temp = src1[1] + src2[1] - 255;
+		if (temp < 0) temp = 0;
+		dst[1] = (temp * fac + src1[1] * mfac) / 255;
+
+		temp = src1[2] + src2[2] - 255;
+		if (temp < 0) temp = 0;
+		dst[2] = (temp * fac + src1[2] * mfac) / 255;
+	}
+	else {
+		/* no op */
+		dst[0] = src1[0];
+		dst[1] = src1[1];
+		dst[2] = src1[2];
+		dst[3] = src1[3];
+	}
+}
+
+
+MINLINE void blend_color_dodge_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4])
+{
+	const unsigned char fac = src2[3];
+	if (fac != 0) {
+		int temp;
+		int mfac = 255 - fac;
+
+		if (src2[0] == 255) temp = 255;
+		else temp = (src1[0] * 255) / (255 - src2[0]);
+		if (temp > 255) temp = 255;
+		dst[0] = (temp * fac + src1[0] * mfac) / 255;
+
+		if (src2[1] == 255) temp = 255;
+		else temp = (src1[1] * 255) / (255 - src2[1]);
+		if (temp > 255) temp = 255;
+		dst[1] = (temp * fac + src1[1] * mfac) / 255;
+
+		if (src2[2] == 255) temp = 255;
+		else temp = (src1[2] * 255) / (255 - src2[2]);
+		if (temp > 255) temp = 255;
+		dst[2] = (temp * fac + src1[2] * mfac) / 255;
+	}
+	else {
+		/* no op */
+		dst[0] = src1[0];
+		dst[1] = src1[1];
+		dst[2] = src1[2];
+		dst[3] = src1[3];
+	}
+}
+
+MINLINE void blend_color_screen_byte(unsigned char dst[4], unsigned const char src1[4], unsigned const char src2[4])
+{
+	const unsigned char fac = src2[3];
+	if (fac != 0) {
+		int temp;
+		int mfac = 255 - fac;
+
+		temp = 255 - (((255 - src1[0]) * (255 - src2[0])) / 255);
+		if (temp < 0) temp = 0;
+		dst[0] = (temp * fac + src1[0] * mfac) / 255;
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list