Changeset View
Changeset View
Standalone View
Standalone View
source/blender/imbuf/intern/writeimage.c
| Show All 40 Lines | |||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_filetype.h" | #include "IMB_filetype.h" | ||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "IMB_colormanagement_intern.h" | #include "IMB_colormanagement_intern.h" | ||||
| static ImBuf *prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf) | static bool prepare_write_imbuf(const ImFileType *type, ImBuf *ibuf) | ||||
| { | { | ||||
| return IMB_prepare_write_ImBuf((type->flag & IM_FTYPE_FLOAT), ibuf); | return IMB_prepare_write_ImBuf((type->flag & IM_FTYPE_FLOAT), ibuf); | ||||
| } | } | ||||
| short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags) | short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags) | ||||
| { | { | ||||
| const ImFileType *type; | const ImFileType *type; | ||||
| errno = 0; | errno = 0; | ||||
| BLI_assert(!BLI_path_is_rel(name)); | BLI_assert(!BLI_path_is_rel(name)); | ||||
| if (ibuf == NULL) return (false); | if (ibuf == NULL) return (false); | ||||
| ibuf->flags = flags; | ibuf->flags = flags; | ||||
| for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { | for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) { | ||||
| if (type->save && type->ftype(type, ibuf)) { | if (type->save && type->ftype(type, ibuf)) { | ||||
| ImBuf *write_ibuf; | |||||
| short result = false; | short result = false; | ||||
| write_ibuf = prepare_write_imbuf(type, ibuf); | prepare_write_imbuf(type, ibuf); | ||||
| result = type->save(write_ibuf, name, flags); | result = type->save(ibuf, name, flags); | ||||
| if (write_ibuf != ibuf) | |||||
| IMB_freeImBuf(write_ibuf); | |||||
| return result; | return result; | ||||
| } | } | ||||
| } | } | ||||
| fprintf(stderr, "Couldn't save picture.\n"); | fprintf(stderr, "Couldn't save picture.\n"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| ImBuf *IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf) | bool IMB_prepare_write_ImBuf(const bool isfloat, ImBuf *ibuf) | ||||
| { | { | ||||
| ImBuf *write_ibuf = ibuf; | bool changed = false; | ||||
| if (isfloat) { | if (isfloat) { | ||||
| /* pass */ | /* pass */ | ||||
| } | } | ||||
| else { | else { | ||||
| if (ibuf->rect == NULL && ibuf->rect_float) { | if (ibuf->rect == NULL && ibuf->rect_float) { | ||||
| ibuf->rect_colorspace = colormanage_colorspace_get_roled(COLOR_ROLE_DEFAULT_BYTE); | ibuf->rect_colorspace = colormanage_colorspace_get_roled(COLOR_ROLE_DEFAULT_BYTE); | ||||
| IMB_rect_from_float(ibuf); | IMB_rect_from_float(ibuf); | ||||
| if (ibuf->rect != NULL) { | |||||
| changed = true; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| return write_ibuf; | return changed; | ||||
| } | } | ||||