Refactor: Use enum class instead of bool video
Pull Request: https://projects.blender.org/blender/blender/pulls/146888
This commit is contained in:
@@ -45,6 +45,8 @@ enum ColorManagedDisplaySpace {
|
||||
DISPLAY_SPACE_COLOR_INSPECTION,
|
||||
};
|
||||
|
||||
enum class ColorManagedFileOutput { Image, Video };
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Generic Functions
|
||||
* \{ */
|
||||
@@ -79,10 +81,11 @@ blender::Vector<char> IMB_colormanagement_space_to_icc_profile(const ColorSpace
|
||||
/* Get CICP code for colorspace.
|
||||
* For describing the colorspace of videos and high dynamic range image files. */
|
||||
bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace,
|
||||
const bool video,
|
||||
const ColorManagedFileOutput output,
|
||||
const bool rgb_matrix,
|
||||
int cicp[4]);
|
||||
const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], const bool video);
|
||||
const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4],
|
||||
const ColorManagedFileOutput output);
|
||||
|
||||
/* Get identifier for colorspaces that works with multiple OpenColorIO configurations,
|
||||
* as defined by the ASWF Color Interop Forum. */
|
||||
|
||||
@@ -8,10 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_math_matrix_types.hh"
|
||||
#include "BLI_math_vector_types.hh"
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
namespace blender::ocio {
|
||||
class ColorSpace;
|
||||
class CPUProcessor;
|
||||
@@ -20,6 +16,7 @@ class CPUProcessor;
|
||||
using ColorSpace = blender::ocio::ColorSpace;
|
||||
|
||||
struct ImBuf;
|
||||
enum class ColorManagedFileOutput;
|
||||
|
||||
#define MAX_COLORSPACE_NAME 64
|
||||
|
||||
@@ -34,4 +31,6 @@ const ColorSpace *colormanage_colorspace_get_named(const char *name);
|
||||
const ColorSpace *colormanage_colorspace_get_roled(int role);
|
||||
|
||||
void colormanage_imbuf_set_default_spaces(ImBuf *ibuf);
|
||||
void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, bool video);
|
||||
void colormanage_imbuf_make_linear(ImBuf *ibuf,
|
||||
const char *from_colorspace,
|
||||
ColorManagedFileOutput output);
|
||||
|
||||
@@ -871,7 +871,9 @@ void colormanage_imbuf_set_default_spaces(ImBuf *ibuf)
|
||||
ibuf->byte_buffer.colorspace = g_config->get_color_space(global_role_default_byte);
|
||||
}
|
||||
|
||||
void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, bool video)
|
||||
void colormanage_imbuf_make_linear(ImBuf *ibuf,
|
||||
const char *from_colorspace,
|
||||
const ColorManagedFileOutput output)
|
||||
{
|
||||
const ColorSpace *colorspace = g_config->get_color_space(from_colorspace);
|
||||
|
||||
@@ -888,7 +890,7 @@ void colormanage_imbuf_make_linear(ImBuf *ibuf, const char *from_colorspace, boo
|
||||
IMB_free_byte_pixels(ibuf);
|
||||
}
|
||||
|
||||
if (!video) {
|
||||
if (output != ColorManagedFileOutput::Video) {
|
||||
const ColorSpace *image_colorspace = g_config->get_color_space_for_hdr_image(
|
||||
from_colorspace);
|
||||
if (image_colorspace) {
|
||||
@@ -1434,7 +1436,7 @@ static const int CICP_MATRIX_REC2020_NCL = 9;
|
||||
static const int CICP_RANGE_FULL = 1;
|
||||
|
||||
bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace,
|
||||
const bool video,
|
||||
const ColorManagedFileOutput output,
|
||||
const bool rgb_matrix,
|
||||
int cicp[4])
|
||||
{
|
||||
@@ -1506,7 +1508,7 @@ bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace,
|
||||
* But we have been writing sRGB like this forever, and there is the so called
|
||||
* "Quicktime gamma shift bug" that complicates things. */
|
||||
cicp[0] = CICP_PRI_P3D65;
|
||||
cicp[1] = (video) ? CICP_TRC_BT709 : CICP_TRC_SRGB;
|
||||
cicp[1] = (output == ColorManagedFileOutput::Video) ? CICP_TRC_BT709 : CICP_TRC_SRGB;
|
||||
cicp[2] = (rgb_matrix) ? CICP_MATRIX_RGB : CICP_MATRIX_BT709;
|
||||
cicp[3] = CICP_RANGE_FULL;
|
||||
return true;
|
||||
@@ -1520,7 +1522,8 @@ bool IMB_colormanagement_space_to_cicp(const ColorSpace *colorspace,
|
||||
return false;
|
||||
}
|
||||
|
||||
const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], const bool video)
|
||||
const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4],
|
||||
const ColorManagedFileOutput output)
|
||||
{
|
||||
StringRefNull interop_id;
|
||||
|
||||
@@ -1545,7 +1548,7 @@ const ColorSpace *IMB_colormanagement_space_from_cicp(const int cicp[4], const b
|
||||
interop_id = "g24_rec2020_display";
|
||||
}
|
||||
else if (cicp[0] == CICP_PRI_REC709 && cicp[1] == CICP_TRC_BT709) {
|
||||
if (video) {
|
||||
if (output == ColorManagedFileOutput::Video) {
|
||||
/* Arguably this should be g24_rec709_display, but we write sRGB like this.
|
||||
* So there is an exception for now. */
|
||||
interop_id = "srgb_rec709_display";
|
||||
|
||||
@@ -163,8 +163,8 @@ static void set_file_colorspace(ImFileColorSpace &r_colorspace,
|
||||
/* Get colorspace from CICP. */
|
||||
int cicp[4] = {};
|
||||
if (spec.getattribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp, true)) {
|
||||
const bool for_video = false;
|
||||
const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp(cicp, for_video);
|
||||
const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp(
|
||||
cicp, ColorManagedFileOutput::Image);
|
||||
if (colorspace) {
|
||||
STRNCPY_UTF8(r_colorspace.metadata_colorspace,
|
||||
IMB_colormanagement_colorspace_get_name(colorspace));
|
||||
@@ -484,10 +484,11 @@ ImageSpec imb_create_write_spec(const WriteContext &ctx, int file_channels, Type
|
||||
|
||||
/* PNG only supports RGB matrix. For AVIF and HEIF we want to use a YUV matrix
|
||||
* as these are based on video codecs designed to use them. */
|
||||
const bool for_video = false;
|
||||
const bool rgb_matrix = STREQ(ctx.file_format, "png");
|
||||
int cicp[4];
|
||||
if (IMB_colormanagement_space_to_cicp(colorspace, for_video, rgb_matrix, cicp)) {
|
||||
if (IMB_colormanagement_space_to_cicp(
|
||||
colorspace, ColorManagedFileOutput::Image, rgb_matrix, cicp))
|
||||
{
|
||||
file_spec.attribute("CICP", TypeDesc(TypeDesc::INT, 4), cicp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ static void imb_handle_colorspace_and_alpha(ImBuf *ibuf,
|
||||
}
|
||||
}
|
||||
|
||||
colormanage_imbuf_make_linear(ibuf, new_colorspace, false);
|
||||
colormanage_imbuf_make_linear(ibuf, new_colorspace, ColorManagedFileOutput::Image);
|
||||
}
|
||||
|
||||
ImBuf *IMB_load_image_from_memory(const uchar *mem,
|
||||
|
||||
@@ -126,8 +126,8 @@ static void probe_video_colorspace(MovieReader *anim, char r_colorspace_name[IM_
|
||||
anim->pCodecCtx->color_trc,
|
||||
anim->pCodecCtx->colorspace,
|
||||
anim->pCodecCtx->color_range};
|
||||
const bool for_video = true;
|
||||
const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp(cicp, for_video);
|
||||
const ColorSpace *colorspace = IMB_colormanagement_space_from_cicp(
|
||||
cicp, ColorManagedFileOutput::Video);
|
||||
|
||||
if (colorspace == nullptr) {
|
||||
return;
|
||||
@@ -1329,7 +1329,8 @@ static ImBuf *ffmpeg_fetchibuf(MovieReader *anim, int position, IMB_Timecode_Typ
|
||||
* It might not be the most optimal thing to do from the playback performance in the
|
||||
* sequencer perspective, but it ensures that other areas in Blender do not run into obscure
|
||||
* color space mismatches. */
|
||||
colormanage_imbuf_make_linear(cur_frame_final, anim->colorspace, true);
|
||||
colormanage_imbuf_make_linear(
|
||||
cur_frame_final, anim->colorspace, ColorManagedFileOutput::Video);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -794,11 +794,12 @@ static void set_colorspace_options(AVCodecContext *c, const ColorSpace *colorspa
|
||||
{
|
||||
const AVPixFmtDescriptor *pix_fmt_desc = av_pix_fmt_desc_get(c->pix_fmt);
|
||||
const bool is_rgb_format = (pix_fmt_desc->flags & AV_PIX_FMT_FLAG_RGB);
|
||||
const bool for_video = true;
|
||||
const bool rgb_matrix = false;
|
||||
|
||||
int cicp[4];
|
||||
if (colorspace && IMB_colormanagement_space_to_cicp(colorspace, for_video, rgb_matrix, cicp)) {
|
||||
if (colorspace && IMB_colormanagement_space_to_cicp(
|
||||
colorspace, ColorManagedFileOutput::Video, rgb_matrix, cicp))
|
||||
{
|
||||
/* Note ffmpeg enums are documented to match CICP. */
|
||||
c->color_primaries = AVColorPrimaries(cicp[0]);
|
||||
c->color_trc = AVColorTransferCharacteristic(cicp[1]);
|
||||
|
||||
Reference in New Issue
Block a user