diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-06-15 06:14:38 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-06-15 06:14:38 +0400 |
commit | b89924f5dde483fffbd071a5c84713a2bb357557 (patch) | |
tree | 6e9a836f306479ccc7df460f3e7dfd6c64c2c4ed /source/blender/render | |
parent | 1d41694e6974ee870fdeef2a5516d8368a2b9853 (diff) |
de-duplicate multires image filter function. (no functional change)
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/extern/include/RE_shader_ext.h | 4 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 87 |
2 files changed, 46 insertions, 45 deletions
diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h index 958c19ab9ca..a59ebdaa5a2 100644 --- a/source/blender/render/extern/include/RE_shader_ext.h +++ b/source/blender/render/extern/include/RE_shader_ext.h @@ -193,6 +193,8 @@ typedef struct ShadeInput /* node shaders... */ struct Tex; struct MTex; +struct ImBuf; + /* this one uses nodes */ int multitex_ext(struct Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, struct TexResult *texres); /* nodes disabled */ @@ -209,6 +211,6 @@ struct Object; void RE_shade_external(struct Render *re, struct ShadeInput *shi, struct ShadeResult *shr); int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob, short *do_update, float *progress); struct Image *RE_bake_shade_get_image(void); +void RE_bake_ibuf_filter(struct ImBuf *ibuf, unsigned char *mask, const int filter); #endif /* RE_SHADER_EXT_H */ - diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index e6206007b7a..d0daf5b817a 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2590,6 +2590,48 @@ static void *do_bake_thread(void *bs_v) return NULL; } +void RE_bake_ibuf_filter(ImBuf *ibuf, unsigned char *mask, const int filter) +{ + /* must check before filtering */ + const short is_new_alpha= (ibuf->depth != 32) && BKE_alphatest_ibuf(ibuf); + + /* Margin */ + if(filter) { + char *temprect; + int i; + + /* extend the mask +2 pixels from the image, + * this is so colors dont blend in from outside */ + + for(i=0; i< filter; i++) + IMB_mask_filter_extend((char *)ibuf->userdata, ibuf->x, ibuf->y); + + temprect = MEM_dupallocN(ibuf->userdata); + + /* expand twice to clear this many pixels, so they blend back in */ + IMB_mask_filter_extend(temprect, ibuf->x, ibuf->y); + IMB_mask_filter_extend(temprect, ibuf->x, ibuf->y); + + /* clear all pixels in the margin */ + IMB_mask_clear(ibuf, temprect, FILTER_MASK_MARGIN); + MEM_freeN(temprect); + + for(i= 0; i < filter; i++) + IMB_filter_extend(ibuf, (char *)ibuf->userdata); + } + + /* if the bake results in new alpha then change the image setting */ + if(is_new_alpha) { + ibuf->depth= 32; + } + else { + if(filter) { + /* clear alpha added by filtering */ + IMB_rectfill_alpha(ibuf, 1.0f); + } + } +} + /* using object selection tags, the faces with UV maps get baked */ /* render should have been setup */ /* returns 0 if nothing was handled */ @@ -2677,50 +2719,7 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up if(!ibuf) continue; - /* must check before filtering */ - is_new_alpha= (ibuf->depth != 32) && BKE_alphatest_ibuf(ibuf); - - if(re->r.bake_filter) { - if (usemask) { - /* extend the mask +2 pixels from the image, - * this is so colors dont blend in from outside */ - char *temprect; - - for(a=0; a<re->r.bake_filter; a++) - IMB_mask_filter_extend((char *)ibuf->userdata, ibuf->x, ibuf->y); - - temprect = MEM_dupallocN(ibuf->userdata); - - /* expand twice to clear this many pixels, so they blend back in */ - IMB_mask_filter_extend(temprect, ibuf->x, ibuf->y); - IMB_mask_filter_extend(temprect, ibuf->x, ibuf->y); - - /* clear all pixels in the margin*/ - IMB_mask_clear(ibuf, temprect, FILTER_MASK_MARGIN); - MEM_freeN(temprect); - } - - for(a=0; a<re->r.bake_filter; a++) { - /*the mask, ibuf->userdata - can be null, in this case only zero alpha is used */ - IMB_filter_extend(ibuf, (char *)ibuf->userdata); - } - - if (ibuf->userdata) { - MEM_freeN(ibuf->userdata); - ibuf->userdata= NULL; - } - } - - /* if the bake results in new alpha then change the image setting */ - if(is_new_alpha) { - ibuf->depth= 32; - } - else { - if(re->r.bake_filter) { - /* clear alpha added by filtering */ - IMB_rectfill_alpha(ibuf, 1.0f); - } - } + RE_bake_ibuf_filter(ibuf, (unsigned char *)ibuf->userdata, re->r.bake_filter); ibuf->userflags |= IB_BITMAPDIRTY; if (ibuf->rect_float) IMB_rect_from_float(ibuf); |