HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imageio.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: Apache-2.0
3 // https://github.com/AcademySoftwareFoundation/OpenImageIO
4 
5 
6 /////////////////////////////////////////////////////////////////////////////
7 /// \file
8 ///
9 /// Provides a simple API that abstracts the reading and writing of
10 /// images. Subclasses, which may be found in DSO/DLL's, implement
11 /// particular formats.
12 ///
13 /////////////////////////////////////////////////////////////////////////////
14 
15 // clang-format off
16 
17 #pragma once
18 #define OPENIMAGEIO_IMAGEIO_H
19 
20 #if defined(_MSC_VER)
21 // Ignore warnings about DLL exported classes with member variables that are template classes.
22 // This happens with the std::vector<T> and std::string members of the classes below.
23 # pragma warning(disable : 4251)
24 #endif
25 
26 #include <cmath>
27 #include <limits>
28 #include <string>
29 #include <vector>
30 
31 #include <OpenImageIO/span.h>
32 #include <OpenImageIO/export.h>
34 #include <OpenImageIO/paramlist.h>
35 #include <OpenImageIO/platform.h>
36 #include <OpenImageIO/strutil.h>
37 #include <OpenImageIO/thread.h>
38 #include <OpenImageIO/typedesc.h>
39 
41 
42 class DeepData;
43 class ImageBuf;
44 
45 
46 /// Type we use for stride lengths between pixels, scanlines, or image
47 /// planes.
48 using stride_t = int64_t;
49 
50 /// Type we use to express how many pixels (or bytes) constitute an image,
51 /// tile, or scanline.
52 using imagesize_t = uint64_t;
53 
54 /// Special value to indicate a stride length that should be
55 /// auto-computed.
57 
58 
59 
60 /// Pointer to a function called periodically by read_image and
61 /// write_image. This can be used to implement progress feedback, etc.
62 /// It takes an opaque data pointer (passed to read_image/write_image)
63 /// and a float giving the portion of work done so far. It returns a
64 /// bool, which if 'true' will STOP the read or write.
65 typedef bool (*ProgressCallback)(void *opaque_data, float portion_done);
66 
67 
68 
69 // Deprecated typedefs. Just use ParamValue and ParamValueList directly.
72 
73 
74 // Forward declaration of IOProxy
75 namespace Filesystem {
76  class IOProxy;
77 }
78 
79 
80 /// ROI is a small helper struct describing a rectangular region of interest
81 /// in an image. The region is [xbegin,xend) x [begin,yend) x [zbegin,zend),
82 /// with the "end" designators signifying one past the last pixel in each
83 /// dimension, a la STL style.
84 ///
85 struct ROI {
86  ///@{
87  /// @name ROI data members
88  /// The data members are:
89  ///
90  /// int xbegin, xend, ybegin, yend, zbegin, zend;
91  /// int chbegin, chend;
92  ///
93  /// These describe the spatial extent
94  /// [xbegin,xend) x [ybegin,yend) x [zbegin,zend)
95  /// And the channel extent:
96  /// [chbegin,chend)]
97  int xbegin, xend;
98  int ybegin, yend;
99  int zbegin, zend;
101  ///@}
102 
103  /// Default constructor is an undefined region. Note that this is also
104  /// interpreted as All().
105  constexpr ROI () noexcept : xbegin(std::numeric_limits<int>::min()), xend(0),
106  ybegin(0), yend(0), zbegin(0), zend(0), chbegin(0), chend(0)
107  { }
108 
109  /// Constructor with an explicitly defined region.
110  ///
111  constexpr ROI (int xbegin, int xend, int ybegin, int yend,
112  int zbegin=0, int zend=1, int chbegin=0, int chend=10000) noexcept
113  : xbegin(xbegin), xend(xend), ybegin(ybegin), yend(yend),
115  { }
116 
117  /// Is a region defined?
118  constexpr bool defined () const noexcept { return (xbegin != std::numeric_limits<int>::min()); }
119 
120  ///@{
121  /// @name Spatial size functions.
122  /// The width, height, and depth of the region.
123  constexpr int width () const noexcept { return xend - xbegin; } ///< Height
124  constexpr int height () const noexcept { return yend - ybegin; } ///< Width
125  constexpr int depth () const noexcept { return zend - zbegin; } ///< Depth
126  ///@}
127 
128  /// Number of channels in the region. Beware -- this defaults to a
129  /// huge number, and to be meaningful you must consider
130  /// std::min (imagebuf.nchannels(), roi.nchannels()).
131  constexpr int nchannels () const noexcept { return chend - chbegin; }
132 
133  /// Total number of pixels in the region.
134  constexpr imagesize_t npixels () const noexcept {
135  return defined()
137  : 0;
138  }
139 
140  /// All() is an alias for the default constructor, which indicates that
141  /// it means "all" of the image, or no region restriction. For example,
142  /// float myfunc (ImageBuf &buf, ROI roi = ROI::All());
143  /// Note that this is equivalent to:
144  /// float myfunc (ImageBuf &buf, ROI roi = {});
145  static constexpr ROI All () noexcept { return ROI(); }
146 
147  /// Test equality of two ROIs
148  friend constexpr bool operator== (const ROI &a, const ROI &b) noexcept {
149  return (a.xbegin == b.xbegin && a.xend == b.xend &&
150  a.ybegin == b.ybegin && a.yend == b.yend &&
151  a.zbegin == b.zbegin && a.zend == b.zend &&
152  a.chbegin == b.chbegin && a.chend == b.chend);
153  }
154  /// Test inequality of two ROIs
155  friend constexpr bool operator!= (const ROI &a, const ROI &b) noexcept {
156  return (a.xbegin != b.xbegin || a.xend != b.xend ||
157  a.ybegin != b.ybegin || a.yend != b.yend ||
158  a.zbegin != b.zbegin || a.zend != b.zend ||
159  a.chbegin != b.chbegin || a.chend != b.chend);
160  }
161 
162  /// Test if the coordinate is within the ROI.
163  constexpr bool contains (int x, int y, int z=0, int ch=0) const noexcept {
164  return x >= xbegin && x < xend && y >= ybegin && y < yend
165  && z >= zbegin && z < zend && ch >= chbegin && ch < chend;
166  }
167 
168  /// Test if another ROI is entirely within our ROI.
169  constexpr bool contains (const ROI& other) const noexcept {
170  return (other.xbegin >= xbegin && other.xend <= xend &&
171  other.ybegin >= ybegin && other.yend <= yend &&
172  other.zbegin >= zbegin && other.zend <= zend &&
173  other.chbegin >= chbegin && other.chend <= chend);
174  }
175 
176  /// Stream output of the range
177  friend std::ostream & operator<< (std::ostream &out, const ROI &roi) {
178  out << roi.xbegin << ' ' << roi.xend << ' ' << roi.ybegin << ' '
179  << roi.yend << ' ' << roi.zbegin << ' ' << roi.zend << ' '
180  << roi.chbegin << ' ' << roi.chend;
181  return out;
182  }
183 };
184 
185 
186 
187 /// Union of two regions, the smallest region containing both.
188 inline constexpr ROI roi_union (const ROI &A, const ROI &B) noexcept {
189  return (A.defined() && B.defined())
190  ? ROI (std::min (A.xbegin, B.xbegin), std::max (A.xend, B.xend),
191  std::min (A.ybegin, B.ybegin), std::max (A.yend, B.yend),
192  std::min (A.zbegin, B.zbegin), std::max (A.zend, B.zend),
193  std::min (A.chbegin, B.chbegin), std::max (A.chend, B.chend))
194  : (A.defined() ? A : B);
195 }
196 
197 /// Intersection of two regions.
198 inline constexpr ROI roi_intersection (const ROI &A, const ROI &B) noexcept {
199  return (A.defined() && B.defined())
200  ? ROI (std::max (A.xbegin, B.xbegin), std::min (A.xend, B.xend),
201  std::max (A.ybegin, B.ybegin), std::min (A.yend, B.yend),
202  std::max (A.zbegin, B.zbegin), std::min (A.zend, B.zend),
203  std::max (A.chbegin, B.chbegin), std::min (A.chend, B.chend))
204  : (A.defined() ? A : B);
205 }
206 
207 
208 
209 
210 /// ImageSpec describes the data format of an image -- dimensions, layout,
211 /// number and meanings of image channels.
212 ///
213 /// The `width, height, depth` are the size of the data of this image, i.e.,
214 /// the number of pixels in each dimension. A ``depth`` greater than 1
215 /// indicates a 3D "volumetric" image. The `x, y, z` fields indicate the
216 /// *origin* of the pixel data of the image. These default to (0,0,0), but
217 /// setting them differently may indicate that this image is offset from the
218 /// usual origin.
219 /// Therefore the pixel data are defined over pixel coordinates
220 /// [`x` ... `x+width-1`] horizontally,
221 /// [`y` ... `y+height-1`] vertically,
222 /// and [`z` ... `z+depth-1`] in depth.
223 ///
224 /// The analogous `full_width`, `full_height`, `full_depth` and `full_x`,
225 /// `full_y`, `full_z` fields define a "full" or "display" image window over
226 /// the region [`full_x` ... `full_x+full_width-1`] horizontally, [`full_y`
227 /// ... `full_y+full_height-1`] vertically, and [`full_z`...
228 /// `full_z+full_depth-1`] in depth.
229 ///
230 /// Having the full display window different from the pixel data window can
231 /// be helpful in cases where you want to indicate that your image is a
232 /// *crop window* of a larger image (if the pixel data window is a subset of
233 /// the full display window), or that the pixels include *overscan* (if the
234 /// pixel data is a superset of the full display window), or may simply
235 /// indicate how different non-overlapping images piece together.
236 ///
237 /// For tiled images, `tile_width`, `tile_height`, and `tile_depth` specify
238 /// that the image is stored in a file organized into rectangular *tiles*
239 /// of these dimensions. The default of 0 value for these fields indicates
240 /// that the image is stored in scanline order, rather than as tiles.
241 ///
242 
244 public:
245  ///@{
246  /// @name ImageSpec data members
247  ///
248  /// The `ImageSpec` contains data fields for the values that are
249  /// required to describe nearly any image, and an extensible list of
250  /// arbitrary attributes that can hold metadata that may be user-defined
251  /// or specific to individual file formats.
252  ///
253  /// Here are the hard-coded data fields:
254 
255  int x; ///< origin (upper left corner) of pixel data
256  int y; ///< origin (upper left corner) of pixel data
257  int z; ///< origin (upper left corner) of pixel data
258  int width; ///< width of the pixel data window
259  int height; ///< height of the pixel data window
260  int depth; ///< depth of pixel data, >1 indicates a "volume"
261  int full_x; ///< origin of the full (display) window
262  int full_y; ///< origin of the full (display) window
263  int full_z; ///< origin of the full (display) window
264  int full_width; ///< width of the full (display) window
265  int full_height; ///< height of the full (display) window
266  int full_depth; ///< depth of the full (display) window
267  int tile_width; ///< tile width (0 for a non-tiled image)
268  int tile_height; ///< tile height (0 for a non-tiled image)
269  int tile_depth; ///< tile depth (0 for a non-tiled image,
270  ///< 1 for a non-volume image)
271  int nchannels; ///< number of image channels, e.g., 4 for RGBA
272 
273  TypeDesc format; ///< Data format of the channels.
274  ///< Describes the native format of the pixel data values
275  /// themselves, as a `TypeDesc`. Typical values would be
276  /// `TypeDesc::UINT8` for 8-bit unsigned values, `TypeDesc::FLOAT`
277  /// for 32-bit floating-point values, etc.
278  std::vector<TypeDesc> channelformats;
279  ///< Optional per-channel data formats. If all channels of the image
280  /// have the same data format, that will be described by `format`
281  /// and `channelformats` will be empty (zero length). If there are
282  /// different data formats for each channel, they will be described
283  /// in the `channelformats` vector, and the `format` field will
284  /// indicate a single default data format for applications that
285  /// don't wish to support per-channel formats (usually this will be
286  /// the format of the channel that has the most precision).
287 
288  std::vector<std::string> channelnames;
289  ///< The names of each channel, in order. Typically this will be "R",
290  ///< "G", "B", "A" (alpha), "Z" (depth), or other arbitrary names.
292  ///< The index of the channel that represents *alpha* (pixel
293  ///< coverage and/or transparency). It defaults to -1 if no alpha
294  ///< channel is present, or if it is not known which channel
295  ///< represents alpha.
297  ///< The index of the channel that represents *z* or *depth* (from
298  ///< the camera). It defaults to -1 if no depth channel is present,
299  ///< or if it is not know which channel represents depth.
300  bool deep; ///< True if the image contains deep data.
301  ///< If `true`, this indicates that the image describes contains
302  ///< "deep" data consisting of multiple samples per pixel. If
303  ///< `false`, it's an ordinary image with one data value (per
304  ///< channel) per pixel.
306  ///< A list of arbitrarily-named and arbitrarily-typed additional
307  /// attributes of the image, for any metadata not described by the
308  /// hard-coded fields described above. This list may be manipulated
309  /// with the `attribute()` and `find_attribute()` methods.
310 
311  ///@}
312 
313  /// Constructor: given just the data format, set all other fields to
314  /// something reasonable.
316 
317  /// Constructor: given just the data format (as any type name recognized
318  /// by the `TypeDesc` constructor), set all other fields to something
319  /// reasonable.
321 
322  /// Constructs an `ImageSpec` with the given x and y resolution, number
323  /// of channels, and pixel data format.
324  ///
325  /// All other fields are set to the obvious defaults -- the image is an
326  /// ordinary 2D image (not a volume), the image is not offset or a crop
327  /// of a bigger image, the image is scanline-oriented (not tiled),
328  /// channel names are "R", "G", "B"' and "A" (up to and including 4
329  /// channels, beyond that they are named "channel *n*"), the fourth
330  /// channel (if it exists) is assumed to be alpha.
331  ImageSpec (int xres, int yres, int nchans, TypeDesc fmt = TypeUInt8) noexcept;
332 
333  /// Construct an `ImageSpec` with the given x and y resolution, number
334  /// of channels, and pixel data format name (as any type name recognized
335  /// by the `TypeDesc` constructor).
336  ImageSpec (int xres, int yres, int nchans, string_view fmt) noexcept
337  : ImageSpec(xres, yres, nchans, TypeDesc(fmt)) {}
338 
339  /// Construct an `ImageSpec` whose dimensions (both data and "full") and
340  /// number of channels are given by the `ROI`, pixel data type by `fmt`,
341  /// and other fields are set to their default values.
342  explicit ImageSpec (const ROI &roi, TypeDesc fmt = TypeUInt8) noexcept;
343 
344  /// Construct an `ImageSpec` from an ROI giving dimensions, and the name
345  /// of a data type that will be recognized by the `TypeDesc` constructor.
346  explicit ImageSpec (const ROI &roi, string_view fmt) noexcept
347  : ImageSpec(roi, TypeDesc(fmt)) {}
348 
349  /// Set the data format, and clear any per-channel format information
350  /// in `channelformats`.
351  void set_format (TypeDesc fmt) noexcept;
352 
353  /// Set the data format, and clear any per-channel format information
354  /// in `channelformats`. The `fmt` may be a string such as `"uint8"`,
355  /// or any other type name recognized by the TypeDesc constructor.
356  void set_format (string_view fmt) noexcept { set_format(TypeDesc(fmt)); }
357 
358  /// Sets the `channelnames` to reasonable defaults for the number of
359  /// channels. Specifically, channel names are set to "R", "G", "B,"
360  /// and "A" (up to and including 4 channels, beyond that they are named
361  /// "channel*n*".
362  void default_channel_names () noexcept;
363 
364  /// Returns the number of bytes comprising each channel of each pixel
365  /// (i.e., the size of a single value of the type described by the
366  /// `format` field).
367  size_t channel_bytes() const noexcept { return format.size(); }
368 
369  /// Return the number of bytes needed for the single specified
370  /// channel. If native is false (default), compute the size of one
371  /// channel of `this->format`, but if native is true, compute the size
372  /// of the channel in terms of the "native" data format of that
373  /// channel as stored in the file.
374  size_t channel_bytes (int chan, bool native=false) const noexcept;
375 
376  /// Return the number of bytes for each pixel (counting all channels).
377  /// If `native` is false (default), assume all channels are in
378  /// `this->format`, but if `native` is true, compute the size of a pixel
379  /// in the "native" data format of the file (these may differ in
380  /// the case of per-channel formats).
381  size_t pixel_bytes (bool native=false) const noexcept;
382 
383  /// Return the number of bytes for just the subset of channels in each
384  /// pixel described by [chbegin,chend). If native is false (default),
385  /// assume all channels are in this->format, but if native is true,
386  /// compute the size of a pixel in the "native" data format of the file
387  /// (these may differ in the case of per-channel formats).
388  size_t pixel_bytes (int chbegin, int chend, bool native=false) const noexcept;
389 
390  /// Returns the number of bytes comprising each scanline, i.e.,
391  /// `pixel_bytes(native) * width` This will return
392  /// `std::numeric_limits<imagesize_t>::max()` in the event of an
393  /// overflow where it's not representable in an `imagesize_t`.
394  imagesize_t scanline_bytes (bool native=false) const noexcept;
395 
396  /// Return the number of pixels comprising a tile (or 0 if it is not a
397  /// tiled image). This will return
398  /// `std::numeric_limits<imagesize_t>::max()` in the event of an
399  /// overflow where it's not representable in an `imagesize_t`.
400  imagesize_t tile_pixels () const noexcept;
401 
402  /// Returns the number of bytes comprising an image tile, i.e.,
403  /// `pixel_bytes(native) * tile_width * tile_height * tile_depth`
404  /// If native is false (default), assume all channels are in
405  /// `this->format`, but if `native` is true, compute the size of a pixel
406  /// in the "native" data format of the file (these may differ in the
407  /// case of per-channel formats).
408  imagesize_t tile_bytes (bool native=false) const noexcept;
409 
410  /// Return the number of pixels for an entire image. This will
411  /// return `std::numeric_limits<imagesize_t>::max()` in the event of
412  /// an overflow where it's not representable in an `imagesize_t`.
413  imagesize_t image_pixels () const noexcept;
414 
415  /// Returns the number of bytes comprising an entire image of these
416  /// dimensions, i.e.,
417  /// `pixel_bytes(native) * width * height * depth`
418  /// This will return `std::numeric_limits<image size_t>::max()` in the
419  /// event of an overflow where it's not representable in an
420  /// `imagesize_t`. If `native` is false (default), assume all channels
421  /// are in `this->format`, but if `native` is true, compute the size of
422  /// a pixel in the "native" data format of the file (these may differ in
423  /// the case of per-channel formats).
424  imagesize_t image_bytes (bool native=false) const noexcept;
425 
426  /// Verify that on this platform, a `size_t` is big enough to hold the
427  /// number of bytes (and pixels) in a scanline, a tile, and the
428  /// whole image. If this returns false, the image is much too big
429  /// to allocate and read all at once, so client apps beware and check
430  /// these routines for overflows!
431  bool size_t_safe() const noexcept {
433  return image_bytes() < big && scanline_bytes() < big &&
434  tile_bytes() < big;
435  }
436 
437  /// Adjust the stride values, if set to AutoStride, to be the right
438  /// sizes for contiguous data with the given format, channels,
439  /// width, height.
440  static void auto_stride (stride_t &xstride, stride_t &ystride,
441  stride_t &zstride, stride_t channelsize,
442  int nchannels, int width, int height) noexcept {
443  if (xstride == AutoStride)
444  xstride = nchannels * channelsize;
445  if (ystride == AutoStride)
446  ystride = xstride * width;
447  if (zstride == AutoStride)
448  zstride = ystride * height;
449  }
450 
451  /// Adjust the stride values, if set to AutoStride, to be the right
452  /// sizes for contiguous data with the given format, channels,
453  /// width, height.
454  static void auto_stride (stride_t &xstride, stride_t &ystride,
455  stride_t &zstride, TypeDesc format,
456  int nchannels, int width, int height) noexcept {
457  auto_stride (xstride, ystride, zstride, format.size(),
458  nchannels, width, height);
459  }
460 
461  /// Adjust xstride, if set to AutoStride, to be the right size for
462  /// contiguous data with the given format and channels.
463  static void auto_stride (stride_t &xstride, TypeDesc format, int nchannels) noexcept {
464  if (xstride == AutoStride)
465  xstride = nchannels * format.size();
466  }
467 
468  /// Add a metadata attribute to `extra_attribs`, with the given name and
469  /// data type. The `value` pointer specifies the address of the data to
470  /// be copied.
471  void attribute (string_view name, TypeDesc type, const void *value);
472 
473  /// Add an `unsigned int` attribute to `extra_attribs`.
474  void attribute (string_view name, unsigned int value) {
475  attribute (name, TypeDesc::UINT, &value);
476  }
477 
478  /// Add an `int` attribute to `extra_attribs`.
480  attribute (name, TypeDesc::INT, &value);
481  }
482 
483  /// Add a `float` attribute to `extra_attribs`.
484  void attribute (string_view name, float value) {
485  attribute (name, TypeDesc::FLOAT, &value);
486  }
487 
488  /// Add a string attribute to `extra_attribs`.
490 
491  /// Add a string attribute (passed as a ustring) to `extra_attribs`.
493 
494  /// Parse a string containing a textual representation of a value of
495  /// the given `type`, and add that as an attribute to `extra_attribs`.
496  /// Example:
497  ///
498  /// spec.attribute ("temperature", TypeFloat, "-273.15");
499  ///
501 
502  /// Searches `extra_attribs` for any attributes matching `name` (as a
503  /// regular expression), removing them entirely from `extra_attribs`. If
504  /// `searchtype` is anything other than `TypeDesc::UNKNOWN`, matches
505  /// will be restricted only to attributes with the given type. The name
506  /// comparison will be case-sensitive if `casesensitive` is true,
507  /// otherwise in a case-insensitive manner.
508  void erase_attribute (string_view name,
509  TypeDesc searchtype=TypeDesc::UNKNOWN,
510  bool casesensitive=false);
511 
512  /// Searches `extra_attribs` for an attribute matching `name`, returning
513  /// a pointer to the attribute record, or NULL if there was no match.
514  /// If `searchtype` is anything other than `TypeDesc::UNKNOWN`, matches
515  /// will be restricted only to attributes with the given type. The name
516  /// comparison will be exact if `casesensitive` is true, otherwise in a
517  /// case-insensitive manner if `caseinsensitive` is false.
518  ParamValue * find_attribute (string_view name,
519  TypeDesc searchtype=TypeDesc::UNKNOWN,
520  bool casesensitive=false);
521  const ParamValue *find_attribute (string_view name,
522  TypeDesc searchtype=TypeDesc::UNKNOWN,
523  bool casesensitive=false) const;
524 
525  /// Search for the named attribute and return the pointer to its
526  /// `ParamValue` record, or NULL if not found. This variety of
527  /// `find_attribute(}` can retrieve items such as "width", which are
528  /// data members of the `ImageSpec`, but not in `extra_attribs`. The
529  /// `tmpparam` is a storage area owned by the caller, which is used as
530  /// temporary buffer in cases where the information does not correspond
531  /// to an actual `extra_attribs` (in this case, the return value will be
532  /// `&tmpparam`). The extra names it understands are:
533  ///
534  /// - `"x"` `"y"` `"z"` `"width"` `"height"` `"depth"`
535  /// `"full_x"` `"full_y"` `"full_z"` `"full_width"` `"full_height"` `"full_depth"`
536  ///
537  /// Returns the `ImageSpec` fields of those names (despite the
538  /// fact that they are technically not arbitrary named attributes
539  /// in `extra_attribs`). All are of type `int`.
540  ///
541  /// - `"datawindow"`
542  ///
543  /// Without a type, or if requested explicitly as an `int[4]`,
544  /// returns the OpenEXR-like pixel data min and max coordinates,
545  /// as a 4-element integer array: `{ x, y, x+width-1, y+height-1
546  /// }`. If instead you specifically request as an `int[6]`, it
547  /// will return the volumetric data window, `{ x, y, z, x+width-1,
548  /// y+height-1, z+depth-1 }`.
549  ///
550  /// - `"displaywindow"`
551  ///
552  /// Without a type, or if requested explicitly as an `int[4]`,
553  /// returns the OpenEXR-like pixel display min and max
554  /// coordinates, as a 4-element integer array: `{ full_x, full_y,
555  /// full_x+full_width-1, full_y+full_height-1 }`. If instead you
556  /// specifically request as an `int[6]`, it will return the
557  /// volumetric display window, `{ full_x, full_y, full_z,
558  /// full_x+full_width-1, full_y+full_height-1, full_z+full_depth-1 }`.
559  ///
560  /// EXAMPLES
561  ///
562  /// ImageSpec spec; // has the info
563  /// Imath::Box2i dw; // we want the displaywindow here
564  /// ParamValue tmp; // so we can retrieve pseudo-values
565  /// TypeDesc int4("int[4]"); // Equivalent: TypeDesc int4(TypeDesc::INT,4);
566  /// const ParamValue* p = spec.find_attribute ("displaywindow", int4);
567  /// if (p)
568  /// dw = Imath::Box2i(p->get<int>(0), p->get<int>(1),
569  /// p->get<int>(2), p->get<int>(3));
570  ///
571  /// p = spec.find_attribute("temperature", TypeFloat);
572  /// if (p)
573  /// float temperature = p->get<float>();
574  ///
575  const ParamValue * find_attribute (string_view name,
576  ParamValue &tmpparam,
577  TypeDesc searchtype=TypeDesc::UNKNOWN,
578  bool casesensitive=false) const;
579 
580  /// If the named attribute can be found in the `ImageSpec`, return its
581  /// data type. If no such attribute exists, return `TypeUnknown`.
582  ///
583  /// This was added in version 2.1.
584  TypeDesc getattributetype (string_view name,
585  bool casesensitive = false) const;
586 
587  /// If the `ImageSpec` contains the named attribute and its type matches
588  /// `type`, copy the attribute value into the memory pointed to by `val`
589  /// (it is up to the caller to ensure there is enough space) and return
590  /// `true`. If no such attribute is found, or if it doesn't match the
591  /// type, return `false` and do not modify `val`.
592  ///
593  /// EXAMPLES:
594  ///
595  /// ImageSpec spec;
596  /// ...
597  /// // Retrieving an integer attribute:
598  /// int orientation = 0;
599  /// spec.getattribute ("orientation", TypeInt, &orientation);
600  ///
601  /// // Retrieving a string attribute with a char*:
602  /// const char* compression = nullptr;
603  /// spec.getattribute ("compression", TypeString, &compression);
604  ///
605  /// // Alternately, retrieving a string with a ustring:
606  /// ustring compression;
607  /// spec.getattribute ("compression", TypeString, &compression);
608  ///
609  /// Note that when passing a string, you need to pass a pointer to the
610  /// `char*`, not a pointer to the first character. Also, the `char*`
611  /// will end up pointing to characters owned by the `ImageSpec`; the
612  /// caller does not need to ever free the memory that contains the
613  /// characters.
614  ///
615  /// This was added in version 2.1.
617  bool casesensitive = false) const;
618 
619  /// Retrieve the named metadata attribute and return its value as an
620  /// `int`. Any integer type will convert to `int` by truncation or
621  /// expansion, string data will parsed into an `int` if its contents
622  /// consist of of the text representation of one integer. Floating point
623  /// data will not succeed in converting to an `int`. If no such metadata
624  /// exists, or are of a type that cannot be converted, the `defaultval`
625  /// will be returned.
626  int get_int_attribute (string_view name, int defaultval=0) const;
627 
628  /// Retrieve the named metadata attribute and return its value as a
629  /// `float`. Any integer or floating point type will convert to `float`
630  /// in the obvious way (like a C cast), and so will string metadata if
631  /// its contents consist of of the text representation of one floating
632  /// point value. If no such metadata exists, or are of a type that cannot
633  /// be converted, the `defaultval` will be returned.
634  float get_float_attribute (string_view name, float defaultval=0) const;
635 
636  /// Retrieve any metadata attribute, converted to a string.
637  /// If no such metadata exists, the `defaultval` will be returned.
639  string_view defaultval = string_view()) const;
640 
641  /// For a given parameter `p`, format the value nicely as a string. If
642  /// `human` is true, use especially human-readable explanations (units,
643  /// or decoding of values) for certain known metadata.
644  static std::string metadata_val (const ParamValue &p, bool human=false);
645 
646  enum SerialFormat { SerialText, SerialXML };
647  enum SerialVerbose { SerialBrief, SerialDetailed, SerialDetailedHuman };
648 
649  /// Returns, as a string, a serialized version of the `ImageSpec`. The
650  /// `format` may be either `ImageSpec::SerialText` or
651  /// `ImageSpec::SerialXML`. The `verbose` argument may be one of:
652  /// `ImageSpec::SerialBrief` (just resolution and other vital
653  /// statistics, one line for `SerialText`, `ImageSpec::SerialDetailed`
654  /// (contains all metadata in original form), or
655  /// `ImageSpec::SerialDetailedHuman` (contains all metadata, in many
656  /// cases with human-readable explanation).
657  std::string serialize (SerialFormat format,
658  SerialVerbose verbose = SerialDetailed) const;
659 
660  /// Converts the contents of the `ImageSpec` as an XML string.
661  std::string to_xml () const;
662 
663  /// Populates the fields of the `ImageSpec` based on the XML passed in.
664  void from_xml (const char *xml);
665 
666  /// Hunt for the "Compression" and "CompressionQuality" settings in the
667  /// spec and turn them into the compression name and quality. This
668  /// handles compression name/qual combos of the form "name:quality".
669  std::pair<string_view, int>
670  decode_compression_metadata(string_view defaultcomp = "",
671  int defaultqual = -1) const;
672 
673  /// Helper function to verify that the given pixel range exactly covers
674  /// a set of tiles. Also returns false if the spec indicates that the
675  /// image isn't tiled at all.
676  bool valid_tile_range (int xbegin, int xend, int ybegin, int yend,
677  int zbegin, int zend) noexcept {
678  return (tile_width &&
679  ((xbegin-x) % tile_width) == 0 &&
680  ((ybegin-y) % tile_height) == 0 &&
681  ((zbegin-z) % tile_depth) == 0 &&
682  (((xend-x) % tile_width) == 0 || (xend-x) == width) &&
683  (((yend-y) % tile_height) == 0 || (yend-y) == height) &&
684  (((zend-z) % tile_depth) == 0 || (zend-z) == depth));
685  }
686 
687  /// Return the channelformat of the given channel. This is safe even
688  /// if channelformats is not filled out.
689  TypeDesc channelformat (int chan) const {
690  return chan >= 0 && chan < (int)channelformats.size()
691  ? channelformats[chan] : format;
692  }
693 
694  /// Return the channel name of the given channel. This is safe even if
695  /// channelnames is not filled out.
696  string_view channel_name (int chan) const {
697  return chan >= 0 && chan < (int)channelnames.size()
698  ? string_view(channelnames[chan]) : "";
699  }
700 
701  /// Fill in an array of channel formats describing all channels in
702  /// the image. (Note that this differs slightly from the member
703  /// data channelformats, which is empty if there are not separate
704  /// per-channel formats.)
705  void get_channelformats (std::vector<TypeDesc> &formats) const {
706  formats = channelformats;
707  if ((int)formats.size() < nchannels)
708  formats.resize (nchannels, format);
709  }
710 
711  /// Return the index of the channel with the given name, or -1 if no
712  /// such channel is present in `channelnames`.
713  int channelindex (string_view name) const;
714 
715  /// Return pixel data window for this ImageSpec expressed as a ROI.
716  ROI roi () const noexcept {
717  return ROI (x, x+width, y, y+height, z, z+depth, 0, nchannels);
718  }
719 
720  /// Return full/display window for this ImageSpec expressed as a ROI.
721  ROI roi_full () const noexcept {
722  return ROI (full_x, full_x+full_width, full_y, full_y+full_height,
723  full_z, full_z+full_depth, 0, nchannels);
724  }
725 
726  /// Set pixel data window parameters (x, y, z, width, height, depth)
727  /// for this ImageSpec from an ROI.
728  /// Does NOT change the channels of the spec, regardless of r.
729  void set_roi (const ROI &r) noexcept {
730  x = r.xbegin;
731  y = r.ybegin;
732  z = r.zbegin;
733  width = r.width();
734  height = r.height();
735  depth = r.depth();
736  }
737 
738  /// Set full/display window parameters (full_x, full_y, full_z,
739  /// full_width, full_height, full_depth) for this ImageSpec from an ROI.
740  /// Does NOT change the channels of the spec, regardless of r.
741  void set_roi_full (const ROI &r) noexcept {
742  full_x = r.xbegin;
743  full_y = r.ybegin;
744  full_z = r.zbegin;
745  full_width = r.width();
746  full_height = r.height();
747  full_depth = r.depth();
748  }
749 
750  /// Copy from `other` the image dimensions (x, y, z, width, height,
751  /// depth, full*, nchannels, format) and data types. It does *not* copy
752  /// arbitrary named metadata or channel names (thus, for an `ImageSpec`
753  /// with lots of metadata, it is much less expensive than copying the
754  /// whole thing with `operator=()`).
755  void copy_dimensions (const ImageSpec &other) {
756  x = other.x;
757  y = other.y;
758  z = other.z;
759  width = other.width;
760  height = other.height;
761  depth = other.depth;
762  full_x = other.full_x;
763  full_y = other.full_y;
764  full_z = other.full_z;
765  full_width = other.full_width;
766  full_height = other.full_height;
767  full_depth = other.full_depth;
768  tile_width = other.tile_width;
769  tile_height = other.tile_height;
770  tile_depth = other.tile_depth;
771  nchannels = other.nchannels;
772  format = other.format;
773  channelformats = other.channelformats;
774  alpha_channel = other.alpha_channel;
775  z_channel = other.z_channel;
776  deep = other.deep;
777  }
778 
779  /// Set the metadata to presume that color space is `name` (or to assume
780  /// nothing about the color space if `name` is empty). The core operation
781  /// is to set the "oiio:ColorSpace" attribute, but it also removes or
782  /// alters several other attributes that may hint color space in ways that
783  /// might be contradictory or no longer true.
784  ///
785  /// @version 2.5
786  void set_colorspace(string_view name);
787 
788  /// Returns `true` for a newly initialized (undefined) `ImageSpec`.
789  /// (Designated by no channels and undefined data type -- true of the
790  /// uninitialized state of an ImageSpec, and presumably not for any
791  /// ImageSpec that is useful or purposefully made.)
792  bool undefined () const noexcept {
793  return nchannels == 0 && format == TypeUnknown;
794  }
795 
796  /// Array indexing by string will create an AttrDelegate that enables a
797  /// convenient shorthand for adding and retrieving values from the spec:
798  ///
799  /// 1. Assigning to the delegate adds a metadata attribute:
800  ///
801  /// ImageSpec spec;
802  /// spec["foo"] = 42; // int
803  /// spec["pi"] = float(M_PI); // float
804  /// spec["oiio:ColorSpace"] = "sRGB"; // string
805  /// spec["cameratoworld"] = Imath::Matrix44(...); // matrix
806  ///
807  /// Be very careful, the attribute's type will be implied by the C++
808  /// type of what you assign.
809  ///
810  /// 2. String data may be retrieved directly, and for other types, the
811  /// delegate supports a get<T>() that retrieves an item of type T:
812  ///
813  /// std::string colorspace = spec["oiio:ColorSpace"];
814  /// int dither = spec["oiio:dither"].get<int>();
815  ///
816  /// This was added in version 2.1.
818  {
819  return { this, name };
820  }
822  {
823  return { this, name };
824  }
825 };
826 
827 
828 
829 
830 /// ImageInput abstracts the reading of an image file in a file
831 /// format-agnostic manner.
833 public:
834  /// unique_ptr to an ImageInput
835  using unique_ptr = std::unique_ptr<ImageInput>;
836 
837  /// @{
838  /// @name Creating an ImageInput
839 
840  /// Create an ImageInput subclass instance that is able to read the
841  /// given file and open it, returning a `unique_ptr` to the ImageInput
842  /// if successful. The `unique_ptr` is set up with an appropriate
843  /// deleter so the ImageInput will be properly closed and deleted when
844  /// the `unique_ptr` goes out of scope or is reset. If the open fails,
845  /// return an empty `unique_ptr` and set an error that can be retrieved
846  /// by `OIIO::geterror()`.
847  ///
848  /// The `config`, if not nullptr, points to an ImageSpec giving hints,
849  /// requests, or special instructions. ImageInput implementations are
850  /// free to not respond to any such requests, so the default
851  /// implementation is just to ignore `config`.
852  ///
853  /// `open()` will first try to make an ImageInput corresponding to
854  /// the format implied by the file extension (for example, `"foo.tif"`
855  /// will try the TIFF plugin), but if one is not found or if the
856  /// inferred one does not open the file, every known ImageInput type
857  /// will be tried until one is found that will open the file.
858  ///
859  /// @param filename
860  /// The name of the file to open, UTF-8 encoded.
861  ///
862  /// @param config
863  /// Optional pointer to an ImageSpec whose metadata contains
864  /// "configuration hints."
865  ///
866  /// @param ioproxy
867  /// Optional pointer to an IOProxy to use (not supported by all
868  /// formats, see `supports("ioproxy")`). The caller retains
869  /// ownership of the proxy.
870  ///
871  /// @returns
872  /// A `unique_ptr` that will close and free the ImageInput when
873  /// it exits scope or is reset. The pointer will be empty if the
874  /// required writer was not able to be created.
875  static unique_ptr open (const std::string& filename,
876  const ImageSpec *config = nullptr,
877  Filesystem::IOProxy* ioproxy = nullptr);
878 
879  /// Create and open an ImageInput using a UTF-16 encoded wstring filename.
880  static unique_ptr open (const std::wstring& filename,
881  const ImageSpec *config = nullptr,
882  Filesystem::IOProxy* ioproxy = nullptr) {
883  return open(Strutil::utf16_to_utf8(filename), config, ioproxy);
884  }
885 
886  /// Create and return an ImageInput implementation that is able to read
887  /// the given file or format. If `do_open` is true (and the `filename`
888  /// is the name of a file, not just a format), fully open it if possible
889  /// (using the optional `config` configuration spec, if supplied),
890  /// otherwise just create the ImageInput but don't open it. The
891  /// plugin_searchpath parameter is an override of the searchpath.
892  /// colon-separated list of directories to search for ImageIO plugin
893  /// DSO/DLL's (not a searchpath for the image itself!).
894  ///
895  /// If the `filename` parameter is the name of a file format (such as
896  /// "openexr"), it will create an ImageInput that reads that particular
897  /// format. If the name is a file extension (such as "exr" or ".exr"),
898  /// it will guess the file format from the extension and return that
899  /// type of ImageInput.
900  ///
901  /// If `filename` is a full file name (such as "hawaii.exr"), it will
902  /// create an ImageInput that reads the format implied by the file
903  /// extension (".tif") and try to open the file with that reader. If the
904  /// file can be opened and appears to be of the correct type, then that
905  /// ImageInput (after being closed) will be returned to the caller. But
906  /// if it fails (say, because the file type does not match the
907  /// extension), then every known kind of image reader will be tried in
908  /// turn, until one can be found that succeeds in opening that file. The
909  /// `create()` file will fail entirely only if no known image reader
910  /// type succeeds.
911  ///
912  /// If the caller intends to immediately open the file, then it is often
913  /// simpler to call static `ImageInput::open()`.
914  ///
915  /// @param filename
916  /// The name of an image file, or a file extension, or the name
917  /// of a file format. The filename is UTF-8 encoded.
918  ///
919  /// @param do_open
920  /// If `true`, not only create but also open the file.
921  ///
922  /// @param config
923  /// Optional pointer to an ImageSpec whose metadata contains
924  /// "configuration hints" for the ImageInput implementation.
925  ///
926  /// @param ioproxy
927  /// Optional pointer to an IOProxy to use (not supported by all
928  /// formats, see `supports("ioproxy")`). The caller retains
929  /// ownership of the proxy. If this is not supplied, it is still
930  /// possible to set the proxy with a call to `set_proxy()` prior
931  /// to `open()`.
932  ///
933  /// @param plugin_searchpath
934  /// An optional colon-separated list of directories to search
935  /// for OpenImageIO plugin DSO/DLL's.
936  ///
937  /// @returns
938  /// A `unique_ptr` that will close and free the ImageInput when
939  /// it exits scope or is reset. The pointer will be empty if the
940  /// required writer was not able to be created.
941  static unique_ptr create (string_view filename, bool do_open=false,
942  const ImageSpec *config=nullptr,
943  Filesystem::IOProxy* ioproxy = nullptr,
944  string_view plugin_searchpath = "");
945 
946  /// Create an ImageInput using a UTF-16 encoded wstring filename.
947  static unique_ptr create (const std::wstring& filename, bool do_open=false,
948  const ImageSpec *config=nullptr,
949  Filesystem::IOProxy* ioproxy = nullptr,
950  string_view plugin_searchpath = "") {
951  return create(Strutil::utf16_to_utf8(filename), do_open, config,
952  ioproxy, plugin_searchpath);
953  }
954 
955  // DEPRECATED(2.2): back compatible version
956  static unique_ptr create (const std::string& filename, bool do_open,
957  const ImageSpec *config,
958  string_view plugin_searchpath);
959  // DEPRECATED(2.1) This method should no longer be used, it is redundant.
960  static unique_ptr create (const std::string& filename,
961  const std::string& plugin_searchpath);
962 
963  /// @}
964 
965  // DEPRECATED(2.1)
966  static void destroy (ImageInput *x);
967 
968 protected:
969  ImageInput ();
970 public:
971  virtual ~ImageInput ();
972 
973  /// Return the name of the format implemented by this class.
974  virtual const char *format_name (void) const = 0;
975 
976  /// Given the name of a "feature", return whether this ImageInput
977  /// supports output of images with the given properties. Most queries
978  /// will simply return 0 for "doesn't support" and 1 for "supports it,"
979  /// but it is acceptable to have queries return other nonzero integers
980  /// to indicate varying degrees of support or limits (but should be
981  /// clearly documented as such).
982  ///
983  /// Feature names that ImageInput implementations are expected to
984  /// recognize include:
985  ///
986  /// - `"arbitrary_metadata"` : Does this format allow metadata with
987  /// arbitrary names and types?
988  ///
989  /// - `"exif"` :
990  /// Can this format store Exif camera data?
991  ///
992  /// - `"ioproxy"` :
993  /// Does this format reader support reading from an `IOProxy`?
994  ///
995  /// - `"iptc"` :
996  /// Can this format store IPTC data?
997  ///
998  /// - `"procedural"` :
999  /// Can this format create images without reading from a disk
1000  /// file?
1001  ///
1002  /// - `"thumbnail"` :
1003  /// Does this format reader support retrieving a reduced
1004  /// resolution copy of the image via the `thumbnail()` method?
1005  ///
1006  /// - `"multiimage"` :
1007  /// Does this format support multiple subimages within a file?
1008  /// (Note: this doesn't necessarily mean that the particular
1009  /// file this ImageInput is reading has multiple subimages.)
1010  ///
1011  /// - `"noimage"` :
1012  /// Does this format allow 0x0 sized images, i.e. an image file
1013  /// with metadata only and no pixels?
1014  ///
1015  /// This list of queries may be extended in future releases. Since this
1016  /// can be done simply by recognizing new query strings, and does not
1017  /// require any new API entry points, addition of support for new
1018  /// queries does not break ``link compatibility'' with
1019  /// previously-compiled plugins.
1020  virtual int supports (string_view feature OIIO_MAYBE_UNUSED) const {
1021  return false;
1022  }
1023 
1024  /// Return true if the `filename` names a file of the type for this
1025  /// ImageInput. The implementation will try to determine this as
1026  /// efficiently as possible, in most cases much less expensively than
1027  /// doing a full `open()`. Note that there can be false positives: a
1028  /// file can appear to be of the right type (i.e., `valid_file()`
1029  /// returning `true`) but still fail a subsequent call to `open()`, such
1030  /// as if the contents of the file are truncated, nonsensical, or
1031  /// otherwise corrupted. The filename is UTF-8 encoded.
1032  ///
1033  /// @returns
1034  /// `true` upon success, or `false` upon failure.
1035  virtual bool valid_file (const std::string& filename) const;
1036 
1037  /// Check valid file using a UTF-16 encoded wstring filename.
1038  bool valid_file (const std::wstring& filename) const {
1039  return valid_file(Strutil::utf16_to_utf8(filename));
1040  }
1041 
1042  /// Return true if the `ioproxy` represents a file of the type for this
1043  /// ImageInput. The implementation will try to determine this as
1044  /// efficiently as possible, in most cases much less expensively than
1045  /// doing a full `open()`. Note that there can be false positives: a
1046  /// file can appear to be of the right type (i.e., `valid_file()`
1047  /// returning `true`) but still fail a subsequent call to `open()`, such
1048  /// as if the contents of the file are truncated, nonsensical, or
1049  /// otherwise corrupted.
1050  ///
1051  /// @returns
1052  /// `true` upon success, or `false` upon failure.
1053  virtual bool valid_file (Filesystem::IOProxy* ioproxy) const;
1054 
1055  /// Opens the file with given name and seek to the first subimage in the
1056  /// file. Various file attributes are put in `newspec` and a copy
1057  /// is also saved internally to the `ImageInput` (retrievable via
1058  /// `spec()`. From examining `newspec` or `spec()`, you can
1059  /// discern the resolution, if it's tiled, number of channels, native
1060  /// data format, and other metadata about the image.
1061  ///
1062  /// @param name
1063  /// Filename to open, UTF-8 encoded.
1064  ///
1065  /// @param newspec
1066  /// Reference to an ImageSpec in which to deposit a full
1067  /// description of the contents of the first subimage of the
1068  /// file.
1069  ///
1070  /// @returns
1071  /// `true` if the file was found and opened successfully.
1072  virtual bool open (const std::string& name, ImageSpec &newspec) = 0;
1073 
1074  /// Open the ImageInput using a UTF-16 encoded wstring filename.
1075  bool open (const std::wstring& name, ImageSpec &newspec) {
1076  return open(Strutil::utf16_to_utf8(name), newspec);
1077  }
1078 
1079  /// Open file with given name, similar to `open(name,newspec)`. The
1080  /// `config` is an ImageSpec giving requests or special instructions.
1081  /// ImageInput implementations are free to not respond to any such
1082  /// requests, so the default implementation is just to ignore config and
1083  /// call regular `open(name,newspec)`.
1084  ///
1085  /// @param name
1086  /// Filename to open, UTF-8 encoded.
1087  ///
1088  /// @param newspec
1089  /// Reference to an ImageSpec in which to deposit a full
1090  /// description of the contents of the first subimage of the
1091  /// file.
1092  ///
1093  /// @param config
1094  /// An ImageSpec whose metadata contains "configuration hints"
1095  /// for the ImageInput implementation.
1096  ///
1097  /// @returns
1098  /// `true` if the file was found and opened successfully.
1099  virtual bool open (const std::string& name, ImageSpec &newspec,
1100  const ImageSpec& config OIIO_MAYBE_UNUSED) {
1101  return open(name,newspec);
1102  }
1103  /// Open the ImageInput using a UTF-16 encoded wstring filename.
1104  bool open (const std::wstring& name, ImageSpec &newspec,
1105  const ImageSpec& config OIIO_MAYBE_UNUSED) {
1106  return open(name,newspec);
1107  }
1108 
1109  /// Return a reference to the image specification of the current
1110  /// subimage/MIPlevel. Note that the contents of the spec are invalid
1111  /// before `open()` or after `close()`, and may change with a call to
1112  /// `seek_subimage()`. It is thus not thread-safe, since the spec may
1113  /// change if another thread calls `seek_subimage`, or any of the
1114  /// `read_*()` functions that take explicit subimage/miplevel.
1115  virtual const ImageSpec &spec (void) const { return m_spec; }
1116 
1117  /// Return a full copy of the ImageSpec of the designated subimage and
1118  /// MIPlevel. This method is thread-safe, but it is potentially
1119  /// expensive, due to the work that needs to be done to fully copy an
1120  /// ImageSpec if there is lots of named metadata to allocate and copy.
1121  /// See also the less expensive `spec_dimensions()`. Errors (such as
1122  /// having requested a nonexistent subimage) are indicated by returning
1123  /// an ImageSpec with `format==TypeUnknown`.
1124  virtual ImageSpec spec (int subimage, int miplevel=0);
1125 
1126  /// Return a copy of the ImageSpec of the designated subimage and
1127  /// miplevel, but only the dimension and type fields. Just as with a
1128  /// call to `ImageSpec::copy_dimensions()`, neither the channel names
1129  /// nor any of the arbitrary named metadata will be copied, thus this is
1130  /// a relatively inexpensive operation if you don't need that
1131  /// information. It is guaranteed to be thread-safe. Errors (such as
1132  /// having requested a nonexistent subimage) are indicated by returning
1133  /// an ImageSpec with `format==TypeUnknown`.
1134  virtual ImageSpec spec_dimensions (int subimage, int miplevel=0);
1135 
1136  /// Retrieve a reduced-resolution ("thumbnail") version of the given
1137  /// subimage. It is guaranteed to be thread-safe.
1138  ///
1139  /// @param thumb
1140  /// A reference to an `ImageBuf` which will be overwritten with
1141  /// the thumbnail image.
1142  /// @param subimage
1143  /// The index of the subimage in the file whose thumbnail is to
1144  /// be retrieved.
1145  /// @returns
1146  /// `true` upon success, `false` if no thumbnail was available,
1147  /// or if this file format (or reader) does not support
1148  /// thumbnails.
1149  ///
1150  /// @note This method was added to OpenImageIO 2.3.
1151  virtual bool get_thumbnail(ImageBuf& thumb, int subimage) {
1152  return false;
1153  }
1154 
1155  /// Close an open ImageInput. The call to close() is not strictly
1156  /// necessary if the ImageInput is destroyed immediately afterwards,
1157  /// since it is required for the destructor to close if the file is
1158  /// still open.
1159  ///
1160  /// @returns
1161  /// `true` upon success, or `false` upon failure.
1162  virtual bool close () = 0;
1163 
1164  /// Returns the index of the subimage that is currently being read.
1165  /// The first subimage (or the only subimage, if there is just one)
1166  /// is number 0.
1167  virtual int current_subimage (void) const { return 0; }
1168 
1169  /// Returns the index of the MIPmap image that is currently being read.
1170  /// The highest-res MIP level (or the only level, if there is just
1171  /// one) is number 0.
1172  virtual int current_miplevel (void) const { return 0; }
1173 
1174  /// Seek to the given subimage and MIP-map level within the open image
1175  /// file. The first subimage of the file has index 0, the highest-
1176  /// resolution MIP level has index 0. The new subimage's vital
1177  /// statistics=may be retrieved by `this->spec()`. The reader is
1178  /// expected to give the appearance of random access to subimages and
1179  /// MIP levels -- in other words, if it can't randomly seek to the given
1180  /// subimage/level, it should transparently close, reopen, and
1181  /// sequentially read through prior subimages and levels.
1182  ///
1183  /// @returns
1184  /// `true` upon success, or `false` upon failure. A failure may
1185  /// indicate that no such subimage or MIP level exists in the
1186  /// file.
1187  virtual bool seek_subimage (int subimage, int miplevel) {
1188  // Default implementation assumes no support for subimages or
1189  // mipmaps, so there is no work to do.
1190  return subimage == current_subimage() && miplevel == current_miplevel();
1191  }
1192 
1193  // Old version for backwards-compatibility: pass reference to newspec.
1194  // Some day this will be deprecated.
1195  bool seek_subimage (int subimage, int miplevel, ImageSpec &newspec) {
1196  bool ok = seek_subimage (subimage, miplevel);
1197  if (ok)
1198  newspec = spec();
1199  return ok;
1200  }
1201 
1202  // DEPRECATED(2.1)
1203  // Seek to the given subimage -- backwards-compatible call that
1204  // doesn't worry about MIP-map levels at all.
1205  bool seek_subimage (int subimage, ImageSpec &newspec) {
1206  return seek_subimage (subimage, 0 /* miplevel */, newspec);
1207  }
1208 
1209  /// @{
1210  /// @name Reading pixels
1211  ///
1212  /// Common features of all the `read` methods:
1213  ///
1214  /// * The `format` parameter describes the data type of the `data[]`
1215  /// buffer. The read methods automatically convert the data from the
1216  /// data type it is stored in the file into the `format` of the `data`
1217  /// buffer. If `format` is `TypeUnknown` it will just copy pixels of
1218  /// file's native data layout (including, possibly, per-channel data
1219  /// formats as specified by the ImageSpec's `channelformats` field).
1220  ///
1221  /// * The `stride` values describe the layout of the `data` buffer:
1222  /// `xstride` is the distance in bytes between successive pixels
1223  /// within each scanline. `ystride` is the distance in bytes between
1224  /// successive scanlines. For volumetric images `zstride` is the
1225  /// distance in bytes between successive "volumetric planes". Strides
1226  /// set to the special value `AutoStride` imply contiguous data, i.e.,
1227  ///
1228  /// xstride = format.size() * nchannels
1229  /// ystride = xstride * width
1230  /// zstride = ystride * height
1231  ///
1232  /// * Any *range* parameters (such as `ybegin` and `yend`) describe a
1233  /// "half open interval", meaning that `begin` is the first item and
1234  /// `end` is *one past the last item*. That means that the number of
1235  /// items is `end - begin`.
1236  ///
1237  /// * For ordinary 2D (non-volumetric) images, any `z` or `zbegin`
1238  /// coordinates should be 0 and any `zend` should be 1, indicating
1239  /// that only a single image "plane" exists.
1240  ///
1241  /// * Some read methods take a channel range [chbegin,chend) to allow
1242  /// reading of a contiguous subset of channels (chbegin=0,
1243  /// chend=spec.nchannels reads all channels).
1244  ///
1245  /// * ImageInput readers are expected to give the appearance of random
1246  /// access -- in other words, if it can't randomly seek to the given
1247  /// scanline or tile, it should transparently close, reopen, and
1248  /// sequentially read through prior scanlines.
1249  ///
1250  /// * All read functions return `true` for success, `false` for failure
1251  /// (after which a call to `geterror()` may retrieve a specific error
1252  /// message).
1253  ///
1254 
1255  /// Read the scanline that includes pixels (*,y,z) from the "current"
1256  /// subimage and MIP level. The `xstride` value gives the distance
1257  /// between successive pixels (in bytes). Strides set to `AutoStride`
1258  /// imply "contiguous" data.
1259  ///
1260  /// @note This variety of `read_scanline` is not re-entrant nor
1261  /// thread-safe. If you require concurrent reads to the same open
1262  /// ImageInput, you should use `read_scanlines` that has the `subimage`
1263  /// and `miplevel` passed explicitly.
1264  ///
1265  /// @param y/z The y & z coordinates of the scanline. For 2D
1266  /// images, z should be 0.
1267  /// @param format A TypeDesc describing the type of `data`.
1268  /// @param data Pointer to the pixel data buffer.
1269  /// @param xstride The distance in bytes between successive
1270  /// pixels in `data` (or `AutoStride`).
1271  /// @returns `true` upon success, or `false` upon failure.
1272  virtual bool read_scanline (int y, int z, TypeDesc format, void *data,
1273  stride_t xstride=AutoStride);
1274 
1275  /// Simple read_scanline reads into contiguous float pixels.
1276  bool read_scanline (int y, int z, float *data) {
1277  return read_scanline (y, z, TypeFloat, data);
1278  }
1279 
1280  /// Read multiple scanlines that include pixels (*,y,z) for all ybegin
1281  /// <= y < yend in the specified subimage and mip level, into `data`,
1282  /// using the strides given and converting to the requested data
1283  /// `format` (TypeUnknown indicates no conversion, just copy native data
1284  /// types). Only channels [chbegin,chend) will be read/copied
1285  /// (chbegin=0, chend=spec.nchannels reads all channels, yielding
1286  /// equivalent behavior to the simpler variant of `read_scanlines`).
1287  ///
1288  /// This version of read_scanlines, because it passes explicit
1289  /// subimage/miplevel, does not require a separate call to
1290  /// seek_subimage, and is guaranteed to be thread-safe against other
1291  /// concurrent calls to any of the read_* methods that take an explicit
1292  /// subimage/miplevel (but not against any other ImageInput methods).
1293  ///
1294  /// @param subimage The subimage to read from (starting with 0).
1295  /// @param miplevel The MIP level to read (0 is the highest
1296  /// resolution level).
1297  /// @param ybegin/yend The y range of the scanlines being passed.
1298  /// @param z The z coordinate of the scanline.
1299  /// @param chbegin/chend
1300  /// The channel range to read.
1301  /// @param format A TypeDesc describing the type of `data`.
1302  /// @param data Pointer to the pixel data.
1303  /// @param xstride/ystride
1304  /// The distance in bytes between successive pixels
1305  /// and scanlines (or `AutoStride`).
1306  /// @returns `true` upon success, or `false` upon failure.
1307  ///
1308  /// @note This call was changed for OpenImageIO 2.0 to include the
1309  /// explicit subimage and miplevel parameters. The previous
1310  /// versions, which lacked subimage and miplevel parameters (thus
1311  /// were dependent on a prior call to `seek_subimage`) are
1312  /// considered deprecated.
1313  virtual bool read_scanlines (int subimage, int miplevel,
1314  int ybegin, int yend, int z,
1315  int chbegin, int chend,
1316  TypeDesc format, void *data,
1317  stride_t xstride=AutoStride,
1318  stride_t ystride=AutoStride);
1319 
1320 #ifndef OIIO_DOXYGEN
1321  // DEPRECATED versions of read_scanlines (pre-1.9 OIIO). These will
1322  // eventually be removed. Try to replace these calls with ones to the
1323  // new variety of read_scanlines that takes an explicit subimage and
1324  // miplevel. These old versions are NOT THREAD-SAFE.
1325  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1326  bool read_scanlines (int ybegin, int yend, int z,
1327  TypeDesc format, void *data,
1328  stride_t xstride=AutoStride,
1329  stride_t ystride=AutoStride);
1330  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1331  bool read_scanlines (int ybegin, int yend, int z,
1332  int chbegin, int chend,
1333  TypeDesc format, void *data,
1334  stride_t xstride=AutoStride,
1335  stride_t ystride=AutoStride);
1336 #endif
1337 
1338  /// Read the tile whose upper-left origin is (x,y,z) into `data[]`,
1339  /// converting if necessary from the native data format of the file into
1340  /// the `format` specified. The stride values give the data spacing of
1341  /// adjacent pixels, scanlines, and volumetric slices (measured in
1342  /// bytes). Strides set to AutoStride imply 'contiguous' data in the
1343  /// shape of a full tile, i.e.,
1344  ///
1345  /// xstride = format.size() * spec.nchannels
1346  /// ystride = xstride * spec.tile_width
1347  /// zstride = ystride * spec.tile_height
1348  ///
1349  /// @note This variety of `read_tile` is not re-entrant nor thread-safe.
1350  /// If you require concurrent reads to the same open ImageInput, you
1351  /// should use `read_tiles()` that has the `subimage` and `miplevel`
1352  /// passed explicitly.
1353  ///
1354  /// @param x/y/z The upper left coordinate of the tile being passed.
1355  /// @param format A TypeDesc describing the type of `data`.
1356  /// @param data Pointer to the pixel data.
1357  /// @param xstride/ystride/zstride
1358  /// The distance in bytes between successive pixels,
1359  /// scanlines, and image planes (or `AutoStride` to
1360  /// indicate a "contiguous" single tile).
1361  /// @returns `true` upon success, or `false` upon failure.
1362  ///
1363  /// @note This call will fail if the image is not tiled, or if (x,y,z)
1364  /// is not the upper left corner coordinates of a tile.
1365  virtual bool read_tile (int x, int y, int z, TypeDesc format,
1366  void *data, stride_t xstride=AutoStride,
1367  stride_t ystride=AutoStride,
1368  stride_t zstride=AutoStride);
1369 
1370  /// Simple read_tile reads into contiguous float pixels.
1371  bool read_tile (int x, int y, int z, float *data) {
1372  return read_tile (x, y, z, TypeDesc::FLOAT, data,
1373  AutoStride, AutoStride, AutoStride);
1374  }
1375 
1376  /// Read the block of multiple tiles that include all pixels in
1377  ///
1378  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend)
1379  ///
1380  /// This is analogous to calling `read_tile(x,y,z,...)` for each tile
1381  /// in turn (but for some file formats, reading multiple tiles may allow
1382  /// it to read more efficiently or in parallel).
1383  ///
1384  /// The begin/end pairs must correctly delineate tile boundaries, with
1385  /// the exception that it may also be the end of the image data if the
1386  /// image resolution is not a whole multiple of the tile size. The
1387  /// stride values give the data spacing of adjacent pixels, scanlines,
1388  /// and volumetric slices (measured in bytes). Strides set to AutoStride
1389  /// imply contiguous data in the shape of the [begin,end) region, i.e.,
1390  ///
1391  /// xstride = format.size() * spec.nchannels
1392  /// ystride = xstride * (xend-xbegin)
1393  /// zstride = ystride * (yend-ybegin)
1394  ///
1395  /// This version of read_tiles, because it passes explicit subimage and
1396  /// miplevel, does not require a separate call to seek_subimage, and is
1397  /// guaranteed to be thread-safe against other concurrent calls to any
1398  /// of the read_* methods that take an explicit subimage/miplevel (but
1399  /// not against any other ImageInput methods).
1400  ///
1401  /// @param subimage The subimage to read from (starting with 0).
1402  /// @param miplevel The MIP level to read (0 is the highest
1403  /// resolution level).
1404  /// @param xbegin/xend The x range of the pixels covered by the group
1405  /// of tiles being read.
1406  /// @param ybegin/yend The y range of the pixels covered by the tiles.
1407  /// @param zbegin/zend The z range of the pixels covered by the tiles
1408  /// (for a 2D image, zbegin=0 and zend=1).
1409  /// @param chbegin/chend
1410  /// The channel range to read.
1411  /// @param format A TypeDesc describing the type of `data`.
1412  /// @param data Pointer to the pixel data.
1413  /// @param xstride/ystride/zstride
1414  /// The distance in bytes between successive pixels,
1415  /// scanlines, and image planes (or `AutoStride`).
1416  /// @returns `true` upon success, or `false` upon failure.
1417  ///
1418  /// @note The call will fail if the image is not tiled, or if the pixel
1419  /// ranges do not fall along tile (or image) boundaries, or if it is not
1420  /// a valid tile range.
1421  virtual bool read_tiles (int subimage, int miplevel, int xbegin, int xend,
1422  int ybegin, int yend, int zbegin, int zend,
1423  int chbegin, int chend, TypeDesc format, void *data,
1424  stride_t xstride=AutoStride, stride_t ystride=AutoStride,
1425  stride_t zstride=AutoStride);
1426 
1427 #ifndef OIIO_DOXYGEN
1428  // DEPRECATED versions of read_tiles (pre-1.9 OIIO). These will
1429  // eventually be removed. Try to replace these calls with ones to the
1430  // new variety of read_tiles that takes an explicit subimage and
1431  // miplevel. These old versions are NOT THREAD-SAFE.
1432  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1433  bool read_tiles (int xbegin, int xend, int ybegin, int yend,
1434  int zbegin, int zend, TypeDesc format, void *data,
1435  stride_t xstride=AutoStride, stride_t ystride=AutoStride,
1436  stride_t zstride=AutoStride);
1437  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1438  bool read_tiles (int xbegin, int xend, int ybegin, int yend,
1439  int zbegin, int zend, int chbegin, int chend,
1440  TypeDesc format, void *data, stride_t xstride=AutoStride,
1441  stride_t ystride=AutoStride, stride_t zstride=AutoStride);
1442 #endif
1443 
1444  /// Read the entire image of `spec.width x spec.height x spec.depth`
1445  /// pixels into a buffer with the given strides and in the desired
1446  /// data format.
1447  ///
1448  /// Depending on the spec, this will read either all tiles or all
1449  /// scanlines. Assume that data points to a layout in row-major order.
1450  ///
1451  /// This version of read_image, because it passes explicit subimage and
1452  /// miplevel, does not require a separate call to seek_subimage, and is
1453  /// guaranteed to be thread-safe against other concurrent calls to any
1454  /// of the read_* methods that take an explicit subimage/miplevel (but
1455  /// not against any other ImageInput methods).
1456  ///
1457  /// Because this may be an expensive operation, a progress callback
1458  /// may be passed. Periodically, it will be called as follows:
1459  ///
1460  /// progress_callback (progress_callback_data, float done);
1461  ///
1462  /// where `done` gives the portion of the image (between 0.0 and 1.0)
1463  /// that has been written thus far.
1464  ///
1465  /// @param subimage The subimage to read from (starting with 0).
1466  /// @param miplevel The MIP level to read (0 is the highest
1467  /// resolution level).
1468  /// @param chbegin/chend
1469  /// The channel range to read. If chend is -1, it
1470  /// will be set to spec.nchannels.
1471  /// @param format A TypeDesc describing the type of `data`.
1472  /// @param data Pointer to the pixel data.
1473  /// @param xstride/ystride/zstride
1474  /// The distance in bytes between successive pixels,
1475  /// scanlines, and image planes (or `AutoStride`).
1476  /// @param progress_callback/progress_callback_data
1477  /// Optional progress callback.
1478  /// @returns `true` upon success, or `false` upon failure.
1479  virtual bool read_image (int subimage, int miplevel,
1480  int chbegin, int chend,
1481  TypeDesc format, void *data,
1482  stride_t xstride=AutoStride,
1483  stride_t ystride=AutoStride,
1484  stride_t zstride=AutoStride,
1485  ProgressCallback progress_callback=NULL,
1486  void *progress_callback_data=NULL);
1487 
1488 #ifndef OIIO_DOXYGEN
1489  // DEPRECATED versions of read_image (pre-1.9 OIIO). These will
1490  // eventually be removed. Try to replace these calls with ones to the
1491  // new variety of read_image that takes an explicit subimage and
1492  // miplevel. These old versions are NOT THREAD-SAFE.
1493  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1494  virtual bool read_image (TypeDesc format, void *data,
1495  stride_t xstride=AutoStride,
1496  stride_t ystride=AutoStride,
1497  stride_t zstride=AutoStride,
1498  ProgressCallback progress_callback=NULL,
1499  void *progress_callback_data=NULL);
1500  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1501  virtual bool read_image (int chbegin, int chend,
1502  TypeDesc format, void *data,
1503  stride_t xstride=AutoStride,
1504  stride_t ystride=AutoStride,
1505  stride_t zstride=AutoStride,
1506  ProgressCallback progress_callback=NULL,
1507  void *progress_callback_data=NULL);
1508  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1509  bool read_image (float *data) {
1510  return read_image (current_subimage(), current_miplevel(),
1511  0, -1, TypeFloat, data);
1512  }
1513 #endif
1514 
1515  /// Read deep scanlines containing pixels (*,y,z), for all y in the
1516  /// range [ybegin,yend) into `deepdata`. This will fail if it is not a
1517  /// deep file.
1518  ///
1519  /// @param subimage The subimage to read from (starting with 0).
1520  /// @param miplevel The MIP level to read (0 is the highest
1521  /// resolution level).
1522  /// @param chbegin/chend
1523  /// The channel range to read.
1524  /// @param ybegin/yend The y range of the scanlines being passed.
1525  /// @param z The z coordinate of the scanline.
1526  /// @param deepdata A `DeepData` object into which the data for
1527  /// these scanlines will be placed.
1528  /// @returns `true` upon success, or `false` upon failure.
1529  virtual bool read_native_deep_scanlines (int subimage, int miplevel,
1530  int ybegin, int yend, int z,
1531  int chbegin, int chend,
1532  DeepData &deepdata);
1533 
1534  /// Read into `deepdata` the block of native deep data tiles that
1535  /// include all pixels and channels specified by pixel range.
1536  ///
1537  /// @param subimage The subimage to read from (starting with 0).
1538  /// @param miplevel The MIP level to read (0 is the highest
1539  /// resolution level).
1540  /// @param xbegin/xend The x range of the pixels covered by the group
1541  /// of tiles being read.
1542  /// @param ybegin/yend The y range of the pixels covered by the tiles.
1543  /// @param zbegin/zend The z range of the pixels covered by the tiles
1544  /// (for a 2D image, zbegin=0 and zend=1).
1545  /// @param chbegin/chend
1546  /// The channel range to read.
1547  /// @param deepdata A `DeepData` object into which the data for
1548  /// these tiles will be placed.
1549  /// @returns `true` upon success, or `false` upon failure.
1550  ///
1551  /// @note The call will fail if the image is not tiled, or if the pixel
1552  /// ranges do not fall along tile (or image) boundaries, or if it is not
1553  /// a valid tile range.
1554  virtual bool read_native_deep_tiles (int subimage, int miplevel,
1555  int xbegin, int xend,
1556  int ybegin, int yend,
1557  int zbegin, int zend,
1558  int chbegin, int chend,
1559  DeepData &deepdata);
1560 
1561  /// Read the entire deep data image of spec.width x spec.height x
1562  /// spec.depth pixels, all channels, into `deepdata`.
1563  ///
1564  /// @param subimage The subimage to read from (starting with 0).
1565  /// @param miplevel The MIP level to read (0 is the highest
1566  /// resolution level).
1567  /// @param deepdata A `DeepData` object into which the data for
1568  /// the image will be placed.
1569  /// @returns `true` upon success, or `false` upon failure.
1570  virtual bool read_native_deep_image (int subimage, int miplevel,
1571  DeepData &deepdata);
1572 
1573 #ifndef OIIO_DOXYGEN
1574  // DEPRECATED(1.9), Now just used for back compatibility:
1575  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1576  bool read_native_deep_scanlines (int ybegin, int yend, int z,
1577  int chbegin, int chend, DeepData &deepdata) {
1578  return read_native_deep_scanlines (current_subimage(), current_miplevel(),
1579  ybegin, yend, z,
1580  chbegin, chend, deepdata);
1581  }
1582  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1583  bool read_native_deep_tiles (int xbegin, int xend, int ybegin, int yend,
1584  int zbegin, int zend, int chbegin, int chend,
1585  DeepData &deepdata) {
1586  return read_native_deep_tiles (current_subimage(), current_miplevel(),
1587  xbegin, xend, ybegin, yend,
1588  zbegin, zend, chbegin, chend, deepdata);
1589  }
1590  OIIO_DEPRECATED("replace with version that takes subimage & miplevel parameters (2.0)")
1591  bool read_native_deep_image (DeepData &deepdata) {
1592  return read_native_deep_image (current_subimage(), current_miplevel(),
1593  deepdata);
1594  }
1595 #endif
1596 
1597  /// @}
1598 
1599  /// @{
1600  /// @name Reading native pixels -- implementation overloads
1601  ///
1602  /// @note read_native_* methods are usually not directly called by user
1603  /// code (except for read_native_deep_* varieties). These are the
1604  /// methods that are overloaded by the ImageInput subclasses that
1605  /// implement the individual file format readers.
1606  //
1607  // The read_native_* methods always read the "native" data types
1608  // (including per-channel data types) and assume that `data` points to
1609  // contiguous memory (no non-default strides). In contrast, the
1610  // read_scanline/scanlines/tile/tiles handle data type translation and
1611  // arbitrary strides.
1612  //
1613  // The read_native_* methods take an explicit subimage and miplevel, and
1614  // thus do not require a prior call to seek_subimage (and therefore no
1615  // saved state). They are all required to be thread-safe when called
1616  // concurrently with any other read_native_* call or with the varieties
1617  // of read_tiles() that also takes an explicit subimage and miplevel
1618  // parameter.
1619  //
1620  // As far as format-reading ImageInput subclasses are concerned, the
1621  // only truly required overloads are read_native_scanline (always) and
1622  // read_native_tile (only for formats that support tiles). The other
1623  // varieties are special cases, for example if the particular format is
1624  // able to efficiently read multiple scanlines or tiles at once, and if
1625  // the subclass does not provide overloads, the base class
1626  // implementation will be used instead, which is implemented by reducing
1627  // the operation to multiple calls to read_scanline or read_tile.
1628 
1629  /// Read a single scanline (all channels) of native data into contiguous
1630  /// memory.
1631  virtual bool read_native_scanline (int subimage, int miplevel,
1632  int y, int z, void *data) = 0;
1633  /// Read a range of scanlines (all channels) of native data into
1634  /// contiguous memory.
1635  virtual bool read_native_scanlines (int subimage, int miplevel,
1636  int ybegin, int yend, int z,
1637  void *data);
1638  /// Read a range of scanlines (with optionally a subset of channels) of
1639  /// native data into contiguous memory.
1640  virtual bool read_native_scanlines (int subimage, int miplevel,
1641  int ybegin, int yend, int z,
1642  int chbegin, int chend, void *data);
1643 
1644  /// Read a single tile (all channels) of native data into contiguous
1645  /// memory. The base class read_native_tile fails. A format reader that
1646  /// supports tiles MUST overload this virtual method that reads a single
1647  /// tile (all channels).
1648  virtual bool read_native_tile (int subimage, int miplevel,
1649  int x, int y, int z, void *data);
1650 
1651  /// Read multiple tiles (all channels) of native data into contiguous
1652  /// memory. A format reader that supports reading multiple tiles at once
1653  /// (in a way that's more efficient than reading the tiles one at a
1654  /// time) is advised (but not required) to overload this virtual method.
1655  /// If an ImageInput subclass does not overload this, the default
1656  /// implementation here is simply to loop over the tiles, calling the
1657  /// single-tile read_native_tile() for each one.
1658  virtual bool read_native_tiles (int subimage, int miplevel,
1659  int xbegin, int xend, int ybegin, int yend,
1660  int zbegin, int zend, void *data);
1661 
1662  /// Read multiple tiles (potentially a subset of channels) of native
1663  /// data into contiguous memory. A format reader that supports reading
1664  /// multiple tiles at once, and can handle a channel subset while doing
1665  /// so, is advised (but not required) to overload this virtual method.
1666  /// If an ImageInput subclass does not overload this, the default
1667  /// implementation here is simply to loop over the tiles, calling the
1668  /// single-tile read_native_tile() for each one (and copying carefully
1669  /// to handle the channel subset issues).
1670  virtual bool read_native_tiles (int subimage, int miplevel,
1671  int xbegin, int xend, int ybegin, int yend,
1672  int zbegin, int zend,
1673  int chbegin, int chend, void *data);
1674  /// @}
1675 
1676 
1677  // General message passing between client and image input server. This
1678  // is currently undefined and is reserved for future use.
1679  virtual int send_to_input (const char *format, ...);
1680  int send_to_client (const char *format, ...);
1681 
1682  /// Set an IOProxy for this reader. This must be called prior to
1683  /// `open()`, and only for readers that support them
1684  /// (`supports("ioproxy")`). The caller retains ownership of the proxy.
1685  ///
1686  /// @returns `true` for success, `false` for failure.
1687  virtual bool set_ioproxy (Filesystem::IOProxy* ioproxy);
1688 
1689  /// Is there a pending error message waiting to be retrieved, that
1690  /// resulted from an ImageInput API call made by the this thread?
1691  ///
1692  /// Note that any `error()` calls issued are thread-specific, and the
1693  /// `geterror()/has_error()` are expected to be called by the same
1694  /// thread that called whichever API function encountered an error.
1695  bool has_error() const;
1696 
1697  /// Return the text of all pending error messages issued against this
1698  /// ImageInput by the calling thread, and clear the pending error
1699  /// message unless `clear` is false. If no error message is pending, it
1700  /// will return an empty string.
1701  ///
1702  /// Note that any `error()` calls issued are thread-specific, and the
1703  /// `geterror()/has_error()` are expected to be called by the same
1704  /// thread that called whichever API function encountered an error.
1705  std::string geterror(bool clear = true) const;
1706 
1707  /// Error reporting for the plugin implementation: call this with
1708  /// Strutil::format-like arguments. It is not necessary to have the
1709  /// error message contain a trailing newline.
1710  /// Use with caution! Some day this will change to be fmt-like rather
1711  /// than printf-like.
1712  template<typename... Args>
1714  void error(const char* fmt, const Args&... args) const {
1715  append_error(Strutil::format (fmt, args...));
1716  }
1717 
1718  /// Error reporting for the plugin implementation: call this with
1719  /// printf-like arguments. It is not necessary to have the error message
1720  /// contain a trailing newline.
1721  template<typename... Args>
1722  void errorf(const char* fmt, const Args&... args) const {
1723  append_error(Strutil::sprintf (fmt, args...));
1724  }
1725 
1726  /// Error reporting for the plugin implementation: call this with
1727  /// std::format-like arguments. It is not necessary to have the error
1728  /// message contain a trailing newline.
1729  template<typename... Args>
1730  void errorfmt(const char* fmt, const Args&... args) const {
1731  append_error(Strutil::fmt::format (fmt, args...));
1732  }
1733 
1734  // Error reporting for the plugin implementation: call this with
1735  // std::format-like arguments. It is not necessary to have the
1736  // error message contain a trailing newline.
1737  template<typename... Args>
1738  OIIO_DEPRECATED("use `errorfmt` instead")
1739  void fmterror(const char* fmt, const Args&... args) const {
1740  append_error(Strutil::fmt::format (fmt, args...));
1741  }
1742 
1743  /// Set the threading policy for this ImageInput, controlling the
1744  /// maximum amount of parallelizing thread "fan-out" that might occur
1745  /// during large read operations. The default of 0 means that the global
1746  /// `attribute("threads")` value should be used (which itself defaults
1747  /// to using as many threads as cores; see Section `Global Attributes`_).
1748  ///
1749  /// The main reason to change this value is to set it to 1 to indicate
1750  /// that the calling thread should do all the work rather than spawning
1751  /// new threads. That is probably the desired behavior in situations
1752  /// where the calling application has already spawned multiple worker
1753  /// threads.
1754  void threads(int n);
1755 
1756  /// Retrieve the current thread-spawning policy.
1757  /// @see `threads(int)`
1758  int threads() const;
1759 
1760  /// There is a (hidden) internal recursive mutex to each ImageInput
1761  /// that can be used by the II to enforce thread safety. This is exposed
1762  /// via the obvious lock()/unlock()/try_lock() semantics.
1763  void lock() const;
1764  void unlock() const;
1765  bool try_lock() const;
1766 
1767  /// The presence of lock() and unlock() establish an ImageInput itself
1768  /// as having the BasicLockable concept and therefore can be used by
1769  /// std::lock_guard.
1770  typedef std::lock_guard<const ImageInput&> lock_guard;
1771 
1772  // Custom new and delete to ensure that allocations & frees happen in
1773  // the OpenImageIO library, not in the app or plugins (because Windows).
1774  void* operator new (size_t size);
1775  void operator delete (void *ptr);
1776 
1777  /// Call signature of a function that creates and returns an
1778  /// `ImageInput*`.
1779  typedef ImageInput* (*Creator)();
1780 
1781 protected:
1782  ImageSpec m_spec; // format spec of the current open subimage/MIPlevel
1783  // BEWARE using m_spec directly -- not thread-safe
1784 
1785  /// @{
1786  /// @name IOProxy aids for ImageInput implementations.
1787  ///
1788  /// This set of utility functions are not meant to be called by user code.
1789  /// They are protected methods of ImageInput, and are used internally by
1790  /// the ImageInput implementation to help it properly implement support of
1791  /// IOProxy.
1792  ///
1793 
1794  /// Get the IOProxy being used underneath.
1795  Filesystem::IOProxy* ioproxy();
1796  const Filesystem::IOProxy* ioproxy() const;
1797 
1798  /// Is this file currently opened (active proxy)?
1799  bool ioproxy_opened() const;
1800 
1801  /// Clear the proxy ptr, and close/destroy any "local" proxy.
1802  void ioproxy_clear();
1803 
1804  /// Retrieve any ioproxy request from the configuration hint spec, and
1805  /// make `m_io` point to it. But if no IOProxy is found in the config,
1806  /// don't overwrite one we already have.
1807  void ioproxy_retrieve_from_config(const ImageSpec& config);
1808 
1809  /// Presuming that `ioproxy_retrieve_from_config` has already been called,
1810  /// if `m_io` is still not set (i.e., wasn't found in the config), open a
1811  /// IOFile local proxy with the given read/write `mode`. Return true if a
1812  /// proxy is set up. If it can't be done (i.e., no proxy passed, file
1813  /// couldn't be opened), issue an error and return false.
1814  bool ioproxy_use_or_open(string_view name);
1815 
1816  /// Helper: read from the proxy akin to fread(). Return true on success,
1817  /// false upon failure and issue a helpful error message. NOTE: this is
1818  /// not the same return value as std::fread, which returns the number of
1819  /// items read.
1820  bool ioread(void* buf, size_t itemsize, size_t nitems = 1);
1821 
1822  /// Helper: seek the proxy, akin to fseek. Return true on success, false
1823  /// upon failure and issue an error message. (NOTE: this is not the same
1824  /// return value as std::fseek, which returns 0 on success.)
1825  bool ioseek(int64_t pos, int origin = SEEK_SET);
1826 
1827  /// Helper: retrieve the current position of the proxy, akin to ftell.
1828  int64_t iotell() const;
1829 
1830  /// Helper: convenience boilerplate for several checks and operations that
1831  /// every implementation of ImageInput::open() will need to do. Failure is
1832  /// presumed to indicate a file that is corrupt (or perhaps maliciously
1833  /// crafted) and no further reading should be attempted.
1834  ///
1835  /// @param spec
1836  /// The ImageSpec that we are validating.
1837  ///
1838  /// @param range
1839  /// An ROI that describes the allowable pixel coordinates and channel
1840  /// indices as half-open intervals. For example, the default value
1841  /// `{0, 65535, 0, 65535, 0, 1, 0, 4}` means that pixel coordinates
1842  /// must be non-negative and the width and height be representable by
1843  /// a uint16 value, up to 4 channels are allowed, and volumes are not
1844  /// permitted (z coordinate may only be 0). File formats that can
1845  /// handle larger resolutions, or volumes, or >4 channels must
1846  /// override these limits!
1847  ///
1848  /// @param flags
1849  /// A bitfield flag (bits defined by `enum OpenChecks`) that can
1850  /// indicate additional checks to perform, or checks that should be
1851  /// skipped.
1852  ///
1853  /// @returns
1854  /// Return `true` if the spec is valid and passes all checks,
1855  /// otherwise return `false` and make appropriate calls to
1856  /// this->errorfmt() to record the errors.
1857  ///
1858  /// Checks performed include:
1859  ///
1860  /// * Whether the resolution and channel count are within the range
1861  /// implied by `range`.
1862  /// * Whether the channel count is within the `"limit:channels"` OIIO
1863  /// attribute.
1864  /// * The total uncompressed pixel data size is expected to be within the
1865  /// `"limit:imagesize_MB"` OIIO attribute.
1866  ///
1867  bool check_open (const ImageSpec &spec,
1868  ROI range = {0, 65535, 0, 65535, 0, 1, 0, 4},
1869  uint64_t flags = 0);
1870 
1871  /// Bit field definitions for the `flags` argument to `check_open()`.
1872  enum class OpenChecks : uint64_t {
1873  Defaults = 0,
1874  // Reserved for future use
1875  };
1876 
1877  /// @}
1878 
1879 private:
1880  // PIMPL idiom -- this lets us hide details of the internals of the
1881  // ImageInput parent class so that changing them does not break the
1882  // ABI.
1883  class Impl;
1884  static void impl_deleter(Impl*);
1885  std::unique_ptr<Impl, decltype(&impl_deleter)> m_impl;
1886 
1887  void append_error(string_view message) const; // add to error message
1888  // Deprecated:
1889  OIIO_DEPRECATED("Deprecated")
1890  static unique_ptr create (const std::string& filename, bool do_open,
1891  const std::string& plugin_searchpath);
1892 };
1893 
1894 
1895 
1896 
1897 /// ImageOutput abstracts the writing of an image file in a file
1898 /// format-agnostic manner.
1899 ///
1900 /// Users don't directly declare these. Instead, you call the `create()`
1901 /// static method, which will return a `unique_ptr` holding a subclass of
1902 /// ImageOutput that implements writing the particular format.
1903 ///
1905 public:
1906  /// unique_ptr to an ImageOutput.
1907  using unique_ptr = std::unique_ptr<ImageOutput>;
1908 
1909  /// @{
1910  /// @name Creating an ImageOutput
1911 
1912  /// Create an `ImageOutput` that can be used to write an image file.
1913  /// The type of image file (and hence, the particular subclass of
1914  /// `ImageOutput` returned, and the plugin that contains its methods) is
1915  /// inferred from the name, if it appears to be a full filename, or it
1916  /// may also name the format.
1917  ///
1918  /// @param filename
1919  /// The name of the file format (e.g., "openexr"), a file
1920  /// extension (e.g., "exr"), or a filename from which the the
1921  /// file format can be inferred from its extension (e.g.,
1922  /// "hawaii.exr"). The filename is UTF-8 encoded.
1923  ///
1924  /// @param plugin_searchpath
1925  /// An optional colon-separated list of directories to search
1926  /// for OpenImageIO plugin DSO/DLL's.
1927  ///
1928  /// @param ioproxy
1929  /// Optional pointer to an IOProxy to use (not supported by all
1930  /// formats, see `supports("ioproxy")`). The caller retains
1931  /// ownership of the proxy.
1932  ///
1933  /// @returns
1934  /// A `unique_ptr` that will close and free the ImageOutput when
1935  /// it exits scope or is reset. The pointer will be empty if the
1936  /// required writer was not able to be created.
1937  static unique_ptr create (string_view filename,
1938  Filesystem::IOProxy* ioproxy = nullptr,
1939  string_view plugin_searchpath = "");
1940 
1941  /// Create an ImageOutput using a UTF-16 encoded wstring filename and
1942  /// plugin searchpath.
1943  static unique_ptr create (const std::wstring& filename,
1944  Filesystem::IOProxy* ioproxy = nullptr,
1945  const std::wstring& plugin_searchpath = {}) {
1946  return create(Strutil::utf16_to_utf8(filename), ioproxy,
1947  Strutil::utf16_to_utf8(plugin_searchpath));
1948  }
1949 
1950  // DEPRECATED(2.2)
1951  static unique_ptr create (const std::string &filename,
1952  const std::string &plugin_searchpath);
1953 
1954  /// @}
1955 
1956  // @deprecated
1957  static void destroy (ImageOutput *x);
1958 
1959 protected:
1960  ImageOutput ();
1961 public:
1962  virtual ~ImageOutput ();
1963 
1964  /// Return the name of the format implemented by this class.
1965  virtual const char *format_name (void) const = 0;
1966 
1967  // Override these functions in your derived output class
1968  // to inform the client which formats are supported
1969 
1970  /// @{
1971  /// @name Opening and closing files for output
1972 
1973  /// Given the name of a "feature", return whether this ImageOutput
1974  /// supports output of images with the given properties. Most queries
1975  /// will simply return 0 for "doesn't support" and 1 for "supports it,"
1976  /// but it is acceptable to have queries return other nonzero integers
1977  /// to indicate varying degrees of support or limits (but should be
1978  /// clearly documented as such).
1979  ///
1980  /// Feature names that ImageOutput implementations are expected to
1981  /// recognize include:
1982  ///
1983  /// - `"tiles"` :
1984  /// Is this format writer able to write tiled images?
1985  ///
1986  /// - `"rectangles"` :
1987  /// Does this writer accept arbitrary rectangular pixel regions
1988  /// (via `write_rectangle()`)? Returning 0 indicates that
1989  /// pixels must be transmitted via `write_scanline()` (if
1990  /// scanline-oriented) or `write_tile()` (if tile-oriented, and
1991  /// only if `supports("tiles")` returns true).
1992  ///
1993  /// - `"random_access"` :
1994  /// May tiles or scanlines be written in any order (0 indicates
1995  /// that they *must* be in successive order)?
1996  ///
1997  /// - `"multiimage"` :
1998  /// Does this format support multiple subimages within a file?
1999  ///
2000  /// - `"appendsubimage"` :
2001  /// Does this format support multiple subimages that can be
2002  /// successively appended at will via
2003  /// `open(name,spec,AppendSubimage)`? A value of 0 means that
2004  /// the format requires pre-declaring the number and
2005  /// specifications of the subimages when the file is first
2006  /// opened, with `open(name,subimages,specs)`.
2007  ///
2008  /// - `"mipmap"` :
2009  /// Does this format support multiple resolutions for an
2010  /// image/subimage?
2011  ///
2012  /// - `"volumes"` :
2013  /// Does this format support "3D" pixel arrays (a.k.a. volume
2014  /// images)?
2015  ///
2016  /// - `"alpha"` :
2017  /// Can this format support an alpha channel?
2018  ///
2019  /// - `"nchannels"` :
2020  /// Can this format support arbitrary number of channels (beyond RGBA)?
2021  ///
2022  /// - `"rewrite"` :
2023  /// May the same scanline or tile be sent more than once?
2024  /// Generally, this is true for plugins that implement
2025  /// interactive display, rather than a saved image file.
2026  ///
2027  /// - `"empty"` :
2028  /// Does this plugin support passing a NULL data pointer to the
2029  /// various `write` routines to indicate that the entire data
2030  /// block is composed of pixels with value zero? Plugins that
2031  /// support this achieve a speedup when passing blank scanlines
2032  /// or tiles (since no actual data needs to be transmitted or
2033  /// converted).
2034  ///
2035  /// - `"channelformats"` :
2036  /// Does this format writer support per-channel data formats,
2037  /// respecting the ImageSpec's `channelformats` field? If not,
2038  /// it only accepts a single data format for all channels and
2039  /// will ignore the `channelformats` field of the spec.
2040  ///
2041  /// - `"displaywindow"` :
2042  /// Does the format support display ("full") windows distinct
2043  /// from the pixel data window?
2044  ///
2045  /// - `"origin"` :
2046  /// Does the image format support specifying a pixel window
2047  /// origin (i.e., nonzero ImageSpec `x`, `y`, `z`)?
2048  ///
2049  /// - `"negativeorigin"` :
2050  /// Does the image format allow data and display window origins
2051  /// (i.e., ImageSpec `x`, `y`, `z`, `full_x`, `full_y`, `full_z`)
2052  /// to have negative values?
2053  ///
2054  /// - `"deepdata"` :
2055  /// Does the image format allow "deep" data consisting of
2056  /// multiple values per pixel (and potentially a differing number
2057  /// of values from pixel to pixel)?
2058  ///
2059  /// - `"arbitrary_metadata"` :
2060  /// Does the image file format allow metadata with arbitrary
2061  /// names (and either arbitrary, or a reasonable set of, data
2062  /// types)? (Versus the file format supporting only a fixed list
2063  /// of specific metadata names/values.)
2064  ///
2065  /// - `"exif"`
2066  /// Does the image file format support Exif camera data (either
2067  /// specifically, or via arbitrary named metadata)?
2068  ///
2069  /// - `"iptc"`
2070  /// Does the image file format support IPTC data (either
2071  /// specifically, or via arbitrary named metadata)?
2072  ///
2073  /// - `"ioproxy"`
2074  /// Does the image file format support writing to an `IOProxy`?
2075  ///
2076  /// - `"procedural"` :
2077  /// Is this a purely procedural output that doesn't write an
2078  /// actual file?
2079  ///
2080  /// - `"thumbnail"` :
2081  /// Does this format writer support adding a reduced resolution
2082  /// copy of the image via the `thumbnail()` method?
2083  ///
2084  /// - `"thumbnail_after_write"` :
2085  /// Does this format writer support calling `thumbnail()` after
2086  /// the scanlines or tiles have been specified? (Supporting
2087  /// `"thumbnail"` but not `"thumbnail_after_write"` means that any
2088  /// thumbnail must be supplied immediately after `open()`, prior
2089  /// to any of the `write_*()` calls.)
2090  ///
2091  /// - `"noimage"` :
2092  /// Does this format allow 0x0 sized images, i.e. an image file
2093  /// with metadata only and no pixels?
2094  ///
2095  /// This list of queries may be extended in future releases. Since this
2096  /// can be done simply by recognizing new query strings, and does not
2097  /// require any new API entry points, addition of support for new
2098  /// queries does not break ``link compatibility'' with
2099  /// previously-compiled plugins.
2100  virtual int supports (string_view feature OIIO_MAYBE_UNUSED) const {
2101  return false;
2102  }
2103 
2104  /// Modes passed to the `open()` call.
2105  enum OpenMode { Create, AppendSubimage, AppendMIPLevel };
2106 
2107  /// Open the file with given name, with resolution and other format
2108  /// data as given in newspec. It is legal to call open multiple times
2109  /// on the same file without a call to `close()`, if it supports
2110  /// multiimage and mode is AppendSubimage, or if it supports
2111  /// MIP-maps and mode is AppendMIPLevel -- this is interpreted as
2112  /// appending a subimage, or a MIP level to the current subimage,
2113  /// respectively.
2114  ///
2115  /// @param filename The name of the image file to open, UTF-8 encoded.
2116  /// @param newspec The ImageSpec describing the resolution, data
2117  /// types, etc.
2118  /// @param mode Specifies whether the purpose of the `open` is
2119  /// to create/truncate the file (default: `Create`),
2120  /// append another subimage (`AppendSubimage`), or
2121  /// append another MIP level (`AppendMIPLevel`).
2122  /// @returns `true` upon success, or `false` upon failure.
2123  virtual bool open (const std::string &filename, const ImageSpec &newspec,
2124  OpenMode mode=Create) = 0;
2125 
2126  /// Open an ImageOutput using a UTF-16 encoded wstring filename.
2127  bool open (const std::wstring &filename, const ImageSpec &newspec,
2128  OpenMode mode=Create) {
2129  return open(Strutil::utf16_to_utf8(filename), newspec, mode);
2130  }
2131 
2132  /// Open a multi-subimage file with given name and specifications for
2133  /// each of the subimages. Upon success, the first subimage will be
2134  /// open and ready for transmission of pixels. Subsequent subimages
2135  /// will be denoted with the usual call of
2136  /// `open(name,spec,AppendSubimage)` (and MIP levels by
2137  /// `open(name,spec,AppendMIPLevel)`).
2138  ///
2139  /// The purpose of this call is to accommodate format-writing
2140  /// libraries that must know the number and specifications of the
2141  /// subimages upon first opening the file; such formats can be
2142  /// detected by::
2143  /// supports("multiimage") && !supports("appendsubimage")
2144  /// The individual specs passed to the appending open() calls for
2145  /// subsequent subimages *must* match the ones originally passed.
2146  ///
2147  /// @param filename The name of the image file to open, UTF-8 encoded.
2148  /// @param subimages The number of subimages (and therefore the
2149  /// length of the `specs[]` array.
2150  /// @param specs[]
2151  /// Pointer to an array of `ImageSpec` objects
2152  /// describing each of the expected subimages.
2153  /// @returns `true` upon success, or `false` upon failure.
2154  virtual bool open (const std::string &filename,
2155  int subimages OIIO_MAYBE_UNUSED,
2156  const ImageSpec *specs) {
2157  // Default implementation: just a regular open, assume that
2158  // appending will work.
2159  return open (filename, specs[0]);
2160  }
2161 
2162  bool open (const std::wstring &filename, int subimages OIIO_MAYBE_UNUSED,
2163  const ImageSpec *specs) {
2164  // Default implementation: just a regular open, assume that
2165  // appending will work.
2166  return open (Strutil::utf16_to_utf8(filename), specs[0]);
2167  }
2168 
2169  /// Return a reference to the image format specification of the current
2170  /// subimage. Note that the contents of the spec are invalid before
2171  /// `open()` or after `close()`.
2172  const ImageSpec &spec (void) const { return m_spec; }
2173 
2174  /// Closes the currently open file associated with this ImageOutput and
2175  /// frees any memory or resources associated with it.
2176  virtual bool close () = 0;
2177  /// @}
2178 
2179  /// @{
2180  /// @name Writing pixels
2181  ///
2182  /// Common features of all the `write` methods:
2183  ///
2184  /// * The `format` parameter describes the data type of the `data[]`. The
2185  /// write methods automatically convert the data from the specified
2186  /// `format` to the actual output data type of the file (as was
2187  /// specified by the ImageSpec passed to `open()`). If `format` is
2188  /// `TypeUnknown`, then rather than converting from `format`, it will
2189  /// just copy pixels assumed to already be in the file's native data
2190  /// layout (including, possibly, per-channel data formats as specified
2191  /// by the ImageSpec's `channelformats` field).
2192  ///
2193  /// * The `stride` values describe the layout of the `data` buffer:
2194  /// `xstride` is the distance in bytes between successive pixels
2195  /// within each scanline. `ystride` is the distance in bytes between
2196  /// successive scanlines. For volumetric images `zstride` is the
2197  /// distance in bytes between successive "volumetric planes". Strides
2198  /// set to the special value `AutoStride` imply contiguous data, i.e.,
2199  ///
2200  /// xstride = format.size() * nchannels
2201  /// ystride = xstride * width
2202  /// zstride = ystride * height
2203  ///
2204  /// * Any *range* parameters (such as `ybegin` and `yend`) describe a
2205  /// "half open interval", meaning that `begin` is the first item and
2206  /// `end` is *one past the last item*. That means that the number of
2207  /// items is `end - begin`.
2208  ///
2209  /// * For ordinary 2D (non-volumetric) images, any `z` or `zbegin`
2210  /// coordinates should be 0 and any `zend` should be 1, indicating
2211  /// that only a single image "plane" exists.
2212  ///
2213  /// * Scanlines or tiles must be written in successive increasing
2214  /// coordinate order, unless the particular output file driver allows
2215  /// random access (indicated by `supports("random_access")`).
2216  ///
2217  /// * All write functions return `true` for success, `false` for failure
2218  /// (after which a call to `geterror()` may retrieve a specific error
2219  /// message).
2220  ///
2221 
2222  /// Write the full scanline that includes pixels (*,y,z). For 2D
2223  /// non-volume images, `z` should be 0. The `xstride` value gives the
2224  /// distance between successive pixels (in bytes). Strides set to
2225  /// `AutoStride` imply "contiguous" data.
2226  ///
2227  /// @param y/z The y & z coordinates of the scanline.
2228  /// @param format A TypeDesc describing the type of `data`.
2229  /// @param data Pointer to the pixel data.
2230  /// @param xstride The distance in bytes between successive
2231  /// pixels in `data` (or `AutoStride`).
2232  /// @returns `true` upon success, or `false` upon failure.
2233  virtual bool write_scanline (int y, int z, TypeDesc format,
2234  const void *data, stride_t xstride=AutoStride);
2235 
2236  /// Write multiple scanlines that include pixels (*,y,z) for all ybegin
2237  /// <= y < yend, from data. This is analogous to
2238  /// `write_scanline(y,z,format,data,xstride)` repeatedly for each of the
2239  /// scanlines in turn (the advantage, though, is that some image file
2240  /// types may be able to write multiple scanlines more efficiently or
2241  /// in parallel, than it could with one scanline at a time).
2242  ///
2243  /// @param ybegin/yend The y range of the scanlines being passed.
2244  /// @param z The z coordinate of the scanline.
2245  /// @param format A TypeDesc describing the type of `data`.
2246  /// @param data Pointer to the pixel data.
2247  /// @param xstride/ystride
2248  /// The distance in bytes between successive pixels
2249  /// and scanlines (or `AutoStride`).
2250  /// @returns `true` upon success, or `false` upon failure.
2251  virtual bool write_scanlines (int ybegin, int yend, int z,
2252  TypeDesc format, const void *data,
2253  stride_t xstride=AutoStride,
2254  stride_t ystride=AutoStride);
2255 
2256  /// Write the tile with (x,y,z) as the upper left corner. The three
2257  /// stride values give the distance (in bytes) between successive
2258  /// pixels, scanlines, and volumetric slices, respectively. Strides set
2259  /// to AutoStride imply 'contiguous' data in the shape of a full tile,
2260  /// i.e.,
2261  ///
2262  /// xstride = format.size() * spec.nchannels
2263  /// ystride = xstride * spec.tile_width
2264  /// zstride = ystride * spec.tile_height
2265  ///
2266  /// @param x/y/z The upper left coordinate of the tile being passed.
2267  /// @param format A TypeDesc describing the type of `data`.
2268  /// @param data Pointer to the pixel data.
2269  /// @param xstride/ystride/zstride
2270  /// The distance in bytes between successive pixels,
2271  /// scanlines, and image planes (or `AutoStride` to
2272  /// indicate a "contiguous" single tile).
2273  /// @returns `true` upon success, or `false` upon failure.
2274  ///
2275  /// @note This call will fail if the image is not tiled, or if (x,y,z)
2276  /// is not the upper left corner coordinates of a tile.
2277  virtual bool write_tile (int x, int y, int z, TypeDesc format,
2278  const void *data, stride_t xstride=AutoStride,
2279  stride_t ystride=AutoStride,
2280  stride_t zstride=AutoStride);
2281 
2282  /// Write the block of multiple tiles that include all pixels in
2283  ///
2284  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend)
2285  ///
2286  /// This is analogous to calling `write_tile(x,y,z,...)` for each tile
2287  /// in turn (but for some file formats, passing multiple tiles may allow
2288  /// it to write more efficiently or in parallel).
2289  ///
2290  /// The begin/end pairs must correctly delineate tile boundaries, with
2291  /// the exception that it may also be the end of the image data if the
2292  /// image resolution is not a whole multiple of the tile size. The
2293  /// stride values give the data spacing of adjacent pixels, scanlines,
2294  /// and volumetric slices (measured in bytes). Strides set to AutoStride
2295  /// imply contiguous data in the shape of the [begin,end) region, i.e.,
2296  ///
2297  /// xstride = format.size() * spec.nchannels
2298  /// ystride = xstride * (xend-xbegin)
2299  /// zstride = ystride * (yend-ybegin)
2300  ///
2301  /// @param xbegin/xend The x range of the pixels covered by the group
2302  /// of tiles passed.
2303  /// @param ybegin/yend The y range of the pixels covered by the tiles.
2304  /// @param zbegin/zend The z range of the pixels covered by the tiles
2305  /// (for a 2D image, zbegin=0 and zend=1).
2306  /// @param format A TypeDesc describing the type of `data`.
2307  /// @param data Pointer to the pixel data.
2308  /// @param xstride/ystride/zstride
2309  /// The distance in bytes between successive pixels,
2310  /// scanlines, and image planes (or `AutoStride`).
2311  /// @returns `true` upon success, or `false` upon failure.
2312  ///
2313  /// @note The call will fail if the image is not tiled, or if the pixel
2314  /// ranges do not fall along tile (or image) boundaries, or if it is not
2315  /// a valid tile range.
2316  virtual bool write_tiles (int xbegin, int xend, int ybegin, int yend,
2317  int zbegin, int zend, TypeDesc format,
2318  const void *data, stride_t xstride=AutoStride,
2319  stride_t ystride=AutoStride,
2320  stride_t zstride=AutoStride);
2321 
2322  /// Write a rectangle of pixels given by the range
2323  ///
2324  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend)
2325  ///
2326  /// The stride values give the data spacing of adjacent pixels,
2327  /// scanlines, and volumetric slices (measured in bytes). Strides set to
2328  /// AutoStride imply contiguous data in the shape of the [begin,end)
2329  /// region, i.e.,
2330  ///
2331  /// xstride = format.size() * spec.nchannels
2332  /// ystride = xstride * (xend-xbegin)
2333  /// zstride = ystride * (yend-ybegin)
2334  ///
2335  /// @param xbegin/xend The x range of the pixels being passed.
2336  /// @param ybegin/yend The y range of the pixels being passed.
2337  /// @param zbegin/zend The z range of the pixels being passed
2338  /// (for a 2D image, zbegin=0 and zend=1).
2339  /// @param format A TypeDesc describing the type of `data`.
2340  /// @param data Pointer to the pixel data.
2341  /// @param xstride/ystride/zstride
2342  /// The distance in bytes between successive pixels,
2343  /// scanlines, and image planes (or `AutoStride`).
2344  /// @returns `true` upon success, or `false` upon failure.
2345  ///
2346  /// @note The call will fail for a format plugin that does not return
2347  /// true for `supports("rectangles")`.
2348  virtual bool write_rectangle (int xbegin, int xend, int ybegin, int yend,
2349  int zbegin, int zend, TypeDesc format,
2350  const void *data, stride_t xstride=AutoStride,
2351  stride_t ystride=AutoStride,
2352  stride_t zstride=AutoStride);
2353 
2354  /// Write the entire image of `spec.width x spec.height x spec.depth`
2355  /// pixels, from a buffer with the given strides and in the desired
2356  /// format.
2357  ///
2358  /// Depending on the spec, this will write either all tiles or all
2359  /// scanlines. Assume that data points to a layout in row-major order.
2360  ///
2361  /// Because this may be an expensive operation, a progress callback
2362  /// may be passed. Periodically, it will be called as follows:
2363  ///
2364  /// progress_callback (progress_callback_data, float done);
2365  ///
2366  /// where `done` gives the portion of the image (between 0.0 and 1.0)
2367  /// that has been written thus far.
2368  ///
2369  /// @param format A TypeDesc describing the type of `data`.
2370  /// @param data Pointer to the pixel data.
2371  /// @param xstride/ystride/zstride
2372  /// The distance in bytes between successive pixels,
2373  /// scanlines, and image planes (or `AutoStride`).
2374  /// @param progress_callback/progress_callback_data
2375  /// Optional progress callback.
2376  /// @returns `true` upon success, or `false` upon failure.
2377  virtual bool write_image (TypeDesc format, const void *data,
2378  stride_t xstride=AutoStride,
2379  stride_t ystride=AutoStride,
2380  stride_t zstride=AutoStride,
2381  ProgressCallback progress_callback=nullptr,
2382  void *progress_callback_data=nullptr);
2383 
2384  /// Write deep scanlines containing pixels (*,y,z), for all y in the
2385  /// range [ybegin,yend), to a deep file. This will fail if it is not a
2386  /// deep file.
2387  ///
2388  /// @param ybegin/yend The y range of the scanlines being passed.
2389  /// @param z The z coordinate of the scanline.
2390  /// @param deepdata A `DeepData` object with the data for these
2391  /// scanlines.
2392  /// @returns `true` upon success, or `false` upon failure.
2393  virtual bool write_deep_scanlines (int ybegin, int yend, int z,
2394  const DeepData &deepdata);
2395 
2396  /// Write the block of deep tiles that include all pixels in
2397  /// the range
2398  ///
2399  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend)
2400  ///
2401  /// The begin/end pairs must correctly delineate tile boundaries, with
2402  /// the exception that it may also be the end of the image data if the
2403  /// image resolution is not a whole multiple of the tile size.
2404  ///
2405  /// @param xbegin/xend The x range of the pixels covered by the group
2406  /// of tiles passed.
2407  /// @param ybegin/yend The y range of the pixels covered by the tiles.
2408  /// @param zbegin/zend The z range of the pixels covered by the tiles
2409  /// (for a 2D image, zbegin=0 and zend=1).
2410  /// @param deepdata A `DeepData` object with the data for the tiles.
2411  /// @returns `true` upon success, or `false` upon failure.
2412  ///
2413  /// @note The call will fail if the image is not tiled, or if the pixel
2414  /// ranges do not fall along tile (or image) boundaries, or if it is not
2415  /// a valid tile range.
2416  virtual bool write_deep_tiles (int xbegin, int xend, int ybegin, int yend,
2417  int zbegin, int zend,
2418  const DeepData &deepdata);
2419 
2420  /// Write the entire deep image described by `deepdata`. Depending on
2421  /// the spec, this will write either all tiles or all scanlines.
2422  ///
2423  /// @param deepdata A `DeepData` object with the data for the image.
2424  /// @returns `true` upon success, or `false` upon failure.
2425  virtual bool write_deep_image (const DeepData &deepdata);
2426 
2427  /// Specify a reduced-resolution ("thumbnail") version of the image.
2428  /// Note that many image formats may require the thumbnail to be
2429  /// specified prior to writing the pixels.
2430  ///
2431  /// @param thumb
2432  /// A reference to an `ImageBuf` containing the thumbnail image.
2433  /// @returns
2434  /// `true` upon success, `false` if it was not possible to write
2435  /// the thumbnail, or if this file format (or writer) does not
2436  /// support thumbnails.
2437  ///
2438  /// @note This method was added to OpenImageIO 2.3.
2439  virtual bool set_thumbnail(const ImageBuf& thumb) { return false; }
2440 
2441  /// @}
2442 
2443  /// Read the pixels of the current subimage of `in`, and write it as the
2444  /// next subimage of `*this`, in a way that is efficient and does not
2445  /// alter pixel values, if at all possible. Both `in` and `this` must
2446  /// be a properly-opened `ImageInput` and `ImageOutput`, respectively,
2447  /// and their current images must match in size and number of channels.
2448  ///
2449  /// If a particular ImageOutput implementation does not supply a
2450  /// `copy_image` method, it will inherit the default implementation,
2451  /// which is to simply read scanlines or tiles from `in` and write them
2452  /// to `*this`. However, some file format implementations may have a
2453  /// special technique for directly copying raw pixel data from the input
2454  /// to the output, when both are the same file type and the same pixel
2455  /// data type. This can be more efficient than `in->read_image()`
2456  /// followed by `out->write_image()`, and avoids any unintended pixel
2457  /// alterations, especially for formats that use lossy compression.
2458  ///
2459  /// If the function fails and returns `false`, an error message can be
2460  /// retrieved from `this->geterror()`, even if the actual error was
2461  /// related to reading from `in` (i.e., reading errors are automatically
2462  /// transferrred to `*this`).
2463  ///
2464  /// Note: this method is NOT thread-safe (against other threads that may
2465  /// also be using `in`), since it depends on persistent state in the
2466  /// ImageInput.
2467  ///
2468  /// @param in A pointer to the open `ImageInput` to read from.
2469  /// @returns `true` upon success, or `false` upon failure.
2470  virtual bool copy_image (ImageInput *in);
2471 
2472  // General message passing between client and image output server. This
2473  // is currently undefined and is reserved for future use.
2474  virtual int send_to_output (const char *format, ...);
2475  int send_to_client (const char *format, ...);
2476 
2477  /// Set an IOProxy for this writer. This must be called prior to
2478  /// `open()`, and only for writers that support them
2479  /// (`supports("ioproxy")`). The caller retains ownership of the proxy.
2480  ///
2481  /// @returns `true` for success, `false` for failure.
2482  virtual bool set_ioproxy (Filesystem::IOProxy* ioproxy);
2483 
2484  /// Is there a pending error message waiting to be retrieved, that
2485  /// resulted from an ImageOutput API call made by the this thread?
2486  ///
2487  /// Note that any `error()` calls issued are thread-specific, and the
2488  /// `geterror()/has_error()` are expected to be called by the same
2489  /// thread that called whichever API function encountered an error.
2490  bool has_error() const;
2491 
2492  /// Return the text of all pending error messages issued against this
2493  /// ImageOutput by the calling thread, and clear the pending error
2494  /// message unless `clear` is false. If no error message is pending, it
2495  /// will return an empty string.
2496  ///
2497  /// Note that any `error()` calls issued are thread-specific, and the
2498  /// `geterror()/has_error()` are expected to be called by the same
2499  /// thread that called whichever API function encountered an error.
2500  std::string geterror(bool clear = true) const;
2501 
2502  /// Error reporting for the plugin implementation: call this with
2503  /// `Strutil::format`-like arguments. It is not necessary to have the
2504  /// error message contain a trailing newline.
2505  /// Use with caution! Some day this will change to be fmt-like rather
2506  /// than printf-like.
2507  template<typename... Args>
2509  void error(const char* fmt, const Args&... args) const {
2510  append_error(Strutil::format (fmt, args...));
2511  }
2512 
2513  /// Error reporting for the plugin implementation: call this with
2514  /// printf-like arguments. It is not necessary to have the error message
2515  /// contain a trailing newline.
2516  template<typename... Args>
2517  void errorf(const char* fmt, const Args&... args) const {
2518  append_error(Strutil::sprintf (fmt, args...));
2519  }
2520 
2521  /// Error reporting for the plugin implementation: call this with
2522  /// std::format-like arguments. It is not necessary to have the error
2523  /// message contain a trailing newline.
2524  template<typename... Args>
2525  void errorfmt(const char* fmt, const Args&... args) const {
2526  append_error(Strutil::fmt::format (fmt, args...));
2527  }
2528 
2529  // Error reporting for the plugin implementation: call this with
2530  // std::format-like arguments. It is not necessary to have the error
2531  // message contain a trailing newline.
2532  template<typename... Args>
2533  OIIO_DEPRECATED("use `errorfmt` instead")
2534  void fmterror(const char* fmt, const Args&... args) const {
2535  append_error(Strutil::fmt::format (fmt, args...));
2536  }
2537 
2538  /// Set the threading policy for this ImageOutput, controlling the
2539  /// maximum amount of parallelizing thread "fan-out" that might occur
2540  /// during large write operations. The default of 0 means that the
2541  /// global `attribute("threads")` value should be used (which itself
2542  /// defaults to using as many threads as cores; see Section
2543  /// `Global Attributes`_).
2544  ///
2545  /// The main reason to change this value is to set it to 1 to indicate
2546  /// that the calling thread should do all the work rather than spawning
2547  /// new threads. That is probably the desired behavior in situations
2548  /// where the calling application has already spawned multiple worker
2549  /// threads.
2550  void threads(int n);
2551 
2552  /// Retrieve the current thread-spawning policy.
2553  /// @see `threads(int)`
2554  int threads() const;
2555 
2556  // Custom new and delete to ensure that allocations & frees happen in
2557  // the OpenImageIO library, not in the app or plugins (because Windows).
2558  void* operator new (size_t size);
2559  void operator delete (void *ptr);
2560 
2561  /// Call signature of a function that creates and returns an
2562  /// `ImageOutput*`.
2563  typedef ImageOutput* (*Creator)();
2564 
2565 protected:
2566  /// @{
2567  /// @name Helper functions for ImageOutput implementations.
2568  ///
2569  /// This set of utility functions are not meant to be called by user code.
2570  /// They are protected methods of ImageOutput, and are used internally by
2571  /// the ImageOutput implementation to help it properly implement support
2572  /// of IOProxy.
2573  ///
2574 
2575  /// Helper: convenience boilerplate for several checks and operations that
2576  /// every implementation of ImageOutput::open() will need to do.
2577  ///
2578  /// 1. Check if the open `mode` is one allowed by `supports("multiimage")`
2579  /// and `supports("mipmap")`.
2580  /// 2. Copy the passed spec to the internal m_spec.
2581  /// 3. Do all possible validity checks based on `supports()` (for example,
2582  /// is the request to write volumetric data but the format writer
2583  /// doesn't support it).
2584  ///
2585  /// Returns true if ok, false if the open request can't be satisfied (and
2586  /// makes appropriate calls to this->errorfmt() to record the errors).
2587  ///
2588  /// Having a central helper method for this is beneficial:
2589  ///
2590  /// * Less repeated code in the many open() implementations, which also
2591  /// means less opportunity for bugs.
2592  /// * Ensures that all image writers perform the full set of possible
2593  /// validity checks.
2594  /// * Ensures that error messages are consistent across all writers and
2595  /// can be improved in a single location.
2596  /// * Better code coverage for testing, because the error handling that is
2597  /// done centrally means we don't need to separately test every possible
2598  /// error condition in every writer.
2599  ///
2600  /// @param mode
2601  /// The mode in which the file is to be opened (`Create`,
2602  /// `AppendSubimage`, or `AppendMIPLevel`).
2603  ///
2604  /// @param spec
2605  /// The ImageSpec that we are validating.
2606  ///
2607  /// @param range
2608  /// An ROI that describes the allowable pixel coordinates and channel
2609  /// indices as half-open intervals. For example, the default value
2610  /// `{0, 65535, 0, 65535, 0, 1, 0, 4}` means that pixel coordinates
2611  /// must be non-negative and the width and height be representable by
2612  /// a uint16 value, up to 4 channels are allowed, and volumes are not
2613  /// permitted (z coordinate may only be 0). File formats that can
2614  /// handle larger resolutions, or volumes, or >4 channels must
2615  /// override these limits!
2616  ///
2617  /// @param flags
2618  /// A bitfield flag (bits defined by `enum OpenChecks`) that can
2619  /// indicate additional checks to perform, or checks that should be
2620  /// skipped.
2621  ///
2622  /// @returns
2623  /// Return `true` if the spec is valid and passes all checks,
2624  /// otherwise return `false` and make appropriate calls to
2625  /// this->errorfmt() to record the errors.
2626  ///
2627  /// Checks performed include:
2628  ///
2629  /// * Whether the open `mode` is one allowed by `supports("multiimage")`
2630  /// and `supports("mipmap")`.
2631  /// * Whether the resolution and channel count is within the range
2632  /// implied by `range`. If `spec.depth < 1`, it will be set to 1.
2633  /// * Whether the request for volumes or deep images can be accommodated
2634  /// by the format (according to its `supports()` queries).
2635  /// * If per-channel data types are supplied (and not all the same), but
2636  /// but the file format does not not `supports("channelformats")`. If
2637  /// `spec.channelformats` is used but all formats are equal, then
2638  /// the `channelformats` vector will be cleared and only `spec.format`
2639  /// will be used.
2640  /// * If any of the "full" size fields are negative or zero, they will be
2641  /// set to the corresponding pixel data size fields.
2642  /// * Whether the pixel origin offset (`spec.x`, `spec.y`, `spec.z`) is
2643  /// allowed to be non-zero (according to `supports("origin")` or
2644  /// negative (`supports("negativeorigin")`) -- if it is not allowed,
2645  /// it is an error if flags includes `Strict`, otherwise it will simply
2646  /// be adjusted to 0.
2647  /// * Whether the `extra_attribs` contains a request to use an IOProxy,
2648  /// but the format writer does not report `supports("ioproxy")`.
2649  bool check_open(OpenMode mode, const ImageSpec &spec,
2650  ROI range = {0, 65535, 0, 65535, 0, 1, 0, 4},
2651  uint64_t flags = 0);
2652 
2653  /// Bit field definitions for the `flags` argument to `check_open()`.
2654  enum class OpenChecks : uint64_t {
2655  Defaults = 0,
2656  Disallow1Channel = 1,
2657  Disallow2Channel = 2,
2658  Disallow1or2Channel = Disallow1Channel | Disallow2Channel,
2659  Strict = (uint64_t(1) << 32)
2660  };
2661 
2662  /// Helper routines used by write_* implementations: convert data (in
2663  /// the given format and stride) to the "native" format of the file
2664  /// (described by the 'spec' member variable), in contiguous order. This
2665  /// requires a scratch space to be passed in so that there are no memory
2666  /// leaks. Returns a pointer to the native data, which may be the
2667  /// original data if it was already in native format and contiguous, or
2668  /// it may point to the scratch space if it needed to make a copy or do
2669  /// conversions. For float->uint8 conversions only, if dither is
2670  /// nonzero, random dither will be added to reduce quantization banding
2671  /// artifacts; in this case, the specific nonzero dither value is used
2672  /// as a seed for the hash function that produces the per-pixel dither
2673  /// amounts, and the optional [xyz]origin parameters help it to align
2674  /// the pixels to the right position in the dither pattern.
2675  const void *to_native_scanline (TypeDesc format,
2676  const void *data, stride_t xstride,
2677  std::vector<unsigned char> &scratch,
2678  unsigned int dither=0,
2679  int yorigin=0, int zorigin=0);
2680  const void *to_native_tile (TypeDesc format, const void *data,
2681  stride_t xstride, stride_t ystride,
2682  stride_t zstride,
2683  std::vector<unsigned char> &scratch,
2684  unsigned int dither=0,
2685  int xorigin=0, int yorigin=0, int zorigin=0);
2686  const void *to_native_rectangle (int xbegin, int xend, int ybegin, int yend,
2687  int zbegin, int zend,
2688  TypeDesc format, const void *data,
2689  stride_t xstride, stride_t ystride,
2690  stride_t zstride,
2691  std::vector<unsigned char> &scratch,
2692  unsigned int dither=0,
2693  int xorigin=0, int yorigin=0, int zorigin=0);
2694 
2695  /// Helper function to copy a rectangle of data into the right spot in
2696  /// an image-sized buffer. In addition to copying to the right place,
2697  /// this handles data format conversion and dither (if the spec's
2698  /// "oiio:dither" is nonzero, and if it's converting from a float-like
2699  /// type to UINT8). The buf_format describes the type of image_buffer,
2700  /// if it's TypeDesc::UNKNOWN it will be assumed to be spec.format.
2701  bool copy_to_image_buffer (int xbegin, int xend, int ybegin, int yend,
2702  int zbegin, int zend, TypeDesc format,
2703  const void *data, stride_t xstride,
2704  stride_t ystride, stride_t zstride,
2705  void *image_buffer,
2706  TypeDesc buf_format = TypeDesc::UNKNOWN);
2707  /// Helper function to copy a tile of data into the right spot in an
2708  /// image-sized buffer. This is really just a wrapper for
2709  /// copy_to_image_buffer, passing all the right parameters to copy
2710  /// exactly one tile.
2711  bool copy_tile_to_image_buffer (int x, int y, int z, TypeDesc format,
2712  const void *data, stride_t xstride,
2713  stride_t ystride, stride_t zstride,
2714  void *image_buffer,
2715  TypeDesc buf_format = TypeDesc::UNKNOWN);
2716 
2717  /// @}
2718 
2719  /// @{
2720  /// @name IOProxy aids for ImageOutput implementations.
2721  ///
2722  /// This set of utility functions are not meant to be called by user code.
2723  /// They are protected methods of ImageOutput, and are used internally by
2724  /// the ImageOutput implementation to help it properly implement support
2725  /// of IOProxy.
2726  ///
2727 
2728  /// Get the IOProxy being used underneath.
2729  Filesystem::IOProxy* ioproxy();
2730  const Filesystem::IOProxy* ioproxy() const;
2731 
2732  /// Is this file currently opened (active proxy)?
2733  bool ioproxy_opened() const;
2734 
2735  /// Clear the proxy ptr, and close/destroy any "local" proxy.
2736  void ioproxy_clear();
2737 
2738  /// Retrieve any ioproxy request from the configuration hint spec, and
2739  /// make `m_io` point to it. But if no IOProxy is found in the config,
2740  /// don't overwrite one we already have.
2741  void ioproxy_retrieve_from_config(const ImageSpec& config);
2742 
2743  /// Presuming that `ioproxy_retrieve_from_config` has already been called,
2744  /// if `m_io` is still not set (i.e., wasn't found in the config), open a
2745  /// IOFile local proxy with the given read/write `mode`. Return true if a
2746  /// proxy is set up. If it can't be done (i.e., no proxy passed, file
2747  /// couldn't be opened), issue an error and return false.
2748  bool ioproxy_use_or_open(string_view name);
2749 
2750  /// Helper: write to the proxy akin to fwrite(). Return true on success,
2751  /// false upon failure and issue a helpful error message. NOTE: this is
2752  /// not the same return value as std::fwrite, which returns the number of
2753  /// items written.
2754  bool iowrite(const void* buf, size_t itemsize, size_t nitems = 1);
2755 
2756  /// Helper: seek the proxy, akin to fseek. Return true on success, false
2757  /// upon failure and issue an error message. (NOTE: this isionot the same
2758  /// return value as std::fseek, which returns 0 on success.)
2759  bool ioseek(int64_t pos, int origin = SEEK_SET);
2760 
2761  /// Helper: retrieve the current position of the proxy, akin to ftell.
2762  int64_t iotell() const;
2763 
2764  /// Write a formatted string to the output proxy. Return true on success,
2765  /// false upon failure and issue an error message.
2766  template<typename Str, typename... Args>
2767  inline bool iowritefmt(const Str& fmt, Args&&... args)
2768  {
2769  std::string s = Strutil::fmt::format(fmt, args...);
2770  return iowrite(s.data(), s.size());
2771  }
2772 
2773  /// @}
2774 
2775 protected:
2776  ImageSpec m_spec; // format spec of the currently open image
2777 
2778 private:
2779  // PIMPL idiom -- this lets us hide details of the internals of the
2780  // ImageInput parent class so that changing them does not break the
2781  // ABI.
2782  class Impl;
2783  static void impl_deleter(Impl*);
2784  std::unique_ptr<Impl, decltype(&impl_deleter)> m_impl;
2785 
2786  void append_error(string_view message) const; // add to m_errmessage
2787 };
2788 
2789 
2790 
2791 // Utility functions
2792 
2793 /// `OIIO::shutdown` prepares OpenImageIO for shutdown. Before exiting an
2794 /// application that utilizes OpenImageIO the `OIIO::shutdown` function must be
2795 /// called, which will perform shutdown of any running thread-pools. Failing
2796 /// to call `OIIO::shutdown` could lead to a sporadic dead-lock during
2797 /// application shutdown on certain platforms such as Windows.
2798 OIIO_API void shutdown ();
2799 
2800 /// Returns a numeric value for the version of OpenImageIO, 10000 for each
2801 /// major version, 100 for each minor version, 1 for each patch. For
2802 /// example, OpenImageIO 1.2.3 would return a value of 10203. One example of
2803 /// how this is useful is for plugins to query the version to be sure they
2804 /// are linked against an adequate version of the library.
2806 
2807 /// Is there a pending global error message waiting to be retrieved?
2808 OIIO_API bool has_error();
2809 
2810 /// Returns any error string describing what went wrong if
2811 /// `ImageInput::create()` or `ImageOutput::create()` failed (since in such
2812 /// cases, the ImageInput or ImageOutput itself does not exist to have its
2813 /// own `geterror()` function called). This function returns the last error
2814 /// for this particular thread, and clear the pending error message unless
2815 /// `clear` is false; separate threads will not clobber each other's global
2816 /// error messages.
2817 OIIO_API std::string geterror(bool clear = true);
2818 
2819 /// `OIIO::attribute()` sets a global attribute (i.e., a property or
2820 /// option) of OpenImageIO. The `name` designates the name of the attribute,
2821 /// `type` describes the type of data, and `val` is a pointer to memory
2822 /// containing the new value for the attribute.
2823 ///
2824 /// If the name is known, valid attribute that matches the type specified,
2825 /// the attribute will be set to the new value and `attribute()` will return
2826 /// `true`. If `name` is not recognized, or if the types do not match
2827 /// (e.g., `type` is `TypeFloat` but the named attribute is a string), the
2828 /// attribute will not be modified, and `attribute()` will return `false`.
2829 ///
2830 /// The following are the recognized attributes:
2831 ///
2832 /// - `string options`
2833 ///
2834 /// This catch-all is simply a comma-separated list of `name=value`
2835 /// settings of named options, which will be parsed and individually set.
2836 /// For example,
2837 ///
2838 /// OIIO::attribute ("options", "threads=4,log_times=1");
2839 ///
2840 /// Note that if an option takes a string value that must itself contain
2841 /// a comma, it is permissible to enclose the value in either 'single'
2842 /// or "double" quotes.
2843 ///
2844 /// - `int threads`
2845 ///
2846 /// How many threads to use for operations that can be sped up by being
2847 /// multithreaded. (Examples: simultaneous format conversions of multiple
2848 /// scanlines read together, or many ImageBufAlgo operations.) The
2849 /// default is 0, meaning to use the full available hardware concurrency
2850 /// detected.
2851 ///
2852 /// Situations where the main application logic is essentially single
2853 /// threaded (i.e., one top-level call into OIIO at a time) should leave
2854 /// this at the default value, or some reasonable number of cores, thus
2855 /// allowing lots of threads to fill the cores when OIIO has big tasks to
2856 /// complete. But situations where you have many threads at the
2857 /// application level, each of which is expected to be making separate
2858 /// OIIO calls simultaneously, should set this to 1, thus having each
2859 /// calling thread do its own work inside of OIIO rather than spawning
2860 /// new threads with a high overall "fan out."
2861 ///
2862 /// - `int exr_threads`
2863 ///
2864 /// Sets the internal OpenEXR thread pool size. The default is to use as
2865 /// many threads as the amount of hardware concurrency detected. Note
2866 /// that this is separate from the OIIO `"threads"` attribute.
2867 ///
2868 /// - `string font_searchpath`
2869 ///
2870 /// Colon-separated (or semicolon-separated) list of directories to search
2871 /// if fonts are needed. (Such as for `ImageBufAlgo::render_text()`.)
2872 ///
2873 /// - `int use_tbb`
2874 ///
2875 /// If nonzero and TBB was found and support configured when OIIO was
2876 /// compiled, parallel processing within OIIO (including inside the
2877 /// parallel.h utilities) will try to use TBB by default where possible.
2878 /// If zero, they will try to use OIIO's native thread pool even if TBB
2879 /// is available.
2880 ///
2881 /// - `string plugin_searchpath`
2882 ///
2883 /// Colon-separated (or semicolon-separated) list of directories to search
2884 /// for dynamically-loaded format plugins.
2885 ///
2886 /// - `int try_all_readers`
2887 ///
2888 /// When nonzero (the default), a call to `ImageInput::create()` or
2889 /// `ImageInput::open()` that does not succeed in opening the file with the
2890 /// format reader implied by the file extension will try all available
2891 /// format readers to see if one of them can open the file. If this is
2892 /// zero, the only reader that will be tried is the one implied by the file
2893 /// extension.
2894 ///
2895 /// - `int read_chunk`
2896 ///
2897 /// When performing a `read_image()`, this is the number of scanlines it
2898 /// will attempt to read at a time (some formats are more efficient when
2899 /// reading and decoding multiple scanlines). The default is 256. The
2900 /// special value of 0 indicates that it should try to read the whole
2901 /// image if possible.
2902 ///
2903 /// - `float[] missingcolor`, `string missingcolor`
2904 ///
2905 /// This attribute may either be an array of float values, or a string
2906 /// containing a comma-separated list of the values. Setting this option
2907 /// globally is equivalent to always passing an `ImageInput`
2908 /// open-with-configuration hint `"oiio:missingcolor"` with the value.
2909 ///
2910 /// When set, it gives some `ImageInput` readers the option of ignoring
2911 /// any *missing* tiles or scanlines in the file, and instead of treating
2912 /// the read failure of an individual tile as a full error, will
2913 /// interpret is as an intentionally missing tile and proceed by simply
2914 /// filling in the missing pixels with the color specified. If the first
2915 /// element is negative, it will use the absolute value, but draw
2916 /// alternating diagonal stripes of the color. For example,
2917 ///
2918 /// float missing[4] = { -1.0, 0.0, 0.0, 0.0 }; // striped red
2919 /// OIIO::attribute ("missingcolor", TypeDesc("float[4]"), &missing);
2920 ///
2921 /// Note that only some file formats support files with missing tiles or
2922 /// scanlines, and this is only taken as a hint. Please see
2923 /// chap-bundledplugins_ for details on which formats accept a
2924 /// `"missingcolor"` configuration hint.
2925 ///
2926 /// - `int debug`
2927 ///
2928 /// When nonzero, various debug messages may be printed. The default is 0
2929 /// for release builds, 1 for DEBUG builds (values > 1 are for OIIO
2930 /// developers to print even more debugging information), This attribute
2931 /// but also may be overridden by the OPENIMAGEIO_DEBUG environment
2932 /// variable.
2933 ///
2934 /// - `int tiff:half`
2935 ///
2936 /// When nonzero, allows TIFF to write `half` pixel data. N.B. Most apps
2937 /// may not read these correctly, but OIIO will. That's why the default
2938 /// is not to support it.
2939 ///
2940 /// - `int dds:bc5normal`
2941 ///
2942 /// When nonzero, treats BC5/ATI2 format files as normal maps (loads as
2943 /// 3 channels, computes blue from red and green). Default is 0.
2944 ///
2945 /// - `int openexr:core`
2946 ///
2947 /// When nonzero, use the new "OpenEXR core C library" when available,
2948 /// for OpenEXR >= 3.1. This is experimental, and currently defaults to 0.
2949 ///
2950 /// - `int limits:channels` (1024)
2951 ///
2952 /// When nonzero, the maximum number of color channels in an image. Image
2953 /// files whose headers indicate they have more channels might be assumed
2954 /// to be corrupted or malicious files. In situations when more channels
2955 /// are expected to be encountered, the application should raise this
2956 /// limit. The default is 1024 channels.
2957 ///
2958 /// - `int limits:imagesize_MB` (32768)
2959 ///
2960 /// When nonzero, the maximum expected size in MB of the uncompressed pixel
2961 /// data of a single 2D image. Images whose headers indicate that they are
2962 /// larger than this might be assumed to be corrupted or malicious files.
2963 /// The default is 32768 (32 GB of uncompressed pixel data -- equivalent to
2964 /// 64k x 64k x 4 channel x half), or the total amount of total physical
2965 /// memory available to the running process, whichever is smaller. In
2966 /// situations when images larger than this are expected to be encountered,
2967 /// you should raise this limit. Setting the limit to 0 means having no
2968 /// limit.
2969 ///
2970 /// - `int log_times` (0)
2971 ///
2972 /// When the `"log_times"` attribute is nonzero, `ImageBufAlgo` functions
2973 /// are instrumented to record the number of times they were called and
2974 /// the total amount of time spent executing them. It can be overridden
2975 /// by environment variable `OPENIMAGEIO_LOG_TIMES`. The totals will be
2976 /// recorded and can be retrieved as a string by using
2977 /// `OIIO::getattribute("timing_report", ...)`. Additionally, if the
2978 /// value is 2 or more, the timing report will be printed to `stdout`
2979 /// upon application exit (not advised in contexts where it isn't ok to
2980 /// print to the terminal via stdout, such as GUI apps or libraries).
2981 ///
2982 /// When enabled, there is a slight runtime performance cost due to
2983 /// checking the time at the start and end of each of those function
2984 /// calls, and the locking and recording of the data structure that holds
2985 /// the log information. When the `log_times` attribute is disabled,
2986 /// there is no additional performance cost.
2987 ///
2988 /// - `oiio:print_uncaught_errors` (1)
2989 ///
2990 /// If nonzero, upon program exit, any error messages that would have been
2991 /// retrieved by a call to `OIIO::geterror()`, but never were, will be
2992 /// printed to stdout. While this may seem chaotic, we are presuming that
2993 /// any well-written library or application will proactively check error
2994 /// codes and retrieve errors, so this will never print anything upon exit.
2995 /// But for less sophisticated applications (or users), this is very useful
2996 /// for forcing display of error messages so that users can see relevant
2997 /// errors even if they never check them explicitly, thus self-diagnose
2998 /// their troubles before asking the project dev deam for help. Advanced
2999 /// users who for some reason desire to neither retrieve errors themselves
3000 /// nor have them printed in this manner can disable the behavior by setting
3001 /// this attribute to 0.
3002 ///
3003 /// - `imagebuf:print_uncaught_errors` (1)
3004 ///
3005 /// If nonzero, an `ImageBuf` upon destruction will print any error messages
3006 /// that were never retrieved by its `geterror()` method. While this may
3007 /// seem chaotic, we are presuming that any well-written library or
3008 /// application will proactively check error codes and retrieve errors, so
3009 /// will never print anything upon destruction. But for less sophisticated
3010 /// applications (or users), this is very useful for forcing display of
3011 /// error messages so that users can see relevant errors even if they never
3012 /// check them explicitly, thus self-diagnose their troubles before asking
3013 /// the project dev deam for help. Advanced users who for some reason desire
3014 /// to neither retrieve errors themselves nor have them printed in this
3015 /// manner can disable the behavior by setting this attribute to 0.
3016 ///
3017 /// - `imagebuf:use_imagecache` (0)
3018 ///
3019 /// If nonzero, an `ImageBuf` that references a file but is not given an
3020 /// ImageCache will read the image through the default ImageCache.
3021 ///
3022 OIIO_API bool attribute(string_view name, TypeDesc type, const void* val);
3023 
3024 /// Shortcut attribute() for setting a single integer.
3025 inline bool attribute (string_view name, int val) {
3026  return attribute (name, TypeInt, &val);
3027 }
3028 /// Shortcut attribute() for setting a single float.
3029 inline bool attribute (string_view name, float val) {
3030  return attribute (name, TypeFloat, &val);
3031 }
3032 /// Shortcut attribute() for setting a single string.
3034  std::string valstr = val;
3035  const char *s = valstr.c_str();
3036  return attribute (name, TypeString, &s);
3037 }
3038 
3039 /// Get the named global attribute of OpenImageIO, store it in `*val`.
3040 /// Return `true` if found and it was compatible with the type specified,
3041 /// otherwise return `false` and do not modify the contents of `*val`. It
3042 /// is up to the caller to ensure that `val` points to the right kind and
3043 /// size of storage for the given type.
3044 ///
3045 /// In addition to being able to retrieve all the attributes that are
3046 /// documented as settable by the `OIIO::attribute()` call, `getattribute()`
3047 /// can also retrieve the following read-only attributes:
3048 ///
3049 /// - `string version`
3050 ///
3051 /// The version designation of the OpenImageIO library, as a string.
3052 ///
3053 /// - `string format_list`
3054 /// - `string input_format_list`
3055 /// - `string output_format_list`
3056 ///
3057 /// A comma-separated list of all the names of, respectively, all
3058 /// supported image formats, all formats accepted as inputs, and all
3059 /// formats accepted as outputs.
3060 ///
3061 /// - `string extension_list`
3062 ///
3063 /// For each format, the format name, followed by a colon, followed by a
3064 /// comma-separated list of all extensions that are presumed to be used
3065 /// for that format. Semicolons separate the lists for formats. For
3066 /// example,
3067 ///
3068 /// "tiff:tif;jpeg:jpg,jpeg;openexr:exr"
3069 ///
3070 /// - `string library_list`
3071 ///
3072 /// For each format that uses a dependent library, the format name,
3073 /// followed by a colon, followed by the name and version of the
3074 /// dependency. Semicolons separate the lists for formats. For example,
3075 ///
3076 /// "tiff:LIBTIFF 4.0.4;gif:gif_lib 4.2.3;openexr:OpenEXR 2.2.0"
3077 ///
3078 /// - `string font_list`
3079 /// - `string font_file_list`
3080 /// - `string font_dir_list`
3081 ///
3082 /// A semicolon-separated list of, respectively, all the fonts that
3083 /// OpenImageIO can find, all the font files that OpenImageIO can find (with
3084 /// full paths), and all the directories that OpenImageIO will search for
3085 /// fonts. (Added in OpenImageIO 2.5)
3086 ///
3087 /// - `string filter_list`
3088 ///
3089 /// A semicolon-separated list of all built-in 2D filters. (Added in
3090 /// OpenImageIO 2.5.9)
3091 ///
3092 /// - int64_t IB_local_mem_current
3093 /// - int64_t IB_local_mem_peak
3094 ///
3095 /// Current and peak size (in bytes) of how much memory was consumed by
3096 /// ImageBufs that owned their own allcoated local pixel buffers. (Added in
3097 /// OpenImageIO 2.5.)
3098 ///
3099 /// - float IB_total_open_time
3100 /// - float IB_total_image_read_time
3101 ///
3102 /// Total amount of time (in seconds) that ImageBufs spent opening
3103 /// (including reading header information) and reading pixel data from files
3104 /// that they opened and read themselves (that is, excluding I/O from IBs
3105 /// that were backed by ImageCach. (Added in OpenImageIO 2.5.)
3106 ///
3107 /// - `string opencolorio_version`
3108 ///
3109 /// Returns the version (such as "2.2.0") of OpenColorIO that is used by
3110 /// OpenImageiO, or "0.0.0" if no OpenColorIO support has been enabled.
3111 /// (Added in OpenImageIO 2.4.6)
3112 ///
3113 /// - `int opencv_version`
3114 ///
3115 /// Returns the encoded version (such as 40701 for 4.7.1) of the OpenCV that
3116 /// is used by OpenImageIO, or 0 if no OpenCV support has been enabled.
3117 /// (Added in OpenImageIO 2.5.2)
3118 ///
3119 /// - `string hw:simd`
3120 /// - `string build:simd` (read-only)
3121 ///
3122 /// A comma-separated list of hardware CPU features for SIMD (and some
3123 /// other things). The `"build:simd"` attribute is similarly a list of
3124 /// which features this build of OIIO was compiled to support.
3125 ///
3126 /// These were added in OpenImageIO 1.8. The `"build:simd"` attribute was
3127 /// added added in OpenImageIO 2.5.8 as a preferred synonym for what
3128 /// previously was called `"oiio:simd"`, which is now deprecated.
3129 ///
3130 /// - `string build:platform` (read-only)
3131 ///
3132 /// THe name of the OS and CPU architecture that OpenImageIO was built
3133 /// for (e.g., `"Linux/x86_64"`). (Added in OpenImageIO 2.5.8.)
3134 ///
3135 /// - `string build:compiler` (read-only)
3136 ///
3137 /// THe name and version of the compiler used to build OIIO.
3138 /// (Added in OpenImageIO 2.5.8.)
3139 ///
3140 /// - `string build:dependencies` (read-only)
3141 ///
3142 /// List of library dependencieis (where known) and versions, separatd by
3143 /// semicolons. (Added in OpenImageIO 2.5.8.)
3144 ///
3145 /// - `float resident_memory_used_MB`
3146 ///
3147 /// This read-only attribute can be used for debugging purposes to report
3148 /// the approximate process memory used (resident) by the application, in
3149 /// MB.
3150 ///
3151 /// - `string timing_report`
3152 ///
3153 /// Retrieving this attribute returns the timing report generated by the
3154 /// `log_timing` attribute (if it was enabled). The report is sorted
3155 /// alphabetically and for each named instrumentation region, prints the
3156 /// number of times it executed, the total runtime, and the average per
3157 /// call, like this:
3158 ///
3159 /// IBA::computePixelStats 2 2.69ms (avg 1.34ms)
3160 /// IBA::make_texture 1 74.05ms (avg 74.05ms)
3161 /// IBA::mul 8 2.42ms (avg 0.30ms)
3162 /// IBA::over 10 23.82ms (avg 2.38ms)
3163 /// IBA::resize 20 0.24s (avg 12.18ms)
3164 /// IBA::zero 8 0.66ms (avg 0.08ms)
3165 ///
3167 
3168 /// Shortcut getattribute() for retrieving a single integer.
3169 /// The value is placed in `val`, and the function returns `true` if the
3170 /// attribute was found and was legally convertible to an int.
3171 inline bool getattribute (string_view name, int &val) {
3172  return getattribute (name, TypeInt, &val);
3173 }
3174 /// Shortcut getattribute() for retrieving a single float.
3175 /// The value is placed in `val`, and the function returns `true` if the
3176 /// attribute was found and was legally convertible to a float.
3177 inline bool getattribute (string_view name, float &val) {
3178  return getattribute (name, TypeFloat, &val);
3179 }
3180 /// Shortcut getattribute() for retrieving a single string as a
3181 /// `std::string`. The value is placed in `val`, and the function returns
3182 /// `true` if the attribute was found.
3183 inline bool getattribute (string_view name, std::string &val) {
3184  ustring s;
3185  bool ok = getattribute (name, TypeString, &s);
3186  if (ok)
3187  val = s.string();
3188  return ok;
3189 }
3190 /// Shortcut getattribute() for retrieving a single string as a `char*`.
3191 inline bool getattribute (string_view name, char **val) {
3192  return getattribute (name, TypeString, val);
3193 }
3194 /// Shortcut getattribute() for retrieving a single integer, with a supplied
3195 /// default value that will be returned if the attribute is not found or
3196 /// could not legally be converted to an int.
3197 inline int get_int_attribute (string_view name, int defaultval=0) {
3198  int val;
3199  return getattribute (name, TypeInt, &val) ? val : defaultval;
3200 }
3201 /// Shortcut getattribute() for retrieving a single float, with a supplied
3202 /// default value that will be returned if the attribute is not found or
3203 /// could not legally be converted to a float.
3204 inline float get_float_attribute (string_view name, float defaultval=0) {
3205  float val;
3206  return getattribute (name, TypeFloat, &val) ? val : defaultval;
3207 }
3208 /// Shortcut getattribute() for retrieving a single string, with a supplied
3209 /// default value that will be returned if the attribute is not found.
3211  string_view defaultval = string_view()) {
3212  ustring val;
3213  return getattribute (name, TypeString, &val) ? string_view(val) : defaultval;
3214 }
3215 
3216 
3217 /// Register the input and output 'create' routines and list of file
3218 /// extensions for a particular format.
3219 OIIO_API void declare_imageio_format (const std::string &format_name,
3220  ImageInput::Creator input_creator,
3221  const char **input_extensions,
3222  ImageOutput::Creator output_creator,
3223  const char **output_extensions,
3224  const char *lib_version);
3225 
3226 /// Is `name` one of the known format names?
3228 
3229 /// Utility: Parse the "extension_list" attribute into a std::map string
3230 /// keys are the names of all the file formats OIIO knows how to read, and
3231 /// whose values are vectors of strings of the file extensions associated
3232 /// with the file format. (Added in OIIO 2.2.13.)
3233 inline std::map<std::string, std::vector<std::string>>
3235 {
3236  std::map<std::string, std::vector<std::string>> map;
3237  auto all_extensions = OIIO::get_string_attribute("extension_list");
3238  for (auto oneformat : OIIO::Strutil::splitsv(all_extensions, ";")) {
3239  auto format_exts = OIIO::Strutil::splitsv(oneformat, ":", 2);
3240  if (format_exts.size() != 2)
3241  continue; // something went wrong
3242  map[format_exts[0]] = OIIO::Strutil::splits(format_exts[1], ",");
3243  }
3244  return map;
3245 }
3246 
3247 
3248 
3249 /// Helper function: convert contiguous data between two arbitrary pixel
3250 /// data types (specified by TypeDesc's). Return true if ok, false if it
3251 /// didn't know how to do the conversion. If dst_type is UNKNOWN, it will
3252 /// be assumed to be the same as src_type.
3253 ///
3254 /// The conversion is of normalized (pixel-like) values -- for example
3255 /// 'UINT8' 255 will convert to float 1.0 and vice versa, not float 255.0.
3256 /// If you want a straight C-like data cast conversion (e.g., uint8 255 ->
3257 /// float 255.0), then you should prefer the un-normalized convert_type()
3258 /// utility function found in typedesc.h.
3259 OIIO_API bool convert_pixel_values (TypeDesc src_type, const void *src,
3260  TypeDesc dst_type, void *dst, int n = 1);
3261 
3262 /// DEPRECATED(2.1): old name
3263 inline bool convert_types (TypeDesc src_type, const void *src,
3264  TypeDesc dst_type, void *dst, int n = 1) {
3265  return convert_pixel_values (src_type, src, dst_type, dst, n);
3266 }
3267 
3268 
3269 /// Helper routine for data conversion: Convert an image of nchannels x
3270 /// width x height x depth from src to dst. The src and dst may have
3271 /// different data formats and layouts. Clever use of this function can
3272 /// not only exchange data among different formats (e.g., half to 8-bit
3273 /// unsigned), but also can copy selective channels, copy subimages,
3274 /// etc. If you're lazy, it's ok to pass AutoStride for any of the
3275 /// stride values, and they will be auto-computed assuming contiguous
3276 /// data. Return true if ok, false if it didn't know how to do the
3277 /// conversion.
3278 OIIO_API bool convert_image (int nchannels, int width, int height, int depth,
3279  const void *src, TypeDesc src_type,
3280  stride_t src_xstride, stride_t src_ystride,
3281  stride_t src_zstride,
3282  void *dst, TypeDesc dst_type,
3283  stride_t dst_xstride, stride_t dst_ystride,
3284  stride_t dst_zstride);
3285 /// DEPRECATED(2.0) -- the alpha_channel, z_channel were never used
3286 inline bool convert_image(int nchannels, int width, int height, int depth,
3287  const void *src, TypeDesc src_type,
3288  stride_t src_xstride, stride_t src_ystride, stride_t src_zstride,
3289  void *dst, TypeDesc dst_type,
3290  stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride,
3291  int /*alpha_channel*/, int /*z_channel*/ = -1)
3292 {
3293  return convert_image(nchannels, width, height, depth, src, src_type,
3294  src_xstride, src_ystride, src_zstride, dst, dst_type,
3295  dst_xstride, dst_ystride, dst_zstride);
3296 }
3297 
3298 
3299 /// A version of convert_image that will break up big jobs into multiple
3300 /// threads.
3302  int nchannels, int width, int height, int depth,
3303  const void *src, TypeDesc src_type,
3304  stride_t src_xstride, stride_t src_ystride,
3305  stride_t src_zstride,
3306  void *dst, TypeDesc dst_type,
3307  stride_t dst_xstride, stride_t dst_ystride,
3308  stride_t dst_zstride, int nthreads=0);
3309 /// DEPRECATED(2.0) -- the alpha_channel, z_channel were never used
3311  int nchannels, int width, int height, int depth,
3312  const void *src, TypeDesc src_type,
3313  stride_t src_xstride, stride_t src_ystride, stride_t src_zstride,
3314  void *dst, TypeDesc dst_type,
3315  stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride,
3316  int /*alpha_channel*/, int /*z_channel*/, int nthreads=0)
3317 {
3318  return parallel_convert_image (nchannels, width, height, depth,
3319  src, src_type, src_xstride, src_ystride, src_zstride,
3320  dst, dst_type, dst_xstride, dst_ystride, dst_zstride, nthreads);
3321 }
3322 
3323 /// Add random [-ditheramplitude,ditheramplitude] dither to the color channels
3324 /// of the image. Dither will not be added to the alpha or z channel. The
3325 /// image origin and dither seed values allow a reproducible (or variable)
3326 /// dither pattern. If the strides are set to AutoStride, they will be
3327 /// assumed to be contiguous floats in data of the given dimensions.
3328 OIIO_API void add_dither (int nchannels, int width, int height, int depth,
3329  float *data,
3330  stride_t xstride, stride_t ystride, stride_t zstride,
3331  float ditheramplitude,
3332  int alpha_channel = -1, int z_channel = -1,
3333  unsigned int ditherseed = 1,
3334  int chorigin=0, int xorigin=0,
3335  int yorigin=0, int zorigin=0);
3336 
3337 /// Convert unassociated to associated alpha by premultiplying all color
3338 /// (non-alpha, non-z) channels by alpha. The nchannels, width, height, and
3339 /// depth parameters describe the "shape" of the image data (along with
3340 /// optional stride overrides). The chbegin/chend describe which range of
3341 /// channels to actually premultiply.
3342 OIIO_API void premult (int nchannels, int width, int height, int depth,
3343  int chbegin, int chend,
3344  TypeDesc datatype, void *data, stride_t xstride,
3345  stride_t ystride, stride_t zstride,
3346  int alpha_channel = -1, int z_channel = -1);
3347 
3348 /// Helper routine for data conversion: Copy an image of nchannels x
3349 /// width x height x depth from src to dst. The src and dst may have
3350 /// different data layouts, but must have the same data type. Clever
3351 /// use of this function can change layouts or strides, copy selective
3352 /// channels, copy subimages, etc. If you're lazy, it's ok to pass
3353 /// AutoStride for any of the stride values, and they will be
3354 /// auto-computed assuming contiguous data. Return true if ok, false if
3355 /// it didn't know how to do the conversion.
3356 OIIO_API bool copy_image (int nchannels, int width, int height, int depth,
3357  const void *src, stride_t pixelsize,
3358  stride_t src_xstride, stride_t src_ystride,
3359  stride_t src_zstride,
3360  void *dst, stride_t dst_xstride,
3361  stride_t dst_ystride, stride_t dst_zstride);
3362 
3363 
3364 // All the wrap_foo functions implement a wrap mode, wherein coord is
3365 // altered to be origin <= coord < origin+width. The return value
3366 // indicates if the resulting wrapped value is valid (example, for
3367 // wrap_black, values outside the region are invalid and do not modify
3368 // the coord parameter).
3369 OIIO_API bool wrap_black (int &coord, int origin, int width);
3370 OIIO_API bool wrap_clamp (int &coord, int origin, int width);
3371 OIIO_API bool wrap_periodic (int &coord, int origin, int width);
3372 OIIO_API bool wrap_periodic_pow2 (int &coord, int origin, int width);
3373 OIIO_API bool wrap_mirror (int &coord, int origin, int width);
3374 
3375 // Typedef for the function signature of a wrap implementation.
3376 typedef bool (*wrap_impl) (int &coord, int origin, int width);
3377 
3378 
3379 /// `debug(format, ...)` prints debugging message when attribute "debug" is
3380 /// nonzero, which it is by default for DEBUG compiles or when the
3381 /// environment variable OPENIMAGEIO_DEBUG is set. This is preferred to raw
3382 /// output to stderr for debugging statements.
3383 OIIO_API void debug (string_view str);
3384 
3385 /// debug output with `std::format` conventions.
3386 /// This is just a wrapped synonym for Strutil::debug().
3387 template<typename... Args>
3388 void debugfmt (const char* fmt, Args&&... args)
3389 {
3390  Strutil::debug(fmt, std::forward<Args>(args)...);
3391 }
3392 
3393 // (Unfortunate old synonym)
3394 template<typename... Args>
3395 OIIO_DEPRECATED("use `debugfmt` instead")
3396 void fmtdebug (const char* fmt, const Args&... args)
3397 {
3398  debug (Strutil::fmt::format(fmt, args...));
3399 }
3400 
3401 /// debug output with printf conventions.
3402 template<typename... Args>
3404 void debugf (const char* fmt, const Args&... args)
3405 {
3406  debug (Strutil::sprintf(fmt, args...));
3407 }
3408 
3409 /// debug output with the same conventions as Strutil::format. Beware, this
3410 /// will change one day!
3411 template<typename T1, typename... Args>
3413 void debug (const char* fmt, const T1& v1, const Args&... args)
3414 {
3415  debug (Strutil::format(fmt, v1, args...));
3416 }
3417 
3418 
3419 // to force correct linkage on some systems
3421 
3423 
3424 
3425 #if FMT_VERSION >= 100000
3427 template<> struct formatter<OIIO::ROI> : ostream_formatter {};
3429 #endif
int chend
Definition: imageio.h:100
int tile_width
tile width (0 for a non-tiled image)
Definition: imageio.h:267
int nchannels
number of image channels, e.g., 4 for RGBA
Definition: imageio.h:271
static void auto_stride(stride_t &xstride, TypeDesc format, int nchannels) noexcept
Definition: imageio.h:463
int alpha_channel
Definition: imageio.h:291
std::unique_ptr< ImageInput > unique_ptr
unique_ptr to an ImageInput
Definition: imageio.h:835
32-bit IEEE floating point values, (C/C++ float).
Definition: typedesc.h:82
std::unique_ptr< ImageOutput > unique_ptr
unique_ptr to an ImageOutput.
Definition: imageio.h:1907
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
OIIO_API bool wrap_periodic_pow2(int &coord, int origin, int width)
OIIO_API std::string geterror(bool clear=true)
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
int xend
Definition: imageio.h:97
OIIO_API bool has_error()
Is there a pending global error message waiting to be retrieved?
void set_roi(const ROI &r) noexcept
Definition: imageio.h:729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GLbitfield flags
Definition: glcorearb.h:1596
int tile_depth
Definition: imageio.h:269
string_view channel_name(int chan) const
Definition: imageio.h:696
int64_t stride_t
Definition: imageio.h:48
OpenChecks
Bit field definitions for the flags argument to check_open().
Definition: imageio.h:2654
GT_API const UT_StringHolder filename
bool convert_types(TypeDesc src_type, const void *src, TypeDesc dst_type, void *dst, int n=1)
DEPRECATED(2.1): old name.
Definition: imageio.h:3263
bool seek_subimage(int subimage, int miplevel, ImageSpec &newspec)
Definition: imageio.h:1195
GLenum GLint * range
Definition: glcorearb.h:1925
void errorfmt(const char *fmt, const Args &...args) const
Definition: imageio.h:1730
virtual bool open(const std::string &filename, int subimages OIIO_MAYBE_UNUSED, const ImageSpec *specs)
Definition: imageio.h:2154
OIIO_UTIL_API std::vector< string_view > splitsv(string_view str, string_view sep="", int maxsplit=-1)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:632
ImageOutput *(* Creator)()
Definition: imageio.h:2563
void
Definition: png.h:1083
const ImageSpec & spec(void) const
Definition: imageio.h:2172
bool valid_file(const std::wstring &filename) const
Check valid file using a UTF-16 encoded wstring filename.
Definition: imageio.h:1038
constexpr imagesize_t npixels() const noexcept
Total number of pixels in the region.
Definition: imageio.h:134
bool undefined() const noexcept
Definition: imageio.h:792
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression _ which means *the weaker expression when composing expressions together See with
GLsizei const GLfloat * value
Definition: glcorearb.h:824
bool read_tile(int x, int y, int z, float *data)
Simple read_tile reads into contiguous float pixels.
Definition: imageio.h:1371
constexpr bool contains(int x, int y, int z=0, int ch=0) const noexcept
Test if the coordinate is within the ROI.
Definition: imageio.h:163
friend constexpr bool operator==(const ROI &a, const ROI &b) noexcept
Test equality of two ROIs.
Definition: imageio.h:148
void get_channelformats(std::vector< TypeDesc > &formats) const
Definition: imageio.h:705
ROI roi_full() const noexcept
Return full/display window for this ImageSpec expressed as a ROI.
Definition: imageio.h:721
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
static unique_ptr open(const std::wstring &filename, const ImageSpec *config=nullptr, Filesystem::IOProxy *ioproxy=nullptr)
Create and open an ImageInput using a UTF-16 encoded wstring filename.
Definition: imageio.h:880
ImageSpec m_spec
Definition: imageio.h:1782
OIIO_NODISCARD std::string format(const Str &fmt, Args &&...args)
Definition: strutil.h:128
virtual int current_subimage(void) const
Definition: imageio.h:1167
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
unknown type
Definition: typedesc.h:57
GLdouble s
Definition: glad.h:3009
static unique_ptr create(const std::wstring &filename, Filesystem::IOProxy *ioproxy=nullptr, const std::wstring &plugin_searchpath={})
Definition: imageio.h:1943
constexpr ROI() noexcept
Definition: imageio.h:105
OIIO_API bool wrap_periodic(int &coord, int origin, int width)
bool open(const std::wstring &name, ImageSpec &newspec, const ImageSpec &config OIIO_MAYBE_UNUSED)
Open the ImageInput using a UTF-16 encoded wstring filename.
Definition: imageio.h:1104
TypeDesc channelformat(int chan) const
Definition: imageio.h:689
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int depth
depth of pixel data, >1 indicates a "volume"
Definition: imageio.h:260
int full_height
height of the full (display) window
Definition: imageio.h:265
std::vector< std::string > channelnames
Definition: imageio.h:288
OIIO_API void declare_imageio_format(const std::string &format_name, ImageInput::Creator input_creator, const char **input_extensions, ImageOutput::Creator output_creator, const char **output_extensions, const char *lib_version)
void copy_dimensions(const ImageSpec &other)
Definition: imageio.h:755
#define OIIO_DEPRECATED(msg)
Definition: platform.h:466
GLint y
Definition: glcorearb.h:103
void attribute(string_view name, int value)
Add an int attribute to extra_attribs.
Definition: imageio.h:479
std::lock_guard< const ImageInput & > lock_guard
Definition: imageio.h:1770
bool read_scanline(int y, int z, float *data)
Simple read_scanline reads into contiguous float pixels.
Definition: imageio.h:1276
int tile_height
tile height (0 for a non-tiled image)
Definition: imageio.h:268
virtual const ImageSpec & spec(void) const
Definition: imageio.h:1115
void close() override
static constexpr ROI All() noexcept
Definition: imageio.h:145
String-related utilities, all in namespace Strutil.
int zend
Definition: imageio.h:99
OIIO_FORMAT_DEPRECATED void error(const char *fmt, const Args &...args) const
Definition: imageio.h:2509
friend std::ostream & operator<<(std::ostream &out, const ROI &roi)
Stream output of the range.
Definition: imageio.h:177
ImageInput *(* Creator)()
Definition: imageio.h:1779
static unique_ptr create(const std::wstring &filename, bool do_open=false, const ImageSpec *config=nullptr, Filesystem::IOProxy *ioproxy=nullptr, string_view plugin_searchpath="")
Create an ImageInput using a UTF-16 encoded wstring filename.
Definition: imageio.h:947
OutGridT const XformOp bool bool
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
bool valid_tile_range(int xbegin, int xend, int ybegin, int yend, int zbegin, int zend) noexcept
Definition: imageio.h:676
std::map< std::string, std::vector< std::string > > get_extension_map()
Definition: imageio.h:3234
#define FMT_END_NAMESPACE
Definition: core.h:179
OIIO_API void premult(int nchannels, int width, int height, int depth, int chbegin, int chend, TypeDesc datatype, void *data, stride_t xstride, stride_t ystride, stride_t zstride, int alpha_channel=-1, int z_channel=-1)
OIIO_API void add_dither(int nchannels, int width, int height, int depth, float *data, stride_t xstride, stride_t ystride, stride_t zstride, float ditheramplitude, int alpha_channel=-1, int z_channel=-1, unsigned int ditherseed=1, int chorigin=0, int xorigin=0, int yorigin=0, int zorigin=0)
OIIO_INLINE_CONSTEXPR TypeDesc TypeInt(TypeDesc::INT)
basic_string_view< char > string_view
Definition: core.h:501
OIIO_INLINE_CONSTEXPR TypeDesc TypeUnknown(TypeDesc::UNKNOWN)
OIIO_API bool wrap_black(int &coord, int origin, int width)
static void auto_stride(stride_t &xstride, stride_t &ystride, stride_t &zstride, TypeDesc format, int nchannels, int width, int height) noexcept
Definition: imageio.h:454
void errorfmt(const char *fmt, const Args &...args) const
Definition: imageio.h:2525
virtual int current_miplevel(void) const
Definition: imageio.h:1172
OpenChecks
Bit field definitions for the flags argument to check_open().
Definition: imageio.h:1872
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
Wrappers and utilities for multithreading.
#define OIIO_MAYBE_UNUSED
Definition: platform.h:441
virtual bool seek_subimage(int subimage, int miplevel)
Definition: imageio.h:1187
GLdouble n
Definition: glcorearb.h:2008
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
constexpr int height() const noexcept
Width.
Definition: imageio.h:124
constexpr ROI roi_intersection(const ROI &A, const ROI &B) noexcept
Intersection of two regions.
Definition: imageio.h:198
bool(* ProgressCallback)(void *opaque_data, float portion_done)
Definition: imageio.h:65
void errorf(const char *fmt, const Args &...args) const
Definition: imageio.h:1722
ImageSpec m_spec
Definition: imageio.h:2776
int open(float queuesize) override
OIIO_INLINE_CONSTEXPR TypeDesc TypeFloat(TypeDesc::FLOAT)
constexpr bool defined() const noexcept
Is a region defined?
Definition: imageio.h:118
virtual int supports(string_view feature OIIO_MAYBE_UNUSED) const
Definition: imageio.h:1020
OIIO_API bool convert_image(int nchannels, int width, int height, int depth, const void *src, TypeDesc src_type, stride_t src_xstride, stride_t src_ystride, stride_t src_zstride, void *dst, TypeDesc dst_type, stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride)
constexpr int depth() const noexcept
Definition: imageio.h:125
void set_roi_full(const ROI &r) noexcept
Definition: imageio.h:741
std::string OIIO_UTIL_API replace(string_view str, string_view pattern, string_view replacement, bool global=false)
void fmtdebug(const char *fmt, const Args &...args)
Definition: imageio.h:3396
OIIO_API bool parallel_convert_image(int nchannels, int width, int height, int depth, const void *src, TypeDesc src_type, stride_t src_xstride, stride_t src_ystride, stride_t src_zstride, void *dst, TypeDesc dst_type, stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride, int nthreads=0)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
constexpr ROI roi_union(const ROI &A, const ROI &B) noexcept
Union of two regions, the smallest region containing both.
Definition: imageio.h:188
constexpr int nchannels() const noexcept
Definition: imageio.h:131
SerialFormat
Definition: imageio.h:646
friend constexpr bool operator!=(const ROI &a, const ROI &b) noexcept
Test inequality of two ROIs.
Definition: imageio.h:155
virtual bool get_thumbnail(ImageBuf &thumb, int subimage)
Definition: imageio.h:1151
void attribute(string_view name, unsigned int value)
Add an unsigned int attribute to extra_attribs.
Definition: imageio.h:474
int full_width
width of the full (display) window
Definition: imageio.h:264
OIIO_API void _ImageIO_force_link()
bool deep
Definition: imageio.h:300
OIIO_API bool wrap_mirror(int &coord, int origin, int width)
GLuint const GLchar * name
Definition: glcorearb.h:786
OIIO_HOSTDEVICE size_t size() const noexcept
Definition: typedesc.h:205
int full_y
origin of the full (display) window
Definition: imageio.h:262
OIIO_INLINE_CONSTEXPR TypeDesc TypeString(TypeDesc::STRING)
void set_format(string_view fmt) noexcept
Definition: imageio.h:356
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
float get_float_attribute(string_view name, float defaultval=0)
Definition: imageio.h:3204
Attempt to access an object that no longer exists in Houdini Invalid output Invalid type The attempted operation failed Node initialization script failed Failed to modify node or parameter because of a permission error Possible causes include locked takes
Definition: HOM_Errors.h:191
void debug(const char *fmt, Args &&...args)
Definition: strutil.h:293
GLenum mode
Definition: glcorearb.h:99
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
ROI roi() const noexcept
Return pixel data window for this ImageSpec expressed as a ROI.
Definition: imageio.h:716
OIIO_FORMAT_DEPRECATED void debugf(const char *fmt, const Args &...args)
debug output with printf conventions.
Definition: imageio.h:3404
virtual bool set_thumbnail(const ImageBuf &thumb)
Definition: imageio.h:2439
GT_API const UT_StringHolder version
ParamValue ImageIOParameter
Definition: imageio.h:70
int full_depth
depth of the full (display) window
Definition: imageio.h:266
OIIO_API bool wrap_clamp(int &coord, int origin, int width)
constexpr auto size() const noexcept-> size_t
Definition: core.h:443
std::vector< TypeDesc > channelformats
Definition: imageio.h:278
int x
origin (upper left corner) of pixel data
Definition: imageio.h:255
GLsizeiptr size
Definition: glcorearb.h:664
#define SEEK_SET
Definition: zconf.h:183
OIIO_API bool is_imageio_format_name(string_view name)
Is name one of the known format names?
GLenum GLenum dst
Definition: glcorearb.h:1793
OIIO_API int openimageio_version()
virtual bool open(const std::string &name, ImageSpec &newspec, const ImageSpec &config OIIO_MAYBE_UNUSED)
Definition: imageio.h:1099
Definition: imageio.h:85
OIIO_API bool getattribute(string_view name, TypeDesc type, void *val)
static void auto_stride(stride_t &xstride, stride_t &ystride, stride_t &zstride, stride_t channelsize, int nchannels, int width, int height) noexcept
Definition: imageio.h:440
constexpr int width() const noexcept
Height.
Definition: imageio.h:123
const stride_t AutoStride
Definition: imageio.h:56
bool seek_subimage(int subimage, ImageSpec &newspec)
Definition: imageio.h:1205
int z
origin (upper left corner) of pixel data
Definition: imageio.h:257
ParamValueList extra_attribs
Definition: imageio.h:305
int xbegin
Definition: imageio.h:97
int full_z
origin of the full (display) window
Definition: imageio.h:263
int width
width of the pixel data window
Definition: imageio.h:258
int chbegin
Definition: imageio.h:100
OIIO_INLINE_CONSTEXPR TypeDesc TypeUInt8(TypeDesc::UINT8)
OIIO_FORMAT_DEPRECATED void error(const char *fmt, const Args &...args) const
Definition: imageio.h:1714
bool(* wrap_impl)(int &coord, int origin, int width)
Definition: imageio.h:3376
OIIO_UTIL_API std::vector< std::string > splits(string_view str, string_view sep="", int maxsplit=-1)
GLfloat GLfloat v1
Definition: glcorearb.h:817
auto ptr(T p) -> const void *
Definition: format.h:4331
GLuint GLfloat * val
Definition: glcorearb.h:1608
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int z_channel
Definition: imageio.h:296
constexpr bool contains(const ROI &other) const noexcept
Test if another ROI is entirely within our ROI.
Definition: imageio.h:169
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
SerialVerbose
Definition: imageio.h:647
**If you just want to fire and args
Definition: thread.h:618
void debugfmt(const char *fmt, Args &&...args)
Definition: imageio.h:3388
GLint GLsizei width
Definition: glcorearb.h:103
AttrDelegate< ImageSpec > operator[](string_view name)
Definition: imageio.h:817
ParamValueList ImageIOParameterList
Definition: imageio.h:71
#define OIIO_FORMAT_DEPRECATED
Definition: strutil.h:50
constexpr ROI(int xbegin, int xend, int ybegin, int yend, int zbegin=0, int zend=1, int chbegin=0, int chend=10000) noexcept
Definition: imageio.h:111
int height
height of the pixel data window
Definition: imageio.h:259
GLboolean r
Definition: glcorearb.h:1222
#define FMT_BEGIN_NAMESPACE
Definition: core.h:176
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:127
auto sprintf(const S &fmt, const T &...args) -> std::basic_string< Char >
Definition: printf.h:617
int zbegin
Definition: imageio.h:99
int yend
Definition: imageio.h:98
AttrDelegate< const ImageSpec > operator[](string_view name) const
Definition: imageio.h:821
bool iowritefmt(const Str &fmt, Args &&...args)
Definition: imageio.h:2767
string_view get_string_attribute(string_view name, string_view defaultval=string_view())
Definition: imageio.h:3210
bool open(const std::wstring &filename, const ImageSpec &newspec, OpenMode mode=Create)
Open an ImageOutput using a UTF-16 encoded wstring filename.
Definition: imageio.h:2127
std::string OIIO_UTIL_API utf16_to_utf8(const std::wstring &utf16str) noexcept
OIIO_API bool copy_image(int nchannels, int width, int height, int depth, const void *src, stride_t pixelsize, stride_t src_xstride, stride_t src_ystride, stride_t src_zstride, void *dst, stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride)
int get_int_attribute(string_view name, int defaultval=0)
Definition: imageio.h:3197
uint64_t imagesize_t
Definition: imageio.h:52
const std::string & string() const noexcept
Return a C++ std::string representation of a ustring.
Definition: ustring.h:296
OIIO_API bool convert_pixel_values(TypeDesc src_type, const void *src, TypeDesc dst_type, void *dst, int n=1)
virtual int supports(string_view feature OIIO_MAYBE_UNUSED) const
Definition: imageio.h:2100
TypeDesc format
Definition: imageio.h:273
void attribute(string_view name, float value)
Add a float attribute to extra_attribs.
Definition: imageio.h:484
void errorf(const char *fmt, const Args &...args) const
Definition: imageio.h:2517
Definition: format.h:1821
OpenMode
Modes passed to the open() call.
Definition: imageio.h:2105
bool open(const std::wstring &filename, int subimages OIIO_MAYBE_UNUSED, const ImageSpec *specs)
Modes passed to the open() call.
Definition: imageio.h:2162
int full_x
origin of the full (display) window
Definition: imageio.h:261
bool open(const std::wstring &name, ImageSpec &newspec)
Open the ImageInput using a UTF-16 encoded wstring filename.
Definition: imageio.h:1075
int ybegin
Definition: imageio.h:98
OIIO_API void shutdown()
int y
origin (upper left corner) of pixel data
Definition: imageio.h:256
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:126
#define OIIO_API
Definition: export.h:65
GLenum src
Definition: glcorearb.h:1793