Fix Cycles standalone float textures not taking into account colorspace metadata

This got lost in colorspace refactoring at some point. It probably does not
affect many files in practice, but implementation was wrong regardless.
This commit is contained in:
Brecht Van Lommel 2022-11-14 18:09:45 +01:00
parent f627abea2d
commit ec04870091
5 changed files with 11 additions and 5 deletions

View File

@ -95,16 +95,19 @@ bool ColorSpaceManager::colorspace_is_data(ustring colorspace)
}
ustring ColorSpaceManager::detect_known_colorspace(ustring colorspace,
const char *file_colorspace,
const char *file_format,
bool is_float)
{
if (colorspace == u_colorspace_auto) {
/* Auto detect sRGB or raw if none specified. */
if (is_float) {
bool srgb = (colorspace == "sRGB" || colorspace == "GammaCorrected" ||
(colorspace.empty() &&
(strcmp(file_format, "png") == 0 || strcmp(file_format, "tiff") == 0 ||
strcmp(file_format, "dpx") == 0 || strcmp(file_format, "jpeg2000") == 0)));
bool srgb = (strcmp(file_colorspace, "sRGB") == 0 ||
strcmp(file_colorspace, "GammaCorrected") == 0 ||
(file_colorspace[0] == '\0' &&
(strcmp(file_format, "png") == 0 || strcmp(file_format, "jpeg") == 0 ||
strcmp(file_format, "tiff") == 0 || strcmp(file_format, "dpx") == 0 ||
strcmp(file_format, "jpeg2000") == 0)));
return srgb ? u_colorspace_srgb : u_colorspace_raw;
}
else {

View File

@ -21,6 +21,7 @@ class ColorSpaceManager {
* convert to and from. If the colorspace is u_colorspace_auto, we auto
* detect a colospace. */
static ustring detect_known_colorspace(ustring colorspace,
const char *file_colorspace,
const char *file_format,
bool is_float);

View File

@ -261,7 +261,7 @@ void ImageMetaData::detect_colorspace()
{
/* Convert used specified color spaces to one we know how to handle. */
colorspace = ColorSpaceManager::detect_known_colorspace(
colorspace, colorspace_file_format, is_float());
colorspace, colorspace_file_hint.c_str(), colorspace_file_format, is_float());
if (colorspace == u_colorspace_raw) {
/* Nothing to do. */

View File

@ -69,6 +69,7 @@ class ImageMetaData {
/* Optional color space, defaults to raw. */
ustring colorspace;
string colorspace_file_hint;
const char *colorspace_file_format;
/* Optional transform for 3D images. */

View File

@ -85,6 +85,7 @@ bool OIIOImageLoader::load_metadata(const ImageDeviceFeatures & /*features*/,
}
metadata.colorspace_file_format = in->format_name();
metadata.colorspace_file_hint = spec.get_string_attribute("oiio:ColorSpace");
in->close();