From 7a2725048d9e1595fa2d188815653ab05bdbb9c0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 24 Nov 2011 06:30:37 +0000 Subject: - saving as a jpeg image would set the image as not having an alpha channel even when saving a copy. - setting the color channels on save as would ignore the channel - BW/RGB/RGBA setting. now its used when available but still need to hide BW for formats blender can only write as color. --- source/blender/blenkernel/BKE_image.h | 1 + source/blender/blenkernel/intern/image.c | 26 +++++++++++++++++++++++++- source/blender/editors/space_image/image_ops.c | 2 +- source/blender/imbuf/intern/jpeg.c | 6 +++++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 96c0371baf3..9ff42bc706b 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -53,6 +53,7 @@ void BKE_stamp_buf(struct Scene *scene, struct Object *camera, unsigned char *re int BKE_alphatest_ibuf(struct ImBuf *ibuf); int BKE_write_ibuf_stamp(struct Scene *scene, struct Object *camera, struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf); int BKE_write_ibuf(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf); +int BKE_write_ibuf_as(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf, const short is_copy); void BKE_makepicstring(char *string, const char *base, const char *relbase, int frame, char imtype, const short use_ext, const short use_frames); int BKE_add_image_extension(char *string, const char imtype); char BKE_ftype_to_imtype(const int ftype); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 964e15f494d..034177e2b5d 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1483,6 +1483,8 @@ int BKE_alphatest_ibuf(ImBuf *ibuf) return FALSE; } +/* note: imf->planes is ignored here, its assumed the image channels + * are already set */ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf) { char imtype= imf->imtype; @@ -1577,7 +1579,6 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf) /* R_IMF_IMTYPE_JPEG90, etc. default we save jpegs */ if(quality < 10) quality= 90; ibuf->ftype= JPG|quality; - if(ibuf->planes==32) ibuf->planes= 24; /* unsupported feature only confuses other s/w */ } BLI_make_existing_file(name); @@ -1590,6 +1591,29 @@ int BKE_write_ibuf(ImBuf *ibuf, const char *name, ImageFormatData *imf) return(ok); } +/* same as BKE_write_ibuf_as but crappy workaround not to perminantly modify + * _some_, values in the imbuf */ +int BKE_write_ibuf_as(ImBuf *ibuf, const char *name, ImageFormatData *imf, + const short save_copy) +{ + ImBuf ibuf_back= *ibuf; + int ok; + + /* all data is rgba anyway, + * this just controls how to save for some formats */ + ibuf->planes= imf->planes; + + ok= BKE_write_ibuf(ibuf, name, imf); + + if (save_copy) { + /* note that we are not restoring _all_ settings */ + ibuf->planes= ibuf_back.planes; + ibuf->ftype= ibuf_back.ftype; + } + + return ok; +} + int BKE_write_ibuf_stamp(Scene *scene, struct Object *camera, ImBuf *ibuf, const char *name, struct ImageFormatData *imf) { if(scene && scene->r.stamp & R_STAMP_ALL) diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index bff2d82e041..0efc89e802a 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1075,7 +1075,7 @@ static void save_image_doit(bContext *C, SpaceImage *sima, wmOperator *op, SaveI BKE_image_release_renderresult(scene, ima); } else { - if (BKE_write_ibuf(ibuf, simopts->filepath, &simopts->im_format)) { + if (BKE_write_ibuf_as(ibuf, simopts->filepath, &simopts->im_format, save_copy)) { ok= TRUE; } } diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index 5a40de0a65e..a43a8672651 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -572,8 +572,12 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct cinfo->in_color_space = JCS_RGB; if (ibuf->planes == 8) cinfo->in_color_space = JCS_GRAYSCALE; +#if 0 + /* just write RGBA as RGB, + * unsupported feature only confuses other s/w */ + if (ibuf->planes == 32) cinfo->in_color_space = JCS_UNKNOWN; - +#endif switch(cinfo->in_color_space){ case JCS_RGB: cinfo->input_components = 3; -- cgit v1.2.3