Revision: 37493
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37493
Author:   campbellbarton
Date:     2011-06-15 02:14:38 +0000 (Wed, 15 Jun 2011)
Log Message:
-----------
de-duplicate multires image filter function. (no functional change)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_bake.c
    trunk/blender/source/blender/render/extern/include/RE_shader_ext.h
    trunk/blender/source/blender/render/intern/source/rendercore.c

Modified: trunk/blender/source/blender/editors/object/object_bake.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_bake.c   2011-06-15 
01:56:49 UTC (rev 37492)
+++ trunk/blender/source/blender/editors/object/object_bake.c   2011-06-15 
02:14:38 UTC (rev 37493)
@@ -854,50 +854,12 @@
                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);
+               RE_bake_ibuf_filter(ibuf, (unsigned char *)ibuf->userdata, 
bkr->bake_filter);
 
-               /* 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);
-                       }
-               }
-
-
                ibuf->userflags|= IB_BITMAPDIRTY;
                if(ibuf->mipmap[0]) {
                        ibuf->userflags|= IB_MIPMAP_INVALID;
@@ -1349,7 +1311,6 @@
 
                                        /* 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;
                                        }

Modified: trunk/blender/source/blender/render/extern/include/RE_shader_ext.h
===================================================================
--- trunk/blender/source/blender/render/extern/include/RE_shader_ext.h  
2011-06-15 01:56:49 UTC (rev 37492)
+++ trunk/blender/source/blender/render/extern/include/RE_shader_ext.h  
2011-06-15 02:14:38 UTC (rev 37493)
@@ -193,6 +193,8 @@
 /* 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 @@
 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 */
-

Modified: trunk/blender/source/blender/render/intern/source/rendercore.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/rendercore.c      
2011-06-15 01:56:49 UTC (rev 37492)
+++ trunk/blender/source/blender/render/intern/source/rendercore.c      
2011-06-15 02:14:38 UTC (rev 37493)
@@ -2590,6 +2590,48 @@
        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,51 +2719,8 @@
                        if(!ibuf)
                                continue;
 
-                       /* must check before filtering */
-                       is_new_alpha= (ibuf->depth != 32) && 
BKE_alphatest_ibuf(ibuf);
+                       RE_bake_ibuf_filter(ibuf, (unsigned char 
*)ibuf->userdata, re->r.bake_filter);
 
-                       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);
-                               }
-                       }
-
                        ibuf->userflags |= IB_BITMAPDIRTY;
                        if (ibuf->rect_float) IMB_rect_from_float(ibuf);
                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to