diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-06-15 05:56:49 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-06-15 05:56:49 +0400 |
commit | 1d41694e6974ee870fdeef2a5516d8368a2b9853 (patch) | |
tree | 37722d5423f557f732e31a4bdda23275fb379830 /source | |
parent | 62ba2d4c6811c1b2b27163c46f9bbc0e696f63ee (diff) |
fix [#27662] Storing png/tga images ignore Alpha settings
- don't clear alpha when baking RGB images
- when baking results in partial alpha. set the depth to 32.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenpluginapi/iff.h | 3 | ||||
-rw-r--r-- | source/blender/editors/object/object_bake.c | 21 | ||||
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 3 | ||||
-rw-r--r-- | source/blender/imbuf/intern/rectop.c | 17 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 20 |
5 files changed, 57 insertions, 7 deletions
diff --git a/source/blender/blenpluginapi/iff.h b/source/blender/blenpluginapi/iff.h index bccc7bdb769..77cdf889ea5 100644 --- a/source/blender/blenpluginapi/iff.h +++ b/source/blender/blenpluginapi/iff.h @@ -113,9 +113,10 @@ LIBIMPORT void interlace(struct ImBuf *ib); LIBIMPORT void IMB_rectcpy(struct ImBuf *dbuf, struct ImBuf *sbuf, int destx, int desty, int srcx, int srcy, int width, int height); -LIBIMPORT void IMB_rectfill(struct ImBuf *drect, float col[4]); +LIBIMPORT void IMB_rectfill(struct ImBuf *drect, const float col[4]); LIBIMPORT void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2); LIBIMPORT void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2); +LIBIMPORT void IMB_rectfill_alpha(struct ImBuf *drect, const float value); #endif /* IFF_H */ diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index 565c5810cff..c669a69b157 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -854,10 +854,14 @@ 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; @@ -882,6 +886,18 @@ static void finish_images(MultiresBakeRender *bkr) 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; @@ -1028,7 +1044,8 @@ static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *l static void clear_images(MTFace *mtface, int totface) { int a; - float vec[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + const float vec_alpha[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + const float vec_solid[4]= {0.0f, 0.0f, 0.0f, 1.0f}; for(a= 0; a<totface; a++) mtface[a].tpage->id.flag&= ~LIB_DOIT; @@ -1039,7 +1056,7 @@ static void clear_images(MTFace *mtface, int totface) if((ima->id.flag&LIB_DOIT)==0) { ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); - IMB_rectfill(ibuf, vec); + IMB_rectfill(ibuf, (ibuf->depth == 32) ? vec_alpha : vec_solid); ima->id.flag|= LIB_DOIT; } } diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 5d61452e149..e9592fdc164 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -442,8 +442,9 @@ void IMB_freezbuffloatImBuf(struct ImBuf *ibuf); * * @attention Defined in rectop.c */ -void IMB_rectfill(struct ImBuf *drect, float col[4]); +void IMB_rectfill(struct ImBuf *drect, const float col[4]); void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, int y2); +void IMB_rectfill_alpha(struct ImBuf *ibuf, const float value); /* this should not be here, really, we needed it for operating on render data, IMB_rectfill_area calls it */ void buf_rectfill_area(unsigned char *rect, float *rectf, int width, int height, float *col, int x1, int y1, int x2, int y2); diff --git a/source/blender/imbuf/intern/rectop.c b/source/blender/imbuf/intern/rectop.c index 44af7ffdb3f..844478e03cb 100644 --- a/source/blender/imbuf/intern/rectop.c +++ b/source/blender/imbuf/intern/rectop.c @@ -450,7 +450,7 @@ void IMB_rectblend(struct ImBuf *dbuf, struct ImBuf *sbuf, int destx, /* fill */ -void IMB_rectfill(struct ImBuf *drect, float col[4]) +void IMB_rectfill(struct ImBuf *drect, const float col[4]) { int num; @@ -561,3 +561,18 @@ void IMB_rectfill_area(struct ImBuf *ibuf, float *col, int x1, int y1, int x2, i if (!ibuf) return; buf_rectfill_area((unsigned char *) ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, col, x1, y1, x2, y2); } + + +void IMB_rectfill_alpha(ImBuf *ibuf, const float value) +{ + int i; + if (ibuf->rect_float) { + float *fbuf= ibuf->rect_float + 3; + for (i = ibuf->x * ibuf->y; i > 0; i--, fbuf+= 4) { *fbuf = value; } + } + else { + const unsigned char cvalue= value * 255; + unsigned char *cbuf= ((unsigned char *)ibuf->rect) + 3; + for (i = ibuf->x * ibuf->y; i > 0; i--, cbuf+= 4) { *cbuf = cvalue; } + } +} diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 0087be8cca9..e6206007b7a 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -2464,7 +2464,8 @@ static int get_next_bake_face(BakeShade *bs) if(tface && tface->tpage) { Image *ima= tface->tpage; ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); - float vec[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + const float vec_alpha[4]= {0.0f, 0.0f, 0.0f, 0.0f}; + const float vec_solid[4]= {0.0f, 0.0f, 0.0f, 1.0f}; if(ibuf==NULL) continue; @@ -2484,7 +2485,7 @@ static int get_next_bake_face(BakeShade *bs) imb_freerectImBuf(ibuf); /* clear image */ if(R.r.bake_flag & R_BAKE_CLEAR) - IMB_rectfill(ibuf, vec); + IMB_rectfill(ibuf, (ibuf->depth == 32) ? vec_alpha : vec_solid); /* might be read by UI to set active image for display */ R.bakebuf= ima; @@ -2671,10 +2672,14 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up for(ima= G.main->image.first; ima; ima= ima->id.next) { if((ima->id.flag & LIB_DOIT)==0) { ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); + short is_new_alpha; 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, @@ -2706,6 +2711,17 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up } } + /* 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); } |