- 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.
This commit is contained in:
Campbell Barton 2011-11-24 06:30:37 +00:00
parent df22957bfc
commit 7a2725048d
4 changed files with 32 additions and 3 deletions

@ -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);

@ -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)

@ -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;
}
}

@ -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;