de-duplicate multires image filter function. (no functional change)
authorCampbell Barton <ideasman42@gmail.com>
Wed, 15 Jun 2011 02:14:38 +0000 (02:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 15 Jun 2011 02:14:38 +0000 (02:14 +0000)
source/blender/editors/object/object_bake.c
source/blender/render/extern/include/RE_shader_ext.h
source/blender/render/intern/source/rendercore.c

index c669a69..fc5f09f 100644 (file)
@@ -854,49 +854,11 @@ static void finish_images(MultiresBakeRender *bkr)
                Image *ima= (Image*)link->data;
                int i;
                ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
-               short is_new_alpha;
 
                if(ibuf->x<=0 || ibuf->y<=0)
                        continue;
 
-               /* must check before filtering */
-               is_new_alpha= (ibuf->depth != 32) && BKE_alphatest_ibuf(ibuf);
-
-               /* Margin */
-               if(bkr->bake_filter) {
-                       char *temprect;
-
-                       /* extend the mask +2 pixels from the image,
-                        * this is so colors dont blend in from outside */
-
-                       for(i=0; i<bkr->bake_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<bkr->bake_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(bkr->bake_filter) {
-                               /* clear alpha added by filtering */
-                               IMB_rectfill_alpha(ibuf, 1.0f);
-                       }
-               }
-
+               RE_bake_ibuf_filter(ibuf, (unsigned char *)ibuf->userdata, bkr->bake_filter);
 
                ibuf->userflags|= IB_BITMAPDIRTY;
                if(ibuf->mipmap[0]) {
@@ -1349,7 +1311,6 @@ static void finish_bake_internal(BakeRender *bkr)
 
                                        /* freed when baking is done, but if its canceled we need to free here */
                                        if (ibuf->userdata) {
-                                               printf("freed\n");
                                                MEM_freeN(ibuf->userdata);
                                                ibuf->userdata= NULL;
                                        }
index 958c19a..a59ebda 100644 (file)
@@ -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 */
-
index e620600..d0daf5b 100644 (file)
@@ -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);