Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-04-27 16:51:23 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-04-27 16:51:23 +0400
commit8f9150871c5f41df948d523c51ed04fc689eaf07 (patch)
tree4b55ddd5dee285d7c6f9fa56be6a15e2a3eea007 /source/blender/blenlib/BLI_math_color_blend.h
parenta5806778012e3baee8ac2ba48c8dbed8b57f3947 (diff)
Fix part of #34233: bad alpha blending for 2D image painting. This is a very
old issue, the formulas here were never quite right, should all work ok now with byte and float images. Some differences: * Colors with zero alpha from the background will never have an influence, so you don't get alpha fringes when painting over such areas. This does give hard edges when looking at the RGB channels alone, but there's no way to avoid that and fringes at the same time, same behavior as other painting apps. * Add/Subtract/Multiply/Lighten/Darken now leave the alpha channel unchanged and work only the RGB channels, again same behavior as many other apps. * Erase/Add alpha now compensates for premultiplied float images to keep the straight RGB colors the same. Next: fix projection painting.
Diffstat (limited to 'source/blender/blenlib/BLI_math_color_blend.h')
-rw-r--r--source/blender/blenlib/BLI_math_color_blend.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_color_blend.h b/source/blender/blenlib/BLI_math_color_blend.h
new file mode 100644
index 00000000000..a54bacf8714
--- /dev/null
+++ b/source/blender/blenlib/BLI_math_color_blend.h
@@ -0,0 +1,71 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: some of this file.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * */
+
+#ifndef __BLI_MATH_COLOR_BLEND_H__
+#define __BLI_MATH_COLOR_BLEND_H__
+
+/** \file BLI_math_color.h
+ * \ingroup bli
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "BLI_math_inline.h"
+
+/******************** Blending Modes **********************
+ * - byte function assume straight alpha
+ * - float functions assume premultiplied alpha
+ */
+
+MINLINE void blend_color_mix_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
+MINLINE void blend_color_add_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
+MINLINE void blend_color_sub_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
+MINLINE void blend_color_mul_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
+MINLINE void blend_color_lighten_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4]);
+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_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]);
+MINLINE void blend_color_mul_float(float dst[4], const float src1[4], const float src2[4]);
+MINLINE void blend_color_lighten_float(float dst[4], const float src1[4], const float src2[4]);
+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]);
+
+#if BLI_MATH_DO_INLINE
+#include "intern/math_color_blend_inline.c"
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BLI_MATH_COLOR_BLEND_H__ */
+