diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-03-11 19:50:57 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-03-21 18:38:13 +0300 |
commit | 6e4d2fa9140864a13356b07ffca082817822987f (patch) | |
tree | cb8894c3b6898e82410f3edffe2fb9d85a3a2399 /source/blender | |
parent | 4abb8a14a2133f876c7718a8e09284baa62b1cf5 (diff) |
Cleanup: add image_format.cc for functions related to ImageFormatData
Also fixes missing code to read/write/free/copy color management settings
in various places. This can't be set through the UI currently, but still
should be handled consistently.
Diffstat (limited to 'source/blender')
30 files changed, 1063 insertions, 915 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index ea0202e3b5f..7b3124cca26 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -90,7 +90,6 @@ int BKE_imbuf_write_stamp(struct Scene *scene, /** * \note imf->planes is ignored here, its assumed the image channels are already set. */ -void BKE_imbuf_write_prepare(struct ImBuf *ibuf, const struct ImageFormatData *imf); int BKE_imbuf_write(struct ImBuf *ibuf, const char *name, const struct ImageFormatData *imf); /** * Same as #BKE_imbuf_write() but crappy workaround not to permanently modify _some_, @@ -100,43 +99,6 @@ int BKE_imbuf_write_as(struct ImBuf *ibuf, const char *name, struct ImageFormatData *imf, bool save_copy); -void BKE_image_path_from_imformat(char *string, - const char *base, - const char *relbase, - int frame, - const struct ImageFormatData *im_format, - bool use_ext, - bool use_frames, - const char *suffix); -void BKE_image_path_from_imtype(char *string, - const char *base, - const char *relbase, - int frame, - char imtype, - bool use_ext, - bool use_frames, - const char *suffix); -int BKE_image_path_ensure_ext_from_imformat(char *string, const struct ImageFormatData *im_format); -int BKE_image_path_ensure_ext_from_imtype(char *string, char imtype); -char BKE_image_ftype_to_imtype(int ftype, const struct ImbFormatOptions *options); -int BKE_image_imtype_to_ftype(char imtype, struct ImbFormatOptions *r_options); - -bool BKE_imtype_is_movie(char imtype); -bool BKE_imtype_supports_zbuf(char imtype); -bool BKE_imtype_supports_compress(char imtype); -bool BKE_imtype_supports_quality(char imtype); -bool BKE_imtype_requires_linear_float(char imtype); -char BKE_imtype_valid_channels(char imtype, bool write_file); -char BKE_imtype_valid_depths(char imtype); - -/** - * String is from command line `--render-format` argument, - * keep in sync with `creator_args.c` help info. - */ -char BKE_imtype_from_arg(const char *arg); - -void BKE_imformat_defaults(struct ImageFormatData *im_format); -void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const struct ImBuf *imbuf); /** * Used by sequencer too. @@ -171,10 +133,6 @@ struct RenderResult; #define IMA_SIGNAL_USER_NEW_IMAGE 6 #define IMA_SIGNAL_COLORMANAGE 7 -#define IMA_CHAN_FLAG_BW 1 -#define IMA_CHAN_FLAG_RGB 2 -#define IMA_CHAN_FLAG_ALPHA 4 - /** * Checks whether there's an image buffer for given image and user. */ diff --git a/source/blender/blenkernel/BKE_image_format.h b/source/blender/blenkernel/BKE_image_format.h new file mode 100644 index 00000000000..189d2db1b4f --- /dev/null +++ b/source/blender/blenkernel/BKE_image_format.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2001-2002 NaN Holding BV. All rights reserved. */ + +#pragma once + +/** \file + * \ingroup bke + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct BlendDataReader; +struct BlendWriter; +struct ImbFormatOptions; +struct ImageFormatData; +struct ImBuf; + +/* Init/Copy/Free */ + +void BKE_image_format_init(struct ImageFormatData *imf, const bool render); +void BKE_image_format_copy(struct ImageFormatData *imf_dst, const struct ImageFormatData *imf_src); +void BKE_image_format_free(struct ImageFormatData *imf); + +void BKE_image_format_blend_read_data(struct BlendDataReader *reader, struct ImageFormatData *imf); +void BKE_image_format_blend_write(struct BlendWriter *writer, struct ImageFormatData *imf); + +/* File Paths */ + +void BKE_image_path_from_imformat(char *string, + const char *base, + const char *relbase, + int frame, + const struct ImageFormatData *im_format, + bool use_ext, + bool use_frames, + const char *suffix); +void BKE_image_path_from_imtype(char *string, + const char *base, + const char *relbase, + int frame, + char imtype, + bool use_ext, + bool use_frames, + const char *suffix); +int BKE_image_path_ensure_ext_from_imformat(char *string, const struct ImageFormatData *im_format); +int BKE_image_path_ensure_ext_from_imtype(char *string, char imtype); + +/* File Types */ + +#define IMA_CHAN_FLAG_BW 1 +#define IMA_CHAN_FLAG_RGB 2 +#define IMA_CHAN_FLAG_ALPHA 4 + +char BKE_ftype_to_imtype(int ftype, const struct ImbFormatOptions *options); +int BKE_imtype_to_ftype(char imtype, struct ImbFormatOptions *r_options); + +bool BKE_imtype_is_movie(char imtype); +bool BKE_imtype_supports_zbuf(char imtype); +bool BKE_imtype_supports_compress(char imtype); +bool BKE_imtype_supports_quality(char imtype); +bool BKE_imtype_requires_linear_float(char imtype); +char BKE_imtype_valid_channels(char imtype, bool write_file); +char BKE_imtype_valid_depths(char imtype); + +/** + * String is from command line `--render-format` argument, + * keep in sync with `creator_args.c` help info. + */ +char BKE_imtype_from_arg(const char *arg); + +/* Conversion between ImBuf settings. */ + +void BKE_image_format_from_imbuf(struct ImageFormatData *im_format, const struct ImBuf *imbuf); +void BKE_image_format_to_imbuf(struct ImBuf *ibuf, const struct ImageFormatData *imf); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/blenkernel/BKE_image_save.h b/source/blender/blenkernel/BKE_image_save.h index ea9ed7d2d26..dea1c25cd5e 100644 --- a/source/blender/blenkernel/BKE_image_save.h +++ b/source/blender/blenkernel/BKE_image_save.h @@ -36,6 +36,8 @@ typedef struct ImageSaveOptions { void BKE_image_save_options_init(struct ImageSaveOptions *opts, struct Main *bmain, struct Scene *scene); +void BKE_image_save_options_free(struct ImageSaveOptions *opts); + bool BKE_image_save(struct ReportList *reports, struct Main *bmain, struct Image *ima, diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 2aedd26616e..3cc65fd252b 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -156,6 +156,7 @@ set(SRC intern/idprop_utils.c intern/idtype.c intern/image.cc + intern/image_format.cc intern/image_partial_update.cc intern/image_gen.c intern/image_gpu.cc @@ -383,6 +384,7 @@ set(SRC BKE_idprop.hh BKE_idtype.h BKE_image.h + BKE_image_format.h BKE_image_partial_update.hh BKE_image_save.h BKE_ipo.h diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index d70ab8ed606..8ec7bbea0e5 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -44,6 +44,7 @@ #include "BKE_dynamicpaint.h" #include "BKE_effect.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_material.h" diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index d78d508336b..51ffd3338c4 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -68,6 +68,7 @@ #include "BKE_icons.h" #include "BKE_idtype.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_node.h" @@ -1490,607 +1491,6 @@ void BKE_image_all_free_anim_ibufs(Main *bmain, int cfra) /** \name Read and Write * \{ */ -int BKE_image_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options) -{ - memset(r_options, 0, sizeof(*r_options)); - - if (imtype == R_IMF_IMTYPE_TARGA) { - return IMB_FTYPE_TGA; - } - if (imtype == R_IMF_IMTYPE_RAWTGA) { - r_options->flag = RAWTGA; - return IMB_FTYPE_TGA; - } - if (imtype == R_IMF_IMTYPE_IRIS) { - return IMB_FTYPE_IMAGIC; - } -#ifdef WITH_HDR - if (imtype == R_IMF_IMTYPE_RADHDR) { - return IMB_FTYPE_RADHDR; - } -#endif - if (imtype == R_IMF_IMTYPE_PNG) { - r_options->quality = 15; - return IMB_FTYPE_PNG; - } -#ifdef WITH_DDS - if (imtype == R_IMF_IMTYPE_DDS) { - return IMB_FTYPE_DDS; - } -#endif - if (imtype == R_IMF_IMTYPE_BMP) { - return IMB_FTYPE_BMP; - } -#ifdef WITH_TIFF - if (imtype == R_IMF_IMTYPE_TIFF) { - return IMB_FTYPE_TIF; - } -#endif - if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { - return IMB_FTYPE_OPENEXR; - } -#ifdef WITH_CINEON - if (imtype == R_IMF_IMTYPE_CINEON) { - return IMB_FTYPE_CINEON; - } - if (imtype == R_IMF_IMTYPE_DPX) { - return IMB_FTYPE_DPX; - } -#endif -#ifdef WITH_OPENJPEG - if (imtype == R_IMF_IMTYPE_JP2) { - r_options->flag |= JP2_JP2; - r_options->quality = 90; - return IMB_FTYPE_JP2; - } -#endif - - r_options->quality = 90; - return IMB_FTYPE_JPG; -} - -char BKE_image_ftype_to_imtype(const int ftype, const ImbFormatOptions *options) -{ - if (ftype == IMB_FTYPE_NONE) { - return R_IMF_IMTYPE_TARGA; - } - if (ftype == IMB_FTYPE_IMAGIC) { - return R_IMF_IMTYPE_IRIS; - } -#ifdef WITH_HDR - if (ftype == IMB_FTYPE_RADHDR) { - return R_IMF_IMTYPE_RADHDR; - } -#endif - if (ftype == IMB_FTYPE_PNG) { - return R_IMF_IMTYPE_PNG; - } -#ifdef WITH_DDS - if (ftype == IMB_FTYPE_DDS) { - return R_IMF_IMTYPE_DDS; - } -#endif - if (ftype == IMB_FTYPE_BMP) { - return R_IMF_IMTYPE_BMP; - } -#ifdef WITH_TIFF - if (ftype == IMB_FTYPE_TIF) { - return R_IMF_IMTYPE_TIFF; - } -#endif - if (ftype == IMB_FTYPE_OPENEXR) { - return R_IMF_IMTYPE_OPENEXR; - } -#ifdef WITH_CINEON - if (ftype == IMB_FTYPE_CINEON) { - return R_IMF_IMTYPE_CINEON; - } - if (ftype == IMB_FTYPE_DPX) { - return R_IMF_IMTYPE_DPX; - } -#endif - if (ftype == IMB_FTYPE_TGA) { - if (options && (options->flag & RAWTGA)) { - return R_IMF_IMTYPE_RAWTGA; - } - - return R_IMF_IMTYPE_TARGA; - } -#ifdef WITH_OPENJPEG - if (ftype == IMB_FTYPE_JP2) { - return R_IMF_IMTYPE_JP2; - } -#endif - - return R_IMF_IMTYPE_JPEG90; -} - -bool BKE_imtype_is_movie(const char imtype) -{ - switch (imtype) { - case R_IMF_IMTYPE_AVIRAW: - case R_IMF_IMTYPE_AVIJPEG: - case R_IMF_IMTYPE_FFMPEG: - case R_IMF_IMTYPE_H264: - case R_IMF_IMTYPE_THEORA: - case R_IMF_IMTYPE_XVID: - return true; - } - return false; -} - -bool BKE_imtype_supports_zbuf(const char imtype) -{ - switch (imtype) { - case R_IMF_IMTYPE_IRIZ: - case R_IMF_IMTYPE_OPENEXR: /* But not #R_IMF_IMTYPE_MULTILAYER. */ - return true; - } - return false; -} - -bool BKE_imtype_supports_compress(const char imtype) -{ - switch (imtype) { - case R_IMF_IMTYPE_PNG: - return true; - } - return false; -} - -bool BKE_imtype_supports_quality(const char imtype) -{ - switch (imtype) { - case R_IMF_IMTYPE_JPEG90: - case R_IMF_IMTYPE_JP2: - case R_IMF_IMTYPE_AVIJPEG: - return true; - } - return false; -} - -bool BKE_imtype_requires_linear_float(const char imtype) -{ - switch (imtype) { - case R_IMF_IMTYPE_CINEON: - case R_IMF_IMTYPE_DPX: - case R_IMF_IMTYPE_RADHDR: - case R_IMF_IMTYPE_OPENEXR: - case R_IMF_IMTYPE_MULTILAYER: - return true; - } - return false; -} - -char BKE_imtype_valid_channels(const char imtype, bool write_file) -{ - char chan_flag = IMA_CHAN_FLAG_RGB; /* Assume all support RGB. */ - - /* Alpha. */ - switch (imtype) { - case R_IMF_IMTYPE_BMP: - if (write_file) { - break; - } - ATTR_FALLTHROUGH; - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_RAWTGA: - case R_IMF_IMTYPE_IRIS: - case R_IMF_IMTYPE_PNG: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_OPENEXR: - case R_IMF_IMTYPE_MULTILAYER: - case R_IMF_IMTYPE_DDS: - case R_IMF_IMTYPE_JP2: - case R_IMF_IMTYPE_DPX: - chan_flag |= IMA_CHAN_FLAG_ALPHA; - break; - } - - /* BW. */ - switch (imtype) { - case R_IMF_IMTYPE_BMP: - case R_IMF_IMTYPE_PNG: - case R_IMF_IMTYPE_JPEG90: - case R_IMF_IMTYPE_TARGA: - case R_IMF_IMTYPE_RAWTGA: - case R_IMF_IMTYPE_TIFF: - case R_IMF_IMTYPE_IRIS: - chan_flag |= IMA_CHAN_FLAG_BW; - break; - } - - return chan_flag; -} - -char BKE_imtype_valid_depths(const char imtype) -{ - switch (imtype) { - case R_IMF_IMTYPE_RADHDR: - return R_IMF_CHAN_DEPTH_32; - case R_IMF_IMTYPE_TIFF: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; - case R_IMF_IMTYPE_OPENEXR: - return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; - case R_IMF_IMTYPE_MULTILAYER: - return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; - /* NOTE: CINEON uses an unusual 10bits-LOG per channel. */ - case R_IMF_IMTYPE_DPX: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_10 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; - case R_IMF_IMTYPE_CINEON: - return R_IMF_CHAN_DEPTH_10; - case R_IMF_IMTYPE_JP2: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; - case R_IMF_IMTYPE_PNG: - return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; - /* Most formats are 8bit only. */ - default: - return R_IMF_CHAN_DEPTH_8; - } -} - -char BKE_imtype_from_arg(const char *imtype_arg) -{ - if (STREQ(imtype_arg, "TGA")) { - return R_IMF_IMTYPE_TARGA; - } - if (STREQ(imtype_arg, "IRIS")) { - return R_IMF_IMTYPE_IRIS; - } -#ifdef WITH_DDS - if (STREQ(imtype_arg, "DDS")) { - return R_IMF_IMTYPE_DDS; - } -#endif - if (STREQ(imtype_arg, "JPEG")) { - return R_IMF_IMTYPE_JPEG90; - } - if (STREQ(imtype_arg, "IRIZ")) { - return R_IMF_IMTYPE_IRIZ; - } - if (STREQ(imtype_arg, "RAWTGA")) { - return R_IMF_IMTYPE_RAWTGA; - } - if (STREQ(imtype_arg, "AVIRAW")) { - return R_IMF_IMTYPE_AVIRAW; - } - if (STREQ(imtype_arg, "AVIJPEG")) { - return R_IMF_IMTYPE_AVIJPEG; - } - if (STREQ(imtype_arg, "PNG")) { - return R_IMF_IMTYPE_PNG; - } - if (STREQ(imtype_arg, "BMP")) { - return R_IMF_IMTYPE_BMP; - } -#ifdef WITH_HDR - if (STREQ(imtype_arg, "HDR")) { - return R_IMF_IMTYPE_RADHDR; - } -#endif -#ifdef WITH_TIFF - if (STREQ(imtype_arg, "TIFF")) { - return R_IMF_IMTYPE_TIFF; - } -#endif -#ifdef WITH_OPENEXR - if (STREQ(imtype_arg, "OPEN_EXR")) { - return R_IMF_IMTYPE_OPENEXR; - } - if (STREQ(imtype_arg, "OPEN_EXR_MULTILAYER")) { - return R_IMF_IMTYPE_MULTILAYER; - } - if (STREQ(imtype_arg, "EXR")) { - return R_IMF_IMTYPE_OPENEXR; - } - if (STREQ(imtype_arg, "MULTILAYER")) { - return R_IMF_IMTYPE_MULTILAYER; - } -#endif - if (STREQ(imtype_arg, "FFMPEG")) { - return R_IMF_IMTYPE_FFMPEG; - } -#ifdef WITH_CINEON - if (STREQ(imtype_arg, "CINEON")) { - return R_IMF_IMTYPE_CINEON; - } - if (STREQ(imtype_arg, "DPX")) { - return R_IMF_IMTYPE_DPX; - } -#endif -#ifdef WITH_OPENJPEG - if (STREQ(imtype_arg, "JP2")) { - return R_IMF_IMTYPE_JP2; - } -#endif - - return R_IMF_IMTYPE_INVALID; -} - -static bool do_add_image_extension(char *string, - const char imtype, - const ImageFormatData *im_format) -{ - const char *extension = nullptr; - const char *extension_test; - (void)im_format; /* may be unused, depends on build options */ - - if (imtype == R_IMF_IMTYPE_IRIS) { - if (!BLI_path_extension_check(string, extension_test = ".rgb")) { - extension = extension_test; - } - } - else if (imtype == R_IMF_IMTYPE_IRIZ) { - if (!BLI_path_extension_check(string, extension_test = ".rgb")) { - extension = extension_test; - } - } -#ifdef WITH_HDR - else if (imtype == R_IMF_IMTYPE_RADHDR) { - if (!BLI_path_extension_check(string, extension_test = ".hdr")) { - extension = extension_test; - } - } -#endif - else if (ELEM(imtype, - R_IMF_IMTYPE_PNG, - R_IMF_IMTYPE_FFMPEG, - R_IMF_IMTYPE_H264, - R_IMF_IMTYPE_THEORA, - R_IMF_IMTYPE_XVID)) { - if (!BLI_path_extension_check(string, extension_test = ".png")) { - extension = extension_test; - } - } -#ifdef WITH_DDS - else if (imtype == R_IMF_IMTYPE_DDS) { - if (!BLI_path_extension_check(string, extension_test = ".dds")) { - extension = extension_test; - } - } -#endif - else if (ELEM(imtype, R_IMF_IMTYPE_TARGA, R_IMF_IMTYPE_RAWTGA)) { - if (!BLI_path_extension_check(string, extension_test = ".tga")) { - extension = extension_test; - } - } - else if (imtype == R_IMF_IMTYPE_BMP) { - if (!BLI_path_extension_check(string, extension_test = ".bmp")) { - extension = extension_test; - } - } -#ifdef WITH_TIFF - else if (imtype == R_IMF_IMTYPE_TIFF) { - if (!BLI_path_extension_check_n(string, extension_test = ".tif", ".tiff", nullptr)) { - extension = extension_test; - } - } -#endif -#ifdef WITH_OPENIMAGEIO - else if (imtype == R_IMF_IMTYPE_PSD) { - if (!BLI_path_extension_check(string, extension_test = ".psd")) { - extension = extension_test; - } - } -#endif -#ifdef WITH_OPENEXR - else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { - if (!BLI_path_extension_check(string, extension_test = ".exr")) { - extension = extension_test; - } - } -#endif -#ifdef WITH_CINEON - else if (imtype == R_IMF_IMTYPE_CINEON) { - if (!BLI_path_extension_check(string, extension_test = ".cin")) { - extension = extension_test; - } - } - else if (imtype == R_IMF_IMTYPE_DPX) { - if (!BLI_path_extension_check(string, extension_test = ".dpx")) { - extension = extension_test; - } - } -#endif -#ifdef WITH_OPENJPEG - else if (imtype == R_IMF_IMTYPE_JP2) { - if (im_format) { - if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) { - if (!BLI_path_extension_check(string, extension_test = ".jp2")) { - extension = extension_test; - } - } - else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) { - if (!BLI_path_extension_check(string, extension_test = ".j2c")) { - extension = extension_test; - } - } - else { - BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec"); - } - } - else { - if (!BLI_path_extension_check(string, extension_test = ".jp2")) { - extension = extension_test; - } - } - } -#endif - else { // R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90 etc - if (!(BLI_path_extension_check_n(string, extension_test = ".jpg", ".jpeg", nullptr))) { - extension = extension_test; - } - } - - if (extension) { - /* prefer this in many cases to avoid .png.tga, but in certain cases it breaks */ - /* remove any other known image extension */ - if (BLI_path_extension_check_array(string, imb_ext_image)) { - return BLI_path_extension_replace(string, FILE_MAX, extension); - } - - return BLI_path_extension_ensure(string, FILE_MAX, extension); - } - - return false; -} - -int BKE_image_path_ensure_ext_from_imformat(char *string, const ImageFormatData *im_format) -{ - return do_add_image_extension(string, im_format->imtype, im_format); -} - -int BKE_image_path_ensure_ext_from_imtype(char *string, const char imtype) -{ - return do_add_image_extension(string, imtype, nullptr); -} - -void BKE_imformat_defaults(ImageFormatData *im_format) -{ - memset(im_format, 0, sizeof(*im_format)); - im_format->planes = R_IMF_PLANES_RGBA; - im_format->imtype = R_IMF_IMTYPE_PNG; - im_format->depth = R_IMF_CHAN_DEPTH_8; - im_format->quality = 90; - im_format->compress = 15; - - BKE_color_managed_display_settings_init(&im_format->display_settings); - BKE_color_managed_view_settings_init_default(&im_format->view_settings, - &im_format->display_settings); -} - -void BKE_imbuf_to_image_format(struct ImageFormatData *im_format, const ImBuf *imbuf) -{ - int ftype = imbuf->ftype; - int custom_flags = imbuf->foptions.flag; - char quality = imbuf->foptions.quality; - - BKE_imformat_defaults(im_format); - - /* file type */ - - if (ftype == IMB_FTYPE_IMAGIC) { - im_format->imtype = R_IMF_IMTYPE_IRIS; - } -#ifdef WITH_HDR - else if (ftype == IMB_FTYPE_RADHDR) { - im_format->imtype = R_IMF_IMTYPE_RADHDR; - } -#endif - else if (ftype == IMB_FTYPE_PNG) { - im_format->imtype = R_IMF_IMTYPE_PNG; - - if (custom_flags & PNG_16BIT) { - im_format->depth = R_IMF_CHAN_DEPTH_16; - } - - im_format->compress = quality; - } - -#ifdef WITH_DDS - else if (ftype == IMB_FTYPE_DDS) { - im_format->imtype = R_IMF_IMTYPE_DDS; - } -#endif - else if (ftype == IMB_FTYPE_BMP) { - im_format->imtype = R_IMF_IMTYPE_BMP; - } -#ifdef WITH_TIFF - else if (ftype == IMB_FTYPE_TIF) { - im_format->imtype = R_IMF_IMTYPE_TIFF; - if (custom_flags & TIF_16BIT) { - im_format->depth = R_IMF_CHAN_DEPTH_16; - } - if (custom_flags & TIF_COMPRESS_NONE) { - im_format->tiff_codec = R_IMF_TIFF_CODEC_NONE; - } - if (custom_flags & TIF_COMPRESS_DEFLATE) { - im_format->tiff_codec = R_IMF_TIFF_CODEC_DEFLATE; - } - if (custom_flags & TIF_COMPRESS_LZW) { - im_format->tiff_codec = R_IMF_TIFF_CODEC_LZW; - } - if (custom_flags & TIF_COMPRESS_PACKBITS) { - im_format->tiff_codec = R_IMF_TIFF_CODEC_PACKBITS; - } - } -#endif - -#ifdef WITH_OPENEXR - else if (ftype == IMB_FTYPE_OPENEXR) { - im_format->imtype = R_IMF_IMTYPE_OPENEXR; - if (custom_flags & OPENEXR_HALF) { - im_format->depth = R_IMF_CHAN_DEPTH_16; - } - if (custom_flags & OPENEXR_COMPRESS) { - im_format->exr_codec = R_IMF_EXR_CODEC_ZIP; /* Can't determine compression */ - } - if (imbuf->zbuf_float) { - im_format->flag |= R_IMF_FLAG_ZBUF; - } - } -#endif - -#ifdef WITH_CINEON - else if (ftype == IMB_FTYPE_CINEON) { - im_format->imtype = R_IMF_IMTYPE_CINEON; - } - else if (ftype == IMB_FTYPE_DPX) { - im_format->imtype = R_IMF_IMTYPE_DPX; - } -#endif - else if (ftype == IMB_FTYPE_TGA) { - if (custom_flags & RAWTGA) { - im_format->imtype = R_IMF_IMTYPE_RAWTGA; - } - else { - im_format->imtype = R_IMF_IMTYPE_TARGA; - } - } -#ifdef WITH_OPENJPEG - else if (ftype == IMB_FTYPE_JP2) { - im_format->imtype = R_IMF_IMTYPE_JP2; - im_format->quality = quality; - - if (custom_flags & JP2_16BIT) { - im_format->depth = R_IMF_CHAN_DEPTH_16; - } - else if (custom_flags & JP2_12BIT) { - im_format->depth = R_IMF_CHAN_DEPTH_12; - } - - if (custom_flags & JP2_YCC) { - im_format->jp2_flag |= R_IMF_JP2_FLAG_YCC; - } - - if (custom_flags & JP2_CINE) { - im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_PRESET; - if (custom_flags & JP2_CINE_48FPS) { - im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_48; - } - } - - if (custom_flags & JP2_JP2) { - im_format->jp2_codec = R_IMF_JP2_CODEC_JP2; - } - else if (custom_flags & JP2_J2K) { - im_format->jp2_codec = R_IMF_JP2_CODEC_J2K; - } - else { - BLI_assert_msg(0, "Unsupported jp2 codec was specified in file type"); - } - } -#endif - - else { - im_format->imtype = R_IMF_IMTYPE_JPEG90; - im_format->quality = quality; - } - - /* planes */ - im_format->planes = imbuf->planes; -} - #define STAMP_NAME_SIZE ((MAX_ID_NAME - 2) + 16) /* could allow access externally - 512 is for long names, * STAMP_NAME_SIZE is for id names, allowing them some room for description */ @@ -2994,171 +2394,9 @@ bool BKE_imbuf_alpha_test(ImBuf *ibuf) return false; } -void BKE_imbuf_write_prepare(ImBuf *ibuf, const ImageFormatData *imf) -{ - char imtype = imf->imtype; - char compress = imf->compress; - char quality = imf->quality; - - /* initialize all from image format */ - ibuf->foptions.flag = 0; - - if (imtype == R_IMF_IMTYPE_IRIS) { - ibuf->ftype = IMB_FTYPE_IMAGIC; - } -#ifdef WITH_HDR - else if (imtype == R_IMF_IMTYPE_RADHDR) { - ibuf->ftype = IMB_FTYPE_RADHDR; - } -#endif - else if (ELEM(imtype, - R_IMF_IMTYPE_PNG, - R_IMF_IMTYPE_FFMPEG, - R_IMF_IMTYPE_H264, - R_IMF_IMTYPE_THEORA, - R_IMF_IMTYPE_XVID)) { - ibuf->ftype = IMB_FTYPE_PNG; - - if (imtype == R_IMF_IMTYPE_PNG) { - if (imf->depth == R_IMF_CHAN_DEPTH_16) { - ibuf->foptions.flag |= PNG_16BIT; - } - - ibuf->foptions.quality = compress; - } - } -#ifdef WITH_DDS - else if (imtype == R_IMF_IMTYPE_DDS) { - ibuf->ftype = IMB_FTYPE_DDS; - } -#endif - else if (imtype == R_IMF_IMTYPE_BMP) { - ibuf->ftype = IMB_FTYPE_BMP; - } -#ifdef WITH_TIFF - else if (imtype == R_IMF_IMTYPE_TIFF) { - ibuf->ftype = IMB_FTYPE_TIF; - - if (imf->depth == R_IMF_CHAN_DEPTH_16) { - ibuf->foptions.flag |= TIF_16BIT; - } - if (imf->tiff_codec == R_IMF_TIFF_CODEC_NONE) { - ibuf->foptions.flag |= TIF_COMPRESS_NONE; - } - else if (imf->tiff_codec == R_IMF_TIFF_CODEC_DEFLATE) { - ibuf->foptions.flag |= TIF_COMPRESS_DEFLATE; - } - else if (imf->tiff_codec == R_IMF_TIFF_CODEC_LZW) { - ibuf->foptions.flag |= TIF_COMPRESS_LZW; - } - else if (imf->tiff_codec == R_IMF_TIFF_CODEC_PACKBITS) { - ibuf->foptions.flag |= TIF_COMPRESS_PACKBITS; - } - } -#endif -#ifdef WITH_OPENEXR - else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { - ibuf->ftype = IMB_FTYPE_OPENEXR; - if (imf->depth == R_IMF_CHAN_DEPTH_16) { - ibuf->foptions.flag |= OPENEXR_HALF; - } - ibuf->foptions.flag |= (imf->exr_codec & OPENEXR_COMPRESS); - - if (!(imf->flag & R_IMF_FLAG_ZBUF)) { - /* Signal for exr saving. */ - IMB_freezbuffloatImBuf(ibuf); - } - } -#endif -#ifdef WITH_CINEON - else if (imtype == R_IMF_IMTYPE_CINEON) { - ibuf->ftype = IMB_FTYPE_CINEON; - if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) { - ibuf->foptions.flag |= CINEON_LOG; - } - if (imf->depth == R_IMF_CHAN_DEPTH_16) { - ibuf->foptions.flag |= CINEON_16BIT; - } - else if (imf->depth == R_IMF_CHAN_DEPTH_12) { - ibuf->foptions.flag |= CINEON_12BIT; - } - else if (imf->depth == R_IMF_CHAN_DEPTH_10) { - ibuf->foptions.flag |= CINEON_10BIT; - } - } - else if (imtype == R_IMF_IMTYPE_DPX) { - ibuf->ftype = IMB_FTYPE_DPX; - if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) { - ibuf->foptions.flag |= CINEON_LOG; - } - if (imf->depth == R_IMF_CHAN_DEPTH_16) { - ibuf->foptions.flag |= CINEON_16BIT; - } - else if (imf->depth == R_IMF_CHAN_DEPTH_12) { - ibuf->foptions.flag |= CINEON_12BIT; - } - else if (imf->depth == R_IMF_CHAN_DEPTH_10) { - ibuf->foptions.flag |= CINEON_10BIT; - } - } -#endif - else if (imtype == R_IMF_IMTYPE_TARGA) { - ibuf->ftype = IMB_FTYPE_TGA; - } - else if (imtype == R_IMF_IMTYPE_RAWTGA) { - ibuf->ftype = IMB_FTYPE_TGA; - ibuf->foptions.flag = RAWTGA; - } -#ifdef WITH_OPENJPEG - else if (imtype == R_IMF_IMTYPE_JP2) { - if (quality < 10) { - quality = 90; - } - ibuf->ftype = IMB_FTYPE_JP2; - ibuf->foptions.quality = quality; - - if (imf->depth == R_IMF_CHAN_DEPTH_16) { - ibuf->foptions.flag |= JP2_16BIT; - } - else if (imf->depth == R_IMF_CHAN_DEPTH_12) { - ibuf->foptions.flag |= JP2_12BIT; - } - - if (imf->jp2_flag & R_IMF_JP2_FLAG_YCC) { - ibuf->foptions.flag |= JP2_YCC; - } - - if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_PRESET) { - ibuf->foptions.flag |= JP2_CINE; - if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_48) { - ibuf->foptions.flag |= JP2_CINE_48FPS; - } - } - - if (imf->jp2_codec == R_IMF_JP2_CODEC_JP2) { - ibuf->foptions.flag |= JP2_JP2; - } - else if (imf->jp2_codec == R_IMF_JP2_CODEC_J2K) { - ibuf->foptions.flag |= JP2_J2K; - } - else { - BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec"); - } - } -#endif - else { - /* #R_IMF_IMTYPE_JPEG90, etc. fallback to JPEG image. */ - if (quality < 10) { - quality = 90; - } - ibuf->ftype = IMB_FTYPE_JPG; - ibuf->foptions.quality = quality; - } -} - int BKE_imbuf_write(ImBuf *ibuf, const char *name, const ImageFormatData *imf) { - BKE_imbuf_write_prepare(ibuf, imf); + BKE_image_format_to_imbuf(ibuf, imf); BLI_make_existing_file(name); @@ -3203,60 +2441,6 @@ int BKE_imbuf_write_stamp(Scene *scene, return BKE_imbuf_write(ibuf, name, imf); } -static void do_makepicstring(char *string, - const char *base, - const char *relbase, - int frame, - const char imtype, - const ImageFormatData *im_format, - const bool use_ext, - const bool use_frames, - const char *suffix) -{ - if (string == nullptr) { - return; - } - BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ - BLI_path_abs(string, relbase); - - if (use_frames) { - BLI_path_frame(string, frame, 4); - } - - if (suffix) { - BLI_path_suffix(string, FILE_MAX, suffix, ""); - } - - if (use_ext) { - do_add_image_extension(string, imtype, im_format); - } -} - -void BKE_image_path_from_imformat(char *string, - const char *base, - const char *relbase, - int frame, - const ImageFormatData *im_format, - const bool use_ext, - const bool use_frames, - const char *suffix) -{ - do_makepicstring( - string, base, relbase, frame, im_format->imtype, im_format, use_ext, use_frames, suffix); -} - -void BKE_image_path_from_imtype(char *string, - const char *base, - const char *relbase, - int frame, - const char imtype, - const bool use_ext, - const bool use_frames, - const char *suffix) -{ - do_makepicstring(string, base, relbase, frame, imtype, nullptr, use_ext, use_frames, suffix); -} - struct anim *openanim_noload(const char *name, int flags, int streamindex, @@ -6116,8 +5300,8 @@ bool BKE_image_buffer_format_writable(ImBuf *ibuf) { ImageFormatData im_format; ImbFormatOptions options_dummy; - BKE_imbuf_to_image_format(&im_format, ibuf); - return (BKE_image_imtype_to_ftype(im_format.imtype, &options_dummy) == ibuf->ftype); + BKE_image_format_from_imbuf(&im_format, ibuf); + return (BKE_imtype_to_ftype(im_format.imtype, &options_dummy) == ibuf->ftype); } void BKE_image_file_format_set(Image *image, int ftype, const ImbFormatOptions *options) diff --git a/source/blender/blenkernel/intern/image_format.cc b/source/blender/blenkernel/intern/image_format.cc new file mode 100644 index 00000000000..f0400417ffc --- /dev/null +++ b/source/blender/blenkernel/intern/image_format.cc @@ -0,0 +1,874 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2001-2002 NaN Holding BV. All rights reserved. */ + +/** \file + * \ingroup bke + */ + +#include <string.h> + +#include "DNA_defaults.h" +#include "DNA_scene_types.h" + +#include "BLI_path_util.h" +#include "BLI_string.h" +#include "BLI_utildefines.h" + +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +#include "BKE_colortools.h" +#include "BKE_image_format.h" + +/* Init/Copy/Free */ + +void BKE_image_format_init(ImageFormatData *imf, const bool render) +{ + *imf = *DNA_struct_default_get(ImageFormatData); + + BKE_color_managed_display_settings_init(&imf->display_settings); + + if (render) { + BKE_color_managed_view_settings_init_render( + &imf->view_settings, &imf->display_settings, "Filmic"); + } + else { + BKE_color_managed_view_settings_init_default(&imf->view_settings, &imf->display_settings); + } + + BKE_color_managed_colorspace_settings_init(&imf->linear_colorspace_settings); +} + +void BKE_image_format_copy(ImageFormatData *imf_dst, const ImageFormatData *imf_src) +{ + memcpy(imf_dst, imf_src, sizeof(*imf_dst)); + BKE_color_managed_display_settings_copy(&imf_dst->display_settings, &imf_src->display_settings); + BKE_color_managed_view_settings_copy(&imf_dst->view_settings, &imf_src->view_settings); + BKE_color_managed_colorspace_settings_copy(&imf_dst->linear_colorspace_settings, + &imf_src->linear_colorspace_settings); +} + +void BKE_image_format_free(ImageFormatData *imf) +{ + BKE_color_managed_view_settings_free(&imf->view_settings); +} + +void BKE_image_format_blend_read_data(BlendDataReader *reader, ImageFormatData *imf) +{ + BKE_color_managed_view_settings_blend_read_data(reader, &imf->view_settings); +} + +void BKE_image_format_blend_write(BlendWriter *writer, ImageFormatData *imf) +{ + BKE_color_managed_view_settings_blend_write(writer, &imf->view_settings); +} + +/* File Types */ + +int BKE_imtype_to_ftype(const char imtype, ImbFormatOptions *r_options) +{ + memset(r_options, 0, sizeof(*r_options)); + + if (imtype == R_IMF_IMTYPE_TARGA) { + return IMB_FTYPE_TGA; + } + if (imtype == R_IMF_IMTYPE_RAWTGA) { + r_options->flag = RAWTGA; + return IMB_FTYPE_TGA; + } + if (imtype == R_IMF_IMTYPE_IRIS) { + return IMB_FTYPE_IMAGIC; + } +#ifdef WITH_HDR + if (imtype == R_IMF_IMTYPE_RADHDR) { + return IMB_FTYPE_RADHDR; + } +#endif + if (imtype == R_IMF_IMTYPE_PNG) { + r_options->quality = 15; + return IMB_FTYPE_PNG; + } +#ifdef WITH_DDS + if (imtype == R_IMF_IMTYPE_DDS) { + return IMB_FTYPE_DDS; + } +#endif + if (imtype == R_IMF_IMTYPE_BMP) { + return IMB_FTYPE_BMP; + } +#ifdef WITH_TIFF + if (imtype == R_IMF_IMTYPE_TIFF) { + return IMB_FTYPE_TIF; + } +#endif + if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { + return IMB_FTYPE_OPENEXR; + } +#ifdef WITH_CINEON + if (imtype == R_IMF_IMTYPE_CINEON) { + return IMB_FTYPE_CINEON; + } + if (imtype == R_IMF_IMTYPE_DPX) { + return IMB_FTYPE_DPX; + } +#endif +#ifdef WITH_OPENJPEG + if (imtype == R_IMF_IMTYPE_JP2) { + r_options->flag |= JP2_JP2; + r_options->quality = 90; + return IMB_FTYPE_JP2; + } +#endif + + r_options->quality = 90; + return IMB_FTYPE_JPG; +} + +char BKE_ftype_to_imtype(const int ftype, const ImbFormatOptions *options) +{ + if (ftype == IMB_FTYPE_NONE) { + return R_IMF_IMTYPE_TARGA; + } + if (ftype == IMB_FTYPE_IMAGIC) { + return R_IMF_IMTYPE_IRIS; + } +#ifdef WITH_HDR + if (ftype == IMB_FTYPE_RADHDR) { + return R_IMF_IMTYPE_RADHDR; + } +#endif + if (ftype == IMB_FTYPE_PNG) { + return R_IMF_IMTYPE_PNG; + } +#ifdef WITH_DDS + if (ftype == IMB_FTYPE_DDS) { + return R_IMF_IMTYPE_DDS; + } +#endif + if (ftype == IMB_FTYPE_BMP) { + return R_IMF_IMTYPE_BMP; + } +#ifdef WITH_TIFF + if (ftype == IMB_FTYPE_TIF) { + return R_IMF_IMTYPE_TIFF; + } +#endif + if (ftype == IMB_FTYPE_OPENEXR) { + return R_IMF_IMTYPE_OPENEXR; + } +#ifdef WITH_CINEON + if (ftype == IMB_FTYPE_CINEON) { + return R_IMF_IMTYPE_CINEON; + } + if (ftype == IMB_FTYPE_DPX) { + return R_IMF_IMTYPE_DPX; + } +#endif + if (ftype == IMB_FTYPE_TGA) { + if (options && (options->flag & RAWTGA)) { + return R_IMF_IMTYPE_RAWTGA; + } + + return R_IMF_IMTYPE_TARGA; + } +#ifdef WITH_OPENJPEG + if (ftype == IMB_FTYPE_JP2) { + return R_IMF_IMTYPE_JP2; + } +#endif + + return R_IMF_IMTYPE_JPEG90; +} + +bool BKE_imtype_is_movie(const char imtype) +{ + switch (imtype) { + case R_IMF_IMTYPE_AVIRAW: + case R_IMF_IMTYPE_AVIJPEG: + case R_IMF_IMTYPE_FFMPEG: + case R_IMF_IMTYPE_H264: + case R_IMF_IMTYPE_THEORA: + case R_IMF_IMTYPE_XVID: + return true; + } + return false; +} + +bool BKE_imtype_supports_zbuf(const char imtype) +{ + switch (imtype) { + case R_IMF_IMTYPE_IRIZ: + case R_IMF_IMTYPE_OPENEXR: /* but not R_IMF_IMTYPE_MULTILAYER */ + return true; + } + return false; +} + +bool BKE_imtype_supports_compress(const char imtype) +{ + switch (imtype) { + case R_IMF_IMTYPE_PNG: + return true; + } + return false; +} + +bool BKE_imtype_supports_quality(const char imtype) +{ + switch (imtype) { + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_JP2: + case R_IMF_IMTYPE_AVIJPEG: + return true; + } + return false; +} + +bool BKE_imtype_requires_linear_float(const char imtype) +{ + switch (imtype) { + case R_IMF_IMTYPE_CINEON: + case R_IMF_IMTYPE_DPX: + case R_IMF_IMTYPE_RADHDR: + case R_IMF_IMTYPE_OPENEXR: + case R_IMF_IMTYPE_MULTILAYER: + return true; + } + return false; +} + +char BKE_imtype_valid_channels(const char imtype, bool write_file) +{ + char chan_flag = IMA_CHAN_FLAG_RGB; /* Assume all support RGB. */ + + /* Alpha. */ + switch (imtype) { + case R_IMF_IMTYPE_BMP: + if (write_file) { + break; + } + ATTR_FALLTHROUGH; + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_RAWTGA: + case R_IMF_IMTYPE_IRIS: + case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_OPENEXR: + case R_IMF_IMTYPE_MULTILAYER: + case R_IMF_IMTYPE_DDS: + case R_IMF_IMTYPE_JP2: + case R_IMF_IMTYPE_DPX: + chan_flag |= IMA_CHAN_FLAG_ALPHA; + break; + } + + /* BW. */ + switch (imtype) { + case R_IMF_IMTYPE_BMP: + case R_IMF_IMTYPE_PNG: + case R_IMF_IMTYPE_JPEG90: + case R_IMF_IMTYPE_TARGA: + case R_IMF_IMTYPE_RAWTGA: + case R_IMF_IMTYPE_TIFF: + case R_IMF_IMTYPE_IRIS: + chan_flag |= IMA_CHAN_FLAG_BW; + break; + } + + return chan_flag; +} + +char BKE_imtype_valid_depths(const char imtype) +{ + switch (imtype) { + case R_IMF_IMTYPE_RADHDR: + return R_IMF_CHAN_DEPTH_32; + case R_IMF_IMTYPE_TIFF: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; + case R_IMF_IMTYPE_OPENEXR: + return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; + case R_IMF_IMTYPE_MULTILAYER: + return R_IMF_CHAN_DEPTH_16 | R_IMF_CHAN_DEPTH_32; + /* NOTE: CINEON uses an unusual 10bits-LOG per channel. */ + case R_IMF_IMTYPE_DPX: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_10 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; + case R_IMF_IMTYPE_CINEON: + return R_IMF_CHAN_DEPTH_10; + case R_IMF_IMTYPE_JP2: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_12 | R_IMF_CHAN_DEPTH_16; + case R_IMF_IMTYPE_PNG: + return R_IMF_CHAN_DEPTH_8 | R_IMF_CHAN_DEPTH_16; + /* Most formats are 8bit only. */ + default: + return R_IMF_CHAN_DEPTH_8; + } +} + +char BKE_imtype_from_arg(const char *imtype_arg) +{ + if (STREQ(imtype_arg, "TGA")) { + return R_IMF_IMTYPE_TARGA; + } + if (STREQ(imtype_arg, "IRIS")) { + return R_IMF_IMTYPE_IRIS; + } +#ifdef WITH_DDS + if (STREQ(imtype_arg, "DDS")) { + return R_IMF_IMTYPE_DDS; + } +#endif + if (STREQ(imtype_arg, "JPEG")) { + return R_IMF_IMTYPE_JPEG90; + } + if (STREQ(imtype_arg, "IRIZ")) { + return R_IMF_IMTYPE_IRIZ; + } + if (STREQ(imtype_arg, "RAWTGA")) { + return R_IMF_IMTYPE_RAWTGA; + } + if (STREQ(imtype_arg, "AVIRAW")) { + return R_IMF_IMTYPE_AVIRAW; + } + if (STREQ(imtype_arg, "AVIJPEG")) { + return R_IMF_IMTYPE_AVIJPEG; + } + if (STREQ(imtype_arg, "PNG")) { + return R_IMF_IMTYPE_PNG; + } + if (STREQ(imtype_arg, "BMP")) { + return R_IMF_IMTYPE_BMP; + } +#ifdef WITH_HDR + if (STREQ(imtype_arg, "HDR")) { + return R_IMF_IMTYPE_RADHDR; + } +#endif +#ifdef WITH_TIFF + if (STREQ(imtype_arg, "TIFF")) { + return R_IMF_IMTYPE_TIFF; + } +#endif +#ifdef WITH_OPENEXR + if (STREQ(imtype_arg, "OPEN_EXR")) { + return R_IMF_IMTYPE_OPENEXR; + } + if (STREQ(imtype_arg, "OPEN_EXR_MULTILAYER")) { + return R_IMF_IMTYPE_MULTILAYER; + } + if (STREQ(imtype_arg, "EXR")) { + return R_IMF_IMTYPE_OPENEXR; + } + if (STREQ(imtype_arg, "MULTILAYER")) { + return R_IMF_IMTYPE_MULTILAYER; + } +#endif + if (STREQ(imtype_arg, "FFMPEG")) { + return R_IMF_IMTYPE_FFMPEG; + } +#ifdef WITH_CINEON + if (STREQ(imtype_arg, "CINEON")) { + return R_IMF_IMTYPE_CINEON; + } + if (STREQ(imtype_arg, "DPX")) { + return R_IMF_IMTYPE_DPX; + } +#endif +#ifdef WITH_OPENJPEG + if (STREQ(imtype_arg, "JP2")) { + return R_IMF_IMTYPE_JP2; + } +#endif + + return R_IMF_IMTYPE_INVALID; +} + +/* File Paths */ + +static bool do_add_image_extension(char *string, + const char imtype, + const ImageFormatData *im_format) +{ + const char *extension = nullptr; + const char *extension_test; + (void)im_format; /* may be unused, depends on build options */ + + if (imtype == R_IMF_IMTYPE_IRIS) { + if (!BLI_path_extension_check(string, extension_test = ".rgb")) { + extension = extension_test; + } + } + else if (imtype == R_IMF_IMTYPE_IRIZ) { + if (!BLI_path_extension_check(string, extension_test = ".rgb")) { + extension = extension_test; + } + } +#ifdef WITH_HDR + else if (imtype == R_IMF_IMTYPE_RADHDR) { + if (!BLI_path_extension_check(string, extension_test = ".hdr")) { + extension = extension_test; + } + } +#endif + else if (ELEM(imtype, + R_IMF_IMTYPE_PNG, + R_IMF_IMTYPE_FFMPEG, + R_IMF_IMTYPE_H264, + R_IMF_IMTYPE_THEORA, + R_IMF_IMTYPE_XVID)) { + if (!BLI_path_extension_check(string, extension_test = ".png")) { + extension = extension_test; + } + } +#ifdef WITH_DDS + else if (imtype == R_IMF_IMTYPE_DDS) { + if (!BLI_path_extension_check(string, extension_test = ".dds")) { + extension = extension_test; + } + } +#endif + else if (ELEM(imtype, R_IMF_IMTYPE_TARGA, R_IMF_IMTYPE_RAWTGA)) { + if (!BLI_path_extension_check(string, extension_test = ".tga")) { + extension = extension_test; + } + } + else if (imtype == R_IMF_IMTYPE_BMP) { + if (!BLI_path_extension_check(string, extension_test = ".bmp")) { + extension = extension_test; + } + } +#ifdef WITH_TIFF + else if (imtype == R_IMF_IMTYPE_TIFF) { + if (!BLI_path_extension_check_n(string, extension_test = ".tif", ".tiff", nullptr)) { + extension = extension_test; + } + } +#endif +#ifdef WITH_OPENIMAGEIO + else if (imtype == R_IMF_IMTYPE_PSD) { + if (!BLI_path_extension_check(string, extension_test = ".psd")) { + extension = extension_test; + } + } +#endif +#ifdef WITH_OPENEXR + else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { + if (!BLI_path_extension_check(string, extension_test = ".exr")) { + extension = extension_test; + } + } +#endif +#ifdef WITH_CINEON + else if (imtype == R_IMF_IMTYPE_CINEON) { + if (!BLI_path_extension_check(string, extension_test = ".cin")) { + extension = extension_test; + } + } + else if (imtype == R_IMF_IMTYPE_DPX) { + if (!BLI_path_extension_check(string, extension_test = ".dpx")) { + extension = extension_test; + } + } +#endif +#ifdef WITH_OPENJPEG + else if (imtype == R_IMF_IMTYPE_JP2) { + if (im_format) { + if (im_format->jp2_codec == R_IMF_JP2_CODEC_JP2) { + if (!BLI_path_extension_check(string, extension_test = ".jp2")) { + extension = extension_test; + } + } + else if (im_format->jp2_codec == R_IMF_JP2_CODEC_J2K) { + if (!BLI_path_extension_check(string, extension_test = ".j2c")) { + extension = extension_test; + } + } + else { + BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec"); + } + } + else { + if (!BLI_path_extension_check(string, extension_test = ".jp2")) { + extension = extension_test; + } + } + } +#endif + else { // R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90 etc + if (!(BLI_path_extension_check_n(string, extension_test = ".jpg", ".jpeg", nullptr))) { + extension = extension_test; + } + } + + if (extension) { + /* prefer this in many cases to avoid .png.tga, but in certain cases it breaks */ + /* remove any other known image extension */ + if (BLI_path_extension_check_array(string, imb_ext_image)) { + return BLI_path_extension_replace(string, FILE_MAX, extension); + } + + return BLI_path_extension_ensure(string, FILE_MAX, extension); + } + + return false; +} + +int BKE_image_path_ensure_ext_from_imformat(char *string, const ImageFormatData *im_format) +{ + return do_add_image_extension(string, im_format->imtype, im_format); +} + +int BKE_image_path_ensure_ext_from_imtype(char *string, const char imtype) +{ + return do_add_image_extension(string, imtype, nullptr); +} + +static void do_makepicstring(char *string, + const char *base, + const char *relbase, + int frame, + const char imtype, + const ImageFormatData *im_format, + const bool use_ext, + const bool use_frames, + const char *suffix) +{ + if (string == nullptr) { + return; + } + BLI_strncpy(string, base, FILE_MAX - 10); /* weak assumption */ + BLI_path_abs(string, relbase); + + if (use_frames) { + BLI_path_frame(string, frame, 4); + } + + if (suffix) { + BLI_path_suffix(string, FILE_MAX, suffix, ""); + } + + if (use_ext) { + do_add_image_extension(string, imtype, im_format); + } +} + +void BKE_image_path_from_imformat(char *string, + const char *base, + const char *relbase, + int frame, + const ImageFormatData *im_format, + const bool use_ext, + const bool use_frames, + const char *suffix) +{ + do_makepicstring( + string, base, relbase, frame, im_format->imtype, im_format, use_ext, use_frames, suffix); +} + +void BKE_image_path_from_imtype(char *string, + const char *base, + const char *relbase, + int frame, + const char imtype, + const bool use_ext, + const bool use_frames, + const char *suffix) +{ + do_makepicstring(string, base, relbase, frame, imtype, nullptr, use_ext, use_frames, suffix); +} + +/* ImBuf Conversion */ + +void BKE_image_format_to_imbuf(ImBuf *ibuf, const ImageFormatData *imf) +{ + /* Write to ImBuf in preparation for file writing. */ + char imtype = imf->imtype; + char compress = imf->compress; + char quality = imf->quality; + + /* initialize all from image format */ + ibuf->foptions.flag = 0; + + if (imtype == R_IMF_IMTYPE_IRIS) { + ibuf->ftype = IMB_FTYPE_IMAGIC; + } +#ifdef WITH_HDR + else if (imtype == R_IMF_IMTYPE_RADHDR) { + ibuf->ftype = IMB_FTYPE_RADHDR; + } +#endif + else if (ELEM(imtype, + R_IMF_IMTYPE_PNG, + R_IMF_IMTYPE_FFMPEG, + R_IMF_IMTYPE_H264, + R_IMF_IMTYPE_THEORA, + R_IMF_IMTYPE_XVID)) { + ibuf->ftype = IMB_FTYPE_PNG; + + if (imtype == R_IMF_IMTYPE_PNG) { + if (imf->depth == R_IMF_CHAN_DEPTH_16) { + ibuf->foptions.flag |= PNG_16BIT; + } + + ibuf->foptions.quality = compress; + } + } +#ifdef WITH_DDS + else if (imtype == R_IMF_IMTYPE_DDS) { + ibuf->ftype = IMB_FTYPE_DDS; + } +#endif + else if (imtype == R_IMF_IMTYPE_BMP) { + ibuf->ftype = IMB_FTYPE_BMP; + } +#ifdef WITH_TIFF + else if (imtype == R_IMF_IMTYPE_TIFF) { + ibuf->ftype = IMB_FTYPE_TIF; + + if (imf->depth == R_IMF_CHAN_DEPTH_16) { + ibuf->foptions.flag |= TIF_16BIT; + } + if (imf->tiff_codec == R_IMF_TIFF_CODEC_NONE) { + ibuf->foptions.flag |= TIF_COMPRESS_NONE; + } + else if (imf->tiff_codec == R_IMF_TIFF_CODEC_DEFLATE) { + ibuf->foptions.flag |= TIF_COMPRESS_DEFLATE; + } + else if (imf->tiff_codec == R_IMF_TIFF_CODEC_LZW) { + ibuf->foptions.flag |= TIF_COMPRESS_LZW; + } + else if (imf->tiff_codec == R_IMF_TIFF_CODEC_PACKBITS) { + ibuf->foptions.flag |= TIF_COMPRESS_PACKBITS; + } + } +#endif +#ifdef WITH_OPENEXR + else if (ELEM(imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { + ibuf->ftype = IMB_FTYPE_OPENEXR; + if (imf->depth == R_IMF_CHAN_DEPTH_16) { + ibuf->foptions.flag |= OPENEXR_HALF; + } + ibuf->foptions.flag |= (imf->exr_codec & OPENEXR_COMPRESS); + + if (!(imf->flag & R_IMF_FLAG_ZBUF)) { + /* Signal for exr saving. */ + IMB_freezbuffloatImBuf(ibuf); + } + } +#endif +#ifdef WITH_CINEON + else if (imtype == R_IMF_IMTYPE_CINEON) { + ibuf->ftype = IMB_FTYPE_CINEON; + if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) { + ibuf->foptions.flag |= CINEON_LOG; + } + if (imf->depth == R_IMF_CHAN_DEPTH_16) { + ibuf->foptions.flag |= CINEON_16BIT; + } + else if (imf->depth == R_IMF_CHAN_DEPTH_12) { + ibuf->foptions.flag |= CINEON_12BIT; + } + else if (imf->depth == R_IMF_CHAN_DEPTH_10) { + ibuf->foptions.flag |= CINEON_10BIT; + } + } + else if (imtype == R_IMF_IMTYPE_DPX) { + ibuf->ftype = IMB_FTYPE_DPX; + if (imf->cineon_flag & R_IMF_CINEON_FLAG_LOG) { + ibuf->foptions.flag |= CINEON_LOG; + } + if (imf->depth == R_IMF_CHAN_DEPTH_16) { + ibuf->foptions.flag |= CINEON_16BIT; + } + else if (imf->depth == R_IMF_CHAN_DEPTH_12) { + ibuf->foptions.flag |= CINEON_12BIT; + } + else if (imf->depth == R_IMF_CHAN_DEPTH_10) { + ibuf->foptions.flag |= CINEON_10BIT; + } + } +#endif + else if (imtype == R_IMF_IMTYPE_TARGA) { + ibuf->ftype = IMB_FTYPE_TGA; + } + else if (imtype == R_IMF_IMTYPE_RAWTGA) { + ibuf->ftype = IMB_FTYPE_TGA; + ibuf->foptions.flag = RAWTGA; + } +#ifdef WITH_OPENJPEG + else if (imtype == R_IMF_IMTYPE_JP2) { + if (quality < 10) { + quality = 90; + } + ibuf->ftype = IMB_FTYPE_JP2; + ibuf->foptions.quality = quality; + + if (imf->depth == R_IMF_CHAN_DEPTH_16) { + ibuf->foptions.flag |= JP2_16BIT; + } + else if (imf->depth == R_IMF_CHAN_DEPTH_12) { + ibuf->foptions.flag |= JP2_12BIT; + } + + if (imf->jp2_flag & R_IMF_JP2_FLAG_YCC) { + ibuf->foptions.flag |= JP2_YCC; + } + + if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_PRESET) { + ibuf->foptions.flag |= JP2_CINE; + if (imf->jp2_flag & R_IMF_JP2_FLAG_CINE_48) { + ibuf->foptions.flag |= JP2_CINE_48FPS; + } + } + + if (imf->jp2_codec == R_IMF_JP2_CODEC_JP2) { + ibuf->foptions.flag |= JP2_JP2; + } + else if (imf->jp2_codec == R_IMF_JP2_CODEC_J2K) { + ibuf->foptions.flag |= JP2_J2K; + } + else { + BLI_assert_msg(0, "Unsupported jp2 codec was specified in im_format->jp2_codec"); + } + } +#endif + else { + /* R_IMF_IMTYPE_JPEG90, etc. default we save jpegs */ + if (quality < 10) { + quality = 90; + } + ibuf->ftype = IMB_FTYPE_JPG; + ibuf->foptions.quality = quality; + } +} + +void BKE_image_format_from_imbuf(ImageFormatData *im_format, const ImBuf *imbuf) +{ + /* Read from ImBuf after file read. */ + int ftype = imbuf->ftype; + int custom_flags = imbuf->foptions.flag; + char quality = imbuf->foptions.quality; + + BKE_image_format_init(im_format, false); + + /* file type */ + if (ftype == IMB_FTYPE_IMAGIC) { + im_format->imtype = R_IMF_IMTYPE_IRIS; + } +#ifdef WITH_HDR + else if (ftype == IMB_FTYPE_RADHDR) { + im_format->imtype = R_IMF_IMTYPE_RADHDR; + } +#endif + else if (ftype == IMB_FTYPE_PNG) { + im_format->imtype = R_IMF_IMTYPE_PNG; + + if (custom_flags & PNG_16BIT) { + im_format->depth = R_IMF_CHAN_DEPTH_16; + } + + im_format->compress = quality; + } + +#ifdef WITH_DDS + else if (ftype == IMB_FTYPE_DDS) { + im_format->imtype = R_IMF_IMTYPE_DDS; + } +#endif + else if (ftype == IMB_FTYPE_BMP) { + im_format->imtype = R_IMF_IMTYPE_BMP; + } +#ifdef WITH_TIFF + else if (ftype == IMB_FTYPE_TIF) { + im_format->imtype = R_IMF_IMTYPE_TIFF; + if (custom_flags & TIF_16BIT) { + im_format->depth = R_IMF_CHAN_DEPTH_16; + } + if (custom_flags & TIF_COMPRESS_NONE) { + im_format->tiff_codec = R_IMF_TIFF_CODEC_NONE; + } + if (custom_flags & TIF_COMPRESS_DEFLATE) { + im_format->tiff_codec = R_IMF_TIFF_CODEC_DEFLATE; + } + if (custom_flags & TIF_COMPRESS_LZW) { + im_format->tiff_codec = R_IMF_TIFF_CODEC_LZW; + } + if (custom_flags & TIF_COMPRESS_PACKBITS) { + im_format->tiff_codec = R_IMF_TIFF_CODEC_PACKBITS; + } + } +#endif + +#ifdef WITH_OPENEXR + else if (ftype == IMB_FTYPE_OPENEXR) { + im_format->imtype = R_IMF_IMTYPE_OPENEXR; + if (custom_flags & OPENEXR_HALF) { + im_format->depth = R_IMF_CHAN_DEPTH_16; + } + if (custom_flags & OPENEXR_COMPRESS) { + im_format->exr_codec = R_IMF_EXR_CODEC_ZIP; /* Can't determine compression */ + } + if (imbuf->zbuf_float) { + im_format->flag |= R_IMF_FLAG_ZBUF; + } + } +#endif + +#ifdef WITH_CINEON + else if (ftype == IMB_FTYPE_CINEON) { + im_format->imtype = R_IMF_IMTYPE_CINEON; + } + else if (ftype == IMB_FTYPE_DPX) { + im_format->imtype = R_IMF_IMTYPE_DPX; + } +#endif + else if (ftype == IMB_FTYPE_TGA) { + if (custom_flags & RAWTGA) { + im_format->imtype = R_IMF_IMTYPE_RAWTGA; + } + else { + im_format->imtype = R_IMF_IMTYPE_TARGA; + } + } +#ifdef WITH_OPENJPEG + else if (ftype == IMB_FTYPE_JP2) { + im_format->imtype = R_IMF_IMTYPE_JP2; + im_format->quality = quality; + + if (custom_flags & JP2_16BIT) { + im_format->depth = R_IMF_CHAN_DEPTH_16; + } + else if (custom_flags & JP2_12BIT) { + im_format->depth = R_IMF_CHAN_DEPTH_12; + } + + if (custom_flags & JP2_YCC) { + im_format->jp2_flag |= R_IMF_JP2_FLAG_YCC; + } + + if (custom_flags & JP2_CINE) { + im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_PRESET; + if (custom_flags & JP2_CINE_48FPS) { + im_format->jp2_flag |= R_IMF_JP2_FLAG_CINE_48; + } + } + + if (custom_flags & JP2_JP2) { + im_format->jp2_codec = R_IMF_JP2_CODEC_JP2; + } + else if (custom_flags & JP2_J2K) { + im_format->jp2_codec = R_IMF_JP2_CODEC_J2K; + } + else { + BLI_assert_msg(0, "Unsupported jp2 codec was specified in file type"); + } + } +#endif + + else { + im_format->imtype = R_IMF_IMTYPE_JPEG90; + im_format->quality = quality; + } + + /* planes */ + im_format->planes = imbuf->planes; +} diff --git a/source/blender/blenkernel/intern/image_save.c b/source/blender/blenkernel/intern/image_save.c index ae8f4c044fe..2361b0b8e9a 100644 --- a/source/blender/blenkernel/intern/image_save.c +++ b/source/blender/blenkernel/intern/image_save.c @@ -22,6 +22,7 @@ #include "BKE_colortools.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_image_save.h" #include "BKE_main.h" #include "BKE_report.h" @@ -36,7 +37,12 @@ void BKE_image_save_options_init(ImageSaveOptions *opts, Main *bmain, Scene *sce opts->bmain = bmain; opts->scene = scene; - BKE_imformat_defaults(&opts->im_format); + BKE_image_format_init(&opts->im_format, false); +} + +void BKE_image_save_options_free(ImageSaveOptions *opts) +{ + BKE_image_format_free(&opts->im_format); } static void image_save_post(ReportList *reports, @@ -349,7 +355,7 @@ static bool image_save_single(ReportList *reports, colormanaged_ibuf = IMB_colormanagement_imbuf_for_write( ibuf, save_as_render, true, &imf->view_settings, &imf->display_settings, imf); - BKE_imbuf_write_prepare(colormanaged_ibuf, imf); + BKE_image_format_to_imbuf(colormanaged_ibuf, imf); IMB_prepare_write_ImBuf(IMB_isfloat(colormanaged_ibuf), colormanaged_ibuf); /* duplicate buffer to prevent locker issue when using render result */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index e08bfac7ce9..e3fe5d77d63 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -55,6 +55,7 @@ #include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_idtype.h" +#include "BKE_image_format.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_main.h" @@ -595,8 +596,13 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree) if (node->type == CMP_NODE_OUTPUT_FILE) { /* Inputs have their own storage data. */ + NodeImageMultiFile *nimf = (NodeImageMultiFile *)node->storage; + BKE_image_format_blend_write(writer, &nimf->format); + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { - BLO_write_struct(writer, NodeImageMultiFileSocket, sock->storage); + NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)sock->storage; + BLO_write_struct(writer, NodeImageMultiFileSocket, sockdata); + BKE_image_format_blend_write(writer, &sockdata->format); } } if (ELEM(node->type, CMP_NODE_IMAGE, CMP_NODE_R_LAYERS)) { @@ -749,6 +755,11 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) iuser->scene = nullptr; break; } + case CMP_NODE_OUTPUT_FILE: { + NodeImageMultiFile *nimf = (NodeImageMultiFile *)node->storage; + BKE_image_format_blend_read_data(reader, &nimf->format); + break; + } case FN_NODE_INPUT_STRING: { NodeInputString *storage = (NodeInputString *)node->storage; BLO_read_data_address(reader, &storage->string); @@ -771,6 +782,14 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree) LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { direct_link_node_socket(reader, sock); } + + /* Socket storage. */ + if (node->type == CMP_NODE_OUTPUT_FILE) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)sock->storage; + BKE_image_format_blend_read_data(reader, &sockdata->format); + } + } } /* interface socket lists */ diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 70a11dce92d..4dc0130366e 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -25,6 +25,7 @@ #include "BLI_utildefines.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_ocean.h" #include "ocean_intern.h" diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 62794e3d0ec..4c5fefefd8e 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -28,6 +28,7 @@ #include "BLI_utildefines.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_packedFile.h" #include "BKE_report.h" @@ -503,7 +504,7 @@ static void unpack_generate_paths(const char *name, const PackedFile *pf = imapf->packedfile; enum eImbFileType ftype = IMB_ispic_type_from_memory((const uchar *)pf->data, pf->size); if (ftype != IMB_FTYPE_NONE) { - const int imtype = BKE_image_ftype_to_imtype(ftype, NULL); + const int imtype = BKE_ftype_to_imtype(ftype, NULL); BKE_image_path_ensure_ext_from_imtype(tempname, imtype); } } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index baf2f0bac8a..86d38064b2d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -70,6 +70,7 @@ #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" @@ -201,15 +202,8 @@ static void scene_init_data(ID *id) colorspace_name, sizeof(scene->sequencer_colorspace_settings.name)); - /* Those next two sets (render and baking settings) are not currently in use, - * but are exposed to RNA API and hence must have valid data. */ - BKE_color_managed_display_settings_init(&scene->r.im_format.display_settings); - BKE_color_managed_view_settings_init_render( - &scene->r.im_format.view_settings, &scene->r.im_format.display_settings, "Filmic"); - - BKE_color_managed_display_settings_init(&scene->r.bake.im_format.display_settings); - BKE_color_managed_view_settings_init_render( - &scene->r.bake.im_format.view_settings, &scene->r.bake.im_format.display_settings, "Filmic"); + BKE_image_format_init(&scene->r.im_format, true); + BKE_image_format_init(&scene->r.bake.im_format, true); /* Curve Profile */ scene->toolsettings->custom_bevel_profile_preset = BKE_curveprofile_add(PROF_PRESET_LINE); @@ -295,15 +289,8 @@ static void scene_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int BKE_color_managed_colorspace_settings_copy(&scene_dst->sequencer_colorspace_settings, &scene_src->sequencer_colorspace_settings); - BKE_color_managed_display_settings_copy(&scene_dst->r.im_format.display_settings, - &scene_src->r.im_format.display_settings); - BKE_color_managed_view_settings_copy(&scene_dst->r.im_format.view_settings, - &scene_src->r.im_format.view_settings); - - BKE_color_managed_display_settings_copy(&scene_dst->r.bake.im_format.display_settings, - &scene_src->r.bake.im_format.display_settings); - BKE_color_managed_view_settings_copy(&scene_dst->r.bake.im_format.view_settings, - &scene_src->r.bake.im_format.view_settings); + BKE_image_format_copy(&scene_dst->r.im_format, &scene_src->r.im_format); + BKE_image_format_copy(&scene_dst->r.bake.im_format, &scene_src->r.bake.im_format); BKE_curvemapping_copy_data(&scene_dst->r.mblur_shutter_curve, &scene_src->r.mblur_shutter_curve); @@ -402,6 +389,8 @@ static void scene_free_data(ID *id) BKE_sound_destroy_scene(scene); BKE_color_managed_view_settings_free(&scene->view_settings); + BKE_image_format_free(&scene->r.im_format); + BKE_image_format_free(&scene->r.bake.im_format); BKE_previewimg_free(&scene->preview); BKE_curvemapping_free_data(&scene->r.mblur_shutter_curve); @@ -1044,6 +1033,8 @@ static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_addres } BKE_color_managed_view_settings_blend_write(writer, &sce->view_settings); + BKE_image_format_blend_write(writer, &sce->r.im_format); + BKE_image_format_blend_write(writer, &sce->r.bake.im_format); /* writing RigidBodyWorld data to the blend file */ if (sce->rigidbody_world) { @@ -1276,6 +1267,8 @@ static void scene_blend_read_data(BlendDataReader *reader, ID *id) } BKE_color_managed_view_settings_blend_read_data(reader, &sce->view_settings); + BKE_image_format_blend_read_data(reader, &sce->r.im_format); + BKE_image_format_blend_read_data(reader, &sce->r.bake.im_format); BLO_read_data_address(reader, &sce->rigidbody_world); RigidBodyWorld *rbw = sce->rigidbody_world; @@ -1855,15 +1848,8 @@ Scene *BKE_scene_duplicate(Main *bmain, Scene *sce, eSceneCopyMethod type) BKE_color_managed_colorspace_settings_copy(&sce_copy->sequencer_colorspace_settings, &sce->sequencer_colorspace_settings); - BKE_color_managed_display_settings_copy(&sce_copy->r.im_format.display_settings, - &sce->r.im_format.display_settings); - BKE_color_managed_view_settings_copy(&sce_copy->r.im_format.view_settings, - &sce->r.im_format.view_settings); - - BKE_color_managed_display_settings_copy(&sce_copy->r.bake.im_format.display_settings, - &sce->r.bake.im_format.display_settings); - BKE_color_managed_view_settings_copy(&sce_copy->r.bake.im_format.view_settings, - &sce->r.bake.im_format.view_settings); + BKE_image_format_copy(&sce_copy->r.im_format, &sce->r.im_format); + BKE_image_format_copy(&sce_copy->r.bake.im_format, &sce->r.bake.im_format); BKE_curvemapping_copy_data(&sce_copy->r.mblur_shutter_curve, &sce->r.mblur_shutter_curve); diff --git a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc index db29a84f7da..4da11cc9053 100644 --- a/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc +++ b/source/blender/compositor/operations/COM_OutputFileMultiViewOperation.cc @@ -4,6 +4,7 @@ #include "COM_OutputFileMultiViewOperation.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_scene.h" diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cc b/source/blender/compositor/operations/COM_OutputFileOperation.cc index 56fbfc570a8..67c92a3bcb0 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cc +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cc @@ -8,6 +8,7 @@ #include "BLI_string.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_scene.h" diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 3529574a3a4..efcb47f76ab 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -23,6 +23,7 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" diff --git a/source/blender/editors/render/render_internal.cc b/source/blender/editors/render/render_internal.cc index 6796eff29d4..e5d2a765ca1 100644 --- a/source/blender/editors/render/render_internal.cc +++ b/source/blender/editors/render/render_internal.cc @@ -31,6 +31,7 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_node.h" diff --git a/source/blender/editors/render/render_opengl.cc b/source/blender/editors/render/render_opengl.cc index be66e87f2e5..872e2867696 100644 --- a/source/blender/editors/render/render_opengl.cc +++ b/source/blender/editors/render/render_opengl.cc @@ -34,6 +34,7 @@ #include "BKE_fcurve.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_lib_query.h" #include "BKE_main.h" #include "BKE_report.h" diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index ff77f9910fb..5464d0a347d 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -24,6 +24,7 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_report.h" #include "BKE_screen.h" @@ -71,7 +72,7 @@ static int screenshot_data_create(bContext *C, wmOperator *op, ScrArea *area) scd->crop = area->totrct; } - BKE_imformat_defaults(&scd->im_format); + BKE_image_format_init(&scd->im_format, false); op->customdata = scd; diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 0af32a717a4..abde5f52bb0 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -20,6 +20,7 @@ #include "BKE_context.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_node.h" #include "BKE_scene.h" #include "BKE_screen.h" diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 3721ea81c04..35be7ffdb8b 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -38,6 +38,7 @@ #include "BKE_global.h" #include "BKE_icons.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_image_save.h" #include "BKE_layer.h" #include "BKE_lib_id.h" @@ -1736,7 +1737,7 @@ static int image_save_options_init(Main *bmain, if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) { /* imtype */ - opts->im_format = scene->r.im_format; + BKE_image_format_copy(&opts->im_format, &scene->r.im_format); is_depth_set = true; if (!BKE_image_is_multiview(ima)) { /* In case multiview is disabled, @@ -1752,7 +1753,7 @@ static int image_save_options_init(Main *bmain, opts->im_format.planes = ibuf->planes; } else { - BKE_imbuf_to_image_format(&opts->im_format, ibuf); + BKE_image_format_from_imbuf(&opts->im_format, ibuf); } /* use the multiview image settings as the default */ @@ -1829,8 +1830,8 @@ static void image_save_options_from_op(Main *bmain, ImageFormatData *imf) { if (imf) { - BKE_color_managed_view_settings_free(&opts->im_format.view_settings); - opts->im_format = *imf; + BKE_image_format_free(&opts->im_format); + BKE_image_format_copy(&opts->im_format, imf); } if (RNA_struct_property_is_set(op->ptr, "filepath")) { @@ -1843,8 +1844,8 @@ static void image_save_options_to_op(ImageSaveOptions *opts, wmOperator *op) { if (op->customdata) { ImageSaveData *isd = op->customdata; - BKE_color_managed_view_settings_free(&isd->im_format.view_settings); - isd->im_format = opts->im_format; + BKE_image_format_free(&isd->im_format); + BKE_image_format_copy(&isd->im_format, &opts->im_format); } RNA_string_set(op->ptr, "filepath", opts->filepath); @@ -1878,7 +1879,7 @@ static void image_save_as_free(wmOperator *op) { if (op->customdata) { ImageSaveData *isd = op->customdata; - BKE_color_managed_view_settings_free(&isd->im_format.view_settings); + BKE_image_format_free(&isd->im_format); MEM_freeN(op->customdata); op->customdata = NULL; @@ -1920,6 +1921,8 @@ static int image_save_as_exec(bContext *C, wmOperator *op) BKE_image_free_packedfiles(image); } + BKE_image_save_options_free(&opts); + image_save_as_free(op); return OPERATOR_FINISHED; @@ -1948,6 +1951,7 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS BKE_image_save_options_init(&opts, bmain, scene); if (image_save_options_init(bmain, &opts, ima, iuser, true, save_as_render) == 0) { + BKE_image_save_options_free(&opts); return OPERATOR_CANCELLED; } image_save_options_to_op(&opts, op); @@ -1964,7 +1968,7 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS isd->image = ima; isd->iuser = iuser; - memcpy(&isd->im_format, &opts.im_format, sizeof(opts.im_format)); + BKE_image_format_copy(&isd->im_format, &opts.im_format); op->customdata = isd; /* show multiview save options only if image has multiviews */ @@ -1974,6 +1978,7 @@ static int image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS RNA_property_boolean_set(op->ptr, prop, BKE_image_is_multiview(ima)); image_filesel(C, op, opts.filepath); + BKE_image_save_options_free(&opts); return OPERATOR_RUNNING_MODAL; } @@ -2132,6 +2137,7 @@ static int image_save_exec(bContext *C, wmOperator *op) BKE_image_save_options_init(&opts, bmain, scene); if (image_save_options_init(bmain, &opts, image, iuser, false, false) == 0) { + BKE_image_save_options_free(&opts); return OPERATOR_CANCELLED; } image_save_options_from_op(bmain, &opts, op, NULL); @@ -2147,7 +2153,7 @@ static int image_save_exec(bContext *C, wmOperator *op) ok = true; } - BKE_color_managed_view_settings_free(&opts.im_format.view_settings); + BKE_image_save_options_free(&opts); if (ok) { return OPERATOR_FINISHED; @@ -2399,6 +2405,7 @@ bool ED_image_save_all_modified(const bContext *C, ReportList *reports) bool saved_successfully = BKE_image_save(reports, bmain, ima, NULL, &opts); ok = ok && saved_successfully; } + BKE_image_save_options_free(&opts); } } } diff --git a/source/blender/imbuf/intern/colormanagement.c b/source/blender/imbuf/intern/colormanagement.c index 15046ea54e1..bf3e50b8870 100644 --- a/source/blender/imbuf/intern/colormanagement.c +++ b/source/blender/imbuf/intern/colormanagement.c @@ -37,6 +37,7 @@ #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "RNA_define.h" @@ -2508,8 +2509,8 @@ ImBuf *IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, * should be pretty safe since this image buffer is supposed to be used for * saving only and ftype would be overwritten a bit later by BKE_imbuf_write */ - colormanaged_ibuf->ftype = BKE_image_imtype_to_ftype(image_format_data->imtype, - &colormanaged_ibuf->foptions); + colormanaged_ibuf->ftype = BKE_imtype_to_ftype(image_format_data->imtype, + &colormanaged_ibuf->foptions); /* if file format isn't able to handle float buffer itself, * we need to allocate byte buffer and store color managed diff --git a/source/blender/io/collada/ImageExporter.cpp b/source/blender/io/collada/ImageExporter.cpp index f57c5dd5e53..1223abbaf95 100644 --- a/source/blender/io/collada/ImageExporter.cpp +++ b/source/blender/io/collada/ImageExporter.cpp @@ -14,6 +14,7 @@ #include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_mesh.h" @@ -48,7 +49,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) bool is_dirty = BKE_image_is_dirty(image); ImageFormatData imageFormat; - BKE_imbuf_to_image_format(&imageFormat, imbuf); + BKE_image_format_from_imbuf(&imageFormat, imbuf); short image_source = image->source; bool is_generated = image_source == IMA_SRC_GENERATED; diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index 09cb0d07493..29ab0479f6e 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -6,6 +6,7 @@ #include "usd_exporter_context.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_main.h" #include "BKE_node.h" @@ -335,7 +336,7 @@ static std::string get_in_memory_texture_filename(Image *ima) } ImageFormatData imageFormat; - BKE_imbuf_to_image_format(&imageFormat, imbuf); + BKE_image_format_from_imbuf(&imageFormat, imbuf); char file_name[FILE_MAX]; /* Use the image name for the file name. */ @@ -368,7 +369,7 @@ static void export_in_memory_texture(Image *ima, } ImageFormatData imageFormat; - BKE_imbuf_to_image_format(&imageFormat, imbuf); + BKE_image_format_from_imbuf(&imageFormat, imbuf); /* This image in its current state only exists in Blender memory. * So we have to export it. The export will keep the image state intact, diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 2f8d1c5eafe..ebc5ebe758f 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -431,6 +431,7 @@ typedef struct ImageFormatData { /* color management */ ColorManagedViewSettings view_settings; ColorManagedDisplaySettings display_settings; + ColorManagedColorspaceSettings linear_colorspace_settings; } ImageFormatData; /** #ImageFormatData.imtype */ @@ -466,8 +467,8 @@ typedef struct ImageFormatData { #define R_IMF_IMTYPE_INVALID 255 /** #ImageFormatData.flag */ -#define R_IMF_FLAG_ZBUF (1 << 0) /* was R_OPENEXR_ZBUF */ -#define R_IMF_FLAG_PREVIEW_JPG (1 << 1) /* was R_PREVIEW_JPG */ +#define R_IMF_FLAG_ZBUF (1 << 0) +#define R_IMF_FLAG_PREVIEW_JPG (1 << 1) /* Return values from #BKE_imtype_valid_depths, note this is depths per channel. */ /** #ImageFormatData.depth */ diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 56e23278176..3a93a44e0d1 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -13,6 +13,7 @@ #include "BLI_utildefines.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_node_tree_update.h" #include "DEG_depsgraph.h" @@ -238,8 +239,8 @@ static int rna_Image_file_format_get(PointerRNA *ptr) { Image *image = (Image *)ptr->data; ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); - int imtype = BKE_image_ftype_to_imtype(ibuf ? ibuf->ftype : IMB_FTYPE_NONE, - ibuf ? &ibuf->foptions : NULL); + int imtype = BKE_ftype_to_imtype(ibuf ? ibuf->ftype : IMB_FTYPE_NONE, + ibuf ? &ibuf->foptions : NULL); BKE_image_release_ibuf(image, ibuf, NULL); @@ -251,7 +252,7 @@ static void rna_Image_file_format_set(PointerRNA *ptr, int value) Image *image = (Image *)ptr->data; if (BKE_imtype_is_movie(value) == 0) { /* should be able to throw an error here */ ImbFormatOptions options; - int ftype = BKE_image_imtype_to_ftype(value, &options); + int ftype = BKE_imtype_to_ftype(value, &options); BKE_image_file_format_set(image, ftype, &options); } } diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index d398dadbec7..c8af634daa9 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -633,6 +633,7 @@ const EnumPropertyItem rna_enum_transform_orientation_items[] = { # include "BKE_gpencil.h" # include "BKE_idprop.h" # include "BKE_image.h" +# include "BKE_image_format.h" # include "BKE_layer.h" # include "BKE_main.h" # include "BKE_mesh.h" diff --git a/source/blender/nodes/composite/nodes/node_composite_output_file.cc b/source/blender/nodes/composite/nodes/node_composite_output_file.cc index 2e1276dda24..0ddeee1d6a7 100644 --- a/source/blender/nodes/composite/nodes/node_composite_output_file.cc +++ b/source/blender/nodes/composite/nodes/node_composite_output_file.cc @@ -12,6 +12,7 @@ #include "BLI_utildefines.h" #include "BKE_context.h" +#include "BKE_image_format.h" #include "RNA_access.h" #include "RNA_prototypes.h" @@ -135,7 +136,7 @@ bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, } } else { - BKE_imformat_defaults(&sockdata->format); + BKE_image_format_init(&sockdata->format, false); } /* use node data format by default */ sockdata->use_node_format = true; @@ -205,7 +206,7 @@ static void init_output_file(const bContext *C, PointerRNA *ptr) format = &nimf->format; } else { - BKE_imformat_defaults(&nimf->format); + BKE_image_format_init(&nimf->format, false); } /* add one socket by default */ @@ -216,9 +217,13 @@ static void free_output_file(bNode *node) { /* free storage data in sockets */ LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)sock->storage; + BKE_image_format_free(&sockdata->format); MEM_freeN(sock->storage); } + NodeImageMultiFile *nimf = (NodeImageMultiFile *)node->storage; + BKE_image_format_free(&nimf->format); MEM_freeN(node->storage); } @@ -229,6 +234,9 @@ static void copy_output_file(bNodeTree *UNUSED(dest_ntree), bNodeSocket *src_sock, *dest_sock; dest_node->storage = MEM_dupallocN(src_node->storage); + NodeImageMultiFile *dest_nimf = (NodeImageMultiFile *)dest_node->storage; + NodeImageMultiFile *src_nimf = (NodeImageMultiFile *)src_node->storage; + BKE_image_format_copy(&dest_nimf->format, &src_nimf->format); /* duplicate storage data in sockets */ for (src_sock = (bNodeSocket *)src_node->inputs.first, @@ -236,6 +244,9 @@ static void copy_output_file(bNodeTree *UNUSED(dest_ntree), src_sock && dest_sock; src_sock = src_sock->next, dest_sock = (bNodeSocket *)dest_sock->next) { dest_sock->storage = MEM_dupallocN(src_sock->storage); + NodeImageMultiFileSocket *dest_sockdata = (NodeImageMultiFileSocket *)dest_sock->storage; + NodeImageMultiFileSocket *src_sockdata = (NodeImageMultiFileSocket *)src_sock->storage; + BKE_image_format_copy(&dest_sockdata->format, &src_sockdata->format); } } diff --git a/source/blender/render/intern/pipeline.c b/source/blender/render/intern/pipeline.c index a025afe4f6a..614c03eba11 100644 --- a/source/blender/render/intern/pipeline.c +++ b/source/blender/render/intern/pipeline.c @@ -44,6 +44,7 @@ #include "BKE_context.h" /* XXX needed by wm_window.h */ #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_lib_remap.h" diff --git a/source/blender/render/intern/render_result.c b/source/blender/render/intern/render_result.c index 41c635e8481..62948d052ba 100644 --- a/source/blender/render/intern/render_result.c +++ b/source/blender/render/intern/render_result.c @@ -26,6 +26,7 @@ #include "BKE_camera.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_report.h" #include "BKE_scene.h" diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 896139796ee..c706e99b592 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -51,6 +51,7 @@ #include "BKE_icons.h" #include "BKE_idprop.h" #include "BKE_image.h" +#include "BKE_image_format.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_main.h" |