bugfix [#22638] Alpha channel not saved when using texture paint
authorCampbell Barton <ideasman42@gmail.com>
Tue, 30 Nov 2010 23:38:31 +0000 (23:38 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 30 Nov 2010 23:38:31 +0000 (23:38 +0000)
check for alpha channel while saving images that have been painted onto.
It would be nicer to do this while in paint mode except this isn't so simple with project paint using multiple images at once.

source/blender/blenkernel/BKE_image.h
source/blender/blenkernel/intern/image.c
source/blender/editors/space_image/image_ops.c

index 7a801c0ef0a4a19b795851c0fe9625d826c63cfd..46c7cd89ecf819a332a2063c75d85a87daaa1788 100644 (file)
@@ -46,6 +46,7 @@ void  free_image(struct Image *me);
 
 void   BKE_stamp_info(struct Scene *scene, struct ImBuf *ibuf);
 void   BKE_stamp_buf(struct Scene *scene, unsigned char *rect, float *rectf, int width, int height, int channels);
+int            BKE_alphatest_ibuf(struct ImBuf *ibuf);
 int            BKE_write_ibuf(struct Scene *scene, struct ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality);
 void   BKE_makepicstring(char *string, const char *base, int frame, int imtype, const short use_ext, const short use_frames);
 int            BKE_add_image_extension(char *string, int imtype);
index b624feeaf9d8dc3004d820f09a50c939d7461b31..31eae70f159855b88354bf2cf99fdb832b48defc 100644 (file)
@@ -1188,6 +1188,29 @@ void BKE_stamp_info(Scene *scene, struct ImBuf *ibuf)
        if (stamp_data.rendertime[0]) IMB_metadata_change_field (ibuf, "RenderTime", stamp_data.rendertime);
 }
 
+int BKE_alphatest_ibuf(ImBuf *ibuf)
+{
+       int tot;
+       if(ibuf->rect_float) {
+               float *buf= ibuf->rect_float;
+               for(tot= ibuf->x * ibuf->y; tot--; buf+=4) {
+                       if(buf[3] < 1.0f) {
+                               return TRUE;
+                       }
+               }
+       }
+       else if (ibuf->rect) {
+               unsigned char *buf= (unsigned char *)ibuf->rect;
+               for(tot= ibuf->x * ibuf->y; tot--; buf+=4) {
+                       if(buf[3] != 255) {
+                               return TRUE;
+                       }
+               }
+       }
+
+       return FALSE;
+}
+
 int BKE_write_ibuf(Scene *scene, ImBuf *ibuf, const char *name, int imtype, int subimtype, int quality)
 {
        int ok;
index d2cf3365423822d02dc5574c35ade4955b39af28..be917f43735bba8e8e359f76251cc2a0c306c496 100644 (file)
@@ -888,6 +888,13 @@ static void save_image_doit(bContext *C, SpaceImage *sima, Scene *scene, wmOpera
                                ibuf->depth= 24;
                        }
                }
+               else {
+                       /* TODO, better solution, if a 24bit image is painted onto it may contain alpha */
+                       if(ibuf->userflags & IB_BITMAPDIRTY) { /* it has been painted onto */
+                               /* checks each pixel, not ideal */
+                               ibuf->depth= BKE_alphatest_ibuf(ibuf) ? 32 : 24;
+                       }
+               }
 
                if(scene->r.scemode & R_EXTENSION)  {
                        BKE_add_image_extension(path, sima->imtypenr);