[Bf-blender-cvs] [b72aff483fb] soc-2017-vertex_paint: added Color Dodge, Difference, Screen, Hardlight, Overlay blend modes

Darshan Kadu noreply at git.blender.org
Sat Jun 3 10:24:35 CEST 2017


Commit: b72aff483fbe6ce84dab9b5a23f6ca6f0c96988c
Author: Darshan Kadu
Date:   Sat Jun 3 10:21:09 2017 +0530
Branches: soc-2017-vertex_paint
https://developer.blender.org/rBb72aff483fbe6ce84dab9b5a23f6ca6f0c96988c

added Color Dodge, Difference, Screen, Hardlight, Overlay blend modes

===================================================================

M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index f647015e41e..bc1092bef13 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -736,6 +736,143 @@ BLI_INLINE unsigned int mcol_darken(unsigned int col1, unsigned int col2, int fa
 	return col;
 }
 
+BLI_INLINE unsigned int mcol_colordodge(unsigned int col1, unsigned int col2, int fac)
+{
+	unsigned char *cp1, *cp2, *cp;
+	int mfac,temp;
+	unsigned int col = 0;
+
+	if (fac == 0) {
+		return col1;
+	}
+
+	mfac = 255 - fac;
+
+	cp1 = (unsigned char *)&col1;
+	cp2 = (unsigned char *)&col2;
+	cp = (unsigned char *)&col;
+
+	temp = (cp2[0] == 255) ? 255 : min_ii((cp1[0] * 225) / (255 - cp2[0]), 255);
+	cp[0] = (mfac * cp1[0] + temp * fac) / 255;
+	temp = (cp2[1] == 255) ? 255 : min_ii((cp1[1] * 225) / (255 - cp2[1]), 255);
+	cp[1] = (mfac * cp1[1] + temp * fac) / 255;
+	temp = (cp2[2] == 255) ? 255 : min_ii((cp1[2] * 225 )/ (255 - cp2[2]), 255);
+	cp[2] = (mfac * cp1[2] + temp * fac) / 255;
+	return col;
+}
+
+BLI_INLINE unsigned int mcol_difference(unsigned int col1, unsigned int col2, int fac)
+{
+	unsigned char *cp1, *cp2, *cp;
+	int mfac, temp;
+	unsigned int col = 0;
+
+	if (fac == 0) {
+		return col1;
+	}
+
+	mfac = 255 - fac;
+
+	cp1 = (unsigned char *)&col1;
+	cp2 = (unsigned char *)&col2;
+	cp = (unsigned char *)&col;
+
+	temp = abs(cp1[0] - cp2[0]);
+	cp[0] = (mfac * cp1[0] + temp * fac) / 255;
+	temp = abs(cp1[0] - cp2[0]);
+	cp[1] = (mfac * cp1[1] + temp * fac) / 255;
+	temp = abs(cp1[2] - cp2[2]);
+	cp[2] = (mfac * cp1[2] + temp * fac) / 255;
+	return col;
+}
+
+BLI_INLINE unsigned int mcol_screen(unsigned int col1, unsigned int col2, int fac)
+{
+	unsigned char *cp1, *cp2, *cp;
+	int mfac, temp;
+	unsigned int col = 0;
+
+	if (fac == 0) {
+		return col1;
+	}
+
+	mfac = 255 - fac;
+
+	cp1 = (unsigned char *)&col1;
+	cp2 = (unsigned char *)&col2;
+	cp = (unsigned char *)&col;
+
+	temp = max_ii(255 - (((255 - cp1[0]) * (255 - cp2[0])) / 255), 0);
+	cp[0] = (mfac * cp1[0] + temp * fac) / 255;
+	temp = max_ii(255 - (((255 - cp1[1]) * (255 - cp2[1])) / 255), 0);
+	cp[1] = (mfac * cp1[1] + temp * fac) / 255;
+	temp = max_ii(255 - (((255 - cp1[2]) * (255 - cp2[2])) / 255), 0);
+	cp[2] = (mfac * cp1[2] + temp * fac) / 255;
+	return col;
+}
+
+BLI_INLINE unsigned int mcol_hardlight(unsigned int col1, unsigned int col2, int fac)
+{
+	unsigned char *cp1, *cp2, *cp;
+	int mfac, temp;
+	unsigned int col = 0;
+
+	if (fac == 0) {
+		return col1;
+	}
+
+	mfac = 255 - fac;
+
+	cp1 = (unsigned char *)&col1;
+	cp2 = (unsigned char *)&col2;
+	cp = (unsigned char *)&col;
+
+	int i = 0;
+
+	for (i = 0; i < 3; i++) {
+		
+		if (cp2[i] > 127) {
+			temp = 255 - ((255 - 2 * (cp2[i] - 127)) * (255 - cp1[i]) / 255);
+		}
+		else {
+			temp = (2 * cp2[i] * cp1[i]) >> 8;
+		}
+		cp[i] = min_ii((mfac * cp1[i] + temp * fac) / 255, 255);
+	}
+	return col;
+}
+
+BLI_INLINE unsigned int mcol_overlay(unsigned int col1, unsigned int col2, int fac)
+{
+	unsigned char *cp1, *cp2, *cp;
+	int mfac, temp;
+	unsigned int col = 0;
+
+	if (fac == 0) {
+		return col1;
+	}
+
+	mfac = 255 - fac;
+
+	cp1 = (unsigned char *)&col1;
+	cp2 = (unsigned char *)&col2;
+	cp = (unsigned char *)&col;
+
+	int i = 0;
+
+	for (i = 0; i < 3; i++) {
+
+		if (cp1[i] > 127) {
+			temp = 255 - ((255 - 2 * (cp1[i] - 127)) * (255 - cp2[i]) / 255);
+		}
+		else {
+			temp = (2 * cp2[i] * cp1[i]) >> 8;
+		}
+		cp[i] = min_ii((mfac * cp1[i] + temp * fac) / 255, 255);
+	}
+	return col;
+}
+
 /* wpaint has 'wpaint_blend_tool' */
 static unsigned int vpaint_blend_tool(const int tool, const unsigned int col,
                                       const unsigned int paintcol, const int alpha_i)
@@ -750,6 +887,11 @@ static unsigned int vpaint_blend_tool(const int tool, const unsigned int col,
 		case PAINT_BLEND_MUL:      return mcol_mul(col, paintcol, alpha_i);
 		case PAINT_BLEND_LIGHTEN:  return mcol_lighten(col, paintcol, alpha_i);
 		case PAINT_BLEND_DARKEN:   return mcol_darken(col, paintcol, alpha_i);
+		case PAINT_BLEND_COLORDODGE: return mcol_colordodge(col, paintcol, alpha_i);
+		case PAINT_BLEND_DIFFERENCE: return mcol_difference(col, paintcol, alpha_i);
+		case PAINT_BLEND_SCREEN:   return mcol_screen(col, paintcol, alpha_i);
+		case PAINT_BLEND_HARDLIGHT: return mcol_hardlight(col, paintcol, alpha_i);
+		case PAINT_BLEND_OVERLAY: return mcol_overlay(col, paintcol, alpha_i);
 		default:
 			BLI_assert(0);
 			return 0;
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index de85ca13f35..62f95c97f2f 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -318,6 +318,11 @@ enum {
 	PAINT_BLEND_DARKEN = 6,
 	PAINT_BLEND_AVERAGE = 7,
 	PAINT_BLEND_SMEAR = 8,
+	PAINT_BLEND_COLORDODGE = 9,
+	PAINT_BLEND_DIFFERENCE = 10,
+	PAINT_BLEND_SCREEN = 11,
+	PAINT_BLEND_HARDLIGHT = 12,
+	PAINT_BLEND_OVERLAY = 13
 };
 
 typedef enum {
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 7b3636f1615..998d8f656ae 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -94,8 +94,13 @@ EnumPropertyItem rna_enum_brush_vertex_tool_items[] = {
 	{PAINT_BLEND_BLUR, "BLUR", ICON_BRUSH_BLUR, "Blur", "Blur the color with surrounding values"},
 	{PAINT_BLEND_LIGHTEN, "LIGHTEN", ICON_BRUSH_LIGHTEN, "Lighten", "Use lighten blending mode while painting"},
 	{PAINT_BLEND_DARKEN, "DARKEN", ICON_BRUSH_DARKEN, "Darken", "Use darken blending mode while painting"},
-	{PAINT_BLEND_AVERAGE, "AVERAGE", ICON_BRUSH_BLUR, "Average", "Use average blending mode while painting" },
-	{PAINT_BLEND_SMEAR, "SMEAR", ICON_BRUSH_BLUR, "Smear", "Use smear blending mode while painting" },
+	{PAINT_BLEND_AVERAGE, "AVERAGE", ICON_BRUSH_BLUR, "Average", "Use average blending mode while painting"},
+	{PAINT_BLEND_SMEAR, "SMEAR", ICON_BRUSH_BLUR, "Smear", "Use smear blending mode while painting"},
+	{PAINT_BLEND_COLORDODGE, "COLORDODGE", ICON_BRUSH_BLUR, "Color Dodge", "Use color dodge blending mode while painting" },
+	{PAINT_BLEND_DIFFERENCE, "DIFFERENCE", ICON_BRUSH_BLUR, "Difference", "Use difference blending mode while painting"},
+	{PAINT_BLEND_SCREEN, "SCREEN", ICON_BRUSH_BLUR, "Screen", "Use screen blending mode while painting"},
+	{PAINT_BLEND_HARDLIGHT, "HARDLIGHT", ICON_BRUSH_BLUR, "Hardlight", "Use hardlight blending mode while painting"},
+	{PAINT_BLEND_OVERLAY, "OVERLAY", ICON_BRUSH_BLUR, "Overlay", "Use overlay blending mode while painting"},
 	{0, NULL, 0, NULL, NULL}
 };




More information about the Bf-blender-cvs mailing list