1Image I/O API Helper Classes
2############################
3
4
5
6.. _sec-typedesc:
7
8Data Type Descriptions: `TypeDesc`
9====================================
10
11There are two kinds of data that are important to OpenImageIO:
12
13* *Internal data* is in the memory of the computer, used by an
14  application program.
15* *Native file data* is what is stored in an image file itself
16  (i.e., on the "other side" of the abstraction layer that OpenImageIO
17  provides).
18
19Both internal and file data is stored in a particular *data format*
20that describes the numerical encoding of the values.  OpenImageIO
21understands several types of data encodings, and there is
22a special class, `TypeDesc`, that allows their enumeration and
23is described in the header file ``OpenImageIO/typedesc.h``.
24A `TypeDesc` describes a base data format type, aggregation into simple
25vector and matrix types, and an array length (if
26it's an array).
27
28The remainder of this section describes the C++ API for `TypeDesc`.
29See Section~\ref{sec:pythontypedesc} for the corresponding Python
30bindings.
31
32.. doxygenstruct:: OIIO::TypeDesc
33    :members:
34
35
36
37A number of ``static constexpr TypeDesc`` aliases for common types exist
38in the outer OpenImageIO scope:
39
40::
41
42    TypeUnknown TypeFloat TypeColor TypePoint TypeVector TypeNormal
43    TypeMatrix33 TypeMatrix44 TypeMatrix TypeHalf
44    TypeInt TypeUInt TypeInt16 TypeUInt16 TypeInt8 TypeUInt8
45    TypeFloat2 TypeVector2 TypeFloat4 TypeVector2i
46    TypeString TypeTimeCode TypeKeyCode
47    TypeRational TypePointer
48
49The only types commonly used to store *pixel values* in image files
50are scalars of ``UINT8``, ``UINT16``, `float`, and ``half``
51(the last only used by OpenEXR, to the best of our knowledge).
52
53Note that the `TypeDesc` (which is also used for applications other
54than images) can describe many types not used by
55OpenImageIO.  Please ignore this extra complexity; only the above simple types are understood by
56OpenImageIO as pixel storage data types, though a few others, including
57`string` and ``MATRIX44`` aggregates, are occasionally used for
58*metadata* for certain image file formats (see `sec-imageoutput-metadata`
59Sections `sec-imageoutput-metadata`, `sec-imageinput-metadata`,
60and the documentation of individual ImageIO plugins for details).
61
62
63
64
65.. _sec-stringview:
66
67Non-owning string views: ``string_view``
68==========================================
69
70.. doxygenclass:: OIIO::string_view
71    :members:
72
73|
74
75
76 .. _sec-ustring:
77
78Efficient unique strings: ``ustring``
79==========================================
80
81.. doxygenclass:: OIIO::ustring
82    :members:
83
84|
85
86.. _sec-span:
87
88Non-owning array views: ``span`` / ``cspan``
89============================================
90
91.. doxygenclass:: OIIO::span
92    :members:
93
94
95Additionally, there is a convenience template:
96
97.. cpp:type:: template<typename T> cspan = span<const T>
98
99    `cspan<T>` is a synonym for a non-mutable `span<const T>`.
100
101|
102
103
104
105 .. _sec-ROI:
106
107Rectangular region of interest: ``ROI``
108==========================================
109
110.. doxygenstruct:: OIIO::ROI
111    :members:
112
113
114In addition, there are several related helper functions that involve ROI:
115
116.. doxygenfunction:: roi_union
117
118.. doxygenfunction:: roi_intersection
119
120.. comment .. doxygenfunction:: get_roi
121
122.. cpp:function:: ROI get_roi (const ImageSpec& spec)
123                  ROI get_roi_full (const ImageSpec& spec)
124
125    Return the ROI describing spec's pixel data window (the x, y, z, width,
126    height, depth fields) or the full (display) window (the full_x, full_y,
127    full_z, full_width, full_height, full_depth fields), respectively.
128
129.. cpp:function:: void set_roi (const ImageSpec& spec, const ROI &newroi)
130    void set_roi_full (const ImageSpec& spec, const ROI &newroi)
131
132    Alters the `spec` so to make its pixel data window or the full (display)
133    window match `newroi`.
134
135
136
137 .. _sec-ImageSpec:
138
139Image Specification: ``ImageSpec``
140==========================================
141
142An ``ImageSpec`` is a structure that describes the complete
143format specification of a single image.  It contains:
144
145* The image resolution (number of pixels) and origin. This specifies
146  what is often called the "pixel data window."
147* The full size and offset of an abstract "full" or "display" window.
148  Differing full and data windows can indicate that the pixels are a crop
149  region or a larger image, or contain overscan pixels.
150* Whether the image is organized into *tiles*, and if so, the tile size.
151* The *native data format* of the pixel values (e.g., float, 8-bit
152  integer, etc.).
153* The number of color channels in the image (e.g., 3 for RGB images), names
154  of the channels, and whether any particular channels represent *alpha*
155  and *depth*.
156* A user-extensible (and format-extensible) list of any other
157  arbitrarily-named and -typed data that may help describe the image or
158  its disk representation.
159
160
161The remainder of this section describes the C++ API for ``ImageSpec``.
162See Section :ref:`sec-pythonimagespec` for the corresponding Python
163bindings.
164
165
166
167.. doxygenclass:: OIIO::ImageSpec
168    :members:
169
170|
171
172
173
174 .. _sec-DeepData:
175
176"Deep" pixel data: `DeepData`
177==========================================
178
179.. doxygenclass:: OIIO::DeepData
180    :members:
181
182|
183
184
185
186
187 .. _sec-globalattribs:
188
189Global Attributes
190==========================================
191
192These helper functions are not part of any other OpenImageIO class, they
193just exist in the OpenImageIO namespace as general utilities. (See
194:ref:`sec-pythonmiscapi` for the corresponding Python bindings.)
195
196.. doxygenfunction:: OIIO::attribute(string_view, TypeDesc, const void *)
197
198.. cpp:function:: bool OIIO::attribute(string_view name, int val)
199                  bool OIIO::attribute(string_view name, float val)
200                  bool OIIO::attribute(string_view name, string_view val)
201
202    Shortcuts for setting an attribute to a single int, float, or string.
203
204
205.. doxygenfunction:: OIIO::getattribute(string_view, TypeDesc, void *)
206
207
208.. cpp:function:: bool getattribute (string_view name, int &val)
209                  bool getattribute (string_view name, float &val)
210                  bool getattribute (string_view name, char **val)
211                  bool getattribute (string_view name, std::string& val)
212
213    Specialized versions of `getattribute()` in which the data type is
214    implied by the type of the argument (for single int, float, or string).
215    Two string versions exist: one that retrieves it as a `std::string` and
216    another that retrieves it as a `char *`. In all cases, the return value
217    is `true` if the attribute is found and the requested data type
218    conversion was legal.
219
220    EXAMPLES::
221
222        int threads;
223        OIIO::getattribute ("threads", &threads);
224        std::string path;
225        OIIO::getattribute ("plugin_searchpath", &path);
226
227.. cpp:function:: int get_int_attribute (string_view name, int defaultvalue=0)
228                  float get_float_attribute (string_view name, float defaultvalue=0)
229                  string_view get_string_attribute (string_view name, string_view defaultvalue="")
230
231    Specialized versions of `getattribute()` for common types, in which the
232    data is returned directly, and a supplied default value is returned if
233    the attribute was not found.
234
235    EXAMPLES::
236
237        int threads = OIIO::getattribute ("threads", 0);
238        string_view path = OIIO::getattribute ("plugin_searchpath");
239
240
241
242
243 .. _sec-MiscUtils:
244
245Miscellaneous Utilities
246==========================================
247
248These helper functions are not part of any other OpenImageIO class, they
249just exist in the OIIO namespace as general utilities. (See
250:ref:`sec-pythonmiscapi` for the corresponding Python bindings.)
251
252.. doxygenfunction:: openimageio_version
253
254
255.. cpp:function:: std::string OIIO::geterror ()
256
257    Returns any error string describing what went wrong if
258    `ImageInput::create()` or `ImageOutput::create()` failed (since in such
259    cases, the `ImageInput` or `ImageOutput` itself does not exist to have
260    its own `geterror()` function called). This function returns the last
261    error for this particular thread; separate threads will not clobber each
262    other's global error messages.
263
264
265
266.. doxygenfunction:: declare_imageio_format
267
268
269.. doxygenfunction:: is_imageio_format_name
270
271
272|
273
274
275 .. _sec-envvars:
276
277Environment variables
278==========================================
279
280There are a few special environment variables that can be used to control
281OpenImageIO at times that it is not convenient to set options individually from
282inside the source code.
283
284``OPENIMAGEIO_OPTIONS``
285
286    Allows you to seed the global OpenImageIO-wide options.
287
288    The value of the environment variable should be a comma-separated list
289    of *name=value* settings. If a value is a string that itself needs to
290    contain commas, it may be enclosed in single or double quotes.
291
292    Upon startup, the contents of this environment variable will be passed
293    to a call to::
294
295        OIIO::attribute ("options", value);
296
297``OPENIMAGEIO_IMAGECACHE_OPTIONS``
298
299    Allows you to seed the options for any ImageCache created.
300
301    The value of the environment variable should be a comma-separated list
302    of *name=value* settings. If a value is a string that itself needs to
303    contain commas, it may be enclosed in single or double quotes.
304
305    Upon creation of any ImageCache, the contents of this environment
306    variable will be passed to a call to::
307
308        imagecache->attribute ("options", value);
309
310
311``OPENIMAGEIO_TEXTURESYSTEM_OPTIONS``
312
313    Allows you to seed the options for any TextureSystem created.
314
315    The value of the environment variable should be a comma-separated list of
316    ``name=value`` settings. If a value is a string that itself needs to
317    contain commas, it may be enclosed in single or double quotes.
318
319    Upon creation of any TextureSystem, the contents of this environment variable
320    will be passed to a call to::
321
322        texturesys->attribute ("options", value);
323