diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-03-09 00:35:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-03-09 00:35:38 +0300 |
commit | 027277fce0565f8518cf1fc3a0b3b34b8d0b3cda (patch) | |
tree | 3af487d383f8d3c653ac680bcb5b13a211579553 /source/blender/imbuf | |
parent | d7ef04a51939c49c32c0d82b0c53bd71788e760f (diff) |
* Bakeing fix for apricot, stop pixels being extended for parts of the image that are not being baked (useful for multiple objects)
* Added support for baking alpha, as well as extending alpha margins.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_imbuf_types.h | 2 | ||||
-rw-r--r-- | source/blender/imbuf/intern/filter.c | 28 |
3 files changed, 18 insertions, 14 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index dbbddd2a070..7cbdfbe32d1 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -321,7 +321,7 @@ void IMB_antialias(struct ImBuf * ibuf); */ void IMB_filter(struct ImBuf *ibuf); void IMB_filterN(struct ImBuf *out, struct ImBuf *in); -void IMB_filter_extend(struct ImBuf *ibuf); +void IMB_filter_extend(struct ImBuf *ibuf, char *mask); void IMB_makemipmap(struct ImBuf *ibuf, int use_filter); /** diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h index 91ffa188fcc..8a642a79889 100644 --- a/source/blender/imbuf/IMB_imbuf_types.h +++ b/source/blender/imbuf/IMB_imbuf_types.h @@ -95,7 +95,7 @@ typedef struct ImBuf { int userflags; /**< Used to set imbuf to Dirty and other stuff */ int *zbuf; /**< z buffer data, original zbuffer */ float *zbuf_float; /**< z buffer data, camera coordinates */ - void *userdata; + void *userdata; /**< temporary storage, only used by baking at the moment */ unsigned char *encodedbuffer; /**< Compressed image only used with png currently */ unsigned int encodedsize; /**< Size of data written to encodedbuffer */ unsigned int encodedbuffersize; /**< Size of encodedbuffer */ diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 156e26fd5d6..1be5cf99e19 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -240,13 +240,16 @@ void IMB_filter(struct ImBuf *ibuf) imb_filterx(ibuf); } -#define EXTEND_PIXEL(a, w) if((a)[3]) {r+= w*(a)[0]; g+= w*(a)[1]; b+= w*(a)[2]; tot+=w;} +#define EXTEND_PIXEL(color, w) if((color)[3]) {r+= w*(color)[0]; g+= w*(color)[1]; b+= w*(color)[2]; a+= w*(color)[3]; tot+=w;} -/* if alpha is zero, it checks surrounding pixels and averages color. sets new alphas to 1.0 */ -void IMB_filter_extend(struct ImBuf *ibuf) +/* if alpha is zero, it checks surrounding pixels and averages color. sets new alphas to 1.0 + * + * When a mask is given, only effect pixels with a mask value of 1, defined as BAKE_MASK_MARGIN in rendercore.c + * */ +void IMB_filter_extend(struct ImBuf *ibuf, char *mask) { register char *row1, *row2, *row3; - register char *cp; + register char *cp; int rowlen, x, y; rowlen= ibuf->x; @@ -269,11 +272,11 @@ void IMB_filter_extend(struct ImBuf *ibuf) row3f= row2f; fp= (float *)(ibuf->rect_float + (y-1)*rowlen*4); - + for(x=0; x<rowlen; x++) { - if(fp[3]==0.0f) { + if((mask==NULL && fp[3]==0.0f) || (mask && mask[((y-1)*rowlen)+x]==1)) { int tot= 0; - float r=0.0f, g=0.0f, b=0.0f; + float r=0.0f, g=0.0f, b=0.0f, a=0.0f; EXTEND_PIXEL(row1f, 1); EXTEND_PIXEL(row2f, 2); @@ -289,7 +292,7 @@ void IMB_filter_extend(struct ImBuf *ibuf) fp[0]= r/tot; fp[1]= g/tot; fp[2]= b/tot; - fp[3]= 1.0; + fp[3]= a/tot; } } fp+=4; @@ -321,8 +324,9 @@ void IMB_filter_extend(struct ImBuf *ibuf) cp= (char *)(ibuf->rect + (y-1)*rowlen); for(x=0; x<rowlen; x++) { - if(cp[3]==0) { - int tot= 0, r=0, g=0, b=0; + /*if(cp[3]==0) {*/ + if((mask==NULL && cp[3]==0) || (mask && mask[((y-1)*rowlen)+x]==1)) { + int tot= 0, r=0, g=0, b=0, a=0; EXTEND_PIXEL(row1, 1); EXTEND_PIXEL(row2, 2); @@ -338,10 +342,10 @@ void IMB_filter_extend(struct ImBuf *ibuf) cp[0]= r/tot; cp[1]= g/tot; cp[2]= b/tot; - cp[3]= 255; + cp[3]= a/tot; } } - cp+=4; + cp+=4; if(x!=0) { row1+=4; row2+=4; row3+=4; |