HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imageio.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
3  All Rights Reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
32 /////////////////////////////////////////////////////////////////////////////
33 /// \file
34 ///
35 /// Provides a simple API that abstracts the reading and writing of
36 /// images. Subclasses, which may be found in DSO/DLL's, implement
37 /// particular formats.
38 ///
39 /////////////////////////////////////////////////////////////////////////////
40 
41 // clang-format off
42 
43 #pragma once
44 #define OPENIMAGEIO_IMAGEIO_H
45 
46 #if defined(_MSC_VER)
47 // Ignore warnings about DLL exported classes with member variables that are template classes.
48 // This happens with the std::vector<T> and std::string members of the classes below.
49 # pragma warning(disable : 4251)
50 #endif
51 
52 #include <cmath>
53 #include <limits>
54 #include <string>
55 #include <vector>
56 
57 #include <OpenImageIO/span.h>
58 #include <OpenImageIO/export.h>
60 #include <OpenImageIO/paramlist.h>
61 #include <OpenImageIO/platform.h>
62 #include <OpenImageIO/strutil.h>
63 #include <OpenImageIO/thread.h>
64 #include <OpenImageIO/typedesc.h>
65 
67 
68 class DeepData;
69 struct ROI;
70 
71 
72 /// Type we use for stride lengths. This is only used to designate
73 /// pixel, scanline, tile, or image plane sizes in user-allocated memory,
74 /// so it doesn't need to represent sizes larger than can be malloced,
75 /// therefore ptrdiff_t seemed right.
76 typedef ptrdiff_t stride_t;
77 
78 
79 /// Type we use to express how many pixels (or bytes) constitute an image,
80 /// tile, or scanline. Needs to be large enough to handle very big images
81 /// (which we presume could be > 4GB).
82 #if defined(LINUX64) || defined(_WIN64) || defined(__x86_64__) /* add others if we know for sure size_t is ok */
83 typedef size_t imagesize_t;
84 #else
85 typedef unsigned long long imagesize_t;
86 #endif
87 
88 
89 
90 /// Special value to indicate a stride length that should be
91 /// auto-computed.
93 
94 
95 
96 /// Pointer to a function called periodically by read_image and
97 /// write_image. This can be used to implement progress feedback, etc.
98 /// It takes an opaque data pointer (passed to read_image/write_image)
99 /// and a float giving the portion of work done so far. It returns a
100 /// bool, which if 'true' will STOP the read or write.
101 typedef bool (*ProgressCallback)(void *opaque_data, float portion_done);
102 
103 
104 
105 // Deprecated typedefs. Just use ParamValue and ParamValueList directly.
108 
109 
110 
111 /// Helper struct describing a region of interest in an image.
112 /// The region is [xbegin,xend) x [begin,yend) x [zbegin,zend),
113 /// with the "end" designators signifying one past the last pixel,
114 /// a la STL style.
115 struct ROI {
118 
119  /// Default constructor is an undefined region. Note that this is also
120  /// interpreted as All().
121  constexpr ROI () : xbegin(std::numeric_limits<int>::min()), xend(0),
122  ybegin(0), yend(0), zbegin(0), zend(0), chbegin(0), chend(0)
123  { }
124 
125  /// Constructor with an explicitly defined region.
126  ///
127  constexpr ROI (int xbegin, int xend, int ybegin, int yend,
128  int zbegin=0, int zend=1, int chbegin=0, int chend=10000)
129  : xbegin(xbegin), xend(xend), ybegin(ybegin), yend(yend),
131  { }
132 
133  /// Is a region defined?
134  constexpr bool defined () const { return (xbegin != std::numeric_limits<int>::min()); }
135 
136  // Region dimensions.
137  constexpr int width () const { return xend - xbegin; }
138  constexpr int height () const { return yend - ybegin; }
139  constexpr int depth () const { return zend - zbegin; }
140 
141  /// Number of channels in the region. Beware -- this defaults to a
142  /// huge number, and to be meaningful you must consider
143  /// std::min (imagebuf.nchannels(), roi.nchannels()).
144  constexpr int nchannels () const { return chend - chbegin; }
145 
146  /// Total number of pixels in the region.
147  constexpr imagesize_t npixels () const {
148  return defined()
150  : 0;
151  }
152 
153  /// All() is an alias for the default constructor, which indicates that
154  /// it means "all" of the image, or no region restruction. For example,
155  /// float myfunc (ImageBuf &buf, ROI roi = ROI::All());
156  /// Note that this is equivalent to:
157  /// float myfunc (ImageBuf &buf, ROI roi = {});
158  static constexpr ROI All () { return ROI(); }
159 
160  /// Test equality of two ROIs
161  friend constexpr bool operator== (const ROI &a, const ROI &b) {
162  return (a.xbegin == b.xbegin && a.xend == b.xend &&
163  a.ybegin == b.ybegin && a.yend == b.yend &&
164  a.zbegin == b.zbegin && a.zend == b.zend &&
165  a.chbegin == b.chbegin && a.chend == b.chend);
166  }
167  /// Test inequality of two ROIs
168  friend constexpr bool operator!= (const ROI &a, const ROI &b) {
169  return (a.xbegin != b.xbegin || a.xend != b.xend ||
170  a.ybegin != b.ybegin || a.yend != b.yend ||
171  a.zbegin != b.zbegin || a.zend != b.zend ||
172  a.chbegin != b.chbegin || a.chend != b.chend);
173  }
174 
175  /// Test if the coordinate is within the ROI.
176  constexpr bool contains (int x, int y, int z=0, int ch=0) const {
177  return x >= xbegin && x < xend && y >= ybegin && y < yend
178  && z >= zbegin && z < zend && ch >= chbegin && ch < chend;
179  }
180 
181  /// Test if another ROI is entirely within our ROI.
182  constexpr bool contains (const ROI& other) const {
183  return (other.xbegin >= xbegin && other.xend <= xend &&
184  other.ybegin >= ybegin && other.yend <= yend &&
185  other.zbegin >= zbegin && other.zend <= zend &&
186  other.chbegin >= chbegin && other.chend <= chend);
187  }
188 
189  /// Stream output of the range
190  friend std::ostream & operator<< (std::ostream &out, const ROI &roi) {
191  out << roi.xbegin << ' ' << roi.xend << ' ' << roi.ybegin << ' '
192  << roi.yend << ' ' << roi.zbegin << ' ' << roi.zend << ' '
193  << roi.chbegin << ' ' << roi.chend;
194  return out;
195  }
196 };
197 
198 
199 
200 /// Union of two regions, the smallest region containing both.
201 inline constexpr ROI roi_union (const ROI &A, const ROI &B) {
202  return (A.defined() && B.defined())
203  ? ROI (std::min (A.xbegin, B.xbegin), std::max (A.xend, B.xend),
204  std::min (A.ybegin, B.ybegin), std::max (A.yend, B.yend),
205  std::min (A.zbegin, B.zbegin), std::max (A.zend, B.zend),
206  std::min (A.chbegin, B.chbegin), std::max (A.chend, B.chend))
207  : (A.defined() ? A : B);
208 }
209 
210 /// Intersection of two regions.
211 inline constexpr ROI roi_intersection (const ROI &A, const ROI &B) {
212  return (A.defined() && B.defined())
213  ? ROI (std::max (A.xbegin, B.xbegin), std::min (A.xend, B.xend),
214  std::max (A.ybegin, B.ybegin), std::min (A.yend, B.yend),
215  std::max (A.zbegin, B.zbegin), std::min (A.zend, B.zend),
216  std::max (A.chbegin, B.chbegin), std::min (A.chend, B.chend))
217  : (A.defined() ? A : B);
218 }
219 
220 
221 
222 
223 /// ImageSpec describes the data format of an image --
224 /// dimensions, layout, number and meanings of image channels.
226 public:
227  int x, y, z; ///< origin (upper left corner) of pixel data
228  int width; ///< width of the pixel data window
229  int height; ///< height of the pixel data window
230  int depth; ///< depth of pixel data, >1 indicates a "volume"
231  int full_x; ///< origin of the full (display) window
232  int full_y; ///< origin of the full (display) window
233  int full_z; ///< origin of the full (display) window
234  int full_width; ///< width of the full (display) window
235  int full_height; ///< height of the full (display) window
236  int full_depth; ///< depth of the full (display) window
237  int tile_width; ///< tile width (0 for a non-tiled image)
238  int tile_height; ///< tile height (0 for a non-tiled image)
239  int tile_depth; ///< tile depth (0 for a non-tiled image,
240  ///< 1 for a non-volume image)
241  int nchannels; ///< number of image channels, e.g., 4 for RGBA
242  TypeDesc format; ///< data format of the channels
243  std::vector<TypeDesc> channelformats; ///< Optional per-channel formats
244  std::vector<std::string> channelnames; ///< Names for each channel,
245  ///< e.g., {"R","G","B","A"}
246  int alpha_channel; ///< Index of alpha channel, or -1 if not known
247  int z_channel; ///< Index of depth channel, or -1 if not known
248  bool deep; ///< Contains deep data
249 
250  /// The above contains all the information that is likely needed for
251  /// every image file, and common to all formats. Rather than bloat
252  /// this structure, customize it for new formats, or break back
253  /// compatibility as we think of new things, we provide extra_attribs
254  /// as a holder for any other properties of the image. The public
255  /// functions attribute and find_attribute may be used to access
256  /// these data. Note, however, that the names and semantics of such
257  /// extra attributes are plugin-dependent and are not enforced by
258  /// the imageio library itself.
259  ParamValueList extra_attribs; ///< Additional attributes
260 
261  /// Constructor: given just the data format, set all other fields to
262  /// something reasonable.
264 
265  /// Constructor for simple 2D scanline image with nothing special.
266  /// If fmt is not supplied, default to unsigned 8-bit data.
267  ImageSpec (int xres, int yres, int nchans, TypeDesc fmt = TypeDesc::UINT8);
268 
269  /// Constructor from an ROI that gives x, y, z, and channel range, and
270  /// a data format.
271  explicit ImageSpec (const ROI &roi, TypeDesc fmt = TypeDesc::UINT8);
272 
273  /// Set the data format.
274  void set_format (TypeDesc fmt);
275 
276  /// Set the channelnames to reasonable defaults ("R", "G", "B", "A"),
277  /// and alpha_channel, based on the number of channels.
278  void default_channel_names ();
279 
280  /// Return the number of bytes for each channel datum, assuming they
281  /// are all stored using the data format given by this->format.
282  size_t channel_bytes() const { return format.size(); }
283 
284  /// Return the number of bytes needed for the single specified
285  /// channel. If native is false (default), compute the size of one
286  /// channel of this->format, but if native is true, compute the size
287  /// of the channel in terms of the "native" data format of that
288  /// channel as stored in the file.
289  size_t channel_bytes (int chan, bool native=false) const;
290 
291  /// Return the number of bytes for each pixel (counting all channels).
292  /// If native is false (default), assume all channels are in
293  /// this->format, but if native is true, compute the size of a pixel
294  /// in the "native" data format of the file (these may differ in
295  /// the case of per-channel formats).
296  /// This will return std::numeric_limits<size_t>::max() in the
297  /// event of an overflow where it's not representable in a size_t.
298  size_t pixel_bytes (bool native=false) const;
299 
300  /// Return the number of bytes for just the subset of channels in
301  /// each pixel described by [chbegin,chend).
302  /// If native is false (default), assume all channels are in
303  /// this->format, but if native is true, compute the size of a pixel
304  /// in the "native" data format of the file (these may differ in
305  /// the case of per-channel formats).
306  /// This will return std::numeric_limits<size_t>::max() in the
307  /// event of an overflow where it's not representable in a size_t.
308  size_t pixel_bytes (int chbegin, int chend, bool native=false) const;
309 
310  /// Return the number of bytes for each scanline. This will return
311  /// std::numeric_limits<imagesize_t>::max() in the event of an
312  /// overflow where it's not representable in an imagesize_t.
313  /// If native is false (default), assume all channels are in
314  /// this->format, but if native is true, compute the size of a pixel
315  /// in the "native" data format of the file (these may differ in
316  /// the case of per-channel formats).
317  imagesize_t scanline_bytes (bool native=false) const;
318 
319  /// Return the number of pixels for a tile. This will return
320  /// std::numeric_limits<imagesize_t>::max() in the event of an
321  /// overflow where it's not representable in an imagesize_t.
322  imagesize_t tile_pixels () const;
323 
324  /// Return the number of bytes for each a tile of the image. This
325  /// will return std::numeric_limits<imagesize_t>::max() in the event
326  /// of an overflow where it's not representable in an imagesize_t.
327  /// If native is false (default), assume all channels are in
328  /// this->format, but if native is true, compute the size of a pixel
329  /// in the "native" data format of the file (these may differ in
330  /// the case of per-channel formats).
331  imagesize_t tile_bytes (bool native=false) const;
332 
333  /// Return the number of pixels for an entire image. This will
334  /// return std::numeric_limits<imagesize_t>::max() in the event of
335  /// an overflow where it's not representable in an imagesize_t.
336  imagesize_t image_pixels () const;
337 
338  /// Return the number of bytes for an entire image. This will
339  /// return std::numeric_limits<image size_t>::max() in the event of
340  /// an overflow where it's not representable in an imagesize_t.
341  /// If native is false (default), assume all channels are in
342  /// this->format, but if native is true, compute the size of a pixel
343  /// in the "native" data format of the file (these may differ in
344  /// the case of per-channel formats).
345  imagesize_t image_bytes (bool native=false) const;
346 
347  /// Verify that on this platform, a size_t is big enough to hold the
348  /// number of bytes (and pixels) in a scanline, a tile, and the
349  /// whole image. If this returns false, the image is much too big
350  /// to allocate and read all at once, so client apps beware and check
351  /// these routines for overflows!
352  bool size_t_safe() const {
354  return image_bytes() < big && scanline_bytes() < big &&
355  tile_bytes() < big;
356  }
357 
358  /// Adjust the stride values, if set to AutoStride, to be the right
359  /// sizes for contiguous data with the given format, channels,
360  /// width, height.
361  static void auto_stride (stride_t &xstride, stride_t &ystride,
362  stride_t &zstride, stride_t channelsize,
363  int nchannels, int width, int height) {
364  if (xstride == AutoStride)
365  xstride = nchannels * channelsize;
366  if (ystride == AutoStride)
367  ystride = xstride * width;
368  if (zstride == AutoStride)
369  zstride = ystride * height;
370  }
371 
372  /// Adjust the stride values, if set to AutoStride, to be the right
373  /// sizes for contiguous data with the given format, channels,
374  /// width, height.
375  static void auto_stride (stride_t &xstride, stride_t &ystride,
376  stride_t &zstride, TypeDesc format,
377  int nchannels, int width, int height) {
378  auto_stride (xstride, ystride, zstride, format.size(),
379  nchannels, width, height);
380  }
381 
382  /// Adjust xstride, if set to AutoStride, to be the right size for
383  /// contiguous data with the given format and channels.
384  static void auto_stride (stride_t &xstride, TypeDesc format, int nchannels) {
385  if (xstride == AutoStride)
386  xstride = nchannels * format.size();
387  }
388 
389  /// Add an optional attribute to the extra attribute list
390  ///
391  void attribute (string_view name, TypeDesc type, const void *value);
392 
393  /// Add an optional attribute to the extra attribute list.
394  ///
396 
397  /// Add an unsigned int attribute
398  ///
399  void attribute (string_view name, unsigned int value) {
400  attribute (name, TypeDesc::UINT, &value);
401  }
402 
403  /// Add an int attribute
404  ///
406  attribute (name, TypeDesc::INT, &value);
407  }
408 
409  /// Add a float attribute
410  ///
411  void attribute (string_view name, float value) {
412  attribute (name, TypeDesc::FLOAT, &value);
413  }
414 
415  /// Add a string attribute
416  ///
418  const char *s = value.c_str();
419  attribute (name, TypeDesc::STRING, &s);
420  }
421 
422  /// Remove the specified attribute from the list of extra_attribs. If
423  /// not found, do nothing. If searchtype is anything but UNKNOWN,
424  /// restrict matches to only those of the given type. If casesensitive
425  /// is true, the name search will be case-sensitive, otherwise the name
426  /// search will be performed without regard to case (this is the
427  /// default).
428  void erase_attribute (string_view name,
429  TypeDesc searchtype=TypeDesc::UNKNOWN,
430  bool casesensitive=false);
431 
432  /// Search for an attribute of the given name in the list of
433  /// extra_attribs. If searchtype is anything but UNKNOWN, restrict
434  /// matches to only those of the given type. If casesensitive is true,
435  /// the name search will be case-sensitive, otherwise the name search
436  /// will be performed without regard to case (this is the default).
437  ParamValue * find_attribute (string_view name,
438  TypeDesc searchtype=TypeDesc::UNKNOWN,
439  bool casesensitive=false);
440  const ParamValue *find_attribute (string_view name,
441  TypeDesc searchtype=TypeDesc::UNKNOWN,
442  bool casesensitive=false) const;
443 
444  /// Search for the named attribute and return a pointer to an
445  /// ParamValue record, or NULL if not found. This variety of
446  /// find_attribute() can retrieve items such as "width", which are part
447  /// of the ImageSpec, but not in extra_attribs. The tmpparam is a
448  /// temporary storage area owned by the caller, which is used as
449  /// temporary buffer in cases where the information does not correspond
450  /// to an actual extra_attribs (in this case, the return value will be
451  /// &tmpparam).
452  const ParamValue * find_attribute (string_view name,
453  ParamValue &tmpparam,
454  TypeDesc searchtype=TypeDesc::UNKNOWN,
455  bool casesensitive=false) const;
456 
457  /// Simple way to get an integer attribute, with default provided.
458  /// Automatically will return an int even if the data is really
459  /// unsigned, short, or byte.
460  int get_int_attribute (string_view name, int defaultval=0) const;
461 
462  /// Simple way to get a float attribute, with default provided.
463  /// Automatically will return a float even if the data is really
464  /// double or half.
465  float get_float_attribute (string_view name, float defaultval=0) const;
466 
467  /// Simple way to get a string attribute, with default provided.
468  ///
470  string_view defaultval = string_view()) const;
471 
472  /// For a given parameter p, format the value nicely as a string. If
473  /// 'human' is true, use especially human-readable explanations (units,
474  /// or decoding of values) for certain known metadata.
475  static std::string metadata_val (const ParamValue &p, bool human=false);
476 
477  enum SerialFormat { SerialText, SerialXML };
478  enum SerialVerbose { SerialBrief, SerialDetailed, SerialDetailedHuman };
479 
480  /// Convert ImageSpec class into a serialized string.
481  std::string serialize (SerialFormat format,
482  SerialVerbose verbose = SerialDetailed) const;
483 
484  /// Convert ImageSpec class into XML string.
485  ///
486  std::string to_xml () const;
487 
488  /// Get an ImageSpec class from XML string.
489  ///
490  void from_xml (const char *xml);
491 
492  /// Hunt for the "Compression" and "CompressionQuality" settings in the
493  /// spec and turn them into the compression name and quality. This
494  /// handles compression name/qual combos of the form "name:quality".
495  std::pair<string_view, int>
496  decode_compression_metadata(string_view defaultcomp = "",
497  int defaultqual = -1) const;
498 
499  /// Helper function to verify that the given pixel range exactly covers
500  /// a set of tiles. Also returns false if the spec indicates that the
501  /// image isn't tiled at all.
502  bool valid_tile_range (int xbegin, int xend, int ybegin, int yend,
503  int zbegin, int zend) {
504  return (tile_width &&
505  ((xbegin-x) % tile_width) == 0 &&
506  ((ybegin-y) % tile_height) == 0 &&
507  ((zbegin-z) % tile_depth) == 0 &&
508  (((xend-x) % tile_width) == 0 || (xend-x) == width) &&
509  (((yend-y) % tile_height) == 0 || (yend-y) == height) &&
510  (((zend-z) % tile_depth) == 0 || (zend-z) == depth));
511  }
512 
513  /// Return the channelformat of the given channel. This is safe even
514  /// if channelformats is not filled out.
515  TypeDesc channelformat (int chan) const {
516  return chan >= 0 && chan < (int)channelformats.size()
517  ? channelformats[chan] : format;
518  }
519 
520  /// Return the channel name of the given channel. This is safe even if
521  /// channelnames is not filled out.
522  string_view channel_name (int chan) const {
523  return chan >= 0 && chan < (int)channelnames.size()
524  ? string_view(channelnames[chan]) : "";
525  }
526 
527  /// Fill in an array of channel formats describing all channels in
528  /// the image. (Note that this differs slightly from the member
529  /// data channelformats, which is empty if there are not separate
530  /// per-channel formats.)
531  void get_channelformats (std::vector<TypeDesc> &formats) const {
532  formats = channelformats;
533  if ((int)formats.size() < nchannels)
534  formats.resize (nchannels, format);
535  }
536 
537  /// Return the index of the named channel, or -1 if not found.
538  int channelindex (string_view name) const;
539 
540  /// Return pixel data window for this ImageSpec as a ROI.
541  ROI roi () const {
542  return ROI (x, x+width, y, y+height, z, z+depth, 0, nchannels);
543  }
544 
545  /// Return full/display window for this ImageSpec as a ROI.
546  ROI roi_full () const {
547  return ROI (full_x, full_x+full_width, full_y, full_y+full_height,
548  full_z, full_z+full_depth, 0, nchannels);
549  }
550 
551  /// Set pixel data window parameters (x, y, z, width, height, depth)
552  /// for this ImageSpec from an ROI.
553  /// Does NOT change the channels of the spec, regardless of r.
554  void set_roi (const ROI &r) {
555  x = r.xbegin;
556  y = r.ybegin;
557  z = r.zbegin;
558  width = r.width();
559  height = r.height();
560  depth = r.depth();
561  }
562 
563  /// Set full/display window parameters (full_x, full_y, full_z,
564  /// full_width, full_height, full_depth) for this ImageSpec from an ROI.
565  /// Does NOT change the channels of the spec, regardless of r.
566  void set_roi_full (const ROI &r) {
567  full_x = r.xbegin;
568  full_y = r.ybegin;
569  full_z = r.zbegin;
570  full_width = r.width();
571  full_height = r.height();
572  full_depth = r.depth();
573  }
574 
575  /// Copy the dimensions (x, y, z, width, height, depth, full*,
576  /// nchannels, format) and types of the other ImageSpec. Be careful,
577  /// this doesn't copy channelnames or the metadata in extra_attribs.
578  void copy_dimensions (const ImageSpec &other) {
579  x = other.x;
580  y = other.y;
581  z = other.z;
582  width = other.width;
583  height = other.height;
584  depth = other.depth;
585  full_x = other.full_x;
586  full_y = other.full_y;
587  full_z = other.full_z;
588  full_width = other.full_width;
589  full_height = other.full_height;
590  full_depth = other.full_depth;
591  tile_width = other.tile_width;
592  tile_height = other.tile_height;
593  tile_depth = other.tile_depth;
594  nchannels = other.nchannels;
595  format = other.format;
596  channelformats = other.channelformats;
597  alpha_channel = other.alpha_channel;
598  z_channel = other.z_channel;
599  deep = other.deep;
600  }
601 
602  /// Is this ImageSpec undefined? (Designated by no channels and
603  /// undefined data type -- true of the uninitialized state of an
604  /// ImageSpec, and presumably not for any ImageSpec that is useful or
605  /// purposefully made.)
606  bool undefined () const {
607  return nchannels == 0 && format == TypeUnknown;
608  }
609 };
610 
611 
612 
613 
614 /// ImageInput abstracts the reading of an image file in a file
615 /// format-agnostic manner.
617 public:
618  /// unique_ptr to an ImageInput
619  using unique_ptr = std::unique_ptr<ImageInput>;
620 
621  /// Create an ImageInput subclass instance that is able to read the
622  /// given file and open it, returning a unique_ptr to the ImageInput if
623  /// successful. The unique_ptr is set up with an appropriate deleter so
624  /// the ImageInput will be properly deleted when the unique_ptr goes out
625  /// of scope or is reset. If the open fails, return an empty unique_ptr
626  /// and set an error that can be retrieved by OpenImageIO::geterror().
627  ///
628  /// The 'config', if not nullptr, points to an ImageSpec giving
629  /// requests or special instructions. ImageInput implementations
630  /// are free to not respond to any such requests, so the default
631  /// implementation is just to ignore config.
632  ///
633  /// open() will first try to make an ImageInput corresponding to
634  /// the format implied by the file extension (for example, "foo.tif"
635  /// will try the TIFF plugin), but if one is not found or if the
636  /// inferred one does not open the file, every known ImageInput type
637  /// will be tried until one is found that will open the file.
638  static unique_ptr open (const std::string &filename,
639  const ImageSpec *config = nullptr);
640 
641  /// Create and return an ImageInput implementation that is able
642  /// to read the given file. If do_open is true, fully open it if
643  /// possible (using the optional configuration spec, if supplied),
644  /// otherwise just create the ImageInput but don't open it.
645  /// The plugin_searchpath parameter is an override of the searchpath.
646  /// colon-separated list of directories to search for ImageIO plugin
647  /// DSO/DLL's (not a searchpath for the image itself!). This will
648  /// actually just try every imageio plugin it can locate, until it
649  /// finds one that's able to open the file without error.
650  ///
651  /// If the caller intends to immediately open the file, then it is
652  /// often simpler to call static ImageInput::open().
653  static unique_ptr create (const std::string &filename, bool do_open=false,
654  const ImageSpec *config=nullptr,
655  string_view plugin_searchpath="");
656  static unique_ptr create (const std::string &filename,
657  const std::string &plugin_searchpath);
658 
659  // Destructor for a raw ImageInput.
660  static void destroy (ImageInput *x);
661 
662  ImageInput ();
663  virtual ~ImageInput ();
664 
665  typedef std::recursive_mutex mutex;
666  typedef std::lock_guard<mutex> lock_guard;
667 
668  /// Return the name of the format implemented by this class.
669  ///
670  virtual const char *format_name (void) const = 0;
671 
672  /// Given the name of a 'feature', return whether this ImageInput
673  /// supports input of images with the given properties. Most queries
674  /// will simply return 0 for "doesn't support" and nonzero for "supports
675  /// it", but it is acceptable to have queries return other nonzero
676  /// integers to indicate varying degrees of support or limits (but
677  /// should be clearly documented as such).
678  ///
679  /// Feature names that ImageIO plugins are expected to recognize
680  /// include:
681  /// "arbitrary_metadata" Does this format allow metadata with
682  /// arbitrary names and types?
683  /// "exif" Can this format store Exif camera data?
684  /// "iptc" Can this format store IPTC data?
685  /// "procedural" Can this format create images without reading
686  /// from a disk file?
687  /// "ioproxy" Does this format reader support IOProxy?
688  ///
689  /// Note that main advantage of this approach, versus having
690  /// separate individual supports_foo() methods, is that this allows
691  /// future expansion of the set of possible queries without changing
692  /// the API, adding new entry points, or breaking linkage
693  /// compatibility.
694  virtual int supports (string_view feature) const { return false; }
695 
696  /// Return true if the named file is file of the type for this
697  /// ImageInput. The implementation will try to determine this as
698  /// efficiently as possible, in most cases much less expensively
699  /// than doing a full open(). Note that a file can appear to be of
700  /// the right type (i.e., valid_file() returning true) but still
701  /// fail a subsequent call to open(), such as if the contents of the
702  /// file are truncated, nonsensical, or otherwise corrupted.
703  virtual bool valid_file (const std::string &filename) const;
704 
705  /// Open file with given name. Various file attributes are put in
706  /// newspec and a copy is also saved in this->spec. From these
707  /// attributes, you can discern the resolution, if it's tiled,
708  /// number of channels, and native data format. Return true if the
709  /// file was found and opened okay.
710  virtual bool open (const std::string &name, ImageSpec &newspec) = 0;
711 
712  /// Open file with given name, similar to open(name,newspec). The
713  /// 'config' is an ImageSpec giving requests or special
714  /// instructions. ImageInput implementations are free to not
715  /// respond to any such requests, so the default implementation is
716  /// just to ignore config and call regular open(name,newspec).
717  virtual bool open (const std::string &name, ImageSpec &newspec,
718  const ImageSpec & /*config*/) { return open(name,newspec); }
719 
720  /// Return a reference to the image format specification of the
721  /// current subimage/MIPlevel. Note that the contents of the spec
722  /// are invalid before open() or after close(), and may change with
723  /// a call to seek_subimage(). It is thus not thread-safe, since the
724  /// spec may change if another thread calls seek_subimage, or any of
725  /// the read_*() functions that take explicit subimage/miplevel.
726  virtual const ImageSpec &spec (void) const { return m_spec; }
727 
728  /// Return a full copy of the ImageSpec of the designated subimage and
729  /// MIPlevel. This method is thread-safe, but it is potentially
730  /// expensive, due to the work that needs to be done to fully copy an
731  /// ImageSpec if there is lots of named metadata to allocate and copy.
732  /// See also the less expensive spec_dimensions(). Errors (such as
733  /// having requested a nonexistant subimage) are indicated by returning
734  /// an ImageSpec with format==TypeUnknown.
735  virtual ImageSpec spec (int subimage, int miplevel=0);
736 
737  /// Return a copy of the ImageSpec of the designated subimage and
738  /// miplevel, but only the dimension and type fields. Just as with a
739  /// call to ImageSpec::copy_dimensions(), neither the channel names nor
740  /// any of the arbitrary named metadata will be copied, thus this is a
741  /// relatively inexpensive operation if you don't need that information.
742  /// It is guaranteed to be thread-safe. Errors (such as having requested
743  /// a nonexistant subimage) are indicated by returning an ImageSpec with
744  /// format==TypeUnknown.
745  virtual ImageSpec spec_dimensions (int subimage, int miplevel=0);
746 
747  /// Close an image that we are totally done with. The call to close() is
748  /// not strictly necessary if the ImageInput is destroyed immediately
749  /// afterwards, since it is required for the destructor to close if the
750  /// file is still open.
751  virtual bool close () = 0;
752 
753  /// Returns the index of the subimage that is currently being read.
754  /// The first subimage (or the only subimage, if there is just one)
755  /// is number 0.
756  virtual int current_subimage (void) const { return 0; }
757 
758  /// Returns the index of the MIPmap image that is currently being read.
759  /// The highest-res MIP level (or the only level, if there is just
760  /// one) is number 0.
761  virtual int current_miplevel (void) const { return 0; }
762 
763  /// Seek to the given subimage and MIP-map level within the open image
764  /// file. The first subimage of the file has index 0, the highest-
765  /// resolution MIP level has index 0. Return true on success, false on
766  /// failure (including that there is not a subimage or MIP level with
767  /// the specified index). The new subimage's vital statistics are put
768  /// in *newspec (if not NULL) and may also be retrieved by in
769  /// this->spec()). The reader is expected to give the appearance of
770  /// random access to subimages and MIP levels -- in other words, if it
771  /// can't randomly seek to the given subimage/level, it should
772  /// transparently close, reopen, and sequentially read through prior
773  /// subimages and levels.
774  virtual bool seek_subimage (int subimage, int miplevel) {
775  // Default implementation assumes no support for subimages or
776  // mipmaps, so there is no work to do.
777  return subimage == current_subimage() && miplevel == current_miplevel();
778  }
779 
780  // Old version for backwards-compatibility: pass reference to newspec.
781  // Some day this will be deprecated.
782  bool seek_subimage (int subimage, int miplevel, ImageSpec &newspec) {
783  bool ok = seek_subimage (subimage, miplevel);
784  if (ok)
785  newspec = spec();
786  return ok;
787  }
788 
789  // Seek to the given subimage -- backwards-compatible call that
790  // doesn't worry about MIP-map levels at all.
791  // Some day this will be deprecated.
792  bool seek_subimage (int subimage, ImageSpec &newspec) {
793  return seek_subimage (subimage, 0 /* miplevel */, newspec);
794  }
795 
796  /// Read the scanline that includes pixels (*,y,z) into data,
797  /// converting if necessary from the native data format of the file
798  /// into the 'format' specified (z==0 for non-volume images). The
799  /// stride value gives the data spacing of adjacent pixels (in
800  /// bytes). Strides set to AutoStride imply 'contiguous' data, i.e.,
801  /// xstride == spec.nchannels*format.size()
802  /// If format is TypeDesc::UNKNOWN, then rather than converting to
803  /// format, it will just copy pixels in the file's native data layout
804  /// (including, possibly, per-channel data formats).
805  /// The reader is expected to give the appearance of random access --
806  /// in other words, if it can't randomly seek to the given scanline,
807  /// it should transparently close, reopen, and sequentially read
808  /// through prior scanlines. The base ImageInput class has a
809  /// default implementation that calls read_native_scanline and then
810  /// does appropriate format conversion, so there's no reason for
811  /// each format plugin to override this method.
812  virtual bool read_scanline (int y, int z, TypeDesc format, void *data,
813  stride_t xstride=AutoStride);
814 
815  ///
816  /// Simple read_scanline reads to contiguous float pixels.
817  bool read_scanline (int y, int z, float *data) {
818  return read_scanline (y, z, TypeDesc::FLOAT, data);
819  }
820 
821  /// Read multiple scanlines that include pixels (*,y,z) for all ybegin
822  /// <= y < yend in the specified subimage and mip level, into data,
823  /// using the strides given and converting to the requested data format
824  /// (unless format is TypeDesc::UNKNOWN, in which case pixels will be
825  /// copied in the native data layout, including per-channel data
826  /// formats). Only channels [chbegin,chend) will be read/copied
827  /// (chbegin=0, chend=spec.nchannels reads all channels, yielding
828  /// equivalent behavior to the simpler variant of read_scanlines).
829  ///
830  /// This version of read_scanlines, because it passes explicit
831  /// subimage/miplevel, does not require a separate call to
832  /// seek_subimage, and is guaranteed to be thread-safe against other
833  /// concurrent calls to any of the read_* methods that take an explicit
834  /// subimage/miplevel (but not against any other ImageInput methods).
835  virtual bool read_scanlines (int subimage, int miplevel,
836  int ybegin, int yend, int z,
837  int chbegin, int chend,
838  TypeDesc format, void *data,
839  stride_t xstride=AutoStride,
840  stride_t ystride=AutoStride);
841 
842  // DEPRECATED versions of read_scanlines (pre-1.9 OIIO). These will
843  // eventually be removed. Try to replace these calls with ones to the
844  // new variety of read_scanlines that takes an explicit subimage and
845  // miplevel. These old versions are NOT THREAD-SAFE.
846  bool read_scanlines (int ybegin, int yend, int z,
847  TypeDesc format, void *data,
848  stride_t xstride=AutoStride,
849  stride_t ystride=AutoStride);
850  bool read_scanlines (int ybegin, int yend, int z,
851  int chbegin, int chend,
852  TypeDesc format, void *data,
853  stride_t xstride=AutoStride,
854  stride_t ystride=AutoStride);
855 
856  /// Read the tile whose upper-left origin is (x,y,z) into data,
857  /// converting if necessary from the native data format of the file
858  /// into the 'format' specified. (z==0 for non-volume images.) The
859  /// stride values give the data spacing of adjacent pixels, scanlines,
860  /// and volumetric slices (measured in bytes). Strides set to AutoStride
861  /// imply 'contiguous' data in the shape of a full tile, i.e.,
862  /// xstride == spec.nchannels*format.size()
863  /// ystride == xstride*spec.tile_width
864  /// zstride == ystride*spec.tile_height
865  /// If format is TypeDesc::UNKNOWN, then rather than converting to
866  /// format, it will just copy pixels in the file's native data layout
867  /// (including, possibly, per-channel data formats).
868  /// The reader is expected to give the appearance of random access
869  /// -- in other words, if it can't randomly seek to the given tile,
870  /// it should transparently close, reopen, and sequentially read
871  /// through prior tiles. The base ImageInput class has a default
872  /// implementation that calls read_native_tile and then does
873  /// appropriate format conversion, so there's no reason for each
874  /// format plugin to override this method.
875  virtual bool read_tile (int x, int y, int z, TypeDesc format,
876  void *data, stride_t xstride=AutoStride,
877  stride_t ystride=AutoStride,
878  stride_t zstride=AutoStride);
879 
880  ///
881  /// Simple read_tile reads to contiguous float pixels.
882  bool read_tile (int x, int y, int z, float *data) {
883  return read_tile (x, y, z, TypeDesc::FLOAT, data,
885  }
886 
887  /// Read the block of tiles that include all pixels and channels in the
888  /// ROI, at the specified subimage and MIP level. The values are
889  /// converted to the requested data format (unless format is
890  /// TypeDesc::UNKNOWN, in which case pixels will be copied in the native
891  /// data layout, including per-channel data formats), and stored in
892  /// `data` according to the optional stride lengths (in bytes).
893  ///
894  /// The stride values give the data spacing of adjacent pixels,
895  /// scanlines, and volumetric slices (measured in bytes). Strides set to
896  /// AutoStride imply 'contiguous' data in the shape of the [begin,end)
897  /// region, i.e.,
898  /// xstride == (chend - chbegin) * format.size()
899  /// ystride == xstride * (xend - xbegin)
900  /// zstride == ystride * (yend - ybegin)
901  ///
902  /// This version of read_tiles, because it passes explicit
903  /// subimage/miplevel, does not require a separate call to
904  /// seek_subimage, and is guaranteed to be thread-safe against other
905  /// concurrent calls to any of the read_* methods that take an explicit
906  /// subimage/miplevel (but not against any other ImageInput methods).
907  virtual bool read_tiles (int subimage, int miplevel, int xbegin, int xend,
908  int ybegin, int yend, int zbegin, int zend,
909  int chbegin, int chend, TypeDesc format, void *data,
910  stride_t xstride=AutoStride, stride_t ystride=AutoStride,
911  stride_t zstride=AutoStride);
912 
913  // DEPRECATED versions of read_tiles (pre-1.9 OIIO). These will
914  // eventually be removed. Try to replace these calls with ones to the
915  // new variety of read_tiles that takes an explicit subimage and
916  // miplevel. These old versions are NOT THREAD-SAFE.
917  bool read_tiles (int xbegin, int xend, int ybegin, int yend,
918  int zbegin, int zend, TypeDesc format, void *data,
919  stride_t xstride=AutoStride, stride_t ystride=AutoStride,
920  stride_t zstride=AutoStride);
921  bool read_tiles (int xbegin, int xend, int ybegin, int yend,
922  int zbegin, int zend, int chbegin, int chend,
923  TypeDesc format, void *data, stride_t xstride=AutoStride,
924  stride_t ystride=AutoStride, stride_t zstride=AutoStride);
925 
926  /// Read the entire image of spec.width x spec.height x spec.depth
927  /// pixels into data (which must already be sized large enough for
928  /// the entire image) with the given strides and in the desired
929  /// format. Read tiles or scanlines automatically. Strides set to
930  /// AutoStride imply 'contiguous' data, i.e.,
931  /// xstride == spec.nchannels*format.size()
932  /// ystride == xstride*spec.width
933  /// zstride == ystride*spec.height
934  /// If format is TypeDesc::UNKNOWN, then rather than converting to
935  /// format, it will just copy pixels in the file's native data layout
936  /// (including, possibly, per-channel data formats).
937  /// Because this may be an expensive operation, a progress callback
938  /// may be passed. Periodically, it will be called as follows:
939  /// progress_callback (progress_callback_data, float done)
940  /// where 'done' gives the portion of the image
941  virtual bool read_image (TypeDesc format, void *data,
942  stride_t xstride=AutoStride,
943  stride_t ystride=AutoStride,
944  stride_t zstride=AutoStride,
945  ProgressCallback progress_callback=NULL,
946  void *progress_callback_data=NULL);
947 
948  /// Read the entire image of spec.width x spec.height x spec.depth
949  /// pixels into data (which must already be sized large enough for
950  /// the entire image) with the given strides and in the desired
951  /// format. Read tiles or scanlines automatically. Only channels
952  /// [chbegin,chend) will be read/copied (chbegin=0, chend=spec.nchannels
953  /// reads all channels, yielding equivalent behavior to the simpler
954  /// variant of read_image).
955  virtual bool read_image (int subimage, int miplevel,
956  int chbegin, int chend,
957  TypeDesc format, void *data,
958  stride_t xstride=AutoStride,
959  stride_t ystride=AutoStride,
960  stride_t zstride=AutoStride,
961  ProgressCallback progress_callback=NULL,
962  void *progress_callback_data=NULL);
963  // DEPRECATED versions of read_image (pre-1.9 OIIO). These will
964  // eventually be removed. Try to replace these calls with ones to the
965  // new variety of read_tiles that takes an explicit subimage and
966  // miplevel. These old versions are NOT THREAD-SAFE.
967  virtual bool read_image (int chbegin, int chend,
968  TypeDesc format, void *data,
969  stride_t xstride=AutoStride,
970  stride_t ystride=AutoStride,
971  stride_t zstride=AutoStride,
972  ProgressCallback progress_callback=NULL,
973  void *progress_callback_data=NULL);
974 
975  ///
976  /// Simple read_image reads to contiguous float pixels.
977  bool read_image (float *data) {
978  return read_image (TypeDesc::FLOAT, data);
979  }
980 
981 
982  ////////////////////////////////////////////////////////////////////////
983  // read_native_* methods are usually not directly called by user code
984  // (except for read_native_deep_* varieties). These are the methods that
985  // are overloaded by the ImageInput subclasses that implement the
986  // individual file format readers.
987  //
988  // The read_native_* methods always read the "native" data types
989  // (including per-channel data types) and assume that `data` points to
990  // contiguous memory (no non-default strides). In contrast, the
991  // read_scanline/scanlines/tile/tiles handle data type translation and
992  // arbitrary strides.
993  //
994  // The read_native_* methods take an explicit subimage and miplevel, and
995  // thus do not require a prior call to seek_subimage (and therefore no
996  // saved state). They are all required to be thread-safe when called
997  // concurrently with any other read_native_* call or with the varieties
998  // of read_tiles() that also takes an explicit subimage and miplevel
999  // parameter.
1000  //
1001  // As far as format-reading ImageInput subclasses are concerned, the
1002  // only truly required overloads are read_native_scanline (always) and
1003  // read_native_tile (only for formats that support tiles). The other
1004  // varieties are special cases, for example if the particular format is
1005  // able to efficiently read multiple scanlines or tiles at once, and if
1006  // the subclass does not provide overloads, the base class
1007  // implementaiton will be used instead, which is implemented by reducing
1008  // the operation to multiple calls to read_scanline or read_tile.
1009 
1010  /// Read a single scanline of native data into contiguous memory.
1011  virtual bool read_native_scanline (int subimage, int miplevel,
1012  int y, int z, void *data) = 0;
1013 
1014  virtual bool read_native_scanlines (int subimage, int miplevel,
1015  int ybegin, int yend, int z,
1016  void *data);
1017  virtual bool read_native_scanlines (int subimage, int miplevel,
1018  int ybegin, int yend, int z,
1019  int chbegin, int chend, void *data);
1020 
1021  /// Read a single tile (all channels) of native data into contiguous
1022  /// mamory. The base class read_native_tile fails. A format reader that
1023  /// supports tiles MUST overload this virtual method that reads a single
1024  /// tile (all channels).
1025  virtual bool read_native_tile (int subimage, int miplevel,
1026  int x, int y, int z, void *data);
1027 
1028  /// Read multiple tiles (all channels) of native data into contigious
1029  /// memory. A format reader that supports reading multiple tiles at once
1030  /// (in a way that's more efficient than reading the tiles one at a
1031  /// time) is advised (but not required) to overload this virtual method.
1032  /// If an ImageInput subclass does not overload this, the default
1033  /// implementation here is simply to loop over the tiles, calling the
1034  /// single-tile read_native_tile() for each one.
1035  virtual bool read_native_tiles (int subimage, int miplevel,
1036  int xbegin, int xend, int ybegin, int yend,
1037  int zbegin, int zend, void *data);
1038 
1039  /// Read multiple tiles (potentially a subset of channels) of native
1040  /// data into contigious memory. A format reader that supports reading
1041  /// multiple tiles at once, and can handle a channel subset while doing
1042  /// so, is advised (but not required) to overload this virtual method.
1043  /// If an ImageInput subclass does not overload this, the default
1044  /// implementation here is simply to loop over the tiles, calling the
1045  /// single-tile read_native_tile() for each one (and copying carefully
1046  /// to handle the channel subset issues).
1047  virtual bool read_native_tiles (int subimage, int miplevel,
1048  int xbegin, int xend, int ybegin, int yend,
1049  int zbegin, int zend,
1050  int chbegin, int chend, void *data);
1051 
1052  /// Read into deepdata the block of native deep scanlines corresponding
1053  /// to pixels (*,y,z) for all roi.ybegin <= y < roi.yend, into deepdata.
1054  /// Only channels [roi.chbegin, chend) will be read (roi.chbegin=0,
1055  /// roi.chend=spec.nchannels reads all channels). The x range must be
1056  /// the full width of the image data, and the z range must be just one
1057  /// depth plane.
1058  virtual bool read_native_deep_scanlines (int subimage, int miplevel,
1059  int ybegin, int yend, int z,
1060  int chbegin, int chend,
1061  DeepData &deepdata);
1062 
1063  /// Read into deepdata the block of native deep data tiles that include
1064  /// all pixels and channels specified by the ROI.
1065  virtual bool read_native_deep_tiles (int subimage, int miplevel,
1066  int xbegin, int xend,
1067  int ybegin, int yend,
1068  int zbegin, int zend,
1069  int chbegin, int chend,
1070  DeepData &deepdata);
1071 
1072  /// Read the entire deep data image of spec.width x spec.height x
1073  /// spec.depth pixels, all channels, into deepdata.
1074  virtual bool read_native_deep_image (int subimage, int miplevel,
1075  DeepData &deepdata);
1076 
1077  // DEPRECATED(1.9), Now just used for back compatibility:
1078  bool read_native_deep_scanlines (int ybegin, int yend, int z,
1079  int chbegin, int chend, DeepData &deepdata) {
1080  return read_native_deep_scanlines (current_subimage(), current_miplevel(),
1081  ybegin, yend, z,
1082  chbegin, chend, deepdata);
1083  }
1084  bool read_native_deep_tiles (int xbegin, int xend, int ybegin, int yend,
1085  int zbegin, int zend, int chbegin, int chend,
1086  DeepData &deepdata) {
1087  return read_native_deep_tiles (current_subimage(), current_miplevel(),
1088  xbegin, xend, ybegin, yend,
1089  zbegin, zend, chbegin, chend, deepdata);
1090  }
1092  return read_native_deep_image (current_subimage(), current_miplevel(),
1093  deepdata);
1094  }
1095 
1096 
1097  /// General message passing between client and image input server
1098  ///
1099  virtual int send_to_input (const char *format, ...);
1100  int send_to_client (const char *format, ...);
1101 
1102  /// If any of the API routines returned false indicating an error,
1103  /// this routine will return the error string (and clear any error
1104  /// flags). If no error has occurred since the last time geterror()
1105  /// was called, it will return an empty string.
1107  lock_guard lock (m_mutex);
1108  std::string e = m_errmessage;
1109  m_errmessage.clear ();
1110  return e;
1111  }
1112 
1113  /// Error reporting for the plugin implementation: call this with
1114  /// Strutil::format-like arguments.
1115  /// Use with caution! Some day this will change to be fmt-like rather
1116  /// than printf-like.
1117  template<typename... Args>
1118  void error(const char* fmt, const Args&... args) const {
1119  append_error(Strutil::format (fmt, args...));
1120  }
1121 
1122  /// Error reporting for the plugin implementation: call this with
1123  /// printf-like arguments.
1124  template<typename... Args>
1125  void errorf(const char* fmt, const Args&... args) const {
1126  append_error(Strutil::sprintf (fmt, args...));
1127  }
1128 
1129  /// Error reporting for the plugin implementation: call this with
1130  /// fmt::format-like arguments.
1131  template<typename... Args>
1132  void fmterror(const char* fmt, const Args&... args) const {
1133  append_error(Strutil::fmt::format (fmt, args...));
1134  }
1135 
1136  /// Set the current thread-spawning policy: the maximum number of
1137  /// threads that may be spawned by ImageInput internals. A value of 1
1138  /// means all work will be done by the calling thread; 0 means to use
1139  /// the global OIIO::attribute("threads") value.
1140  void threads (int n) { m_threads = n; }
1141 
1142  /// Retrieve the current thread-spawning policy.
1143  int threads () const { return m_threads; }
1144 
1145  /// Lock, try_lock, and unlock for the internal mutex.
1146  void lock () { m_mutex.lock(); }
1147  bool try_lock () { return m_mutex.try_lock(); }
1148  void unlock () { m_mutex.unlock(); }
1149 
1150  // Custom new and delete to ensure that allocations & frees happen in
1151  // the OpenImageIO library, not in the app or plugins (because Windows).
1152  void* operator new (size_t size);
1153  void operator delete (void *ptr);
1154 
1155  /// Call signature of a function that creates and returns an ImageInput*
1156  typedef ImageInput* (*Creator)();
1157 
1158 protected:
1159  mutable mutex m_mutex; // lock of the thread-safe methods
1160  ImageSpec m_spec; // format spec of the current open subimage/MIPlevel
1161  // BEWARE using m_spec directly -- not thread-safe
1162 
1163 private:
1164  mutable std::string m_errmessage; // private storage of error message
1165  int m_threads; // Thread policy
1166  void append_error (const std::string& message) const; // add to m_errmessage
1167  // Deprecated:
1168  static unique_ptr create (const std::string &filename, bool do_open,
1169  const std::string &plugin_searchpath);
1170 };
1171 
1172 
1173 
1174 
1175 /// ImageOutput abstracts the writing of an image file in a file
1176 /// format-agnostic manner.
1178 public:
1179  /// unique_ptr to an ImageOutput, with custom deleter.
1180  using unique_ptr = std::unique_ptr<ImageOutput>;
1181 
1182  /// Create an ImageOutput that will write to a file, with the format
1183  /// inferred from the extension of the name. The plugin_searchpath
1184  /// parameter is a colon-separated list of directories to search for
1185  /// ImageIO plugin DSO/DLL's. This just creates the ImageOutput, it
1186  /// does not open the file. If the writer could be created, a
1187  /// unique_ptr to it will be returned, otherwise an empty pointer will
1188  /// be returned and an appropriate error message will be set that can be
1189  /// retrieved with OIIO::geterror().
1190  static unique_ptr create (const std::string &filename,
1191  const std::string &plugin_searchpath="");
1192 
1193  // Destructor for a raw ImageOutput.
1194  static void destroy (ImageOutput *x);
1195 
1196  ImageOutput ();
1197  virtual ~ImageOutput ();
1198 
1199  /// Return the name of the format implemented by this class.
1200  ///
1201  virtual const char *format_name (void) const = 0;
1202 
1203  // Overrride these functions in your derived output class
1204  // to inform the client which formats are supported
1205 
1206  /// Given the name of a 'feature', return whether this ImageOutput
1207  /// supports output of images with the given properties. Most queries
1208  /// will simply return 0 for "doesn't support" and nonzero for "supports
1209  /// it", but it is acceptable to have queries return other nonzero
1210  /// integers to indicate varying degrees of support or limits (but
1211  /// should be clearly documented as such).
1212  ///
1213  /// Feature names that ImageIO plugins are expected to recognize
1214  /// include:
1215  /// "tiles" Is this format able to write tiled images?
1216  /// "rectangles" Does this plugin accept arbitrary rectangular
1217  /// pixel regions, not necessarily aligned to
1218  /// scanlines or tiles?
1219  /// "random_access" May tiles or scanlines be written in
1220  /// any order (false indicates that they MUST
1221  /// be in successive order).
1222  /// "multiimage" Does this format support multiple subimages
1223  /// within a file?
1224  /// "appendsubimage" Does this format support adding subimages one at
1225  /// a time through open(name,spec,AppendSubimage)?
1226  /// If not, then open(name,subimages,specs) must
1227  /// be used instead.
1228  /// "mipmap" Does this format support multiple resolutions
1229  /// for an image/subimage?
1230  /// "volumes" Does this format support "3D" pixel arrays?
1231  /// "alpha" Can this format support an alpha channel?
1232  /// "nchannels" Can this format support arbitrary number of
1233  /// channels (beyond RGBA)?
1234  /// "rewrite" May the same scanline or tile be sent more than
1235  /// once? (Generally, this will be true for
1236  /// plugins that implement interactive display.)
1237  /// "empty" Does this plugin support passing a NULL data
1238  /// pointer to write_scanline or write_tile to
1239  /// indicate that the entire data block is zero?
1240  /// "channelformats" Does the plugin/format support per-channel
1241  /// data formats?
1242  /// "displaywindow" Does the format support display ("full") windows
1243  /// distinct from the pixel data window?
1244  /// "origin" Does the format support a nonzero x,y,z
1245  /// origin of the pixel data window?
1246  /// "negativeorigin" Does the format support negative x,y,z
1247  /// and full_{x,y,z} origin values?
1248  /// "deepdata" Deep (multi-sample per pixel) data
1249  /// "arbitrary_metadata" Does this format allow metadata with
1250  /// arbitrary names and types?
1251  /// "exif" Can this format store Exif camera data?
1252  /// "iptc" Can this format store IPTC data?
1253  /// "ioproxy" Does this format writer support IOProxy?
1254  ///
1255  /// Note that main advantage of this approach, versus having
1256  /// separate individual supports_foo() methods, is that this allows
1257  /// future expansion of the set of possible queries without changing
1258  /// the API, adding new entry points, or breaking linkage
1259  /// compatibility.
1260  virtual int supports (string_view feature) const { return false; }
1261 
1262  enum OpenMode { Create, AppendSubimage, AppendMIPLevel };
1263 
1264  /// Open the file with given name, with resolution and other format
1265  /// data as given in newspec. Open returns true for success, false
1266  /// for failure. Note that it is legal to call open multiple times
1267  /// on the same file without a call to close(), if it supports
1268  /// multiimage and mode is AppendSubimage, or if it supports
1269  /// MIP-maps and mode is AppendMIPLevel -- this is interpreted as
1270  /// appending a subimage, or a MIP level to the current subimage,
1271  /// respectively.
1272  virtual bool open (const std::string &name, const ImageSpec &newspec,
1273  OpenMode mode=Create) = 0;
1274 
1275  /// Open the file with given name, expecting to have a given total
1276  /// number of subimages, described by specs[0..subimages-1].
1277  /// Return true for success, false for failure. Upon success, the
1278  /// first subimage will be open and ready for transmission of
1279  /// pixels. Subsequent subimages will be denoted with the usual
1280  /// call of open(name,spec,AppendSubimage) (and MIP levels by
1281  /// open(name,spec,AppendMIPLevel)).
1282  ///
1283  /// The purpose of this call is to accommodate format-writing
1284  /// libraries that fmust know the number and specifications of the
1285  /// subimages upon first opening the file; such formats can be
1286  /// detected by
1287  /// supports("multiimage") && !supports("appendsubimage")
1288  /// The individual specs passed to the appending open() calls for
1289  /// subsequent subimages MUST match the ones originally passed.
1290  virtual bool open (const std::string &name, int subimages,
1291  const ImageSpec *specs) {
1292  // Default implementation: just a regular open, assume that
1293  // appending will work.
1294  return open (name, specs[0]);
1295  }
1296 
1297  /// Return a reference to the image format specification of the
1298  /// current subimage. Note that the contents of the spec are
1299  /// invalid before open() or after close().
1300  const ImageSpec &spec (void) const { return m_spec; }
1301 
1302  /// Close an image that we are totally done with. This should leave
1303  /// the plugin in a state where it could open a new file safely,
1304  /// without having to destroy the writer.
1305  virtual bool close () = 0;
1306 
1307  /// Write a full scanline that includes pixels (*,y,z). (z is
1308  /// ignored for 2D non-volume images.) The stride value gives the
1309  /// distance between successive pixels (in bytes). Strides set to
1310  /// AutoStride imply 'contiguous' data, i.e.,
1311  /// xstride == spec.nchannels*format.size()
1312  /// The data are automatically converted from 'format' to the actual
1313  /// output format (as specified to open()) by this method.
1314  /// If format is TypeDesc::UNKNOWN, then rather than converting from
1315  /// format, it will just copy pixels in the file's native data layout
1316  /// (including, possibly, per-channel data formats).
1317  /// Return true for success, false for failure. It is a failure to
1318  /// call write_scanline with an out-of-order scanline if this format
1319  /// driver does not support random access.
1320  virtual bool write_scanline (int y, int z, TypeDesc format,
1321  const void *data, stride_t xstride=AutoStride);
1322 
1323  /// Write multiple scanlines that include pixels (*,y,z) for all
1324  /// ybegin <= y < yend, from data. This is analogous to
1325  /// write_scanline except that it may be used to write more than one
1326  /// scanline at a time (which, for some formats, may be able to be
1327  /// done much more efficiently or in parallel).
1328  virtual bool write_scanlines (int ybegin, int yend, int z,
1329  TypeDesc format, const void *data,
1330  stride_t xstride=AutoStride,
1331  stride_t ystride=AutoStride);
1332 
1333  /// Write the tile with (x,y,z) as the upper left corner. (z is
1334  /// ignored for 2D non-volume images.) The three stride values give
1335  /// the distance (in bytes) between successive pixels, scanlines,
1336  /// and volumetric slices, respectively. Strides set to AutoStride
1337  /// imply 'contiguous' data in the shape of a full tile, i.e.,
1338  /// xstride == spec.nchannels*format.size()
1339  /// ystride == xstride*spec.tile_width
1340  /// zstride == ystride*spec.tile_height
1341  /// The data are automatically converted from 'format' to the actual
1342  /// output format (as specified to open()) by this method.
1343  /// If format is TypeDesc::UNKNOWN, then rather than converting from
1344  /// format, it will just copy pixels in the file's native data layout
1345  /// (including, possibly, per-channel data formats).
1346  /// Return true for success, false for failure. It is a failure to
1347  /// call write_tile with an out-of-order tile if this format driver
1348  /// does not support random access.
1349  virtual bool write_tile (int x, int y, int z, TypeDesc format,
1350  const void *data, stride_t xstride=AutoStride,
1351  stride_t ystride=AutoStride,
1352  stride_t zstride=AutoStride);
1353 
1354  /// Write the block of multiple tiles that include all pixels in
1355  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend). This is analogous to
1356  /// write_tile except that it may be used to write more than one tile at
1357  /// a time (which, for some formats, may be able to be done much more
1358  /// efficiently or in parallel).
1359  /// The begin/end pairs must correctly delineate tile boundaries, with
1360  /// the exception that it may also be the end of the image data if the
1361  /// image resolution is not a whole multiple of the tile size.
1362  /// The stride values give the data spacing of adjacent pixels,
1363  /// scanlines, and volumetric slices (measured in bytes). Strides set to
1364  /// AutoStride imply 'contiguous' data in the shape of the [begin,end)
1365  /// region, i.e.,
1366  /// xstride == spec.nchannels*format.size()
1367  /// ystride == xstride * (xend-xbegin)
1368  /// zstride == ystride * (yend-ybegin)
1369  virtual bool write_tiles (int xbegin, int xend, int ybegin, int yend,
1370  int zbegin, int zend, TypeDesc format,
1371  const void *data, stride_t xstride=AutoStride,
1372  stride_t ystride=AutoStride,
1373  stride_t zstride=AutoStride);
1374 
1375  /// Write a rectangle of pixels given by the range
1376  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend)
1377  /// The stride values give the data spacing of adjacent pixels,
1378  /// scanlines, and volumetric slices (measured in bytes). Strides set to
1379  /// AutoStride imply 'contiguous' data in the shape of the [begin,end)
1380  /// region, i.e.,
1381  /// xstride == spec.nchannels*format.size()
1382  /// ystride == xstride * (xend-xbegin)
1383  /// zstride == ystride * (yend-ybegin)
1384  /// The data are automatically converted from 'format' to the actual
1385  /// output format (as specified to open()) by this method. If
1386  /// format is TypeDesc::UNKNOWN, it will just copy pixels assuming
1387  /// they are already in the file's native data layout (including,
1388  /// possibly, per-channel data formats).
1389  ///
1390  /// Return true for success, false for failure. It is a failure to
1391  /// call write_rectangle for a format plugin that does not return
1392  /// true for supports("rectangles").
1393  virtual bool write_rectangle (int xbegin, int xend, int ybegin, int yend,
1394  int zbegin, int zend, TypeDesc format,
1395  const void *data, stride_t xstride=AutoStride,
1396  stride_t ystride=AutoStride,
1397  stride_t zstride=AutoStride);
1398 
1399  /// Write the entire image of spec.width x spec.height x spec.depth
1400  /// pixels, with the given strides and in the desired format.
1401  /// Strides set to AutoStride imply 'contiguous' data, i.e.,
1402  /// xstride == spec.nchannels*format.size()
1403  /// ystride == xstride*spec.width
1404  /// zstride == ystride*spec.height
1405  /// Depending on spec, write either all tiles or all scanlines.
1406  /// Assume that data points to a layout in row-major order.
1407  /// If format is TypeDesc::UNKNOWN, then rather than converting from
1408  /// format, it will just copy pixels in the file's native data layout
1409  /// (including, possibly, per-channel data formats).
1410  /// Because this may be an expensive operation, a progress callback
1411  /// may be passed. Periodically, it will be called as follows:
1412  /// progress_callback (progress_callback_data, float done)
1413  /// where 'done' gives the portion of the image
1414  virtual bool write_image (TypeDesc format, const void *data,
1415  stride_t xstride=AutoStride,
1416  stride_t ystride=AutoStride,
1417  stride_t zstride=AutoStride,
1418  ProgressCallback progress_callback=NULL,
1419  void *progress_callback_data=NULL);
1420 
1421  /// Write deep scanlines containing pixels (*,y,z), for all y in
1422  /// [ybegin,yend), to a deep file.
1423  virtual bool write_deep_scanlines (int ybegin, int yend, int z,
1424  const DeepData &deepdata);
1425 
1426  /// Write the block of deep tiles that include all pixels in
1427  /// [xbegin,xend) X [ybegin,yend) X [zbegin,zend).
1428  /// The begin/end pairs must correctly delineate tile boundaries,
1429  /// with the exception that it may also be the end of the image data
1430  /// if the image resolution is not a whole multiple of the tile size.
1431  virtual bool write_deep_tiles (int xbegin, int xend, int ybegin, int yend,
1432  int zbegin, int zend,
1433  const DeepData &deepdata);
1434 
1435  /// Write the entire deep image denoted by data.
1436  virtual bool write_deep_image (const DeepData &deepdata);
1437 
1438  /// Read the current subimage of 'in', and write it as the next
1439  /// subimage of *this, in a way that is efficient and does not alter
1440  /// pixel values, if at all possible. Both in and this must be a
1441  /// properly-opened ImageInput and ImageOutput, respectively, and
1442  /// their current images must match in size and number of channels.
1443  /// Return true if it works ok, false if for some reason the
1444  /// operation wasn't possible.
1445  ///
1446  /// If a particular ImageOutput implementation does not supply a
1447  /// copy_image method, it will inherit the default implementation,
1448  /// which is to simply read scanlines or tiles from 'in' and write
1449  /// them to *this. However, some ImageIO implementations may have a
1450  /// special technique for directly copying raw pixel data from the
1451  /// input to the output, when both input and output are the SAME
1452  /// file type and the same data format. This can be more efficient
1453  /// than in->read_image followed by out->write_image, and avoids any
1454  /// unintended pixel alterations, especially for formats that use
1455  /// lossy compression.
1456  virtual bool copy_image (ImageInput *in);
1457 
1458  /// General message passing between client and image output server
1459  ///
1460  virtual int send_to_output (const char *format, ...);
1461  int send_to_client (const char *format, ...);
1462 
1463  /// If any of the API routines returned false indicating an error,
1464  /// this routine will return the error string (and clear any error
1465  /// flags). If no error has occurred since the last time geterror()
1466  /// was called, it will return an empty string.
1468  std::string e = m_errmessage;
1469  m_errmessage.clear ();
1470  return e;
1471  }
1472 
1473  /// Error reporting for the plugin implementation: call this with
1474  /// Strutil::format-like arguments.
1475  /// Use with caution! Some day this will change to be fmt-like rather
1476  /// than printf-like.
1477  template<typename... Args>
1478  void error(const char* fmt, const Args&... args) const {
1479  append_error(Strutil::format (fmt, args...));
1480  }
1481 
1482  /// Error reporting for the plugin implementation: call this with
1483  /// printf-like arguments.
1484  template<typename... Args>
1485  void errorf(const char* fmt, const Args&... args) const {
1486  append_error(Strutil::sprintf (fmt, args...));
1487  }
1488 
1489  /// Error reporting for the plugin implementation: call this with
1490  /// fmt::format-like arguments.
1491  template<typename... Args>
1492  void fmterror(const char* fmt, const Args&... args) const {
1493  append_error(Strutil::fmt::format (fmt, args...));
1494  }
1495 
1496  /// Set the current thread-spawning policy: the maximum number of
1497  /// threads that may be spawned by ImageOutput internals. A value of 1
1498  /// means all work will be done by the calling thread; 0 means to use
1499  /// the global OIIO::attribute("threads") value.
1500  void threads (int n) { m_threads = n; }
1501 
1502  /// Retrieve the current thread-spawning policy.
1503  int threads () const { return m_threads; }
1504 
1505  // Custom new and delete to ensure that allocations & frees happen in
1506  // the OpenImageIO library, not in the app or plugins (because Windows).
1507  void* operator new (size_t size);
1508  void operator delete (void *ptr);
1509 
1510  /// Call signature of a function that creates and returns an ImageOutput*
1511  typedef ImageOutput* (*Creator)();
1512 
1513 protected:
1514  /// Helper routines used by write_* implementations: convert data (in
1515  /// the given format and stride) to the "native" format of the file
1516  /// (described by the 'spec' member variable), in contiguous order. This
1517  /// requires a scratch space to be passed in so that there are no memory
1518  /// leaks. Returns a pointer to the native data, which may be the
1519  /// original data if it was already in native format and contiguous, or
1520  /// it may point to the scratch space if it needed to make a copy or do
1521  /// conversions. For float->uint8 conversions only, if dither is
1522  /// nonzero, random dither will be added to reduce quantization banding
1523  /// artifacts; in this case, the specific nonzero dither value is used
1524  /// as a seed for the hash function that produces the per-pixel dither
1525  /// amounts, and the optional [xyz]origin parameters help it to align
1526  /// the pixels to the right position in the dither pattern.
1527  const void *to_native_scanline (TypeDesc format,
1528  const void *data, stride_t xstride,
1529  std::vector<unsigned char> &scratch,
1530  unsigned int dither=0,
1531  int yorigin=0, int zorigin=0);
1532  const void *to_native_tile (TypeDesc format, const void *data,
1533  stride_t xstride, stride_t ystride,
1534  stride_t zstride,
1535  std::vector<unsigned char> &scratch,
1536  unsigned int dither=0,
1537  int xorigin=0, int yorigin=0, int zorigin=0);
1538  const void *to_native_rectangle (int xbegin, int xend, int ybegin, int yend,
1539  int zbegin, int zend,
1540  TypeDesc format, const void *data,
1541  stride_t xstride, stride_t ystride,
1542  stride_t zstride,
1543  std::vector<unsigned char> &scratch,
1544  unsigned int dither=0,
1545  int xorigin=0, int yorigin=0, int zorigin=0);
1546 
1547  /// Helper function to copy a rectangle of data into the right spot in
1548  /// an image-sized buffer. In addition to copying to the right place,
1549  /// this handles data format conversion and dither (if the spec's
1550  /// "oiio:dither" is nonzero, and if it's converting from a float-like
1551  /// type to UINT8). The buf_format describes the type of image_buffer,
1552  /// if it's TypeDesc::UNKNOWN it will be assumed to be spec.format.
1553  bool copy_to_image_buffer (int xbegin, int xend, int ybegin, int yend,
1554  int zbegin, int zend, TypeDesc format,
1555  const void *data, stride_t xstride,
1556  stride_t ystride, stride_t zstride,
1557  void *image_buffer,
1558  TypeDesc buf_format = TypeDesc::UNKNOWN);
1559  /// Helper function to copy a tile of data into the right spot in an
1560  /// image-sized buffer. This is really just a wrapper for
1561  /// copy_to_image_buffer, passing all the right parameters to copy
1562  /// exactly one tile.
1563  bool copy_tile_to_image_buffer (int x, int y, int z, TypeDesc format,
1564  const void *data, stride_t xstride,
1565  stride_t ystride, stride_t zstride,
1566  void *image_buffer,
1567  TypeDesc buf_format = TypeDesc::UNKNOWN);
1568 
1569 protected:
1570  ImageSpec m_spec; ///< format spec of the currently open image
1571 
1572 private:
1573  void append_error (const std::string& message) const; // add to m_errmessage
1574  mutable std::string m_errmessage; ///< private storage of error message
1575  int m_threads; // Thread policy
1576 };
1577 
1578 
1579 
1580 // Utility functions
1581 
1582 /// Retrieve the version of OpenImageIO for the library. This is so
1583 /// plugins can query to be sure they are linked against an adequate
1584 /// version of the library.
1586 
1587 /// Special geterror() called after ImageInput::create or
1588 /// ImageOutput::create, since if create fails, there's no object on
1589 /// which call obj->geterror(). This function returns the last error
1590 /// for this particular thread; separate threads will not clobber each
1591 /// other's global error messages.
1593 
1594 /// Set a global attribute controlling OpenImageIO. Return true
1595 /// if the name and type were recognized and the attribute was set.
1596 ///
1597 /// Documented attributes:
1598 /// int threads
1599 /// How many threads to use for operations that can be sped
1600 /// by spawning threads (default=0, meaning to use the full
1601 /// available hardware concurrency detected).
1602 /// int exr_threads
1603 /// The size of the internal OpenEXR thread pool. The default
1604 /// is to use the full available hardware concurrency detected.
1605 /// Default is 0 meaning to use full available hardware
1606 /// concurrency detected, -1 means to disable usage of the OpenEXR
1607 /// thread pool and execute everything in the caller thread.
1608 /// string plugin_searchpath
1609 /// Colon-separated list of directories to search for
1610 /// dynamically-loaded format plugins.
1611 /// int read_chunk
1612 /// The number of scanlines that will be attempted to read at
1613 /// once for read_image calls (default: 256).
1614 /// int debug
1615 /// When nonzero, various debug messages may be printed.
1616 /// The default is 0 for release builds, >=1 for DEBUG builds,
1617 /// but also may be overridden by the OPENIMAGEIO_DEBUG env
1618 /// variable.
1619 /// int log_times
1620 /// When nonzero, various internals will record how much total
1621 /// time they spend in execution. If the value is >= 2, these
1622 /// times will be printed upon exit. Thd default is 0, but will
1623 /// be initialized to the value of the OPENIMAGEIO_LOG_TIMES
1624 /// environment variable, if it exists.
1625 /// int tiff:half
1626 /// When nonzero, allows TIFF to write 'half' pixel data.
1627 /// N.B. Most apps may not read these correctly, but OIIO will.
1628 /// That's why the default is not to support it.
1629 ///
1630 OIIO_API bool attribute (string_view name, TypeDesc type, const void *val);
1631 // Shortcuts for common types
1632 inline bool attribute (string_view name, int val) {
1633  return attribute (name, TypeInt, &val);
1634 }
1635 inline bool attribute (string_view name, float val) {
1636  return attribute (name, TypeFloat, &val);
1637 }
1639  const char *s = val.c_str();
1640  return attribute (name, TypeString, &s);
1641 }
1642 
1643 /// Get the named global attribute of OpenImageIO, store it in *val.
1644 /// Return true if found and it was compatible with the type specified,
1645 /// otherwise return false and do not modify the contents of *val. It
1646 /// is up to the caller to ensure that val points to the right kind and
1647 /// size of storage for the given type.
1648 ///
1649 /// In addition to being able to retrieve all the attributes that are
1650 /// documented as settable by the attribute() call, getattribute() can
1651 /// also retrieve the following read-only attributes:
1652 /// string "format_list"
1653 /// Comma-separated list of all format names supported
1654 /// or for which plugins could be found.
1655 /// string "input_format_list"
1656 /// Comma-separated list of all format names supported
1657 /// or for which plugins could be found that can read images.
1658 /// string "output_format_list"
1659 /// Comma-separated list of all format names supported
1660 /// or for which plugins could be found that can write images.
1661 /// string "extension_list"
1662 /// For each format, the format name followed by a colon,
1663 /// followed by comma-separated list of all extensions that
1664 /// are presumed to be used for that format. Semicolons
1665 /// separate the lists for formats. For example,
1666 /// "tiff:tif;jpeg:jpg,jpeg;openexr:exr"
1667 /// string "library_list"
1668 /// For each format that uses an external expendent library, the
1669 /// format name followed by a colon, followed by the name of
1670 /// the library. Semicolons separate the lists for formats. For
1671 /// example,
1672 /// "jpeg:jpeg-turbo 1.5.1;png:libpng 1.6.29;gif:gif_lib 5.1.4"
1673 /// string "timing_report"
1674 /// A string containing the report of all the log_times.
1675 /// string "oiio:simd"
1676 /// Comma-separated list of the SIMD-related capabilities
1677 /// enabled when the OIIO library was built. For example,
1678 /// "sse2,sse3,ssse3,sse41,sse42,avx"
1679 /// string "hw:simd"
1680 /// Comma-separated list of the SIMD-related capabilities
1681 /// detected at runtime at the time of the query (which may not
1682 /// match the support compiled into the library).
1683 /// int "resident_memory_used_MB"
1684 /// Approximate process memory used (resident) by the application,
1685 /// in MB. This might be helpful in debugging.
1687 // Shortcuts for common types
1688 inline bool getattribute (string_view name, int &val) {
1689  return getattribute (name, TypeInt, &val);
1690 }
1691 inline bool getattribute (string_view name, float &val) {
1692  return getattribute (name, TypeFloat, &val);
1693 }
1694 inline bool getattribute (string_view name, char **val) {
1695  return getattribute (name, TypeString, val);
1696 }
1698  ustring s;
1699  bool ok = getattribute (name, TypeString, &s);
1700  if (ok)
1701  val = s.string();
1702  return ok;
1703 }
1704 inline int get_int_attribute (string_view name, int defaultval=0) {
1705  int val;
1706  return getattribute (name, TypeInt, &val) ? val : defaultval;
1707 }
1708 inline float get_float_attribute (string_view name, float defaultval=0) {
1709  float val;
1710  return getattribute (name, TypeFloat, &val) ? val : defaultval;
1711 }
1713  string_view defaultval = string_view()) {
1714  ustring val;
1715  return getattribute (name, TypeString, &val) ? string_view(val) : defaultval;
1716 }
1717 
1718 
1719 /// Register the input and output 'create' routines and list of file
1720 /// extensions for a particular format.
1721 OIIO_API void declare_imageio_format (const std::string &format_name,
1722  ImageInput::Creator input_creator,
1723  const char **input_extensions,
1724  ImageOutput::Creator output_creator,
1725  const char **output_extensions,
1726  const char *lib_version);
1727 
1728 /// Helper function: convert contiguous arbitrary data between two
1729 /// arbitrary types (specified by TypeDesc's)
1730 /// Return true if ok, false if it didn't know how to do the
1731 /// conversion. If dst_type is UNKNOWN, it will be assumed to be the
1732 /// same as src_type.
1733 OIIO_API bool convert_types (TypeDesc src_type, const void *src,
1734  TypeDesc dst_type, void *dst, int n);
1735 
1736 /// Helper routine for data conversion: Convert an image of nchannels x
1737 /// width x height x depth from src to dst. The src and dst may have
1738 /// different data formats and layouts. Clever use of this function can
1739 /// not only exchange data among different formats (e.g., half to 8-bit
1740 /// unsigned), but also can copy selective channels, copy subimages,
1741 /// etc. If you're lazy, it's ok to pass AutoStride for any of the
1742 /// stride values, and they will be auto-computed assuming contiguous
1743 /// data. Return true if ok, false if it didn't know how to do the
1744 /// conversion.
1745 OIIO_API bool convert_image (int nchannels, int width, int height, int depth,
1746  const void *src, TypeDesc src_type,
1747  stride_t src_xstride, stride_t src_ystride,
1748  stride_t src_zstride,
1749  void *dst, TypeDesc dst_type,
1750  stride_t dst_xstride, stride_t dst_ystride,
1751  stride_t dst_zstride);
1752 /// DEPRECATED(2.0) -- the alpha_channel, z_channel were never used
1753 inline bool convert_image(int nchannels, int width, int height, int depth,
1754  const void *src, TypeDesc src_type,
1755  stride_t src_xstride, stride_t src_ystride, stride_t src_zstride,
1756  void *dst, TypeDesc dst_type,
1757  stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride,
1758  int alpha_channel, int z_channel = -1)
1759 {
1760  return convert_image(nchannels, width, height, depth, src, src_type,
1761  src_xstride, src_ystride, src_zstride, dst, dst_type,
1762  dst_xstride, dst_ystride, dst_zstride);
1763 }
1764 
1765 
1766 /// A version of convert_image that will break up big jobs into multiple
1767 /// threads.
1769  int nchannels, int width, int height, int depth,
1770  const void *src, TypeDesc src_type,
1771  stride_t src_xstride, stride_t src_ystride,
1772  stride_t src_zstride,
1773  void *dst, TypeDesc dst_type,
1774  stride_t dst_xstride, stride_t dst_ystride,
1775  stride_t dst_zstride, int nthreads=0);
1776 /// DEPRECATED(2.0) -- the alpha_channel, z_channel were never used
1778  int nchannels, int width, int height, int depth,
1779  const void *src, TypeDesc src_type,
1780  stride_t src_xstride, stride_t src_ystride, stride_t src_zstride,
1781  void *dst, TypeDesc dst_type,
1782  stride_t dst_xstride, stride_t dst_ystride, stride_t dst_zstride,
1783  int alpha_channel, int z_channel, int nthreads=0)
1784 {
1785  return parallel_convert_image (nchannels, width, height, depth,
1786  src, src_type, src_xstride, src_ystride, src_zstride,
1787  dst, dst_type, dst_xstride, dst_ystride, dst_zstride, nthreads);
1788 }
1789 
1790 /// Add random [-theramplitude,ditheramplitude] dither to the color channels
1791 /// of the image. Dither will not be added to the alpha or z channel. The
1792 /// image origin and dither seed values allow a reproducible (or variable)
1793 /// dither pattern. If the strides are set to AutoStride, they will be
1794 /// assumed to be contiguous floats in data of the given dimensions.
1795 OIIO_API void add_dither (int nchannels, int width, int height, int depth,
1796  float *data,
1797  stride_t xstride, stride_t ystride, stride_t zstride,
1798  float ditheramplitude,
1799  int alpha_channel = -1, int z_channel = -1,
1800  unsigned int ditherseed = 1,
1801  int chorigin=0, int xorigin=0,
1802  int yorigin=0, int zorigin=0);
1803 
1804 /// Convert unassociated to associated alpha by premultiplying all color
1805 /// (non-alpha, non-z) channels by alpha.
1806 OIIO_API void premult (int nchannels, int width, int height, int depth,
1807  int chbegin, int chend,
1808  TypeDesc datatype, void *data, stride_t xstride,
1809  stride_t ystride, stride_t zstride,
1810  int alpha_channel = -1, int z_channel = -1);
1811 
1812 /// Helper routine for data conversion: Copy an image of nchannels x
1813 /// width x height x depth from src to dst. The src and dst may have
1814 /// different data layouts, but must have the same data type. Clever
1815 /// use of this function can change layouts or strides, copy selective
1816 /// channels, copy subimages, etc. If you're lazy, it's ok to pass
1817 /// AutoStride for any of the stride values, and they will be
1818 /// auto-computed assuming contiguous data. Return true if ok, false if
1819 /// it didn't know how to do the conversion.
1820 OIIO_API bool copy_image (int nchannels, int width, int height, int depth,
1821  const void *src, stride_t pixelsize,
1822  stride_t src_xstride, stride_t src_ystride,
1823  stride_t src_zstride,
1824  void *dst, stride_t dst_xstride,
1825  stride_t dst_ystride, stride_t dst_zstride);
1826 
1827 
1828 // All the wrap_foo functions implement a wrap mode, wherein coord is
1829 // altered to be origin <= coord < origin+width. The return value
1830 // indicates if the resulting wrapped value is valid (example, for
1831 // wrap_black, values outside the region are invalid and do not modify
1832 // the coord parameter).
1833 OIIO_API bool wrap_black (int &coord, int origin, int width);
1834 OIIO_API bool wrap_clamp (int &coord, int origin, int width);
1835 OIIO_API bool wrap_periodic (int &coord, int origin, int width);
1836 OIIO_API bool wrap_periodic_pow2 (int &coord, int origin, int width);
1837 OIIO_API bool wrap_mirror (int &coord, int origin, int width);
1838 
1839 // Typedef for the function signature of a wrap implementation.
1840 typedef bool (*wrap_impl) (int &coord, int origin, int width);
1841 
1842 
1843 /// debug(format, ...) prints debugging message when attribute "debug" is
1844 /// nonzero, which it is by default for DEBUG compiles or when the
1845 /// environment variable OPENIMAGEIO_DEBUG is set. This is preferred to raw
1846 /// output to stderr for debugging statements.
1847 OIIO_API void debug (string_view str);
1848 
1849 /// debug output with fmt/std::format conventions.
1850 template<typename T1, typename... Args>
1851 void fmtdebug (const char* fmt, const T1& v1, const Args&... args)
1852 {
1853  debug (Strutil::fmt::format(fmt, v1, args...));
1854 }
1855 
1856 /// debug output with printf conventions.
1857 template<typename T1, typename... Args>
1858 void debugf (const char* fmt, const T1& v1, const Args&... args)
1859 {
1860  debug (Strutil::sprintf(fmt, v1, args...));
1861 }
1862 
1863 /// debug output with the same conventions as Strutil::format. Beware, this
1864 /// will change one day!
1865 template<typename T1, typename... Args>
1866 void debug (const char* fmt, const T1& v1, const Args&... args)
1867 {
1868  debug (Strutil::format(fmt, v1, args...));
1869 }
1870 
1871 
1872 // to force correct linkage on some systems
1874 
int chend
Definition: imageio.h:117
int tile_width
tile width (0 for a non-tiled image)
Definition: imageio.h:237
GLdouble s
Definition: glew.h:1390
bool try_lock()
Definition: imageio.h:1147
int nchannels
number of image channels, e.g., 4 for RGBA
Definition: imageio.h:241
int alpha_channel
Index of alpha channel, or -1 if not known.
Definition: imageio.h:246
std::unique_ptr< ImageInput > unique_ptr
unique_ptr to an ImageInput
Definition: imageio.h:619
std::unique_ptr< ImageOutput > unique_ptr
unique_ptr to an ImageOutput, with custom deleter.
Definition: imageio.h:1180
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
bool read_native_deep_image(DeepData &deepdata)
Definition: imageio.h:1091
OIIO_API bool wrap_periodic_pow2(int &coord, int origin, int width)
std::string sprintf(const char *fmt, const Args &...args)
Definition: strutil.h:136
int xend
Definition: imageio.h:116
std::string geterror() const
Definition: imageio.h:1467
int tile_depth
Definition: imageio.h:239
string_view channel_name(int chan) const
Definition: imageio.h:522
GT_API const UT_StringHolder filename
GLsizeiptr size
Definition: glew.h:1681
GLenum src
Definition: glew.h:2410
bool seek_subimage(int subimage, int miplevel, ImageSpec &newspec)
Definition: imageio.h:782
void threads(int n)
Definition: imageio.h:1140
friend constexpr bool operator==(const ROI &a, const ROI &b)
Test equality of two ROIs.
Definition: imageio.h:161
GLuint const GLchar * name
Definition: glew.h:1814
constexpr ROI()
Definition: imageio.h:121
ImageOutput *(* Creator)()
Call signature of a function that creates and returns an ImageOutput*.
Definition: imageio.h:1511
GLenum mode
Definition: glew.h:2163
const ImageSpec & spec(void) const
Definition: imageio.h:1300
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1252
const Args & args
Definition: printf.h:628
size_t size() const
Definition: typedesc.h:196
static constexpr ROI All()
Definition: imageio.h:158
GLuint const GLfloat * val
Definition: glew.h:2794
bool read_tile(int x, int y, int z, float *data)
Simple read_tile reads to contiguous float pixels.
Definition: imageio.h:882
void get_channelformats(std::vector< TypeDesc > &formats) const
Definition: imageio.h:531
std::recursive_mutex mutex
Definition: imageio.h:665
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
std::string format(const char *fmt, const Args &...args)
Definition: strutil.h:182
ImageSpec m_spec
Definition: imageio.h:1160
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1252
mutex m_mutex
Definition: imageio.h:1159
constexpr ROI roi_intersection(const ROI &A, const ROI &B)
Intersection of two regions.
Definition: imageio.h:211
virtual int current_subimage(void) const
Definition: imageio.h:756
static void auto_stride(stride_t &xstride, stride_t &ystride, stride_t &zstride, stride_t channelsize, int nchannels, int width, int height)
Definition: imageio.h:361
const std::string & string() const
Definition: ustring.h:332
OIIO_API bool wrap_periodic(int &coord, int origin, int width)
TypeDesc channelformat(int chan) const
Definition: imageio.h:515
int depth
depth of pixel data, >1 indicates a "volume"
Definition: imageio.h:230
int full_height
height of the full (display) window
Definition: imageio.h:235
std::vector< std::string > channelnames
Definition: imageio.h:244
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:578
virtual bool open(const std::string &name, int subimages, const ImageSpec *specs)
Definition: imageio.h:1290
void attribute(string_view name, int value)
Definition: imageio.h:405
constexpr bool defined() const
Is a region defined?
Definition: imageio.h:134
bool read_scanline(int y, int z, float *data)
Simple read_scanline reads to contiguous float pixels.
Definition: imageio.h:817
int tile_height
tile height (0 for a non-tiled image)
Definition: imageio.h:238
virtual const ImageSpec & spec(void) const
Definition: imageio.h:726
void unlock()
Definition: imageio.h:1148
Platform-related macros.
String-related utilities, all in namespace Strutil.
void attribute(string_view name, string_view value)
Definition: imageio.h:417
bool undefined() const
Definition: imageio.h:606
int zend
Definition: imageio.h:116
friend std::ostream & operator<<(std::ostream &out, const ROI &roi)
Stream output of the range.
Definition: imageio.h:190
OIIO_API bool convert_types(TypeDesc src_type, const void *src, TypeDesc dst_type, void *dst, int n)
ImageInput *(* Creator)()
Call signature of a function that creates and returns an ImageInput*.
Definition: imageio.h:1156
bool read_native_deep_tiles(int xbegin, int xend, int ybegin, int yend, int zbegin, int zend, int chbegin, int chend, DeepData &deepdata)
Definition: imageio.h:1084
OIIO_API std::string geterror()
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)
GLdouble GLdouble z
Definition: glew.h:1559
bool valid_tile_range(int xbegin, int xend, int ybegin, int yend, int zbegin, int zend)
Definition: imageio.h:502
void set_roi(const ROI &r)
Definition: imageio.h:554
OIIO_API bool wrap_black(int &coord, int origin, int width)
virtual int current_miplevel(void) const
Definition: imageio.h:761
Wrappers and utilities for multithreading.
virtual bool seek_subimage(int subimage, int miplevel)
Definition: imageio.h:774
static void auto_stride(stride_t &xstride, TypeDesc format, int nchannels)
Definition: imageio.h:384
bool(* ProgressCallback)(void *opaque_data, float portion_done)
Definition: imageio.h:101
void errorf(const char *fmt, const Args &...args) const
Definition: imageio.h:1125
ImageSpec m_spec
format spec of the currently open image
Definition: imageio.h:1570
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
size_type size() const
Definition: string_view.h:161
void error(const char *fmt, const Args &...args) const
Definition: imageio.h:1118
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
constexpr int width() const
Definition: imageio.h:137
GLuint in
Definition: glew.h:11510
constexpr imagesize_t npixels() const
Total number of pixels in the region.
Definition: imageio.h:147
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)
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
GLuint coord
Definition: glew.h:8276
constexpr bool contains(const ROI &other) const
Test if another ROI is entirely within our ROI.
Definition: imageio.h:182
static void auto_stride(stride_t &xstride, stride_t &ystride, stride_t &zstride, TypeDesc format, int nchannels, int width, int height)
Definition: imageio.h:375
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)
basic_string_view< char > string_view
Definition: core.h:426
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
Definition: glew.h:2581
GLsizei n
Definition: glew.h:4040
GLenum GLenum dst
Definition: glew.h:2410
SerialFormat
Definition: imageio.h:477
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
void attribute(string_view name, unsigned int value)
Definition: imageio.h:399
int full_width
width of the full (display) window
Definition: imageio.h:234
OIIO_API void _ImageIO_force_link()
bool deep
Contains deep data.
Definition: imageio.h:248
OIIO_API bool wrap_mirror(int &coord, int origin, int width)
ptrdiff_t stride_t
Definition: imageio.h:69
int full_y
origin of the full (display) window
Definition: imageio.h:232
virtual int open(float queuesize)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
bool read_image(float *data)
Simple read_image reads to contiguous float pixels.
Definition: imageio.h:977
float get_float_attribute(string_view name, float defaultval=0)
Definition: imageio.h:1708
void set_roi_full(const ROI &r)
Definition: imageio.h:566
ParamValue ImageIOParameter
Definition: imageio.h:106
int full_depth
depth of the full (display) window
Definition: imageio.h:236
OIIO_API void debug(string_view str)
OIIO_API bool wrap_clamp(int &coord, int origin, int width)
bool size_t_safe() const
Definition: imageio.h:352
size_t channel_bytes() const
Definition: imageio.h:282
std::string geterror() const
Definition: imageio.h:1106
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
std::vector< TypeDesc > channelformats
Optional per-channel formats.
Definition: imageio.h:243
void threads(int n)
Definition: imageio.h:1500
int x
Definition: imageio.h:227
GLfloat GLfloat p
Definition: glew.h:16321
constexpr ROI(int xbegin, int xend, int ybegin, int yend, int zbegin=0, int zend=1, int chbegin=0, int chend=10000)
Definition: imageio.h:127
GLsizei const GLchar *const * string
Definition: glew.h:1844
OIIO_API int openimageio_version()
Definition: imageio.h:115
OIIO_API bool getattribute(string_view name, TypeDesc type, void *val)
virtual int supports(string_view feature) const
Definition: imageio.h:1260
const stride_t AutoStride
Definition: imageio.h:92
bool seek_subimage(int subimage, ImageSpec &newspec)
Definition: imageio.h:792
constexpr ROI roi_union(const ROI &A, const ROI &B)
Union of two regions, the smallest region containing both.
Definition: imageio.h:201
void fmterror(const char *fmt, const Args &...args) const
Definition: imageio.h:1132
int z
origin (upper left corner) of pixel data
Definition: imageio.h:227
const void * ptr(const T *p)
Definition: format.h:3292
ParamValueList extra_attribs
Additional attributes.
Definition: imageio.h:259
ROI roi_full() const
Return full/display window for this ImageSpec as a ROI.
Definition: imageio.h:546
bool read_native_deep_scanlines(int ybegin, int yend, int z, int chbegin, int chend, DeepData &deepdata)
Definition: imageio.h:1078
int xbegin
Definition: imageio.h:116
virtual bool open(const std::string &name, ImageSpec &newspec, const ImageSpec &)
Definition: imageio.h:717
constexpr bool contains(int x, int y, int z=0, int ch=0) const
Test if the coordinate is within the ROI.
Definition: imageio.h:176
constexpr int nchannels() const
Definition: imageio.h:144
int full_z
origin of the full (display) window
Definition: imageio.h:233
int width
width of the pixel data window
Definition: imageio.h:228
virtual void close()
ROI roi() const
Return pixel data window for this ImageSpec as a ROI.
Definition: imageio.h:541
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glew.h:1254
void fmterror(const char *fmt, const Args &...args) const
Definition: imageio.h:1492
int chbegin
Definition: imageio.h:117
bool(* wrap_impl)(int &coord, int origin, int width)
Definition: imageio.h:1840
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
void fmtdebug(const char *fmt, const T1 &v1, const Args &...args)
debug output with fmt/stdformat conventions.
Definition: imageio.h:1851
void error(const char *fmt, const Args &...args) const
Definition: imageio.h:1478
int z_channel
Index of depth channel, or -1 if not known.
Definition: imageio.h:247
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
SerialVerbose
Definition: imageio.h:478
constexpr int height() const
Definition: imageio.h:138
constexpr int depth() const
Definition: imageio.h:139
ParamValueList ImageIOParameterList
Definition: imageio.h:107
int threads() const
Retrieve the current thread-spawning policy.
Definition: imageio.h:1143
void lock()
Lock, try_lock, and unlock for the internal mutex.
Definition: imageio.h:1146
int height
height of the pixel data window
Definition: imageio.h:229
int threads() const
Retrieve the current thread-spawning policy.
Definition: imageio.h:1503
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:66
const char * c_str() const
Structure to hold "deep" data – multiple samples per pixel.
Definition: deepdata.h:47
void debugf(const char *fmt, const T1 &v1, const Args &...args)
debug output with printf conventions.
Definition: imageio.h:1858
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
int zbegin
Definition: imageio.h:116
int yend
Definition: imageio.h:116
string_view get_string_attribute(string_view name, string_view defaultval=string_view())
Definition: imageio.h:1712
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:1704
GLsizei const GLfloat * value
Definition: glew.h:1849
TypeDesc format
data format of the channels
Definition: imageio.h:242
void attribute(string_view name, float value)
Definition: imageio.h:411
GLfloat GLfloat v1
Definition: glew.h:1852
void errorf(const char *fmt, const Args &...args) const
Definition: imageio.h:1485
int full_x
origin of the full (display) window
Definition: imageio.h:231
int ybegin
Definition: imageio.h:116
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glew.h:1254
int y
Definition: imageio.h:227
unsigned long long imagesize_t
Definition: imageio.h:85
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:65
virtual int supports(string_view feature) const
Definition: imageio.h:694
#define OIIO_API
Definition: export.h:91
friend constexpr bool operator!=(const ROI &a, const ROI &b)
Test inequality of two ROIs.
Definition: imageio.h:168
std::lock_guard< mutex > lock_guard
Definition: imageio.h:666