Skip to content

Commit 68ec7eb

Browse files
committed
Make the default image state an image input config and image cache attribute
Rather than a global attribute, so that different parts of a multithreaded application can use different behavior. Signed-off-by: Brecht Van Lommel <[email protected]>
1 parent a1da725 commit 68ec7eb

File tree

32 files changed

+357
-164
lines changed

32 files changed

+357
-164
lines changed

src/bmp.imageio/bmpinput.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class BmpInput final : public ImageInput {
3535
void* data) override;
3636

3737
private:
38+
std::string m_image_state_default; // Default image state for color space
3839
int64_t m_padded_scanline_size;
3940
int m_pad_size;
4041
bmp_pvt::BmpFileHeader m_bmp_header;
@@ -153,6 +154,9 @@ BmpInput::open(const std::string& name, ImageSpec& newspec,
153154
// this behavior off.
154155
bool monodetect = config["bmp:monochrome_detect"].get<int>(1);
155156

157+
m_image_state_default = config.get_string_attribute(
158+
"oiio:ImageStateDefault");
159+
156160
ioproxy_retrieve_from_config(config);
157161
if (!ioproxy_use_or_open(name))
158162
return false;
@@ -265,7 +269,8 @@ BmpInput::open(const std::string& name, ImageSpec& newspec,
265269
// display, so assume it's sRGB. This is not really correct -- see the
266270
// comments below.
267271
const bool erase_other_attributes = false;
268-
pvt::set_colorspace_srgb(m_spec, erase_other_attributes);
272+
pvt::set_colorspace_srgb(m_spec, m_image_state_default,
273+
erase_other_attributes);
269274
#if 0
270275
if (m_dib_header.size >= WINDOWS_V4
271276
&& m_dib_header.cs_type == CSType::CalibratedRGB) {

src/cineon.imageio/cineoninput.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ CineonInput::open(const std::string& name, ImageSpec& newspec)
182182
// either grayscale or printing density
183183
if (!std::isinf(m_cin.header.Gamma()) && m_cin.header.Gamma() != 0.0f)
184184
// actual gamma value is read later on
185-
set_colorspace_rec709_gamma(m_spec, float(m_cin.header.Gamma()));
185+
pvt::set_colorspace_rec709_gamma(m_spec,
186+
float(m_cin.header.Gamma()));
186187
break;
187188
}
188189
189190
// gamma exponent
190191
if (!std::isinf(m_cin.header.Gamma()) && m_cin.header.Gamma() != 0.0f)
191-
set_colorspace_rec709_gamma(m_spec, float(m_cin.header.Gamma()));
192+
pvt::set_colorspace_rec709_gamma(m_spec, float(m_cin.header.Gamma()));
192193
#endif
193194

194195
// general metadata

src/dds.imageio/ddsinput.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class DDSInput final : public ImageInput {
6161
void* data) override;
6262

6363
private:
64-
std::string m_filename; ///< Stash the filename
65-
std::vector<unsigned char> m_buf; ///< Buffer the image pixels
64+
std::string m_filename; ///< Stash the filename
65+
std::string m_image_state_default; ///< Default image state for color space
66+
std::vector<unsigned char> m_buf; ///< Buffer the image pixels
6667
int m_subimage;
6768
int m_miplevel;
6869
int m_nchans; ///< Number of colour channels in image
@@ -412,6 +413,8 @@ DDSInput::open(const std::string& name, ImageSpec& newspec,
412413
const ImageSpec& config)
413414
{
414415
ioproxy_retrieve_from_config(config);
416+
m_image_state_default = config.get_string_attribute(
417+
"oiio:ImageStateDefault");
415418
return open(name, newspec);
416419
}
417420

@@ -845,7 +848,7 @@ DDSInput::seek_subimage(int subimage, int miplevel)
845848
}
846849

847850
if (is_srgb) {
848-
pvt::set_colorspace_srgb(m_spec);
851+
pvt::set_colorspace_srgb(m_spec, m_image_state_default);
849852
} else if (!is_srgb
850853
&& (basetype == TypeDesc::HALF || basetype == TypeDesc::FLOAT)) {
851854
// linear color space for HDR-ish images

src/doc/builtinplugins.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ options are supported:
8787
- ptr
8888
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
8989
example by reading from memory rather than the file system.
90+
* - ``oiio:ImageStateDefault``
91+
- string
92+
- If ``scene`` or ``display``, prefer to assign the image a scene or
93+
display referred ``oiio:ColorSpace``. The default is ``display``,
94+
while ``scene`` is more common for textures.
9095

9196
**Configuration settings for BMP output**
9297

@@ -211,6 +216,11 @@ attributes are supported:
211216
- ptr
212217
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
213218
example by reading from memory rather than the file system.
219+
* - ``oiio:ImageStateDefault``
220+
- string
221+
- If ``scene`` or ``display``, prefer to assign the image a scene or
222+
display referred ``oiio:ColorSpace``. The default is ``display``,
223+
while ``scene`` is more common for textures.
214224

215225
Additionally, an integer ``dds:bc5normal`` global attribute is supported
216226
to control behaviour of images compressed in BC5/ATI2 compression format.
@@ -294,6 +304,11 @@ options are supported:
294304
* - ``oiio:subimages``
295305
- int
296306
- The number of "image elements" (subimages) in the file.
307+
* - ``oiio:ImageStateDefault``
308+
- string
309+
- If ``scene`` or ``display``, prefer to assign the image a scene or
310+
display referred ``oiio:ColorSpace``. The default is ``display``,
311+
while ``scene`` is more common for textures.
297312

298313

299314
**Configuration settings for DPX output**
@@ -618,6 +633,11 @@ options are supported:
618633
- ptr
619634
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
620635
example by reading from memory rather than the file system.
636+
* - ``oiio:ImageStateDefault``
637+
- string
638+
- If ``scene`` or ``display``, prefer to assign the image a scene or
639+
display referred ``oiio:ColorSpace``. The default is ``display``,
640+
while ``scene`` is more common for textures.
621641

622642
**Configuration settings for GIF output**
623643

@@ -727,6 +747,11 @@ options are supported:
727747
orientation of the image). If this hint is set to 0, the pixels will be
728748
left in their orientation as stored in the file, and the "Orientation"
729749
metadata will reflect that.
750+
* - ``oiio:ImageStateDefault``
751+
- string
752+
- If ``scene`` or ``display``, prefer to assign the image a scene or
753+
display referred ``oiio:ColorSpace``. The default is ``display``,
754+
while ``scene`` is more common for textures.
730755

731756
**Configuration settings for HDR output**
732757

@@ -807,6 +832,12 @@ attributes are supported:
807832
having Orientation 1). If zero, then libheif will not reorient the
808833
image and the Orientation metadata will be set to reflect the camera
809834
orientation.
835+
* - ``oiio:ImageStateDefault``
836+
- string
837+
- If ``scene`` or ``display``, prefer to assign the image a scene or
838+
display referred ``oiio:ColorSpace``. The default is ``display``,
839+
while ``scene`` is more common for textures.
840+
810841

811842
**Configuration settings for HEIF output**
812843

@@ -871,6 +902,11 @@ attributes are supported:
871902
- ptr
872903
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
873904
example by reading from memory rather than the file system.
905+
* - ``oiio:ImageStateDefault``
906+
- string
907+
- If ``scene`` or ``display``, prefer to assign the image a scene or
908+
display referred ``oiio:ColorSpace``. The default is ``display``,
909+
while ``scene`` is more common for textures.
874910

875911
**Configuration settings for ICO output**
876912

@@ -947,6 +983,11 @@ options are supported:
947983
- ptr
948984
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
949985
example by reading from memory rather than the file system.
986+
* - ``oiio:ImageStateDefault``
987+
- string
988+
- If ``scene`` or ``display``, prefer to assign the image a scene or
989+
display referred ``oiio:ColorSpace``. The default is ``display``,
990+
while ``scene`` is more common for textures.
950991

951992
**Configuration settings for IFF output**
952993

@@ -1063,6 +1104,11 @@ attributes are supported:
10631104
- ptr
10641105
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
10651106
example by reading from memory rather than the file system.
1107+
* - ``oiio:ImageStateDefault``
1108+
- string
1109+
- If ``scene`` or ``display``, prefer to assign the image a scene or
1110+
display referred ``oiio:ColorSpace``. The default is ``display``,
1111+
while ``scene`` is more common for textures.
10661112

10671113
**Configuration settings for JPEG output**
10681114

@@ -1195,6 +1241,11 @@ attributes are supported:
11951241
- ptr
11961242
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
11971243
example by reading from memory rather than the file system.
1244+
* - ``oiio:ImageStateDefault``
1245+
- string
1246+
- If ``scene`` or ``display``, prefer to assign the image a scene or
1247+
display referred ``oiio:ColorSpace``. The default is ``display``,
1248+
while ``scene`` is more common for textures.
11981249

11991250
If OpenJPH is installed, the reader will attempt to read the file first with
12001251
the OpenJPH library, and if that fails, it will fall back to the OpenJPEG library.
@@ -1302,6 +1353,11 @@ attributes are supported:
13021353
- ptr
13031354
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
13041355
example by reading from memory rather than the file system.
1356+
* - ``oiio:ImageStateDefault``
1357+
- string
1358+
- If ``scene`` or ``display``, prefer to assign the image a scene or
1359+
display referred ``oiio:ColorSpace``. The default is ``display``,
1360+
while ``scene`` is more common for textures.
13051361

13061362
**Configuration settings for JPEG XL output**
13071363

@@ -1837,6 +1893,11 @@ attributes are supported:
18371893
- ptr
18381894
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
18391895
example by reading from memory rather than the file system.
1896+
* - ``oiio:ImageStateDefault``
1897+
- string
1898+
- If ``scene`` or ``display``, prefer to assign the image a scene or
1899+
display referred ``oiio:ColorSpace``. The default is ``display``,
1900+
while ``scene`` is more common for textures.
18401901
* - ``png:linear_premult``
18411902
- int
18421903
- If nonzero, will convert or gamma-encoded values to linear color
@@ -2317,6 +2378,11 @@ options are supported:
23172378
initialization. This populates the image attributes which depend on the
23182379
pixel values.
23192380
(Default: 0)
2381+
* - ``oiio:ImageStateDefault``
2382+
- string
2383+
- If ``scene`` or ``display``, prefer to assign the image a scene or
2384+
display referred ``oiio:ColorSpace``. The default is ``display``,
2385+
while ``scene`` is more common for textures.
23202386

23212387
|
23222388
@@ -2424,6 +2490,11 @@ options are supported:
24242490
- ptr
24252491
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
24262492
example by reading from memory rather than the file system.
2493+
* - ``oiio:ImageStateDefault``
2494+
- string
2495+
- If ``scene`` or ``display``, prefer to assign the image a scene or
2496+
display referred ``oiio:ColorSpace``. The default is ``display``,
2497+
while ``scene`` is more common for textures.
24272498

24282499
**Configuration settings for RLA output**
24292500

@@ -2674,6 +2745,11 @@ attributes are supported:
26742745
cause the reader to leave alpha unassociated (versus the default of
26752746
premultiplying color channels by alpha if the alpha channel is
26762747
unassociated).
2748+
* - ``oiio:ImageStateDefault``
2749+
- string
2750+
- If ``scene`` or ``display``, prefer to assign the image a scene or
2751+
display referred ``oiio:ColorSpace``. The default is ``display``,
2752+
while ``scene`` is more common for textures.
26772753

26782754
**Configuration settings for Targa output**
26792755

@@ -2842,6 +2918,11 @@ options are supported:
28422918
- ptr
28432919
- Pointer to a ``Filesystem::IOProxy`` that will handle the I/O, for
28442920
example by reading from memory rather than the file system.
2921+
* - ``oiio:ImageStateDefault``
2922+
- string
2923+
- If ``scene`` or ``display``, prefer to assign the image a scene or
2924+
display referred ``oiio:ColorSpace``. The default is ``display``,
2925+
while ``scene`` is more common for textures.
28452926

28462927
**Configuration settings for TIFF output**
28472928

@@ -3152,6 +3233,11 @@ attributes are supported:
31523233
- If nonzero, will leave alpha unassociated (versus the default of
31533234
premultiplying color channels by alpha if the alpha channel is
31543235
unassociated).
3236+
* - ``oiio:ImageStateDefault``
3237+
- string
3238+
- If ``scene`` or ``display``, prefer to assign the image a scene or
3239+
display referred ``oiio:ColorSpace``. The default is ``display``,
3240+
while ``scene`` is more common for textures.
31553241

31563242
**Configuration settings for WebP output**
31573243

src/dpx.imageio/dpxinput.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class DPXInput final : public ImageInput {
6161
dpx::Reader m_dpx;
6262
std::vector<unsigned char> m_userBuf;
6363
bool m_rawcolor;
64+
std::string m_image_state_default;
6465
std::vector<unsigned char> m_decodebuf; // temporary decode buffer
6566

6667
/// Reset everything to initial state
@@ -171,6 +172,8 @@ DPXInput::open(const std::string& name, ImageSpec& newspec,
171172
|| config.get_int_attribute("dpx:RawData") // deprecated
172173
|| config.get_int_attribute("oiio:RawColor");
173174
ioproxy_retrieve_from_config(config);
175+
m_image_state_default = config.get_string_attribute(
176+
"oiio:ImageStateDefault");
174177
return open(name, newspec);
175178
}
176179

@@ -316,10 +319,14 @@ DPXInput::seek_subimage(int subimage, int miplevel)
316319
switch (m_dpx.header.Transfer(subimage)) {
317320
case dpx::kLinear: m_spec.set_colorspace("lin_rec709_scene"); break;
318321
case dpx::kLogarithmic: m_spec.set_colorspace("KodakLog"); break;
319-
case dpx::kITUR709: pvt::set_colorspace_srgb(m_spec); break;
322+
case dpx::kITUR709:
323+
pvt::set_colorspace_srgb(m_spec, m_image_state_default);
324+
break;
320325
case dpx::kUserDefined:
321326
if (!std::isnan(m_dpx.header.Gamma()) && m_dpx.header.Gamma() != 0) {
322-
set_colorspace_rec709_gamma(m_spec, float(m_dpx.header.Gamma()));
327+
pvt::set_colorspace_rec709_gamma(m_spec,
328+
float(m_dpx.header.Gamma()),
329+
m_image_state_default);
323330
break;
324331
}
325332
// intentional fall-through

src/ffmpeg.imageio/ffmpeginput.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class FFmpegInput final : public ImageInput {
9191
}
9292
bool valid_file(const std::string& name) const override;
9393
bool open(const std::string& name, ImageSpec& spec) override;
94+
bool open(const std::string& name, ImageSpec& spec,
95+
const ImageSpec& config) override;
9496
bool close(void) override;
9597
int current_subimage(void) const override
9698
{
@@ -133,6 +135,7 @@ class FFmpegInput final : public ImageInput {
133135
bool m_codec_cap_delay;
134136
bool m_read_frame;
135137
int64_t m_start_time;
138+
std::string m_image_state_default;
136139

137140
// init to initialize state
138141
void init(void)
@@ -212,6 +215,14 @@ FFmpegInput::valid_file(const std::string& name) const
212215
}
213216

214217

218+
bool
219+
FFmpegInput::open(const std::string& name, ImageSpec& spec,
220+
const ImageSpec& config)
221+
{
222+
m_image_state_default = config.get_string_attribute(
223+
"oiio:ImageStateDefault");
224+
return open(name, spec);
225+
}
215226

216227
bool
217228
FFmpegInput::open(const std::string& name, ImageSpec& spec)
@@ -550,7 +561,7 @@ FFmpegInput::open(const std::string& name, ImageSpec& spec)
550561
= { m_codec_context->color_primaries, m_codec_context->color_trc,
551562
m_codec_context->colorspace,
552563
m_codec_context->color_range == AVCOL_RANGE_MPEG ? 0 : 1 };
553-
pvt::set_colorspace_cicp(m_spec, cicp);
564+
pvt::set_colorspace_cicp(m_spec, cicp, m_image_state_default);
554565

555566
m_nsubimages = m_frames;
556567
spec = m_spec;

src/gif.imageio/gifinput.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ class GIFInput final : public ImageInput {
6565
}
6666

6767
private:
68-
std::string m_filename; ///< Stash the filename
69-
GifFileType* m_gif_file; ///< GIFLIB handle
70-
int m_transparent_color; ///< Transparent color index
71-
int m_subimage; ///< Current subimage index
68+
std::string m_filename; ///< Stash the filename
69+
std::string m_image_state_default; ///< Default image state for color space
70+
GifFileType* m_gif_file; ///< GIFLIB handle
71+
int m_transparent_color; ///< Transparent color index
72+
int m_subimage; ///< Current subimage index
7273
int m_disposal_method; ///< Disposal method of current subimage.
7374
/// Indicates what to do with canvas
7475
/// before drawing the _next_ subimage.
@@ -173,6 +174,8 @@ bool
173174
GIFInput::open(const std::string& name, ImageSpec& newspec,
174175
const ImageSpec& config)
175176
{
177+
m_image_state_default = config.get_string_attribute(
178+
"oiio:ImageStateDefault");
176179
// Check 'config' for any special requests
177180
ioproxy_retrieve_from_config(config);
178181
ioseek(0);
@@ -261,7 +264,7 @@ GIFInput::read_subimage_metadata(ImageSpec& newspec)
261264
newspec.nchannels = 4;
262265
newspec.default_channel_names();
263266
newspec.alpha_channel = 4;
264-
pvt::set_colorspace_srgb(newspec);
267+
pvt::set_colorspace_srgb(newspec, m_image_state_default);
265268

266269
m_previous_disposal_method = m_disposal_method;
267270
m_disposal_method = DISPOSAL_UNSPECIFIED;

0 commit comments

Comments
 (0)