diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-11-07 03:10:37 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2006-11-07 03:10:37 +0300 |
commit | 2ef6c48a65b61a07b86b1b79c8abd578701079c7 (patch) | |
tree | 0fb95727c1efb8c973dc8f38bf7b5e74aec51f6e /source/blender/imbuf | |
parent | b48c514db87d360ddfcadfcde582c0cae9344d6c (diff) |
Added two new blend modes to image painting brushes, erase alpha and
add alpha, for painting transparency in images. When using the eraser
tool of a tablet pen, the erase alpha blend mode is activated.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/rectop.c | 27 |
2 files changed, 23 insertions, 6 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 5eaac146c4e..79d2d148c19 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -227,6 +227,8 @@ typedef enum IMB_BlendMode { IMB_BLEND_MUL = 3, IMB_BLEND_LIGHTEN = 4, IMB_BLEND_DARKEN = 5, + IMB_BLEND_ERASE_ALPHA = 6, + IMB_BLEND_ADD_ALPHA = 7, IMB_BLEND_COPY = 1000, IMB_BLEND_COPY_RGB = 1001, diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index 1b8e64d6ff6..41183ce91da 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -117,7 +117,8 @@ static void blend_color_darken(char *cp, char *cp1, char *cp2, int fac) unsigned int IMB_blend_color(unsigned int src1, unsigned int src2, int fac, IMB_BlendMode mode) { - unsigned int dst, temp; + unsigned int dst; + int temp; char *cp, *cp1, *cp2; if (fac==0) @@ -141,11 +142,19 @@ unsigned int IMB_blend_color(unsigned int src1, unsigned int src2, int fac, IMB_ case IMB_BLEND_DARKEN: blend_color_darken(cp, cp1, cp2, fac); break; default: - return src1; + cp[0]= cp1[0]; + cp[1]= cp1[1]; + cp[2]= cp1[2]; } - temp= (cp1[3] + fac*cp2[3]/255); - cp[3]= (temp > 255)? 255: temp; + if (mode == IMB_BLEND_ERASE_ALPHA) { + temp= (cp1[3] - fac*cp2[3]/255); + cp[3]= (temp < 0)? 0: temp; + } + else { /* this does ADD_ALPHA also */ + temp= (cp1[3] + fac*cp2[3]/255); + cp[3]= (temp > 255)? 255: temp; + } return dst; } @@ -244,8 +253,14 @@ void IMB_blend_color_float(float *dst, float *src1, float *src2, float fac, IMB_ dst[2]= src1[2]; } - dst[3]= (src1[3] + fac*src2[3]); - if (dst[3] > 1.0f) dst[3] = 1.0f; + if (mode == IMB_BLEND_ERASE_ALPHA) { + dst[3]= (src1[3] - fac*src2[3]); + if (dst[3] < 0.0f) dst[3] = 0.0f; + } + else { /* this does ADD_ALPHA also */ + dst[3]= (src1[3] + fac*src2[3]); + if (dst[3] > 1.0f) dst[3] = 1.0f; + } } /* clipping */ |