HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
imagebufalgo.h
Go to the documentation of this file.
1 // Copyright 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 
6 // clang-format off
7 
8 #pragma once
9 #define OPENIMAGEIO_IMAGEBUFALGO_H
10 
11 #if defined(_MSC_VER)
12 // Ignore warnings about DLL exported classes with member variables that are template classes.
13 // This happens with the std::vector<T> members of PixelStats below.
14 # pragma warning (disable : 4251)
15 #endif
16 
17 #include <OpenImageIO/imageio.h>
18 #include <OpenImageIO/imagebuf.h>
19 #include <OpenImageIO/fmath.h>
20 #include <OpenImageIO/parallel.h>
21 #include <OpenImageIO/span.h>
22 
23 #include <limits>
24 
25 #if !defined(__OPENCV_CORE_TYPES_H__) && !defined(OPENCV_CORE_TYPES_H)
26 struct IplImage; // Forward declaration; used by Intel Image lib & OpenCV
27 namespace cv {
28  class Mat;
29 }
30 #endif
31 
32 
33 
35 
36 // forward declarations
37 class ColorConfig;
38 class ColorProcessor;
39 class Filter2D;
40 
41 
42 /// @defgroup ImageBufAlgo_intro (ImageBufAlgo common principles)
43 /// @{
44 ///
45 /// This section explains the general rules common to all ImageBufAlgo
46 /// functions. Only exceptions to these rules will be explained in the
47 /// subsequent listings of all the individual ImageBufAlgo functions.
48 ///
49 ///
50 /// **Return values and error messages**
51 ///
52 /// Most ImageBufAlgo functions that produce image data come in two forms:
53 ///
54 /// 1. Return an ImageBuf.
55 ///
56 /// The return value is a new ImageBuf containing the result image. In
57 /// this case, an entirely new image will be created to hold the result.
58 /// In case of error, the result image returned can have any error
59 /// conditions checked with `has_error()` and `geterror()`.
60 ///
61 /// // Method 1: Return an image result
62 /// ImageBuf fg ("fg.exr"), bg ("bg.exr");
63 /// ImageBuf dst = ImageBufAlgo::over (fg, bg);
64 /// if (dst.has_error())
65 /// std::cout << "error: " << dst.geterror() << "\n";
66 ///
67 /// 2. Pass a destination ImageBuf reference as the first parameter.
68 ///
69 /// The function is passed a *destination* ImageBuf where the results
70 /// will be stored, and the return value is a `bool` that is `true` if
71 /// the function succeeds or `false` if the function fails. Upon failure,
72 /// the destination ImageBuf (the one that is being altered) will have an
73 /// error message set.
74 ///
75 /// // Method 2: Write into an existing image
76 /// ImageBuf fg ("fg.exr"), bg ("bg.exr");
77 /// ImageBuf dst; // will be the output image
78 /// bool ok = ImageBufAlgo::over (dst, fg, bg);
79 /// if (! ok)
80 /// std::cout << "error: " << dst.geterror() << "\n";
81 ///
82 /// The first option (return an ImageBuf) is a more compact and intuitive
83 /// notation that is natural for most simple uses. But the second option
84 /// (pass an ImageBuf& referring to an existing destination) offers
85 /// additional flexibility, including more careful control over allocations,
86 /// the ability to partially overwrite regions of an existing image, and the
87 /// ability for the destination image to also be one of the input images
88 /// (for example, add(A,A,B) adds B into existing image A, with no third
89 /// image allocated at all).
90 ///
91 /// **Region of interest**
92 ///
93 /// Most ImageBufAlgo functions take an optional ROI parameter that
94 /// restricts the operation to a range in x, y, z, and channels. The default
95 /// ROI (also known as `ROI::All()`) means no region restriction -- the
96 /// whole image will be copied or altered.
97 ///
98 /// For ImageBufAlgo functions that write into a destination ImageBuf
99 /// parameter and it is already initialized (i.e. allocated with a
100 /// particular size and data type), the operation will be performed on the
101 /// pixels in the destination that overlap the ROI, leaving pixels in the
102 /// destination which are outside the ROI unaltered.
103 ///
104 /// For ImageBufAlgo functions that return an ImageBuf directly, or their
105 /// `dst` parameter that is an uninitialized ImageBuf, the ROI (if set)
106 /// determines the size of the result image. If the ROI is the default
107 /// `All`, the result image size will be the union of the pixel data windows
108 /// of the input images and have a data type determind by the data types of
109 /// the input images.
110 ///
111 /// Most ImageBufAlgo functions also respect the `chbegin` and `chend`
112 /// members of the ROI, thus restricting the channel range on which the
113 /// operation is performed. The default ROI constructor sets up the ROI
114 /// to specify that the operation should be performed on all channels of
115 /// the input image(s).
116 ///
117 /// **Constant and per-channel values**
118 ///
119 /// Many ImageBufAlgo functions take per-channel constant-valued arguments
120 /// (for example, a fill color). These parameters are passed as
121 /// `cspan<float>`. These are generally expected to have length equal to the
122 /// number of channels. But you may also pass a single float which will be
123 /// used as the value for all channels. (More generally, what is happening
124 /// is that the last value supplied is replicated for any missing channel.)
125 ///
126 /// Some ImageBufAlgo functions have parameters of type `Image_or_Const`,
127 /// which may take either an ImageBuf reference, or a per-channel constant,
128 /// or a single constant to be used for all channels.
129 ///
130 /// **Multithreading**
131 ///
132 /// All ImageBufAlgo functions take an optional `nthreads` parameter that
133 /// signifies the maximum number of threads to use to parallelize the
134 /// operation. The default value for `nthreads` is 0, which signifies that
135 /// the number of thread should be the OIIO global default set by
136 /// `OIIO::attribute()`, which itself defaults to be the detected level of
137 /// hardware concurrency (number of cores available).
138 ///
139 /// Generally you can ignore this parameter (or pass 0), meaning to use all
140 /// the cores available in order to perform the computation as quickly as
141 /// possible. The main reason to explicitly pass a different number
142 /// (generally 1) is if the application is multithreaded at a high level,
143 /// and the thread calling the ImageBufAlgo function just wants to continue
144 /// doing the computation without spawning additional threads, which might
145 /// tend to crowd out the other application threads.
146 ///
147 ///@}
148 
149 
150 
151 /// Image_or_Const: Parameter-passing helper that is a non-owning reference
152 /// to either an `ImageBuf&`, `ImageBuf*`, per-channel float constant, or a
153 /// single float constant. This lets us tame the combinatorics of functions
154 /// where each of several input parameters may be either images or constant
155 /// values.
157 public:
158  struct None {};
159  Image_or_Const (None) : m_type(NONE) {}
160  Image_or_Const (const ImageBuf &img) : m_type(IMG), m_img(&img) {}
161  Image_or_Const (const ImageBuf *img) : m_type(IMG), m_img(img) {}
162  Image_or_Const (cspan<float> val) : m_type(VAL), m_val(val) {}
163  Image_or_Const (const float& val) : m_type(VAL), m_val(val) {}
164  Image_or_Const (const std::vector<float>& val) : m_type(VAL), m_val(val) {}
165  Image_or_Const (std::initializer_list<const float> val) : m_type(VAL), m_val(val) {}
166  Image_or_Const (const float *v, size_t s) : m_type(VAL), m_val(v,s) {}
167  Image_or_Const (const float *v, int s) : m_type(VAL), m_val(v,s) {}
168 
169  bool is_img () const { return m_type == IMG; }
170  bool is_val () const { return m_type == VAL; }
171  bool is_empty () const { return m_type == NONE; }
172  const ImageBuf& img () const { return *m_img; }
173  const ImageBuf* imgptr () const { return m_img; }
174  cspan<float> val () const { return m_val; }
175 
176  void swap (Image_or_Const &other) {
177  std::swap (m_type, other.m_type);
178  std::swap (m_img, other.m_img);
179  std::swap (m_val, other.m_val);
180  }
181 private:
182  enum Contents { NONE, VAL, IMG };
183  Contents m_type;
184  const ImageBuf * m_img = nullptr;
185  cspan<float> m_val;
186 };
187 
188 
189 
190 
191 namespace ImageBufAlgo {
192 
193 // old name (DEPRECATED 1.9)
194 OIIO_DEPRECATED("use parallel_options (1.9)")
196 
197 
198 /// Create an all-black `float` image of size and channels as described by
199 /// the ROI.
200 ImageBuf OIIO_API zero (ROI roi, int nthreads=0);
201 /// Write to an existing image `dst` (allocating if it is uninitialized).
202 bool OIIO_API zero (ImageBuf &dst, ROI roi={}, int nthreads=0);
203 
204 
205 /// @defgroup fill (ImageBufAlgo::fill -- fill a region)
206 /// @{
207 ///
208 /// Fill an image region with given channel values, either returning a new
209 /// image or altering the existing `dst` image within the ROI. Note that the
210 /// values arrays start with channel 0, even if the ROI indicates that a
211 /// later channel is the first to be changed.
212 ///
213 /// Three varieties of fill() exist: (a) a single set of channel values that
214 /// will apply to the whole ROI, (b) two sets of values that will create a
215 /// linearly interpolated gradient from top to bottom of the ROI, (c) four
216 /// sets of values that will be bilinearly interpolated across all four
217 /// corners of the ROI.
218 
219 ImageBuf OIIO_API fill (cspan<float> values, ROI roi, int nthreads=0);
221  ROI roi, int nthreads=0);
222 ImageBuf OIIO_API fill (cspan<float> topleft, cspan<float> topright,
223  cspan<float> bottomleft, cspan<float> bottomright,
224  ROI roi, int nthreads=0);
226  ROI roi={}, int nthreads=0);
228  ROI roi={}, int nthreads=0);
229 bool OIIO_API fill (ImageBuf &dst, cspan<float> topleft, cspan<float> topright,
230  cspan<float> bottomleft, cspan<float> bottomright,
231  ROI roi={}, int nthreads=0);
232 /// @}
233 
234 
235 /// Create a checkerboard pattern of size given by `roi`, with origin given
236 /// by the `offset` values, checker size given by the `width`, `height`,
237 /// `depth` values, and alternating between `color1[]` and `color2[]`. The
238 /// pattern is defined in abstract "image space" independently of the pixel
239 /// data window of `dst` or the ROI.
240 ImageBuf OIIO_API checker (int width, int height, int depth,
241  cspan<float> color1, cspan<float> color2,
242  int xoffset, int yoffset, int zoffset,
243  ROI roi, int nthreads=0);
244 /// Write to an existing image `dst` (allocating if it is uninitialized).
245 bool OIIO_API checker (ImageBuf &dst, int width, int height, int depth,
246  cspan<float> color1, cspan<float> color2,
247  int xoffset=0, int yoffset=0, int zoffset=0,
248  ROI roi={}, int nthreads=0);
249 
250 
251 /// Return an image of "noise" in every pixel and channel specified by the
252 /// roi. There are several noise types to choose from, and each behaves
253 /// differently and has a different interpretation of the `A` and `B`
254 /// parameters:
255 ///
256 /// - "gaussian" adds Gaussian (normal distribution) noise values with
257 /// mean value A and standard deviation B.
258 /// - "white" adds independent uniformly distributed values on range
259 /// [A,B).
260 /// - "uniform" (synonym for "white")
261 /// - "blue" adds "blue noise" uniformly distributed on range [A,B) but
262 /// not independent; rather, they are chosen for good spectral
263 /// properties for sampling and dither.
264 /// - "salt" changes to value A a portion of pixels given by B.
265 ///
266 /// If the `mono` flag is true, a single noise value will be applied to all
267 /// channels specified by `roi`, but if `mono` is false, a separate noise
268 /// value will be computed for each channel in the region.
269 ///
270 /// The random number generator is actually driven by a hash on the "image
271 /// space" coordinates and channel, independently of the pixel data window
272 /// of `dst` or the ROI. Choosing different seed values will result in a
273 /// different pattern, but for the same seed value, the noise at a given
274 /// pixel coordinate (x,y,z) channel c will is completely deterministic and
275 /// repeatable.
277  float A = 0.0f, float B = 0.1f, bool mono = false,
278  int seed = 0, ROI roi={}, int nthreads=0);
279 /// Write to an existing image `dst` (allocating if it is uninitialized).
280 bool OIIO_API noise (ImageBuf &dst, string_view noisetype,
281  float A = 0.0f, float B = 0.1f, bool mono = false,
282  int seed = 0, ROI roi={}, int nthreads=0);
283 
284 
285 /// Return a const reference to a periodic bluenoise texture with float data
286 /// in 4 channels that are uncorrelated to each other. Note that unlike most
287 /// other ImageBufAlgo functions, it does not return an ImageBuf by value, but
288 /// by const reference.
290 
291 
292 /// Render a single point at (x,y) of the given color "over" the existing
293 /// image `dst`. If there is no alpha channel, the color will be written
294 /// unconditionally (as if the alpha is 1.0).
295 bool OIIO_API render_point (ImageBuf &dst, int x, int y,
296  cspan<float> color=1.0f,
297  ROI roi={}, int nthreads=0);
298 
299 /// Render a line from pixel (`x1`,`y1`) to (`x2`,`y2`) into `dst`, doing an
300 /// "over" of the color (if it includes an alpha channel) onto the existing
301 /// data in `dst`. The `color` should include as many values as
302 /// `roi.chend-1`. The ROI can be used to limit the pixel area or channels
303 /// that are modified, and default to the entirety of `dst`. If
304 /// `skip_first_point` is `true`, the first point (`x1`, `y1`) will not be
305 /// drawn (this can be helpful when drawing poly-lines, to avoid
306 /// double-rendering of the vertex positions).
307 bool OIIO_API render_line (ImageBuf &dst, int x1, int y1, int x2, int y2,
308  cspan<float> color=1.0f,
309  bool skip_first_point = false,
310  ROI roi={}, int nthreads=0);
311 
312 /// Render a filled or unfilled box with corners at pixels (`x1`,`y1`) and
313 /// (`x2`,`y2`) into `dst`, doing an "over" of the color (if it includes an
314 /// alpha channel) onto the existing data in `dst`. The `color` must include
315 /// as many values as `roi.chend-1`. The ROI can be used to limit the pixel
316 /// area or channels that are modified, and default to the entirety of
317 /// `dst`. If `fill` is `true`, the box will be completely filled in,
318 /// otherwise only its outlien will be drawn.
319 bool OIIO_API render_box (ImageBuf &dst, int x1, int y1, int x2, int y2,
320  cspan<float> color=1.0f, bool fill = false,
321  ROI roi={}, int nthreads=0);
322 
323 
324 enum class TextAlignX { Left, Right, Center };
325 enum class TextAlignY { Baseline, Top, Bottom, Center };
326 
327 /// Render a text string (encoded as UTF-8) into image `dst`. If the `dst`
328 /// image is not yet initialized, it will be initialized to be a black
329 /// background exactly large enough to contain the rasterized text. If
330 /// `dst` is already initialized, the text will be rendered into the
331 /// existing image by essentially doing an "over" of the character into the
332 /// existing pixel data.
333 ///
334 /// @param dst
335 /// Destination ImageBuf -- text is rendered into this image.
336 /// @param x/y
337 /// The position to place the text.
338 /// @param text
339 /// The text to draw. Linefeed (`\n`) characters are respected
340 /// as indications that the text spans multiple rows.
341 /// @param fontsize/fontname
342 /// Size and name of the font. If the name is not a full
343 /// pathname to a font file, it will search for a matching font,
344 /// defaulting to some reasonable system font if not supplied at
345 /// all), and with a nominal height of fontsize (in pixels).
346 /// @param textcolor
347 /// Color for drawing the text, defaulting to opaque white
348 /// (1.0,1.0,...) in all channels if not supplied. If provided,
349 /// it is expected to point to a float array of length at least
350 /// equal to `R.spec().nchannels`, or defaults will be chosen
351 /// for you).
352 /// @param alignx/aligny
353 /// The default behavior is to align the left edge of the
354 /// character baseline to (`x`,`y`). Optionally, `alignx` and
355 /// `aligny` can override the alignment behavior, with
356 /// horizontal alignment choices of TextAlignX::Left, Right, and
357 /// Center, and vertical alignment choices of Baseline, Top,
358 /// Bottom, or Center.
359 /// @param shadow
360 /// If nonzero, a "drop shadow" of this radius will be used to
361 /// make the text look more clear by dilating the alpha channel
362 /// of the composite (makes a black halo around the characters).
363 ///
364 /// Note that any named fonts (if not a full pathname) will search for the
365 /// fonts in the following places: (a) any directories named in the global
366 /// "font_searchpath" attribute or the `$OPENIMAGEIO_FONTS` environment
367 /// variable; (b) any font-related subdirectories (`fonts`, `Fonts`,
368 /// `share/fonts`, or `Library/Fonts`) underneath the directories in
369 /// environment variables `$HOME`, `$SystemRoot`, `$OpenImageIO_ROOT`; (c) a
370 /// number of common system font areas, including `/usr/share/fonts`,
371 /// `/Library/fonts`, and `C:/Windows/fonts`; (d) in fonts directories one
372 /// level up from the place where the currently running binary lives.
373 bool OIIO_API render_text (ImageBuf &dst, int x, int y, string_view text,
374  int fontsize=16, string_view fontname="",
375  cspan<float> textcolor = 1.0f,
376  TextAlignX alignx = TextAlignX::Left,
378  int shadow = 0, ROI roi={}, int nthreads=0);
379 
380 
381 /// The helper function `text_size()` merely computes the dimensions of the
382 /// text, returning it as an ROI relative to the left side of the baseline
383 /// of the first character. Only the `x` and `y` dimensions of the ROI will
384 /// be used. The x dimension runs from left to right, and y runs from top to
385 /// bottom (image coordinates). For a failure (such as an invalid font
386 /// name), the ROI will return `false` if you call its `defined()` method.
387 /// The `text` may contain linefeed characters to designate multiple lines
388 /// of text.
389 ROI OIIO_API text_size (string_view text, int fontsize=16,
390  string_view fontname="");
391 
392 
393 /// Generic channel shuffling: return (or store in `dst`) a copy of `src`,
394 /// but with channels in the order `channelorder[0..nchannels-1]` (or set to
395 /// a constant value, designated by `channelorder[i] = -1` and having the
396 /// fill value in `channelvalues[i]`. In-place operation is allowed (i.e.,
397 /// `dst` and `src` the same image, but an extra copy will occur).
398 ///
399 /// @param nchannels
400 /// The total number of channels that will be set up in the
401 /// `dst` image.
402 /// @param channelorder
403 /// For each channel in `dst`, the index of he `src` channel
404 /// from which to copy. Any `channelorder[i]` < 0 indicates that
405 /// the channel `i` should be filled with constant value
406 /// `channelvalues[i]` rather than copy any channel from `src`.
407 /// If `channelorder` itself is empty, the implied channel order
408 /// will be `{0, 1, ..., nchannels-1}`, meaning that it's only
409 /// renaming, truncating, or extending channels, not reordering
410 /// the channels that are already present.
411 /// @param channelvalues Fill values for color channels in which
412 /// `channelorder[i]` < 0. This can be empty if no channels are
413 /// to be filled with constant values.
414 /// @param newchannelnames
415 /// An array of new channel names. Channels for which this
416 /// specifies an empty string will have their name taken from
417 /// the `src` channel that was copied. If `newchannelnames` is
418 /// entirely empty, all channel names will simply be copied from
419 /// `src`.
420 /// @param shuffle_channel_names
421 /// If true, the channel names will be taken from the
422 /// corresponding channels of the source image -- be careful with
423 /// this, shuffling both channel ordering and their names could
424 /// result in no semantic change at all, if you catch the drift.
425 /// If false (the default), the resulting `dst` image will have
426 /// default channel names in the usual order ("R", "G", etc.).
427 ///
429  int nchannels, cspan<int> channelorder,
430  cspan<float> channelvalues={},
431  cspan<std::string> newchannelnames={},
432  bool shuffle_channel_names=false, int nthreads=0);
433 /// Write to an existing image `dst` (allocating if it is uninitialized).
434 bool OIIO_API channels (ImageBuf &dst, const ImageBuf &src,
435  int nchannels, cspan<int> channelorder,
436  cspan<float> channelvalues={},
437  cspan<std::string> newchannelnames={},
438  bool shuffle_channel_names=false, int nthreads=0);
439 
440 
441 /// Append the channels of `A` and `B` together into `dst` over the region
442 /// of interest. If the region passed is uninitialized (the default), it
443 /// will be interpreted as being the union of the pixel windows of `A` and `B`
444 /// (and all channels of both images). If `dst` is not already initialized,
445 /// it will be resized to be big enough for the region.
447  ROI roi={}, int nthreads=0);
448 /// Write to an existing image `dst` (allocating if it is uninitialized).
449 bool OIIO_API channel_append (ImageBuf &dst, const ImageBuf &A,
450  const ImageBuf &B, ROI roi={}, int nthreads=0);
451 
452 
453 /// Return the specified region of pixels of `src` as specified by `roi`
454 /// (which will default to the whole of `src`, optionally with the pixel
455 /// type overridden by convert (if it is not `TypeUnknown`).
456 ImageBuf OIIO_API copy (const ImageBuf &src, TypeDesc convert=TypeUnknown,
457  ROI roi={}, int nthreads=0);
458 /// Write to an existing image `dst` (allocating if it is uninitialized).
459 /// If `dst` is not already initialized, it will be set to the same size as
460 /// `roi` (defaulting to all of `src`)
461 bool OIIO_API copy (ImageBuf &dst, const ImageBuf &src, TypeDesc convert=TypeUnknown,
462  ROI roi={}, int nthreads=0);
463 
464 
465 /// Return the specified region of `src` as an image, without altering its
466 /// position in the image plane.
467 ///
468 /// Pixels from `src` which are outside `roi` will not be copied, and new
469 /// black pixels will be added for regions of `roi` which were outside the
470 /// data window of `src`.
471 ///
472 /// Note that the `crop` operation does not actually move the pixels on the
473 /// image plane or adjust the full/display window; it merely restricts which
474 /// pixels are copied from `src` to `dst`. (Note the difference compared to
475 /// `cut()`).
476 ImageBuf OIIO_API crop (const ImageBuf &src, ROI roi={}, int nthreads=0);
477 /// Write to an existing image `dst` (allocating if it is uninitialized).
478 bool OIIO_API crop (ImageBuf &dst, const ImageBuf &src, ROI roi={}, int nthreads=0);
479 
480 
481 /// Return the designated region of `src`, but repositioned to the image
482 /// origin and with the full/display window set to exactly cover the new
483 /// pixel data window. (Note the difference compared to `crop()`).
484 ImageBuf OIIO_API cut (const ImageBuf &src, ROI roi={}, int nthreads=0);
485 /// Write to an existing image `dst` (allocating if it is uninitialized).
486 bool OIIO_API cut (ImageBuf &dst, const ImageBuf &src, ROI roi={}, int nthreads=0);
487 
488 
489 /// Copy `src` pixels within `srcroi` into the `dst` image, offset so that
490 /// source location (0,0,0) will be copied to destination location
491 /// (`xbegin`,`ybegin`,`zbegin`). If the `srcroi` is `ROI::All()`, the
492 /// entirety of the data window of `src` will be used. It will copy into
493 /// `channels[chbegin...]`, as many channels as are described by srcroi.
494 /// Pixels or channels of `src` inside `srcroi` will replace the
495 /// corresponding destination pixels entirely, whereas `src` pixels outside
496 /// of `srcroi` will not be copied and the corresponding offset pixels of
497 /// `dst` will not be altered.
498 bool OIIO_API paste (ImageBuf &dst, int xbegin, int ybegin,
499  int zbegin, int chbegin, const ImageBuf &src,
500  ROI srcroi={}, int nthreads=0);
501 
502 
503 /// @defgroup rotateN (rotate in 90 degree increments)
504 /// @{
505 ///
506 /// Return (or copy into `dst`) a rotated copy of the image pixels of `src`,
507 /// in 90 degree increments. Pictorially:
508 ///
509 /// rotate90 rotate180 rotate270
510 /// ----------- ----------- -----------
511 /// AB --> CA AB --> DC AB --> BD
512 /// CD DB CD BA CD AC
513 ///
514 
515 ImageBuf OIIO_API rotate90 (const ImageBuf &src, ROI roi={}, int nthreads=0);
516 ImageBuf OIIO_API rotate180 (const ImageBuf &src, ROI roi={}, int nthreads=0);
517 ImageBuf OIIO_API rotate270 (const ImageBuf &src, ROI roi={}, int nthreads=0);
518 bool OIIO_API rotate90 (ImageBuf &dst, const ImageBuf &src,
519  ROI roi={}, int nthreads=0);
520 bool OIIO_API rotate180 (ImageBuf &dst, const ImageBuf &src,
521  ROI roi={}, int nthreads=0);
522 bool OIIO_API rotate270 (ImageBuf &dst, const ImageBuf &src,
523  ROI roi={}, int nthreads=0);
524 /// @}
525 
526 
527 /// @defgroup flip-flop-transpose (flip/flop/transpose: mirroring)
528 /// @{
529 ///
530 /// Return (or copy into `dst`) a subregion of `src`, but with the scanlines
531 /// exchanged vertically (flip), or columns exchanged horizontally (flop),
532 /// or transposed across the diagonal by swapping rows for columns
533 /// (transpose) within the display/full window. In other words,
534 ///
535 /// flip flop transpose
536 /// ----------- ----------- -----------
537 /// AB --> CD AB --> BA AB --> AC
538 /// CD AB CD DC CD BD
539 ///
540 
541 ImageBuf OIIO_API flip (const ImageBuf &src, ROI roi={}, int nthreads=0);
542 ImageBuf OIIO_API flop (const ImageBuf &src, ROI roi={}, int nthreads=0);
543 ImageBuf OIIO_API transpose (const ImageBuf &src, ROI roi={}, int nthreads=0);
544 bool OIIO_API flip (ImageBuf &dst, const ImageBuf &src,
545  ROI roi={}, int nthreads=0);
546 bool OIIO_API flop (ImageBuf &dst, const ImageBuf &src,
547  ROI roi={}, int nthreads=0);
548 bool OIIO_API transpose (ImageBuf &dst, const ImageBuf &src,
549  ROI roi={}, int nthreads=0);
550 /// @}
551 
552 
553 /// Return (or store into `dst`) a copy of `src`, but with whatever seties
554 /// of rotations, flips, or flops are necessary to transform the pixels into
555 /// the configuration suggested by the "Orientation" metadata of the image
556 /// (and the "Orientation" metadata is then set to 1, ordinary orientation).
557 ImageBuf OIIO_API reorient (const ImageBuf &src, int nthreads=0);
558 /// Write to an existing image `dst` (allocating if it is uninitialized).
559 bool OIIO_API reorient (ImageBuf &dst, const ImageBuf &src, int nthreads=0);
560 
561 
562 /// Return a subregion of `src`, but circularly shifting by the given
563 /// amount. To clarify, the circular shift of [0,1,2,3,4,5] by +2 is
564 /// [4,5,0,1,2,3].
566  int xshift, int yshift, int zshift=0,
567  ROI roi={}, int nthreads=0);
568 /// Write to an existing image `dst` (allocating if it is uninitialized).
569 bool OIIO_API circular_shift (ImageBuf &dst, const ImageBuf &src,
570  int xshift, int yshift, int zshift=0,
571  ROI roi={}, int nthreads=0);
572 
573 
574 /// @defgroup rotate (rotate: arbitrary rotation)
575 /// @{
576 ///
577 /// Rotate the `src` image by the `angle` (in radians, with positive angles
578 /// clockwise). When `center_x` and `center_y` are supplied, they denote the
579 /// center of rotation; in their absence, the rotation will be about the
580 /// center of the image's display window.
581 ///
582 /// Only the pixels (and channels) of `dst` that are specified by `roi` will
583 /// be copied from the rotated `src`; the default `roi` is to alter all the
584 /// pixels in `dst`. If `dst` is uninitialized, it will be resized to be an
585 /// ImageBuf large enough to hold the rotated image if recompute_roi is
586 /// true, or will have the same ROI as `src` if `recompute_roi` is `false`.
587 /// It is an error to pass both an uninitialized `dst` and an undefined
588 /// `roi`.
589 ///
590 /// The filter is used to weight the `src` pixels falling underneath it for
591 /// each `dst` pixel. The caller may specify a reconstruction filter by
592 /// name and width (expressed in pixels units of the `dst` image), or
593 /// `rotate()` will choose a reasonable default high-quality default filter
594 /// (lanczos3) if the empty string is passed, and a reasonable filter width
595 /// if `filterwidth` is 0. (Note that some filter choices only make sense
596 /// with particular width, in which case this filterwidth parameter may be
597 /// ignored.)
598 
599 ImageBuf OIIO_API rotate (const ImageBuf &src, float angle,
600  string_view filtername = string_view(),
601  float filterwidth = 0.0f, bool recompute_roi = false,
602  ROI roi={}, int nthreads=0);
603 ImageBuf OIIO_API rotate (const ImageBuf &src, float angle,
604  Filter2D *filter, bool recompute_roi = false,
605  ROI roi={}, int nthreads=0);
606 ImageBuf OIIO_API rotate (const ImageBuf &src,
607  float angle, float center_x, float center_y,
608  string_view filtername = string_view(),
609  float filterwidth = 0.0f, bool recompute_roi = false,
610  ROI roi={}, int nthreads=0);
611 ImageBuf OIIO_API rotate (const ImageBuf &src,
612  float angle, float center_x, float center_y,
613  Filter2D *filter, bool recompute_roi = false,
614  ROI roi={}, int nthreads=0);
615 bool OIIO_API rotate (ImageBuf &dst, const ImageBuf &src, float angle,
616  string_view filtername = string_view(),
617  float filterwidth = 0.0f, bool recompute_roi = false,
618  ROI roi={}, int nthreads=0);
619 bool OIIO_API rotate (ImageBuf &dst, const ImageBuf &src, float angle,
620  Filter2D *filter, bool recompute_roi = false,
621  ROI roi={}, int nthreads=0);
622 bool OIIO_API rotate (ImageBuf &dst, const ImageBuf &src,
623  float angle, float center_x, float center_y,
624  string_view filtername = string_view(),
625  float filterwidth = 0.0f, bool recompute_roi = false,
626  ROI roi={}, int nthreads=0);
627 bool OIIO_API rotate (ImageBuf &dst, const ImageBuf &src,
628  float angle, float center_x, float center_y,
629  Filter2D *filter, bool recompute_roi = false,
630  ROI roi={}, int nthreads=0);
631 /// @}
632 
633 
634 /// @defgroup resize (resize: resize the image with nicely filtered results)
635 /// @{
636 ///
637 /// Set `dst`, over the region of interest, to be a resized version of the
638 /// corresponding portion of `src` (mapping such that the "full" image
639 /// window of each correspond to each other, regardless of resolution).
640 /// If `dst` is not yet initialized, it will be sized according to `roi`.
641 ///
642 /// The caller may either (a) explicitly pass a reconstruction `filter`, or
643 /// (b) specify one by `filtername` and `filterwidth`. If `filter` is
644 /// `nullptr` or if `filtername` is the empty string `resize()` will choose
645 /// a reasonable high-quality default (blackman-harris when upsizing,
646 /// lanczos3 when downsizing). The filter is used to weight the `src`
647 /// pixels falling underneath it for each `dst` pixel; the filter's size is
648 /// expressed in pixel units of the `dst` image.
649 
650 ImageBuf OIIO_API resize (const ImageBuf &src,
651  string_view filtername = "", float filterwidth=0.0f,
652  ROI roi={}, int nthreads=0);
653 ImageBuf OIIO_API resize (const ImageBuf &src, Filter2D *filter,
654  ROI roi={}, int nthreads=0);
655 bool OIIO_API resize (ImageBuf &dst, const ImageBuf &src,
656  string_view filtername = "", float filterwidth=0.0f,
657  ROI roi={}, int nthreads=0);
658 bool OIIO_API resize (ImageBuf &dst, const ImageBuf &src, Filter2D *filter,
659  ROI roi={}, int nthreads=0);
660 /// @}
661 
662 
663 /// Set `dst`, over the region of interest, to be a resized version of the
664 /// corresponding portion of `src` (mapping such that the "full" image
665 /// window of each correspond to each other, regardless of resolution). If
666 /// `dst` is not yet initialized, it will be sized according to `roi`.
667 ///
668 /// Unlike `ImageBufAlgo::resize()`, `resample()` does not take a filter; it
669 /// just samples either with a bilinear interpolation (if `interpolate` is
670 /// `true`, the default) or uses the single "closest" pixel (if
671 /// `interpolate` is `false`). This makes it a lot faster than a proper
672 /// `resize()`, though obviously with lower quality (aliasing when
673 /// downsizing, pixel replication when upsizing).
674 ///
675 /// For "deep" images, this function returns copies the closest source pixel
676 /// needed, rather than attempting to interpolate deep pixels (regardless of
677 /// the value of `interpolate`).
678 ImageBuf OIIO_API resample (const ImageBuf &src, bool interpolate = true,
679  ROI roi={}, int nthreads=0);
680 /// Write to an existing image `dst` (allocating if it is uninitialized).
681 bool OIIO_API resample (ImageBuf &dst, const ImageBuf &src,
682  bool interpolate = true, ROI roi={}, int nthreads=0);
683 
684 
685 /// @defgroup fit (fit: resize the image with filtering, into a fixed size)
686 /// @{
687 ///
688 /// Fit src into `dst` (to a size specified by `roi`, if `dst` is not
689 /// initialized), resizing but preserving its original aspect ratio. Thus,
690 /// it will resize to be the largest size with the same aspect ratio that
691 /// can fit inside the region, but will not stretch to completely fill it in
692 /// both dimensions.
693 ///
694 /// The `fillmode` determines which of several methods will be used to
695 /// determine how the image will fill the new frame, if its aspect ratio
696 /// does not precisely match the original source aspect ratio:
697 /// - "width" exactly fills the width of the new frame, either cropping
698 /// or letterboxing the height if it isn't precisely the right size to
699 /// preserve the original aspect ratio.
700 /// - "height" exactly fills the height of the new frame, either cropping
701 /// or letterboxing the width if it isn't precisely the right size to
702 /// preserve the original aspect ratio.
703 /// - "letterbox" (the default) chooses whichever of "width" or "height"
704 /// will maximally fill the new frame with no image data lost (it will
705 /// only letterbox, never crop).
706 ///
707 /// If `exact` is true, will result in an exact match on aspect ratio and
708 /// centering (partial pixel shift if necessary), whereas exact=false
709 /// will only preserve aspect ratio and centering to the precision of a
710 /// whole pixel.
711 ///
712 /// The filter is used to weight the `src` pixels falling underneath it for
713 /// each `dst` pixel. The caller may specify a reconstruction filter by
714 /// name and width (expressed in pixels units of the `dst` image), or
715 /// `rotate()` will choose a reasonable default high-quality default filter
716 /// (lanczos3) if the empty string is passed, and a reasonable filter width
717 /// if `filterwidth` is 0. (Note that some filter choices only make sense
718 /// with particular width, in which case this filterwidth parameter may be
719 /// ignored.)
720 ///
721 ImageBuf OIIO_API fit (const ImageBuf &src,
722  string_view filtername = "", float filterwidth=0.0f,
723  string_view fillmode="letterbox", bool exact=false,
724  ROI roi={}, int nthreads=0);
725 ImageBuf OIIO_API fit (const ImageBuf &src, Filter2D *filter,
726  string_view fillmode="letterbox", bool exact=false,
727  ROI roi={}, int nthreads=0);
728 bool OIIO_API fit (ImageBuf &dst, const ImageBuf &src,
729  string_view filtername = "", float filterwidth=0.0f,
730  string_view fillmode="letterbox", bool exact=false,
731  ROI roi={}, int nthreads=0);
732 bool OIIO_API fit (ImageBuf &dst, const ImageBuf &src, Filter2D *filter,
733  string_view fillmode="letterbox", bool exact=false,
734  ROI roi={}, int nthreads=0);
735 
736 #ifndef DOXYGEN_SHOULD_SKIP_THIS
737 // DEPRECATED(2.3): old versions lacking the "fillmode" parameter
738 ImageBuf OIIO_API fit (const ImageBuf &src,
739  string_view filtername, float filterwidth,
740  bool exact, ROI roi={}, int nthreads=0);
741 ImageBuf OIIO_API fit (const ImageBuf &src, Filter2D *filter,
742  bool exact, ROI roi={}, int nthreads=0);
743 bool OIIO_API fit (ImageBuf &dst, const ImageBuf &src,
744  string_view filtername, float filterwidth,
745  bool exact, ROI roi={}, int nthreads=0);
746 bool OIIO_API fit (ImageBuf &dst, const ImageBuf &src, Filter2D *filter,
747  bool exact, ROI roi={}, int nthreads=0);
748 #endif
749 /// @}
750 
751 
752 /// @defgroup warp (warp: arbitrary warp by a 3x3 matrix)
753 /// @{
754 ///
755 /// Warp the `src` image using the supplied 3x3 transformation matrix.
756 ///
757 /// Only the pixels (and channels) of `dst` that are specified by `roi` will
758 /// be copied from the warped `src`; the default roi is to alter all the
759 /// pixels in dst. If `dst` is uninitialized, it will be sized to be an
760 /// ImageBuf large enough to hold the warped image if recompute_roi is true,
761 /// or will have the same ROI as src if recompute_roi is false. It is an
762 /// error to pass both an uninitialized `dst` and an undefined `roi`.
763 ///
764 /// The caller may explicitly pass a reconstruction filter, or specify one
765 /// by name and size, or if the name is the empty string `resize()` will
766 /// choose a reasonable high-quality default if `nullptr` is passed. The
767 /// filter is used to weight the `src` pixels falling underneath it for each
768 /// `dst` pixel; the filter's size is expressed in pixel units of the `dst`
769 /// image.
770 
771 ImageBuf OIIO_API warp (const ImageBuf &src, const Imath::M33f &M,
772  string_view filtername = string_view(),
773  float filterwidth = 0.0f, bool recompute_roi = false,
775  ROI roi={}, int nthreads=0);
776 ImageBuf OIIO_API warp (const ImageBuf &src, const Imath::M33f &M,
777  const Filter2D *filter, bool recompute_roi = false,
779  ROI roi = {}, int nthreads=0);
780 bool OIIO_API warp (ImageBuf &dst, const ImageBuf &src, const Imath::M33f &M,
781  string_view filtername = string_view(),
782  float filterwidth = 0.0f, bool recompute_roi = false,
784  ROI roi={}, int nthreads=0);
785 bool OIIO_API warp (ImageBuf &dst, const ImageBuf &src, const Imath::M33f &M,
786  const Filter2D *filter, bool recompute_roi = false,
788  ROI roi = {}, int nthreads=0);
789 /// @}
790 
791 
792 /// Compute per-pixel sum `A + B`, returning the result image.
793 ///
794 /// `A` and `B` may each either be an `ImageBuf&`, or a `cspan<float>`
795 /// giving a per- channel constant, or a single constant used for all
796 /// channels. (But at least one must be an image.)
798  ROI roi={}, int nthreads=0);
799 /// Write to an existing image `dst` (allocating if it is uninitialized).
801  ROI roi={}, int nthreads=0);
802 
803 
804 /// Compute per-pixel signed difference `A - B`, returning the result image.
805 ///
806 /// `A` and `B` may each either be an `ImageBuf&`, or a `cspan<float>`
807 /// giving a per-channel constant, or a single constant used for all
808 /// channels. (But at least one must be an image.)
810  ROI roi={}, int nthreads=0);
811 /// Write to an existing image `dst` (allocating if it is uninitialized).
813  ROI roi={}, int nthreads=0);
814 
815 
816 /// Compute per-pixel absolute difference `abs(A - B)`, returning the result
817 /// image.
818 ///
819 /// `A` and `B` may each either be an `ImageBuf&`, or a `cspan<float>`
820 /// giving a per- channel constant, or a single constant used for all
821 /// channels. (But at least one must be an image.)
823  ROI roi={}, int nthreads=0);
824 /// Write to an existing image `dst` (allocating if it is uninitialized).
826  ROI roi={}, int nthreads=0);
827 
828 
829 /// Compute per-pixel absolute value `abs(A)`, returning the result image.
830 ImageBuf OIIO_API abs (const ImageBuf &A, ROI roi={}, int nthreads=0);
831 /// Write to an existing image `dst` (allocating if it is uninitialized).
832 bool OIIO_API abs (ImageBuf &dst, const ImageBuf &A, ROI roi={}, int nthreads=0);
833 
834 
835 /// Compute per-pixel product `A * B`, returning the result image.
836 ///
837 /// Either both `A` and `B` are images, or one is an image and the other is
838 /// a `cspan<float>` giving a per-channel constant or a single constant
839 /// used for all channels.
841  ROI roi={}, int nthreads=0);
842 /// Write to an existing image `dst` (allocating if it is uninitialized).
844  ROI roi={}, int nthreads=0);
845 
846 
847 /// Compute per-pixel division `A / B`, returning the result image.
848 /// Division by zero is defined to result in zero.
849 ///
850 /// `A` is always an image, and `B` is either an image or a `cspan<float>`
851 /// giving a per-channel constant or a single constant used for all
852 /// channels.
854  ROI roi={}, int nthreads=0);
855 /// Write to an existing image `dst` (allocating if it is uninitialized).
857  ROI roi={}, int nthreads=0);
858 
859 
860 /// Compute per-pixel multiply-and-add `A * B + C`, returning the result
861 /// image.
862 ///
863 /// `A`, `B`, and `C` are each either an image, or a `cspan<float>` giving a
864 /// per-channel constant or a single constant used for all channels. (Note:
865 /// at least one must be an image.)
867  Image_or_Const C, ROI roi={}, int nthreads=0);
868 /// Write to an existing image `dst` (allocating if it is uninitialized).
870  Image_or_Const C, ROI roi={}, int nthreads=0);
871 
872 
873 /// Return the composite of `A` over `B` using the Porter/Duff definition of
874 /// "over", returning true upon success and false for any of a variety of
875 /// failures (as described below).
876 ///
877 /// `A` and `B` (and dst, if already defined/allocated) must have valid
878 /// alpha channels identified by their ImageSpec `alpha_channel` field. If`
879 /// A` or `B` do not have alpha channels (as determined by those rules) or
880 /// if the number of non-alpha channels do not match between `A` and `B`,
881 /// `over()` will fail, returning false.
882 ///
883 /// If `dst` is not already an initialized ImageBuf, it will be sized to
884 /// encompass the minimal rectangular pixel region containing the union of
885 /// the defined pixels of `A` and `B`, and with a number of channels equal
886 /// to the number of non-alpha channels of `A` and `B`, plus an alpha
887 /// channel. However, if `dst` is already initialized, it will not be
888 /// resized, and the "over" operation will apply to its existing pixel data
889 /// window. In this case, dst must have an alpha channel designated and
890 /// must have the same number of non-alpha channels as `A` and `B`,
891 /// otherwise it will fail, returning false.
892 ///
893 /// `A`, `B`, and `dst` need not perfectly overlap in their pixel data
894 /// windows; pixel values of `A` or `B` that are outside their respective
895 /// pixel data window will be treated as having "zero" (0,0,0...) value.
896 ImageBuf OIIO_API over (const ImageBuf &A, const ImageBuf &B,
897  ROI roi={}, int nthreads=0);
898 /// Write to an existing image `dst` (allocating if it is uninitialized).
899 bool OIIO_API over (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
900  ROI roi={}, int nthreads=0);
901 
902 
903 /// Just like `ImageBufAlgo::over()`, but inputs `A` and `B` must have
904 /// designated 'z' channels, and on a pixel-by-pixel basis, the z values
905 /// will determine which of `A` or `B` will be considered the foreground or
906 /// background (lower z is foreground). If `z_zeroisinf` is true, then z=0
907 /// values will be treated as if they are infinitely far away.
908 ImageBuf OIIO_API zover (const ImageBuf &A, const ImageBuf &B,
909  bool z_zeroisinf=false, ROI roi={}, int nthreads=0);
910 /// Write to an existing image `dst` (allocating if it is uninitialized).
911 bool OIIO_API zover (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
912  bool z_zeroisinf=false, ROI roi={}, int nthreads=0);
913 
914 
915 
916 /// Compute per-pixel value inverse `1.0 - A` (which you can think of as
917 /// roughly meaning switching white and black), returning the result image.
918 ///
919 /// Tips for callers: (1) You probably want to set `roi` to restrict the
920 /// operation to only the color channels, and not accidentally include
921 /// alpha, z, or others. (2) There may be situations where you want to
922 /// `unpremult()` before the invert, then `premult()` the result, so that
923 /// you are computing the inverse of the unmasked color.
924 ImageBuf OIIO_API invert (const ImageBuf &A, ROI roi={}, int nthreads=0);
925 /// Write to an existing image `dst` (allocating if it is uninitialized).
926 bool OIIO_API invert (ImageBuf &dst, const ImageBuf &A, ROI roi={}, int nthreads=0);
927 
928 
929 /// Compute per-pixel raise-to-power `A ^ B`. returning the result image. It
930 /// is permitted for `dst` and `A` to be the same image.
931 ///
932 /// `A` is always an image, and `B` is either an image or a `cspan<float>`
933 /// giving a per-channel constant or a single constant used for all
934 /// channels.
936  ROI roi={}, int nthreads=0);
937 /// Write to an existing image `dst` (allocating if it is uninitialized).
938 bool OIIO_API pow (ImageBuf &dst, const ImageBuf &A, cspan<float> B,
939  ROI roi={}, int nthreads=0);
940 
941 
942 /// Converts a multi-channel image into a one-channel image via a weighted
943 /// sum of channels:
944 ///
945 /// (channel[0]*weight[0] + channel[1]*weight[1] + ...)
946 ///
947 /// returning the resulting one-channel image. The `weights`, if not
948 /// supplied, default to `{ 1, 1, 1, ... }`).
949 ImageBuf OIIO_API channel_sum (const ImageBuf &src, cspan<float> weights=1.0f,
950  ROI roi={}, int nthreads=0);
951 /// Write to an existing image `dst` (allocating if it is uninitialized).
952 bool OIIO_API channel_sum (ImageBuf &dst, const ImageBuf &src,
953  cspan<float> weights=1.0f,
954  ROI roi={}, int nthreads=0);
955 
956 
957 /// @defgroup maxminclamp (Maximum, minimum, clamping)
958 /// @{
959 ///
960 /// `max()` and `min()` take the pixel-by-pixel, channel-by-channel
961 /// maximum and minimum of two images, or of an image and a constant.
962 ///
963 /// `clamp()` restricts values of an image to the range between per-channel
964 /// minimum and maximum constant values.
965 
966 
967 /// Compute per-pixel `max(A, B)`, returning the result image.
968 ///
969 /// Either both `A` and `B` are images, or one is an image and the other is
970 /// a `cspan<float>` giving a per-channel constant or a single constant
971 /// used for all channels.
973  ROI roi={}, int nthreads=0);
974 /// Write to an existing image `dst` (allocating if it is uninitialized).
976  ROI roi={}, int nthreads=0);
977 
978 /// Compute per-pixel `min(A, B)`, returning the result image.
979 ///
980 /// Either both `A` and `B` are images, or one is an image and the other is
981 /// a `cspan<float>` giving a per-channel constant or a single constant
982 /// used for all channels.
984  ROI roi={}, int nthreads=0);
985 /// Write to an existing image `dst` (allocating if it is uninitialized).
987  ROI roi={}, int nthreads=0);
988 
989 
990 
991 /// Return pixels of `src` with pixel values clamped as follows:
992 /// @param min
993 /// The minimum clamp value for each channel. If `min` is
994 /// empty, no minimum clamping is performed.
995 /// @param max
996 /// The maximum clamp value for each channel. If `max` is
997 /// empty, no maximum clamping is performed.
998 /// @param clampalpha01
999 /// If true, then additionally any alpha channel is clamped
1000 /// to the 0-1 range.
1001 ImageBuf OIIO_API clamp (const ImageBuf &src,
1004  bool clampalpha01 = false, ROI roi={}, int nthreads=0);
1005 /// Write to an existing image `dst` (allocating if it is uninitialized).
1006 bool OIIO_API clamp (ImageBuf &dst, const ImageBuf &src,
1009  bool clampalpha01 = false, ROI roi={}, int nthreads=0);
1010 
1011 /// @}
1012 
1013 
1014 /// @defgroup maxminchan (Maximum / minimum of channels)
1015 /// @{
1016 ///
1017 /// `maxchan()` computes a one-channel image that for each pixel, contains the
1018 /// maximum value of all channels of corresponding pixel of the source image.
1019 /// `minchan()` similarly computes the minimum value of all channels.
1020 ///
1021 /// @version 2.3.10
1022 
1023 ImageBuf OIIO_API maxchan (const ImageBuf& A, ROI roi={}, int nthreads=0);
1024 bool OIIO_API maxchan (ImageBuf &dst, const ImageBuf& A,
1025  ROI roi={}, int nthreads=0);
1026 
1027 ImageBuf OIIO_API minchan (const ImageBuf& src, ROI roi={}, int nthreads=0);
1028 bool OIIO_API minchan (ImageBuf &dst, const ImageBuf& src,
1029  ROI roi={}, int nthreads=0);
1030 /// @}
1031 
1032 
1033 /// Return pixel values that are a contrast-remap of the corresponding
1034 /// values of the `src` image, transforming pixel value domain [black,
1035 /// white] to range [min, max], either linearly or with optional application
1036 /// of a smooth sigmoidal remapping (if `scontrast` != 1.0).
1037 ///
1038 /// The following steps are performed, in order:
1039 ///
1040 /// 1. Linearly rescale values [`black`, `white`] to [0, 1].
1041 /// 2. If `scontrast` != 1, apply a sigmoidal remapping where a larger
1042 /// `scontrast` value makes a steeper slope, and the steepest part is at
1043 /// value `sthresh` (relative to the new remapped value after steps 1 &
1044 /// 2; the default is 0.5).
1045 /// 3. Rescale the range of that result: 0.0 -> `min` and 1.0 -> `max`.
1046 ///
1047 /// Values outside of the [black,white] range will be extrapolated to
1048 /// outside [min,max], so it may be prudent to apply a clamp() to the
1049 /// results.
1050 ///
1051 /// The black, white, min, max, scontrast, sthresh parameters may each
1052 /// either be a single float value for all channels, or a span giving
1053 /// per-channel values.
1054 ///
1055 /// You can use this function for a simple linear contrast remapping of
1056 /// [black, white] to [min, max] if you use the default values for sthresh.
1057 /// Or just a simple sigmoidal contrast stretch within the [0,1] range if
1058 /// you leave all other parameters at their defaults, or a combination of
1059 /// these effects. Note that if `black` == `white`, the result will be a
1060 /// simple binary thresholding where values < `black` map to `min` and
1061 /// values >= `black` map to `max`.
1062 
1064  cspan<float> black=0.0f, cspan<float> white=1.0f,
1066  cspan<float> scontrast=1.0f, cspan<float> sthresh=0.5f,
1067  ROI={}, int nthreads=0);
1068 /// Write to an existing image `dst` (allocating if it is uninitialized).
1069 OIIO_API bool contrast_remap (ImageBuf &dst, const ImageBuf &src,
1070  cspan<float> black=0.0f, cspan<float> white=1.0f,
1072  cspan<float> scontrast=1.0f, cspan<float> sthresh=0.5f,
1073  ROI={}, int nthreads=0);
1074 
1075 
1076 /// @defgroup saturate (Adjust saturation of color channels)
1077 /// @{
1078 ///
1079 /// Increase or decrease color saturation of the image.
1080 ///
1081 /// The `saturate` operation returns (or copies into `dst`) the pixels of
1082 /// `src` within the ROI, and in the process adjusts the color saturation of
1083 /// the three consecutive channels starting with `firstchannel` based on the
1084 /// `scale` parameter: 0.0 fully desaturates to a greyscale image of
1085 /// percaptually equivalent luminance, 1.0 leaves the colors unchanged,
1086 /// `scale` values inside this range interpolate between them, and `scale` > 1
1087 /// would increase apparent color saturation.
1088 ///
1089 /// Channels that are within the range of `roi.chbegin` to `roi.chend-1`, but
1090 /// outside the range of `firstchannel` to `firstchannel+2` are simply copied
1091 /// unaltered. Only three channels at a time can be desaturated, by default
1092 /// the first three channels, though `firstchannel` may be used to specify a
1093 /// different subset of channels. It is allowed for `src` and `dst` to be the
1094 /// same image.
1095 ///
1096 /// @version 2.4+
1097 
1098 ImageBuf OIIO_API saturate (const ImageBuf &src, float scale = 0.0f,
1099  int firstchannel = 0, ROI roi={}, int nthreads=0);
1100 bool OIIO_API saturate (ImageBuf &dst, const ImageBuf &src, float scale = 0.0f,
1101  int firstchannel = 0, ROI roi={}, int nthreads=0);
1102 /// @}
1103 
1104 
1105 
1106 /// @defgroup color_map (Remap value range by spline or name)
1107 /// @{
1108 ///
1109 /// Remap value range by spline or name
1110 ///
1111 /// Return (or copy into `dst`) pixel values determined by looking up a
1112 /// color map using values of the source image, using either the channel
1113 /// specified by `srcchannel`, or the luminance of `src`'s RGB if
1114 /// `srcchannel` is -1. This happens for all pixels within the ROI (which
1115 /// defaults to all of `src`), and if `dst` is not already initialized, it
1116 /// will be initialized to the ROI and with color channels equal to
1117 /// `channels`.
1118 ///
1119 /// In the variant that takes a `knots` parameter, this specifies the values
1120 /// of a linearly-interpolated color map given by `knots[nknots*channels]`.
1121 /// An input value of 0.0 is mapped to `knots[0..channels-1]` (one value for
1122 /// each color channel), and an input value of 1.0 is mapped to
1123 /// `knots[(nknots-1)*channels..knots.size()-1]`.
1124 ///
1125 /// In the variant that takes a `mapname` parameter, this is the name of a
1126 /// color map. Recognized map names include: "inferno", "viridis", "magma",
1127 /// "plasma", all of which are perceptually uniform, strictly increasing in
1128 /// luminance, look good when converted to grayscale, and work for people
1129 /// with all types of colorblindness. Also "turbo" has most of these
1130 /// properties (except for being strictly increasing in luminance) and
1131 /// is a nice rainbow-like pattern. Also supported are the following color
1132 /// maps that do not have those desirable qualities (and are thus not
1133 /// recommended, but are present for back-compatibility or for use by
1134 /// clueless people): "blue-red", "spectrum", and "heat". In all cases, the
1135 /// implied `channels` is 3.
1136 
1137 ImageBuf OIIO_API color_map (const ImageBuf &src, int srcchannel,
1138  int nknots, int channels, cspan<float> knots,
1139  ROI roi={}, int nthreads=0);
1140 ImageBuf OIIO_API color_map (const ImageBuf &src, int srcchannel,
1141  string_view mapname, ROI roi={}, int nthreads=0);
1142 bool OIIO_API color_map (ImageBuf &dst, const ImageBuf &src, int srcchannel,
1143  int nknots, int channels, cspan<float> knots,
1144  ROI roi={}, int nthreads=0);
1145 bool OIIO_API color_map (ImageBuf &dst, const ImageBuf &src, int srcchannel,
1146  string_view mapname, ROI roi={}, int nthreads=0);
1147 /// @}
1148 
1149 
1150 /// @defgroup range (Nonlinear range remapping for contrast preservation)
1151 /// @{
1152 ///
1153 /// Nonlinear range remapping for contrast preservation
1154 ///
1155 /// `rangecompress()` returns (or copy into `dst`) all pixels and color
1156 /// channels of `src` within region `roi` (defaulting to all the defined
1157 /// pixels of `dst`), rescaling their range with a logarithmic
1158 /// transformation. Alpha and z channels are not transformed.
1159 ///
1160 /// `rangeexpand()` performs the inverse transformation (logarithmic back
1161 /// into linear).
1162 ///
1163 /// If `useluma` is true, the luma of channels [roi.chbegin..roi.chbegin+2]
1164 /// (presumed to be R, G, and B) are used to compute a single scale factor
1165 /// for all color channels, rather than scaling all channels individually
1166 /// (which could result in a color shift).
1167 ///
1168 /// The purpose of these function is as follows: Some image operations (such
1169 /// as resizing with a "good" filter that contains negative lobes) can have
1170 /// objectionable artifacts when applied to images with very high-contrast
1171 /// regions involving extra bright pixels (such as highlights in HDR
1172 /// captured or rendered images). By compressing the range pixel values,
1173 /// then performing the operation, then expanding the range of the result
1174 /// again, the result can be much more pleasing (even if not exactly
1175 /// correct).
1176 
1177 ImageBuf OIIO_API rangecompress (const ImageBuf &src, bool useluma = false,
1178  ROI roi={}, int nthreads=0);
1179 ImageBuf OIIO_API rangeexpand (const ImageBuf &src, bool useluma = false,
1180  ROI roi={}, int nthreads=0);
1181 bool OIIO_API rangecompress (ImageBuf &dst, const ImageBuf &src,
1182  bool useluma = false, ROI roi={}, int nthreads=0);
1183 bool OIIO_API rangeexpand (ImageBuf &dst, const ImageBuf &src,
1184  bool useluma = false, ROI roi={}, int nthreads=0);
1185 /// @}
1186 
1187 
1189  std::vector<float> min;
1190  std::vector<float> max;
1191  std::vector<float> avg;
1192  std::vector<float> stddev;
1193  std::vector<imagesize_t> nancount;
1194  std::vector<imagesize_t> infcount;
1195  std::vector<imagesize_t> finitecount;
1196  std::vector<double> sum, sum2; // for intermediate calculation
1197 
1199  PixelStats (PixelStats&& other) = default;
1200  PixelStats (int nchannels) { reset(nchannels); }
1201  void reset (int nchannels);
1202  void merge (const PixelStats &p);
1203  const PixelStats& operator= (PixelStats&& other); // Move assignment
1204 };
1205 
1206 
1207 /// Compute statistics about the ROI of the `src` image, returning a
1208 /// PixelStats structure. Upon success, the returned vectors in the result
1209 /// structure will have size == src.nchannels(). If there is a failure, the
1210 /// vector sizes will be 0 and an error will be set in src.
1211 PixelStats OIIO_API computePixelStats (const ImageBuf &src,
1212  ROI roi={}, int nthreads=0);
1213 
1214 // DEPRECATED(1.9): with C++11 move semantics, there's no reason why
1215 // stats needs to be passed as a parameter instead of returned.
1216 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1217 OIIO_DEPRECATED("use version that returns PixelStats (1.9)")
1218 bool OIIO_API computePixelStats (PixelStats &stats, const ImageBuf &src,
1219  ROI roi={}, int nthreads=0);
1220 #endif
1221 
1222 
1223 // Struct holding all the results computed by ImageBufAlgo::compare().
1224 // (maxx,maxy,maxz,maxc) gives the pixel coordinates (x,y,z) and color
1225 // channel of the pixel that differed maximally between the two images.
1226 // nwarn and nfail are the number of "warnings" and "failures",
1227 // respectively.
1230  int maxx, maxy, maxz, maxc;
1232  bool error;
1233 };
1234 
1235 /// Numerically compare two images. The difference threshold (for any
1236 /// individual color channel in any pixel) for a "failure" is
1237 /// failthresh, and for a "warning" is warnthresh. The results are
1238 /// stored in result. If roi is defined, pixels will be compared for
1239 /// the pixel and channel range that is specified. If roi is not
1240 /// defined, the comparison will be for all channels, on the union of
1241 /// the defined pixel windows of the two images (for either image,
1242 /// undefined pixels will be assumed to be black).
1243 CompareResults OIIO_API compare (const ImageBuf &A, const ImageBuf &B,
1244  float failthresh, float warnthresh,
1245  ROI roi={}, int nthreads=0);
1246 
1247 /// Compare two images using Hector Yee's perceptual metric, returning
1248 /// the number of pixels that fail the comparison. Only the first three
1249 /// channels (or first three channels specified by `roi`) are compared.
1250 /// Free parameters are the ambient luminance in the room and the field
1251 /// of view of the image display; our defaults are probably reasonable
1252 /// guesses for an office environment. The 'result' structure will
1253 /// store the maxerror, and the maxx, maxy, maxz of the pixel that
1254 /// failed most severely. (The other fields of the CompareResults
1255 /// are not used for Yee comparison.)
1256 ///
1257 /// Works for all pixel types. But it's basically meaningless if the
1258 /// first three channels aren't RGB in a linear color space that sort
1259 /// of resembles AdobeRGB.
1260 ///
1261 /// Return true on success, false on error.
1262 int OIIO_API compare_Yee (const ImageBuf &A, const ImageBuf &B,
1263  CompareResults &result,
1264  float luminance = 100, float fov = 45,
1265  ROI roi={}, int nthreads=0);
1266 
1267 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1268 // DEPRECATED(1.9): with C++11 move semantics, there's no reason why
1269 // result needs to be passed as a parameter instead of returned.
1270 OIIO_DEPRECATED("use version that returns CompareResults (1.9)")
1271 bool OIIO_API compare (const ImageBuf &A, const ImageBuf &B,
1272  float failthresh, float warnthresh,
1273  CompareResults &result, ROI roi={}, int nthreads=0);
1274 #endif
1275 
1276 
1277 /// Do all pixels within the ROI have the same values for channels
1278 /// `[roi.chbegin..roi.chend-1]`, within a tolerance of +/- `threshold`? If
1279 /// so, return `true` and store that color in `color[chbegin...chend-1]` (if
1280 /// `color` is not empty); otherwise return `false`. If `roi` is not
1281 /// defined (the default), it will be understood to be all of the defined
1282 /// pixels and channels of source.
1283 OIIO_API bool isConstantColor (const ImageBuf &src, float threshold=0.0f,
1284  span<float> color = {},
1285  ROI roi={}, int nthreads=0);
1286 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1287 inline bool isConstantColor (const ImageBuf &src, span<float> color,
1288  ROI roi={}, int nthreads=0) {
1289  return isConstantColor (src, 0.0f, color, roi, nthreads);
1290 }
1291 #endif
1292 
1293 
1294 /// Does the requested channel have a given value (within a tolerance of +/-
1295 /// `threshold`) for every channel within the ROI? (For this function, the
1296 /// ROI's chbegin/chend are ignored.) Return `true` if so, otherwise return
1297 /// `false`. If `roi` is not defined (the default), it will be understood
1298 /// to be all of the defined pixels and channels of source.
1299 OIIO_API bool isConstantChannel (const ImageBuf &src, int channel,
1300  float val, float threshold=0.0f,
1301  ROI roi={}, int nthreads=0);
1302 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1303 inline bool isConstantChannel (const ImageBuf &src, int channel, float val,
1304  ROI roi, int nthreads=0) {
1305  return isConstantChannel (src, channel, val, 0.0f, roi, nthreads);
1306 }
1307 #endif
1308 
1309 
1310 /// Is the image monochrome within the ROI, i.e., for every pixel within the
1311 /// region, do all channels [roi.chbegin, roi.chend) have the same value
1312 /// (within a tolerance of +/- threshold)? If roi is not defined (the
1313 /// default), it will be understood to be all of the defined pixels and
1314 /// channels of source.
1315 OIIO_API bool isMonochrome (const ImageBuf &src, float threshold=0.0f,
1316  ROI roi={}, int nthreads=0);
1317 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1318 inline bool isMonochrome (const ImageBuf &src, ROI roi, int nthreads=0) {
1319  return isMonochrome (src, 0.0f, roi, nthreads);
1320 }
1321 #endif
1322 
1323 
1324 /// Count how many pixels in the ROI match a list of colors. The colors to
1325 /// match are in:
1326 ///
1327 /// colors[0 ... nchans-1]
1328 /// colors[nchans ... 2*nchans-1]
1329 /// ...
1330 /// colors[(ncolors-1)*nchans ... (ncolors*nchans)-1]
1331 ///
1332 /// and so on, a total of `ncolors` consecutively stored colors of `nchans`
1333 /// channels each (`nchans` is the number of channels in the image, itself,
1334 /// it is not passed as a parameter).
1335 ///
1336 /// `eps[0..nchans-1]` are the error tolerances for a match, for each
1337 /// channel. Setting `eps[c]` = `numeric_limits<float>::max()` will
1338 /// effectively make it ignore the channel. The default `eps` is 0.001 for
1339 /// all channels (this value is chosen because it requires exact matches for
1340 /// 8 bit images, but allows a wee bit of imprecision for float images.
1341 ///
1342 /// Upon success, return `true` and store the number of pixels that matched
1343 /// each color `count[0..ncolors-1]`. If there is an error, returns `false`
1344 /// and sets an appropriate error message set in `src`.
1345 bool OIIO_API color_count (const ImageBuf &src, imagesize_t *count,
1346  int ncolors, cspan<float> color,
1347  cspan<float> eps = 0.001f,
1348  ROI roi={}, int nthreads=0);
1349 
1350 
1351 /// Count how many pixels in the image (within the ROI) are outside the
1352 /// value range described by `low[roi.chbegin..roi.chend-1]` and
1353 /// `high[roi.chbegin..roi.chend-1]` as the low and high acceptable values
1354 /// for each color channel.
1355 ///
1356 /// The number of pixels containing values that fall below the lower bound
1357 /// will be stored in `*lowcount`, the number of pixels containing
1358 /// values that fall above the upper bound will be stored in
1359 /// `*highcount`, and the number of pixels for which all channels fell
1360 /// within the bounds will be stored in `*inrangecount`. Any of these
1361 /// may be NULL, which simply means that the counts need not be collected or
1362 /// stored.
1363 bool OIIO_API color_range_check (const ImageBuf &src,
1364  imagesize_t *lowcount,
1365  imagesize_t *highcount,
1366  imagesize_t *inrangecount,
1367  cspan<float> low, cspan<float> high,
1368  ROI roi={}, int nthreads=0);
1369 
1370 /// Find the minimal rectangular region within `roi` (which defaults to the
1371 /// entire pixel data window of `src`) that consists of nonzero pixel
1372 /// values. In other words, gives the region that is a "shrink-wraps" of
1373 /// `src` to exclude black border pixels. Note that if the entire image was
1374 /// black, the ROI returned will contain no pixels.
1375 ///
1376 /// For "deep" images, this function returns the smallest ROI that contains
1377 /// all pixels that contain depth samples, and excludes the border pixels
1378 /// that contain no depth samples at all.
1379 OIIO_API ROI nonzero_region (const ImageBuf &src, ROI roi={}, int nthreads=0);
1380 
1381 
1382 /// Compute the SHA-1 byte hash for all the pixels in the specifed region of
1383 /// the image. If `blocksize` > 0, the function will compute separate SHA-1
1384 /// hashes of each `blocksize` batch of scanlines, then return a hash of the
1385 /// individual hashes. This is just as strong a hash, but will NOT match a
1386 /// single hash of the entire image (`blocksize==0`). But by breaking up
1387 /// the hash into independent blocks, we can parallelize across multiple
1388 /// threads, given by `nthreads` (if `nthreads` is 0, it will use the global
1389 /// OIIO thread count). The `extrainfo` provides additional text that will
1390 /// be incorporated into the hash.
1392  string_view extrainfo = "",
1393  ROI roi={},
1394  int blocksize = 0, int nthreads=0);
1395 
1396 
1397 /// Compute a histogram of `src`, for the given channel and ROI. Return a
1398 /// vector of length `bins` that contains the counts of how many pixel
1399 /// values were in each of `bins` equally spaced bins covering the range of
1400 /// values `[min,max]`. Values < `min` count for bin 0, values > `max` count
1401 /// for bin `nbins-1`. If `ignore_empty` is `true`, no counts will be
1402 /// incremented for any pixels whose value is 0 in all channels.
1403 ///
1404 /// If there was an error, the returned vector will be empty, and an error
1405 /// message will be retrievable from src.geterror().
1406 OIIO_API
1407 std::vector<imagesize_t> histogram (const ImageBuf &src, int channel=0,
1408  int bins=256, float min=0.0f, float max=1.0f,
1409  bool ignore_empty=false,
1410  ROI roi={}, int nthreads=0);
1411 
1412 
1413 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1414 /// DEPRECATED(1.9)
1415 OIIO_DEPRECATED("use version that returns vector (1.9)")
1416 bool OIIO_API histogram (const ImageBuf &src, int channel,
1417  std::vector<imagesize_t> &histogram, int bins=256,
1418  float min=0, float max=1, imagesize_t *submin=nullptr,
1419  imagesize_t *supermax=nullptr, ROI roi={});
1420 
1421 // DEPRECATED(1.9): never liked this.
1422 OIIO_DEPRECATED("this useless function is going away (1.9)")
1423 bool OIIO_API histogram_draw (ImageBuf &dst,
1424  const std::vector<imagesize_t> &histogram);
1425 #endif
1426 
1427 
1428 
1429 /// Make a 1-channel `float` image of the named kernel. The size of the
1430 /// image will be big enough to contain the kernel given its size (`width` x
1431 /// `height`) and rounded up to odd resolution so that the center of the
1432 /// kernel can be at the center of the middle pixel. The kernel image will
1433 /// be offset so that its center is at the (0,0) coordinate. If `normalize`
1434 /// is true, the values will be normalized so that they sum to 1.0. If
1435 /// `depth` > 1, a volumetric kernel will be created. Use with caution!
1436 ///
1437 /// Kernel names can be: "gaussian", "sharp-gaussian", "box",
1438 /// "triangle", "blackman-harris", "mitchell", "b-spline", "catmull-rom",
1439 /// "lanczos3", "disk", "binomial", "laplacian".
1440 ///
1441 /// Note that "catmull-rom" and "lanczos3" are fixed-size kernels that
1442 /// don't scale with the width, and are therefore probably less useful
1443 /// in most cases.
1444 ///
1445 /// The ImageBuf that is returned indicates if there was an error, in which
1446 /// case return.has_error() will be true and return.geterror() can be used
1447 /// to retrieve an error message.
1448 ImageBuf OIIO_API make_kernel (string_view name, float width, float height,
1449  float depth = 1.0f, bool normalize = true);
1450 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1451 // DEPRECATED(1.9):
1452 OIIO_DEPRECATED("use version that returns ImageBuf (1.9)")
1454  float width, float height, float depth = 1.0f,
1455  bool normalize = true) {
1456  dst = make_kernel (name, width, height, depth, normalize);
1457  return ! dst.has_error();
1458 }
1459 #endif
1460 
1461 
1462 /// Return the convolution of `src` and a `kernel`. If `roi` is not defined,
1463 /// it defaults to the full size `src`. If `normalized` is true, the kernel will
1464 /// be normalized for the convolution, otherwise the original values will
1465 /// be used.
1466 ImageBuf OIIO_API convolve (const ImageBuf &src, const ImageBuf &kernel,
1467  bool normalize = true, ROI roi={}, int nthreads=0);
1468 /// Write to an existing image `dst` (allocating if it is uninitialized).
1469 /// If `roi` is not defined, it defaults to the full size of `dst` (or
1470 /// `src`, if `dst` was uninitialized). If `dst` is uninitialized, it will
1471 /// be allocated to be the size specified by `roi`.
1472 bool OIIO_API convolve (ImageBuf &dst, const ImageBuf &src, const ImageBuf &kernel,
1473  bool normalize = true, ROI roi={}, int nthreads=0);
1474 
1475 
1476 /// Return the Laplacian of the corresponding region of `src`. The
1477 /// Laplacian is the generalized second derivative of the image
1478 /// \f[
1479 /// \frac{\partial^2 s}{\partial x^2} + \frac{\partial^2 s}{\partial y^2}
1480 /// \f]
1481 /// which is approximated by convolving the image with a discrete 3x3
1482 /// Laplacian kernel,
1483 ///
1484 /// [ 0 1 0 ]
1485 /// [ 1 -4 1 ]
1486 /// [ 0 1 0 ]
1487 ///
1488 ImageBuf OIIO_API laplacian (const ImageBuf &src, ROI roi={}, int nthreads=0);
1489 /// Write to an existing image `dst` (allocating if it is uninitialized).
1490 bool OIIO_API laplacian (ImageBuf &dst, const ImageBuf &src,
1491  ROI roi={}, int nthreads=0);
1492 
1493 
1494 /// @defgroup fft-ifft (Fast Fourier Transform and inverse)
1495 /// @{
1496 ///
1497 /// Fast Fourier Transform and inverse
1498 ///
1499 /// Return (or copy into `dst`) the discrete Fourier transform (DFT), or its
1500 /// inverse, of the section of `src` denoted by roi, If roi is not defined,
1501 /// it will be all of `src`'s pixels.
1502 ///
1503 /// `fft()` takes the discrete Fourier transform (DFT) of the section of
1504 /// `src` denoted by `roi`, returning it or storing it in `dst`. If `roi` is
1505 /// not defined, it will be all of `src`'s pixels. Only one channel of `src`
1506 /// may be transformed at a time, so it will be the first channel described
1507 /// by `roi` (or, again, channel 0 if `roi` is undefined). If not already
1508 /// in the correct format, `dst` will be re-allocated to be a 2-channel
1509 /// `float` buffer of size `roi.width()` x `roi.height`, with channel 0
1510 /// being the "real" part and channel 1 being the the "imaginary" part. The
1511 /// values returned are actually the unitary DFT, meaning that it is scaled
1512 /// by 1/sqrt(npixels).
1513 ///
1514 /// `ifft()` takes the inverse discrete Fourier transform, transforming a
1515 /// 2-channel complex (real and imaginary) frequency domain image and into a
1516 /// single-channel spatial domain image. `src` must be a 2-channel float
1517 /// image, and is assumed to be a complex frequency-domain signal with the
1518 /// "real" component in channel 0 and the "imaginary" component in channel 1.
1519 /// `dst` will end up being a float image of one channel (the real component
1520 /// is kept, the imaginary component of the spatial-domain will be
1521 /// discarded). Just as with `fft()`, the `ifft()` function is dealing with
1522 /// the unitary DFT, so it is scaled by 1/sqrt(npixels).
1523 ImageBuf OIIO_API fft (const ImageBuf &src, ROI roi={}, int nthreads=0);
1524 ImageBuf OIIO_API ifft (const ImageBuf &src, ROI roi={}, int nthreads=0);
1525 bool OIIO_API fft (ImageBuf &dst, const ImageBuf &src, ROI roi={}, int nthreads=0);
1526 bool OIIO_API ifft (ImageBuf &dst, const ImageBuf &src, ROI roi={}, int nthreads=0);
1527 /// @}
1528 
1529 
1530 /// @defgroup complex-polar (Converting complex to polar and back)
1531 /// @{
1532 ///
1533 /// Converting complex to polar and back
1534 ///
1535 /// The `polar_to_complex()` function transforms a 2-channel image whose
1536 /// channels are interpreted as complex values (real and imaginary
1537 /// components) into the equivalent values expressed in polar form of
1538 /// amplitude and phase (with phase between 0 and \f$ 2\pi \f$.
1539 ///
1540 /// The `complex_to_polar()` function performs the reverse transformation,
1541 /// converting from polar values (amplitude and phase) to complex (real and
1542 /// imaginary).
1543 ///
1544 /// In either case, the section of `src` denoted by `roi` is transformed,
1545 /// storing the result in `dst`. If `roi` is not defined, it will be all of
1546 /// `src`'s pixels. Only the first two channels of `src` will be
1547 /// transformed.
1548 ///
1549 /// The transformation between the two representations are:
1550 ///
1551 /// real = amplitude * cos(phase);
1552 /// imag = amplitude * sin(phase);
1553 ///
1554 /// amplitude = hypot (real, imag);
1555 /// phase = atan2 (imag, real);
1556 
1558  ROI roi={}, int nthreads=0);
1559 bool OIIO_API complex_to_polar (ImageBuf &dst, const ImageBuf &src,
1560  ROI roi={}, int nthreads=0);
1562  ROI roi={}, int nthreads=0);
1563 bool OIIO_API polar_to_complex (ImageBuf &dst, const ImageBuf &src,
1564  ROI roi={}, int nthreads=0);
1565 /// @}
1566 
1567 
1568 
1570 {
1571  NONFINITE_NONE = 0, ///< Do not alter the pixels (but do count the
1572  ///< number of nonfinite pixels in *pixelsFixed,
1573  ///< if non-null).
1574  NONFINITE_BLACK = 1, ///< Replace non-finite values with 0.0.
1575  NONFINITE_BOX3 = 2, ///< Replace non-finite values with the average
1576  ///< value of any finite pixels in a 3x3 window.
1577  NONFINITE_ERROR = 100, ///< EReturn false (error), but don't change any
1578  ///< values, if any nonfinite values are found.
1579 };
1580 
1581 /// `fixNonFinite()` returns in image containing the values of `src` (within
1582 /// the ROI), while repairing any non-finite (NaN/Inf) pixels. If
1583 /// pixelsFixed is not nullptr, store in it the number of pixels that
1584 /// contained non-finite value. It is permissible to operate in-place (with
1585 /// `src` and `dst` referring to the same image).
1586 ///
1587 /// How the non-finite values are repaired is specified by one of the `mode`
1588 /// parameter, which is an enum of `NonFiniteFixMode`.
1589 ///
1590 /// This function works on all pixel data types, though it's just a copy for
1591 /// images with pixel data types that cannot represent NaN or Inf values.
1594  int *pixelsFixed = nullptr,
1595  ROI roi={}, int nthreads=0);
1596 
1597 /// Write to an existing image `dst` (allocating if it is uninitialized).
1598 bool OIIO_API fixNonFinite (ImageBuf &dst, const ImageBuf &src,
1600  int *pixelsFixed = nullptr,
1601  ROI roi={}, int nthreads=0);
1602 
1603 
1604 /// Copy the specified ROI of `src` and fill any holes (pixels where alpha <
1605 /// 1) with plausible values using a push-pull technique. The `src` image
1606 /// must have an alpha channel. The `dst` image will end up with a copy of
1607 /// `src`, but will have an alpha of 1.0 everywhere within `roi`, and any
1608 /// place where the alpha of `src` was < 1, `dst` will have a pixel color
1609 /// that is a plausible "filling" of the original alpha hole.
1611  ROI roi={}, int nthreads=0);
1612 /// Write to an existing image `dst` (allocating if it is uninitialized).
1613 bool OIIO_API fillholes_pushpull (ImageBuf &dst, const ImageBuf &src,
1614  ROI roi={}, int nthreads=0);
1615 
1616 
1617 /// Return a median-filtered version of the corresponding region of `src`.
1618 /// The median filter replaces each pixel with the median value underneath
1619 /// the `width` x `height` window surrounding it. If `height` <= 0, it will
1620 /// be set to `width`, making a square window.
1621 ///
1622 /// Median filters are good for removing high-frequency detail smaller than
1623 /// the window size (including noise), without blurring edges that are
1624 /// larger than the window size.
1626  int width = 3, int height = -1,
1627  ROI roi={}, int nthreads=0);
1628 /// Write to an existing image `dst` (allocating if it is uninitialized).
1629 bool OIIO_API median_filter (ImageBuf &dst, const ImageBuf &src,
1630  int width = 3, int height = -1,
1631  ROI roi={}, int nthreads=0);
1632 
1633 
1634 /// Return a sharpened version of the corresponding region of `src` using
1635 /// the "unsharp mask" technique. Unsharp masking basically works by first
1636 /// blurring the image (low pass filter), subtracting this from the original
1637 /// image, then adding the residual back to the original to emphasize the
1638 /// edges. Roughly speaking,
1639 ///
1640 /// dst = src + contrast * thresh(src - blur(src))
1641 ///
1642 /// The specific blur can be selected by kernel name and width (for example,
1643 /// "gaussian" is typical). As a special case, "median" is also accepted as
1644 /// the kernel name, in which case a median filter is performed rather than
1645 /// a blurring convolution (Gaussian and other blurs sometimes over-sharpen
1646 /// edges, whereas using the median filter will sharpen compact
1647 /// high-frequency details while not over-sharpening long edges).
1648 ///
1649 /// The `contrast` is a multiplier on the overall sharpening effect. The
1650 /// thresholding step causes all differences less than `threshold` to be
1651 /// squashed to zero, which can be useful for suppressing sharpening of
1652 /// low-contrast details (like noise) but allow sharpening of
1653 /// higher-contrast edges.
1655  string_view kernel="gaussian", float width = 3.0f,
1656  float contrast = 1.0f, float threshold = 0.0f,
1657  ROI roi={}, int nthreads=0);
1658 /// Write to an existing image `dst` (allocating if it is uninitialized).
1659 bool OIIO_API unsharp_mask (ImageBuf &dst, const ImageBuf &src,
1660  string_view kernel="gaussian", float width = 3.0f,
1661  float contrast = 1.0f, float threshold = 0.0f,
1662  ROI roi={}, int nthreads=0);
1663 
1664 
1665 /// Return a dilated version of the corresponding region of `src`. Dilation
1666 /// is defined as the maximum value of all pixels under nonzero values of
1667 /// the structuring element (which is taken to be a width x height square).
1668 /// If height is not set, it will default to be the same as width. Dilation
1669 /// makes bright features wider and more prominent, dark features thinner,
1670 /// and removes small isolated dark spots.
1671 ImageBuf OIIO_API dilate (const ImageBuf &src, int width=3, int height=-1,
1672  ROI roi={}, int nthreads=0);
1673 /// Write to an existing image `dst` (allocating if it is uninitialized).
1674 bool OIIO_API dilate (ImageBuf &dst, const ImageBuf &src,
1675  int width=3, int height=-1, ROI roi={}, int nthreads=0);
1676 
1677 
1678 /// Return an eroded version of the corresponding region of `src`. Erosion
1679 /// is defined as the minimum value of all pixels under nonzero values of
1680 /// the structuring element (which is taken to be a width x height square).
1681 /// If height is not set, it will default to be the same as width. Erosion
1682 /// makes dark features wider, bright features thinner, and removes small
1683 /// isolated bright spots.
1684 ImageBuf OIIO_API erode (const ImageBuf &src, int width=3, int height=-1,
1685  ROI roi={}, int nthreads=0);
1686 /// Write to an existing image `dst` (allocating if it is uninitialized).
1687 bool OIIO_API erode (ImageBuf &dst, const ImageBuf &src,
1688  int width=3, int height=-1, ROI roi={}, int nthreads=0);
1689 
1690 
1691 
1692 /// @defgroup colorconvert (Color space conversions)
1693 /// @{
1694 ///
1695 /// Convert between color spaces
1696 ///
1697 /// Return (or copy into `dst`) the pixels of `src` within the ROI, applying
1698 /// a color space transformation. In-place operations (`dst` == `src`) are
1699 /// supported.
1700 ///
1701 /// The first three channels are presumed to be the color to be
1702 /// transformed, and the fourth channel (if it exists) is presumed to be
1703 /// alpha. Any additional channels will be simply copied unaltered.
1704 ///
1705 /// If OIIO was built with OpenColorIO support enabled, then the
1706 /// transformation may be between any two spaces supported by the active
1707 /// OCIO configuration, or may be a "look" transformation created by
1708 /// `ColorConfig::createLookTransform`. If OIIO was not built with
1709 /// OpenColorIO support enabled, then the only transformations available are
1710 /// from "sRGB" to "linear" and vice versa.
1711 ///
1712 /// @param fromspace/tospace
1713 /// For the varieties of `colorconvert()` that use named color
1714 /// spaces, these specify the color spaces by name.
1715 /// @param context_key/context_value
1716 /// For the varieties of `colorconvert()` that use named color
1717 /// spaces, these optionally specify a "key" name/value pair to
1718 /// establish a context (for example, a shot-specific transform).
1719 /// @param processor
1720 /// For the varieties of `colorconvert()` that have a
1721 /// `processor` paramater, it is a raw `ColorProcessor*` object
1722 /// that implements the color transformation. This is a special
1723 /// object created by a `ColorConfig` (see `OpenImageIO/color.h`
1724 /// for details).
1725 /// @param unpremult
1726 /// If true, unpremultiply the image (divide the RGB channels by
1727 /// alpha if it exists and is nonzero) before color conversion,
1728 /// then repremult after the after the color conversion. Passing
1729 /// unpremult=false skips this step, which may be desirable if
1730 /// you know that the image is "unassociated alpha" (a.k.a.,
1731 /// "not pre-multiplied colors").
1732 /// @param colorconfig
1733 /// An optional `ColorConfig*` specifying an OpenColorIO
1734 /// configuration. If not supplied, the default OpenColorIO
1735 /// color configuration found by examining the `$OCIO`
1736 /// environment variable will be used instead.
1737 ///
1738 
1739 /// Transform between named color spaces, returning an ImageBuf result.
1741  string_view fromspace, string_view tospace, bool unpremult=true,
1742  string_view context_key="", string_view context_value="",
1743  ColorConfig *colorconfig=nullptr,
1744  ROI roi={}, int nthreads=0);
1745 
1746 /// Transform using a ColorProcessor, returning an ImageBuf result.
1748  const ColorProcessor *processor,
1749  bool unpremult, ROI roi={}, int nthreads=0);
1750 /// Transform between named color spaces, storing reults into an existing ImageBuf.
1751 bool OIIO_API colorconvert (ImageBuf &dst, const ImageBuf &src,
1752  string_view fromspace, string_view tospace, bool unpremult=true,
1753  string_view context_key="", string_view context_value="",
1754  ColorConfig *colorconfig=nullptr,
1755  ROI roi={}, int nthreads=0);
1756 
1757 /// Transform using a ColorProcessor, storing reults into an existing ImageBuf.
1758 bool OIIO_API colorconvert (ImageBuf &dst, const ImageBuf &src,
1759  const ColorProcessor *processor,
1760  bool unpremult, ROI roi={}, int nthreads=0);
1761 
1762 /// Apply a color transform in-place to just one color:
1763 /// `color[0..nchannels-1]`. `nchannels` should either be 3 or 4 (if 4, the
1764 /// last channel is alpha).
1765 bool OIIO_API colorconvert (span<float> color,
1766  const ColorProcessor *processor, bool unpremult);
1767 
1768 // DEPRECATED(2.1): Less safe version with raw pointer and length.
1769 inline bool colorconvert (float *color, int nchannels,
1770  const ColorProcessor *processor, bool unpremult) {
1771  return colorconvert ({color,nchannels}, processor, unpremult);
1772 }
1773 
1774 /// @}
1775 
1776 
1777 /// Return a copy of the pixels of `src` within the ROI, applying a color
1778 /// transform specified by a 4x4 matrix. In-place operations
1779 /// (`dst` == `src`) are supported.
1780 ///
1781 /// The first three channels are presumed to be the color to be
1782 /// transformed, and the fourth channel (if it exists) is presumed to be
1783 /// alpha. Any additional channels will be simply copied unaltered.
1784 ///
1785 /// @param M
1786 /// A 4x4 matrix. Following Imath conventions, the color is a
1787 /// row vector and the matrix has the "translation" part in
1788 /// elements [12..14] (matching the memory layout of OpenGL or
1789 /// RenderMan), so the math is `color * Matrix` (NOT `M*c`).
1790 /// @param unpremult
1791 /// If true, unpremultiply the image (divide the RGB channels by
1792 /// alpha if it exists and is nonzero) before color conversion,
1793 /// then repremult after the after the color conversion. Passing
1794 /// unpremult=false skips this step, which may be desirable if
1795 /// you know that the image is "unassociated alpha" (a.k.a.,
1796 /// "not pre-multiplied colors").
1797 ///
1798 /// @version 2.1+
1800  const Imath::M44f& M, bool unpremult=true,
1801  ROI roi={}, int nthreads=0);
1802 /// Write to an existing image `dst` (allocating if it is uninitialized).
1803 bool OIIO_API colormatrixtransform (ImageBuf &dst, const ImageBuf &src,
1804  const Imath::M44f& M, bool unpremult=true,
1805  ROI roi={}, int nthreads=0);
1806 
1807 
1808 /// Return a copy of the pixels of `src` within the ROI, applying an
1809 /// OpenColorIO "look" transform to the pixel values. In-place operations
1810 /// (`dst` == `src`) are supported.
1811 ///
1812 /// The first three channels are presumed to be the color to be
1813 /// transformed, and the fourth channel (if it exists) is presumed to be
1814 /// alpha. Any additional channels will be simply copied unaltered.
1815 ///
1816 /// @param looks
1817 /// The looks to apply (comma-separated).
1818 /// @param fromspace/tospace
1819 /// For the varieties of `colorconvert()` that use named color
1820 /// spaces, these specify the color spaces by name.
1821 /// @param unpremult
1822 /// If true, unpremultiply the image (divide the RGB channels by
1823 /// alpha if it exists and is nonzero) before color conversion,
1824 /// then repremult after the after the color conversion. Passing
1825 /// unpremult=false skips this step, which may be desirable if
1826 /// you know that the image is "unassociated alpha" (a.k.a.,
1827 /// "not pre-multiplied colors").
1828 /// @param inverse
1829 /// If `true`, it will reverse the color transformation and look
1830 /// application.
1831 /// @param context_key/context_value
1832 /// Optional key/value to establish a context (for example, a
1833 /// shot-specific transform).
1834 /// @param colorconfig
1835 /// An optional `ColorConfig*` specifying an OpenColorIO
1836 /// configuration. If not supplied, the default OpenColorIO
1837 /// color configuration found by examining the `$OCIO`
1838 /// environment variable will be used instead.
1839 ImageBuf OIIO_API ociolook (const ImageBuf &src, string_view looks,
1840  string_view fromspace, string_view tospace,
1841  bool unpremult=true, bool inverse=false,
1842  string_view context_key="", string_view context_value="",
1843  ColorConfig *colorconfig=nullptr,
1844  ROI roi={}, int nthreads=0);
1845 /// Write to an existing image `dst` (allocating if it is uninitialized).
1846 bool OIIO_API ociolook (ImageBuf &dst, const ImageBuf &src, string_view looks,
1847  string_view fromspace, string_view tospace,
1848  bool unpremult=true, bool inverse=false,
1849  string_view context_key="", string_view context_value="",
1850  ColorConfig *colorconfig=nullptr,
1851  ROI roi={}, int nthreads=0);
1852 
1853 
1854 /// Return the pixels of `src` within the ROI, applying an OpenColorIO
1855 /// "display" transform to the pixel values. In-place operations
1856 /// (`dst` == `src`) are supported.
1857 ///
1858 /// The first three channels are presumed to be the color to be
1859 /// transformed, and the fourth channel (if it exists) is presumed to be
1860 /// alpha. Any additional channels will be simply copied unaltered.
1861 ///
1862 /// @param display
1863 /// The OCIO "display" to apply. If this is the empty string,
1864 /// the default display will be used.
1865 /// @param view
1866 /// The OCIO "view" to use. If this is the empty string, the
1867 /// default view for this display will be used.
1868 /// @param fromspace
1869 /// If `fromspace` is not supplied, it will assume that the
1870 /// source color space is whatever is indicated by the source
1871 /// image's metadata or filename, and if that cannot be deduced,
1872 /// it will be assumed to be scene linear.
1873 /// @param looks
1874 /// The looks to apply (comma-separated). This may be empty,
1875 /// in which case no "look" is used. Note: this parameter value
1876 /// is not used when building against OpenColorIO 2.x.
1877 /// @param unpremult
1878 /// If true, unpremultiply the image (divide the RGB channels by
1879 /// alpha if it exists and is nonzero) before color conversion,
1880 /// then repremult after the after the color conversion. Passing
1881 /// unpremult=false skips this step, which may be desirable if
1882 /// you know that the image is "unassociated alpha" (a.k.a.,
1883 /// "not pre-multiplied colors").
1884 /// @param inverse
1885 /// If `true`, it will reverse the color transformation and
1886 /// display application.
1887 /// @param context_key/context_value
1888 /// Optional key/value to establish a context (for example, a
1889 /// shot-specific transform).
1890 /// @param colorconfig
1891 /// An optional `ColorConfig*` specifying an OpenColorIO
1892 /// configuration. If not supplied, the default OpenColorIO
1893 /// color configuration found by examining the `$OCIO`
1894 /// environment variable will be used instead.
1896  string_view display, string_view view,
1897  string_view fromspace="", string_view looks="",
1898  bool unpremult=true,
1899  string_view context_key="", string_view context_value="",
1900  ColorConfig *colorconfig=nullptr,
1901  ROI roi={}, int nthreads=0);
1902 /// Write to an existing image `dst` (allocating if it is uninitialized).
1903 bool OIIO_API ociodisplay (ImageBuf &dst, const ImageBuf &src,
1904  string_view display, string_view view,
1905  string_view fromspace="", string_view looks="",
1906  bool unpremult=true,
1907  string_view context_key="", string_view context_value="",
1908  ColorConfig *colorconfig=nullptr,
1909  ROI roi={}, int nthreads=0);
1910 
1911 
1912 /// Return the pixels of `src` within the ROI, applying an OpenColorIO
1913 /// "file" transform. In-place operations (`dst` == `src`) are supported.
1914 ///
1915 /// The first three channels are presumed to be the color to be
1916 /// transformed, and the fourth channel (if it exists) is presumed to be
1917 /// alpha. Any additional channels will be simply copied unaltered.
1918 ///
1919 /// @param name
1920 /// The name of the file containing the transform information.
1921 /// @param unpremult
1922 /// If true, unpremultiply the image (divide the RGB channels by
1923 /// alpha if it exists and is nonzero) before color conversion,
1924 /// then repremult after the after the color conversion. Passing
1925 /// unpremult=false skips this step, which may be desirable if
1926 /// you know that the image is "unassociated alpha" (a.k.a.,
1927 /// "not pre-multiplied colors").
1928 /// @param inverse
1929 /// If `true`, it will reverse the color transformation.
1930 /// @param colorconfig
1931 /// An optional `ColorConfig*` specifying an OpenColorIO
1932 /// configuration. If not supplied, the default OpenColorIO
1933 /// color configuration found by examining the `$OCIO`
1934 /// environment variable will be used instead.
1936  string_view name,
1937  bool unpremult=true, bool inverse=false,
1938  ColorConfig *colorconfig=nullptr,
1939  ROI roi={}, int nthreads=0);
1940 /// Write to an existing image `dst` (allocating if it is uninitialized).
1941 bool OIIO_API ociofiletransform (ImageBuf &dst, const ImageBuf &src,
1942  string_view name,
1943  bool unpremult=true, bool inverse=false,
1944  ColorConfig *colorconfig=nullptr,
1945  ROI roi={}, int nthreads=0);
1946 
1947 
1948 /// @defgroup premult (Premultiply or un-premultiply color by alpha)
1949 /// @{
1950 ///
1951 /// Premultiply or un-premultiply color by alpha
1952 ///
1953 /// The `unpremult` operation returns (or copies into `dst`) the pixels of
1954 /// `src` within the ROI, and in the process divides all color channels
1955 /// (those not alpha or z) by the alpha value, to "un-premultiply" them.
1956 /// This presumes that the image starts of as "associated alpha" a.k.a.
1957 /// "premultipled," and you are converting to "unassociated alpha." For
1958 /// pixels with alpha == 0, the color values are not modified.
1959 ///
1960 /// The `premult` operation returns (or copies into `dst`) the pixels of
1961 /// `src` within the ROI, and in the process multiplies all color channels
1962 /// (those not alpha or z) by the alpha value, to "premultiply" them. This
1963 /// presumes that the image starts of as "unassociated alpha" a.k.a.
1964 /// "non-premultipled" and converts it to "associated alpha / premultipled."
1965 ///
1966 /// The `repremult` operation is like `premult`, but preserves the color
1967 /// values of pixels whose alpha is 0. This is intended for cases where you
1968 /// unpremult, do an operation (such as color transforms), then want to
1969 /// return to associated/premultiplied alpha -- in that case, you want to
1970 /// make sure that "glow" pixels (those with alpha=0 but RGB > 0) are
1971 /// preserved for the round trip, and not crushed to black. This use case is
1972 /// distinct from a simple `premult` that is a one-time conversion from
1973 /// unassociated to associated alpha.
1974 ///
1975 /// All three operations are simply a copy if there is no identified alpha
1976 /// channel (and a no-op if `dst` and `src` are the same image).
1977 
1978 ImageBuf OIIO_API unpremult (const ImageBuf &src, ROI roi={}, int nthreads=0);
1979 bool OIIO_API unpremult (ImageBuf &dst, const ImageBuf &src,
1980  ROI roi={}, int nthreads=0);
1981 ImageBuf OIIO_API premult (const ImageBuf &src, ROI roi={}, int nthreads=0);
1982 bool OIIO_API premult (ImageBuf &dst, const ImageBuf &src,
1983  ROI roi={}, int nthreads=0);
1984 ImageBuf OIIO_API repremult (const ImageBuf &src, ROI roi={}, int nthreads=0);
1985 bool OIIO_API repremult (ImageBuf &dst, const ImageBuf &src,
1986  ROI roi={}, int nthreads=0);
1987 /// @}
1988 
1989 
1990 
1996 };
1997 
1998 /// @defgroup make_texture (make_texture -- Turn an image into a texture)
1999 /// @{
2000 ///
2001 /// The `make_texture()` function turns an image into a tiled, MIP-mapped,
2002 /// texture file and write it to disk (outputfilename).
2003 ///
2004 /// The return value is `true` for success, `false` if an error occurred. If
2005 /// there was an error, any error message will be retrievable via the global
2006 /// `OIIO::geterror()` call (since there is no destination `ImageBuf` in
2007 /// which to store it).
2008 ///
2009 /// Named fields in config:
2010 ///
2011 /// - format : Data format of the texture file (default: UNKNOWN = same
2012 /// format as the input)
2013 /// - tile_width/tile_height/tile_depth :
2014 /// Preferred tile size (default: 64x64x1)
2015 ///
2016 /// Metadata in `config.extra_attribs`
2017 ///
2018 /// - `compression` (string) : Default: "zip"
2019 /// - `fovcot` (float) : Default: aspect ratio of the image
2020 /// resolution.
2021 /// - `planarconfig` (string) : Default: "separate"
2022 /// - `worldtocamera` (matrix) : World-to-camera matrix of the view.
2023 /// - `worldtoscreen` (matrix) : World-to-screen space matrix of the view.
2024 /// - `worldtoNDC` (matrix) : World-to-NDC space matrix of the view.
2025 /// - `wrapmodes` (string) : Default: "black,black"
2026 /// - `maketx:verbose` (int) : How much detail should go to outstream (0).
2027 /// - `maketx:runstats` (int) : If nonzero, print run stats to outstream (0).
2028 /// - `maketx:resize` (int) : If nonzero, resize to power of 2. (0)
2029 /// - `maketx:nomipmap` (int) : If nonzero, only output the top MIP level (0).
2030 /// - `maketx:updatemode` (int) : If nonzero, write new output only if the
2031 /// output file doesn't already exist, or is
2032 /// older than the input file, or was created
2033 /// with different command-line arguments. (0)
2034 /// - `maketx:constant_color_detect` (int) :
2035 /// If nonzero, detect images that are entirely
2036 /// one color, and change them to be low
2037 /// resolution (default: 0).
2038 /// - `maketx:monochrome_detect` (int) :
2039 /// If nonzero, change RGB images which have
2040 /// R==G==B everywhere to single-channel
2041 /// grayscale (default: 0).
2042 /// - `maketx:opaque_detect` (int) :
2043 /// If nonzero, drop the alpha channel if alpha
2044 /// is 1.0 in all pixels (default: 0).
2045 /// - `maketx:compute_average` (int) :
2046 /// If nonzero, compute and store the average
2047 /// color of the texture (default: 1).
2048 /// - `maketx:unpremult` (int) : If nonzero, unpremultiply color by alpha
2049 /// before color conversion, then multiply by
2050 /// alpha after color conversion (default: 0).
2051 /// - `maketx:incolorspace`, `maketx:outcolorspace` (string) :
2052 /// These two together will apply a color conversion
2053 /// (with OpenColorIO, if compiled). Default: ""
2054 /// - `maketx:colorconfig` (string) :
2055 /// Specifies a custom OpenColorIO color config
2056 /// file. Default: ""
2057 /// - `maketx:checknan` (int) : If nonzero, will consider it an error if the
2058 /// input image has any NaN pixels. (0)
2059 /// - `maketx:fixnan` (string) : If set to "black" or "box3", will attempt
2060 /// to repair any NaN pixels found in the
2061 /// input image (default: "none").
2062 /// - `maketx:set_full_to_pixels` (int) :
2063 /// If nonzero, doctors the full/display window
2064 /// of the texture to be identical to the
2065 /// pixel/data window and reset the origin
2066 /// to 0,0 (default: 0).
2067 /// - `maketx:filtername` (string) :
2068 /// If set, will specify the name of a high-quality
2069 /// filter to use when resampling for MIPmap
2070 /// levels. Default: "", use bilinear resampling.
2071 /// - `maketx:highlightcomp` (int) :
2072 /// If nonzero, performs highlight compensation --
2073 /// range compression and expansion around
2074 /// the resize, plus clamping negative pixel
2075 /// values to zero. This reduces ringing when
2076 /// using filters with negative lobes on HDR
2077 /// images.
2078 /// - `maketx:sharpen` (float) : If nonzero, sharpens details when creating
2079 /// MIPmap levels. The amount is the contrast
2080 /// metric. The default is 0, meaning no
2081 /// sharpening.
2082 /// - `maketx:nchannels` (int) : If nonzero, will specify how many channels
2083 /// the output texture should have, padding with
2084 /// 0 values or dropping channels, if it doesn't
2085 /// the number of channels in the input.
2086 /// (default: 0, meaning keep all input channels)
2087 /// - `maketx:channelnames` (string) :
2088 /// If set, overrides the channel names of the
2089 /// output image (comma-separated).
2090 /// - `maketx:fileformatname` (string) :
2091 /// If set, will specify the output file format.
2092 /// (default: "", meaning infer the format from
2093 /// the output filename)
2094 /// - `maketx:prman_metadata` (int) :
2095 /// If set, output some metadata that PRMan will
2096 /// need for its textures. (0)
2097 /// - `maketx:oiio_options` (int) :
2098 /// (Deprecated; all are handled by default)
2099 /// - `maketx:prman_options` (int) :
2100 /// If nonzero, override a whole bunch of settings
2101 /// as needed to make textures that are
2102 /// compatible with PRMan. (0)
2103 /// - `maketx:mipimages` (string) :
2104 /// Semicolon-separated list of alternate images
2105 /// to be used for individual MIPmap levels,
2106 /// rather than simply downsizing. (default: "")
2107 /// - `maketx:full_command_line` (string) :
2108 /// The command or program used to generate this
2109 /// call, will be embedded in the metadata.
2110 /// (default: "")
2111 /// - `maketx:ignore_unassoc` (int) :
2112 /// If nonzero, will disbelieve any evidence that
2113 /// the input image is unassociated alpha. (0)
2114 /// - `maketx:read_local_MB` (int) :
2115 /// If nonzero, will read the full input file
2116 /// locally if it is smaller than this
2117 /// threshold. Zero causes the system to make a
2118 /// good guess at a reasonable threshold (e.g. 1
2119 /// GB). (0)
2120 /// - `maketx:forcefloat` (int) :
2121 /// Forces a conversion through float data for
2122 /// the sake of ImageBuf math. (1)
2123 /// - `maketx:hash` (int) :
2124 /// Compute the sha1 hash of the file in parallel. (1)
2125 /// - `maketx:allow_pixel_shift` (int) :
2126 /// Allow up to a half pixel shift per mipmap level.
2127 /// The fastest path may result in a slight shift
2128 /// in the image, accumulated for each mip level
2129 /// with an odd resolution. (0)
2130 /// - `maketx:bumpformat` (string) :
2131 /// For the MakeTxBumpWithSlopes mode, chooses
2132 /// whether to assume the map is a height map
2133 /// ("height"), a normal map ("normal"), or
2134 /// automatically determine it from the number
2135 /// of channels ("auto", the default).
2136 /// - `maketx:uvslopes_scale` (float) :
2137 /// If nonzero, when used in MakeTxBumpWithSlopes
2138 /// mode, this computes derivatives for the
2139 /// bumpslopes data in UV space rather than in
2140 /// texel space, and divides them by this scale
2141 /// factor. The default is 0, disabling the
2142 /// feature. If you use this feature, a suggested
2143 /// value is 256.
2144 /// - `maketx:cdf` (int) :
2145 /// If nonzero, will write a Gaussian CDF and
2146 /// Inverse Gaussian CDF as per-channel metadata
2147 /// in the texture, which can be used by shaders
2148 /// to implement Histogram-Preserving Blending.
2149 /// This is only useful when the texture being
2150 /// created is written to an image format that
2151 /// supports arbitrary metadata (e.g. OpenEXR).
2152 /// (See Burley, "On Histogram-Preserving Blending
2153 /// for Randomized Texture Tiling," JCGT 8(4), 2019,
2154 /// and Heitz/Neyret, "High-Performance By-Example
2155 /// Noise using a Histogram-Preserving Blending
2156 /// Operator," ACM SIGGRAPH / Eurographics Symposium
2157 /// on High-Performance Graphics 2018.) (default: 0)
2158 /// - `maketx:cdfsigma` (float) :
2159 /// When `maketx:cdf` is active, determines the
2160 /// CDF sigma (default: 1.0/6).
2161 /// - `maketx:cdfbits` (int) :
2162 /// When `maketx:cdf` is active, determines the
2163 /// number of bits to use for the size of the CDF
2164 /// table. (default: 8, meaning 256 bins)
2165 ///
2166 /// @param mode
2167 /// Describes what type of texture file we are creating and may
2168 /// be one of:
2169 /// - `MakeTxTexture` : Ordinary 2D texture.
2170 /// - `MakeTxEnvLatl` : Latitude-longitude environment map
2171 /// - `MakeTxEnvLatlFromLightProbe` : Latitude-longitude environment map
2172 /// constructed from a "light probe"
2173 /// image.
2174 /// - `MakeTxBumpWithSlopes` : Bump/displacement map with extra slope
2175 /// data channels (6 channels total,
2176 /// containing both the height and 1st and
2177 /// 2nd moments of slope distributions) for
2178 /// bump-to-roughness conversion in shaders.
2179 /// @param outputfilename
2180 /// Name of the file in which to save the resulting texture.
2181 /// @param config An ImageSpec that contains all the information and
2182 /// special instructions for making the texture. Anything set in config
2183 /// (format, tile size, or named metadata) will take precedence over
2184 /// whatever is specified by the input file itself. Additionally, named
2185 /// metadata that starts with "maketx:" will not be output to the file
2186 /// itself, but may contain instructions controlling how the texture is
2187 /// created. The full list of supported configuration options is listed
2188 /// below.
2189 /// @param outstream
2190 /// If not `nullptr`, it should point to a stream (for example,
2191 /// `&std::out`, or a pointer to a local `std::stringstream` to capture
2192 /// output), which is where console output and errors will be
2193 /// deposited. Note that error messages will also be retrievable from
2194 /// OIIO::geterror().
2195 ///
2196 ///
2197 
2198 /// Version of make_texture that starts with an ImageBuf.
2200  const ImageBuf &input,
2201  string_view outputfilename,
2202  const ImageSpec &config,
2203  std::ostream *outstream = nullptr);
2204 
2205 /// Version of make_texture that starts with a filename and reads the input
2206 /// from that file, rather than being given an ImageBuf directly.
2209  string_view outputfilename,
2210  const ImageSpec &config,
2211  std::ostream *outstream = nullptr);
2212 
2213 /// Version of make_texture that takes multiple filenames (reserved for
2214 /// future expansion, such as assembling several faces into a cube map).
2216  const std::vector<std::string> &filenames,
2217  string_view outputfilename,
2218  const ImageSpec &config,
2219  std::ostream *outstream = nullptr);
2220 /// @}
2221 
2222 
2223 /// Convert an OpenCV cv::Mat into an ImageBuf, copying the pixels
2224 /// (optionally converting to the pixel data type specified by `convert`, if
2225 /// not UNKNOWN, which means to preserve the original data type if
2226 /// possible). Return true if ok, false if it couldn't figure out how to
2227 /// make the conversion from Mat to ImageBuf. If OpenImageIO was compiled
2228 /// without OpenCV support, this function will return an empty image with
2229 /// error message set.
2231 from_OpenCV (const cv::Mat& mat, TypeDesc convert = TypeUnknown,
2232  ROI roi={}, int nthreads=0);
2233 
2234 /// Construct an OpenCV cv::Mat containing the contents of ImageBuf src, and
2235 /// return true. If it is not possible, or if OpenImageIO was compiled
2236 /// without OpenCV support, then return false. Note that OpenCV only
2237 /// supports up to 4 channels, so >4 channel images will be truncated in the
2238 /// conversion.
2239 OIIO_API bool to_OpenCV (cv::Mat& dst, const ImageBuf& src,
2240  ROI roi={}, int nthreads=0);
2241 
2242 
2243 /// Capture a still image from a designated camera. If able to do so,
2244 /// store the image in dst and return true. If there is no such device,
2245 /// or support for camera capture is not available (such as if OpenCV
2246 /// support was not enabled at compile time), return false and do not
2247 /// alter dst.
2248 ImageBuf OIIO_API capture_image (int cameranum = 0,
2249  TypeDesc convert=TypeUnknown);
2250 
2251 
2252 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2253 // DEPRECATED(1.9):
2254 OIIO_DEPRECATED("use version that returns ImageBuf (1.9)")
2255 inline bool capture_image (ImageBuf &dst, int cameranum = 0,
2256  TypeDesc convert=TypeUnknown) {
2257  dst = capture_image (cameranum, convert);
2258  return !dst.has_error();
2259 }
2260 #endif // DOXYGEN_SHOULD_SKIP_THIS
2261 
2262 
2263 #if defined(__OPENCV_CORE_TYPES_H__) || defined(OPENCV_CORE_TYPES_H)
2264 // These declarations are only visible if the OpenCV headers have already
2265 // been encountered.
2266 
2267 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2268 // DEPRECATED(2.0). The OpenCV 1.x era IplImage-based functions should be
2269 // avoided, giving preference to from_OpenCV.
2270 ImageBuf OIIO_API from_IplImage (const IplImage *ipl,
2271  TypeDesc convert=TypeUnknown);
2272 // DEPRECATED(1.9):
2273 OIIO_DEPRECATED("use from_OpenCV (1.9)")
2274 inline bool from_IplImage (ImageBuf &dst, const IplImage *ipl,
2275  TypeDesc convert=TypeUnknown) {
2276  dst = from_IplImage (ipl, convert);
2277  return ! dst.has_error();
2278 }
2279 
2280 // DEPRECATED(2.0). The OpenCV 1.x era IplImage-based functions should be
2281 // avoided, giving preference to from_OpenCV.
2282 OIIO_DEPRECATED("use from_OpenCV (2.9)")
2283 OIIO_API IplImage* to_IplImage (const ImageBuf &src);
2284 #endif // DOXYGEN_SHOULD_SKIP_THIS
2285 
2286 #endif
2287 
2288 
2289 
2290 /// Return the "deep" equivalent of the "flat" input `src`. Turning a flat
2291 /// image into a deep one means:
2292 ///
2293 /// * If the `src` image has a "Z" channel: if the source pixel's Z channel
2294 /// value is not infinite, the corresponding pixel of `dst` will get a
2295 /// single depth sample that copies the data from the source pixel;
2296 /// otherwise, dst will get an empty pixel. In other words, infinitely far
2297 /// pixels will not turn into deep samples.
2298 ///
2299 /// * If the `src` image lacks a "Z" channel: if any of the source pixel's
2300 /// channel values are nonzero, the corresponding pixel of `dst` will get
2301 /// a single depth sample that copies the data from the source pixel and
2302 /// uses the zvalue parameter for the depth; otherwise, if all source
2303 /// channels in that pixel are zero, the destination pixel will get no
2304 /// depth samples.
2305 ///
2306 /// If `src` is already a deep image, it will just copy pixel values from
2307 /// `src`.
2308 ImageBuf OIIO_API deepen (const ImageBuf &src, float zvalue = 1.0f,
2309  ROI roi={}, int nthreads=0);
2310 /// Write to an existing image `dst` (allocating if it is uninitialized).
2311 bool OIIO_API deepen (ImageBuf &dst, const ImageBuf &src, float zvalue = 1.0f,
2312  ROI roi={}, int nthreads=0);
2313 
2314 
2315 /// Return the "flattened" composite of deep image `src`. That is, it
2316 /// converts a deep image to a simple flat image by front-to- back
2317 /// compositing the samples within each pixel. If `src` is already a
2318 /// non-deep/flat image, it will just copy pixel values from `src` to `dst`.
2319 /// If `dst` is not already an initialized ImageBuf, it will be sized to
2320 /// match `src` (but made non-deep).
2321 ImageBuf OIIO_API flatten (const ImageBuf &src, ROI roi={}, int nthreads=0);
2322 /// Write to an existing image `dst` (allocating if it is uninitialized).
2323 bool OIIO_API flatten (ImageBuf &dst, const ImageBuf &src,
2324  ROI roi={}, int nthreads=0);
2325 
2326 
2327 /// Return the deep merge of the samples of deep images `A` and `B`,
2328 /// overwriting any existing samples of `dst` in the ROI. If
2329 /// `occlusion_cull` is true, any samples occluded by an opaque sample will
2330 /// be deleted.
2331 ImageBuf OIIO_API deep_merge (const ImageBuf &A, const ImageBuf &B,
2332  bool occlusion_cull = true,
2333  ROI roi={}, int nthreads=0);
2334 /// Write to an existing image `dst` (allocating if it is uninitialized).
2335 bool OIIO_API deep_merge (ImageBuf &dst, const ImageBuf &A,
2336  const ImageBuf &B, bool occlusion_cull = true,
2337  ROI roi={}, int nthreads=0);
2338 
2339 
2340 /// Return the samples of deep image `src` that are closer than the opaque
2341 /// frontier of deep image holdout, returning true upon success and false
2342 /// for any failures. Samples of `src` that are farther than the first
2343 /// opaque sample of holdout (for the corresponding pixel)will not be copied
2344 /// to `dst`. Image holdout is only used as the depth threshold; no sample
2345 /// values from holdout are themselves copied to `dst`.
2346 ImageBuf OIIO_API deep_holdout (const ImageBuf &src, const ImageBuf &holdout,
2347  ROI roi={}, int nthreads=0);
2348 /// Write to an existing image `dst` (allocating if it is uninitialized).
2349 bool OIIO_API deep_holdout (ImageBuf &dst, const ImageBuf &src,
2350  const ImageBuf &holdout,
2351  ROI roi={}, int nthreads=0);
2352 
2353 
2354 
2355 
2356 ///////////////////////////////////////////////////////////////////////
2357 // DEPRECATED(1.9): These are all functions that take raw pointers,
2358 // which we are deprecating as of 1.9, replaced by new versions that
2359 // take span<> for length safety.
2360 
2361 #ifndef DOXYGEN_SHOULD_SKIP_THIS
2362 
2363 inline bool fill (ImageBuf &dst, const float *values,
2364  ROI roi={}, int nthreads=0) {
2365  int nc (roi.defined() ? roi.nchannels() : dst.nchannels());
2366  return fill (dst, {values, nc}, roi, nthreads);
2367 }
2368 inline bool fill (ImageBuf &dst, const float *top, const float *bottom,
2369  ROI roi={}, int nthreads=0) {
2370  int nc (roi.defined() ? roi.nchannels() : dst.nchannels());
2371  return fill (dst, {top, nc}, {bottom, nc}, roi, nthreads);
2372 }
2373 inline bool fill (ImageBuf &dst, const float *topleft, const float *topright,
2374  const float *bottomleft, const float *bottomright,
2375  ROI roi={}, int nthreads=0) {
2376  int nc (roi.defined() ? roi.nchannels() : dst.nchannels());
2377  return fill (dst, {topleft, nc}, {topright, nc}, {bottomleft, nc},
2378  {bottomright, nc}, roi, nthreads);
2379 }
2380 
2381 inline bool checker (ImageBuf &dst, int width, int height, int depth,
2382  const float *color1, const float *color2,
2383  int xoffset=0, int yoffset=0, int zoffset=0,
2384  ROI roi={}, int nthreads=0) {
2385  int nc (roi.defined() ? roi.nchannels() : dst.nchannels());
2386  return checker (dst, width, height, depth, {color1,nc}, {color2,nc},
2387  xoffset, yoffset, zoffset, roi, nthreads);
2388 }
2389 
2390 inline bool add (ImageBuf &dst, const ImageBuf &A, const float *B,
2391  ROI roi={}, int nthreads=0) {
2392  return add (dst, A, {B,A.nchannels()}, roi, nthreads);
2393 }
2394 inline bool sub (ImageBuf &dst, const ImageBuf &A, const float *B,
2395  ROI roi={}, int nthreads=0) {
2396  return sub (dst, A, {B,A.nchannels()}, roi, nthreads);
2397 }
2398 inline bool absdiff (ImageBuf &dst, const ImageBuf &A, const float *B,
2399  ROI roi={}, int nthreads=0) {
2400  return absdiff (dst, A, cspan<float>(B,A.nchannels()), roi, nthreads);
2401 }
2402 inline bool mul (ImageBuf &dst, const ImageBuf &A, const float *B,
2403  ROI roi={}, int nthreads=0) {
2404  return mul (dst, A, {B, A.nchannels()}, roi, nthreads);
2405 }
2406 inline bool div (ImageBuf &dst, const ImageBuf &A, const float *B,
2407  ROI roi={}, int nthreads=0) {
2408  return div (dst, A, {B, A.nchannels()}, roi, nthreads);
2409 }
2410 inline bool mad (ImageBuf &dst, const ImageBuf &A, const float *B,
2411  const ImageBuf &C, ROI roi={}, int nthreads=0) {
2412  return mad (dst, A, {B, A.nchannels()}, C, roi, nthreads);
2413 }
2414 inline bool mad (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
2415  const float *C, ROI roi={}, int nthreads=0) {
2416  return mad (dst, A, C, B, roi, nthreads);
2417 }
2418 inline bool mad (ImageBuf &dst, const ImageBuf &A, const float *B,
2419  const float *C, ROI roi={}, int nthreads=0) {
2420  return mad (dst, A, {B, A.nchannels()}, {C, A.nchannels()}, roi, nthreads);
2421 }
2422 
2423 inline bool pow (ImageBuf &dst, const ImageBuf &A, const float *B,
2424  ROI roi={}, int nthreads=0) {
2425  return pow (dst, A, {B, A.nchannels()}, roi, nthreads);
2426 }
2427 
2428 inline bool channel_sum (ImageBuf &dst, const ImageBuf &src,
2429  const float *weights=nullptr, ROI roi={},
2430  int nthreads=0) {
2431  return channel_sum (dst, src, {weights, src.nchannels()},
2432  roi, nthreads);
2433 }
2434 
2435 inline bool channels (ImageBuf &dst, const ImageBuf &src,
2436  int nchannels, const int *channelorder,
2437  const float *channelvalues=nullptr,
2438  const std::string *newchannelnames=nullptr,
2439  bool shuffle_channel_names=false, int nthreads=0) {
2440  return channels (dst, src, nchannels,
2441  { channelorder, channelorder?nchannels:0 },
2442  { channelvalues, channelvalues?nchannels:0 },
2443  { newchannelnames, newchannelnames?nchannels:0},
2444  shuffle_channel_names, nthreads);
2445 }
2446 
2447 inline bool clamp (ImageBuf &dst, const ImageBuf &src,
2448  const float *min=nullptr, const float *max=nullptr,
2449  bool clampalpha01 = false,
2450  ROI roi={}, int nthreads=0) {
2451  return clamp (dst, src, { min, min ? src.nchannels() : 0 },
2452  { max, max ? src.nchannels() : 0 }, clampalpha01,
2453  roi, nthreads);
2454 }
2455 
2456 inline bool isConstantColor (const ImageBuf &src, float *color,
2457  ROI roi={}, int nthreads=0) {
2458  int nc = roi.defined() ? std::min(roi.chend,src.nchannels()) : src.nchannels();
2459  return isConstantColor (src, {color, color ? nc : 0}, roi, nthreads);
2460 }
2461 
2462 inline bool color_count (const ImageBuf &src, imagesize_t *count,
2463  int ncolors, const float *color,
2464  const float *eps=nullptr,
2465  ROI roi={}, int nthreads=0) {
2466  return color_count (src, count, ncolors,
2467  { color, ncolors*src.nchannels() },
2468  eps ? cspan<float>(eps,src.nchannels()) : cspan<float>(),
2469  roi, nthreads);
2470 }
2471 
2472 inline bool color_range_check (const ImageBuf &src, imagesize_t *lowcount,
2473  imagesize_t *highcount, imagesize_t *inrangecount,
2474  const float *low, const float *high,
2475  ROI roi={}, int nthreads=0) {
2476  return color_range_check (src, lowcount, highcount, inrangecount,
2477  {low,src.nchannels()}, {high,src.nchannels()},
2478  roi, nthreads);
2479 }
2480 
2481 inline bool render_text (ImageBuf &dst, int x, int y, string_view text,
2482  int fontsize, string_view fontname,
2483  const float *textcolor) {
2484  return render_text (dst, x, y, text, fontsize, fontname,
2485  {textcolor, textcolor?dst.nchannels():0});
2486 }
2487 
2488 #endif // DOXYGEN_SHOULD_SKIP_THIS
2489 
2490 ///////////////////////////////////////////////////////////////////////
2491 
2492 } // end namespace ImageBufAlgo
2493 
OIIO_API std::vector< imagesize_t > histogram(const ImageBuf &src, int channel=0, int bins=256, float min=0.0f, float max=1.0f, bool ignore_empty=false, ROI roi={}, int nthreads=0)
bool OIIO_API paste(ImageBuf &dst, int xbegin, int ybegin, int zbegin, int chbegin, const ImageBuf &src, ROI srcroi={}, int nthreads=0)
std::vector< double > sum2
ImageBuf OIIO_API fill(cspan< float > values, ROI roi, int nthreads=0)
bool OIIO_API render_point(ImageBuf &dst, int x, int y, cspan< float > color=1.0f, ROI roi={}, int nthreads=0)
GLint GLint GLint yoffset
Definition: glcorearb.h:412
GT_API const UT_StringHolder filename
ImageBuf OIIO_API ifft(const ImageBuf &src, ROI roi={}, int nthreads=0)
bool OIIO_API color_count(const ImageBuf &src, imagesize_t *count, int ncolors, cspan< float > color, cspan< float > eps=0.001f, ROI roi={}, int nthreads=0)
const ImageBuf & img() const
Definition: imagebufalgo.h:172
Matrix44< float > M44f
4x4 matrix of float
Definition: ImathMatrix.h:1137
ImageBuf OIIO_API copy(const ImageBuf &src, TypeDesc convert=TypeUnknown, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API complex_to_polar(const ImageBuf &src, ROI roi={}, int nthreads=0)
SIM_API const UT_StringHolder angle
bool OIIO_API max(ImageBuf &dst, Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Write to an existing image dst (allocating if it is uninitialized).
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1639
const GLdouble * v
Definition: glcorearb.h:837
Encapsulation of options that control parallel_image().
Definition: parallel.h:28
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
ImageBuf OIIO_API ociolook(const ImageBuf &src, string_view looks, string_view fromspace, string_view tospace, bool unpremult=true, bool inverse=false, string_view context_key="", string_view context_value="", ColorConfig *colorconfig=nullptr, ROI roi={}, int nthreads=0)
std::string OIIO_API computePixelHashSHA1(const ImageBuf &src, string_view extrainfo="", ROI roi={}, int blocksize=0, int nthreads=0)
Definition: span.h:73
OIIO_API bool isMonochrome(const ImageBuf &src, float threshold=0.0f, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API channel_append(const ImageBuf &A, const ImageBuf &B, ROI roi={}, int nthreads=0)
std::vector< imagesize_t > infcount
ImageBuf OIIO_API mad(Image_or_Const A, Image_or_Const B, Image_or_Const C, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API abs(const ImageBuf &A, ROI roi={}, int nthreads=0)
Compute per-pixel absolute value abs(A), returning the result image.
GLdouble s
Definition: glad.h:3009
bool OIIO_API render_box(ImageBuf &dst, int x1, int y1, int x2, int y2, cspan< float > color=1.0f, bool fill=false, ROI roi={}, int nthreads=0)
Image_or_Const(const std::vector< float > &val)
Definition: imagebufalgo.h:164
ImageBuf OIIO_API reorient(const ImageBuf &src, int nthreads=0)
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define OIIO_DEPRECATED(msg)
Definition: platform.h:458
GLint y
Definition: glcorearb.h:103
Tto convert(const Tfrom &source)
ImageBuf OIIO_API checker(int width, int height, int depth, cspan< float > color1, cspan< float > color2, int xoffset, int yoffset, int zoffset, ROI roi, int nthreads=0)
ImageBuf OIIO_API flatten(const ImageBuf &src, ROI roi={}, int nthreads=0)
**But if you need a result
Definition: thread.h:613
OIIO_API bool to_OpenCV(cv::Mat &dst, const ImageBuf &src, ROI roi={}, int nthreads=0)
std::vector< imagesize_t > finitecount
ImageBuf OIIO_API rotate270(const ImageBuf &src, ROI roi={}, int nthreads=0)
GLdouble GLdouble x2
Definition: glad.h:2349
Matrix33< float > M33f
3x3 matrix of float
Definition: ImathMatrix.h:1131
ImageBuf OIIO_API rangecompress(const ImageBuf &src, bool useluma=false, ROI roi={}, int nthreads=0)
basic_string_view< char > string_view
Definition: core.h:522
std::vector< float > stddev
ImageBuf OIIO_API transpose(const ImageBuf &src, ROI roi={}, int nthreads=0)
OIIO_API ImageBuf from_OpenCV(const cv::Mat &mat, TypeDesc convert=TypeUnknown, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API laplacian(const ImageBuf &src, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API pow(const ImageBuf &A, cspan< float > B, ROI roi={}, int nthreads=0)
const ImageBuf * imgptr() const
Definition: imagebufalgo.h:173
ImageBuf OIIO_API clamp(const ImageBuf &src, cspan< float > min=-std::numeric_limits< float >::max(), cspan< float > max=std::numeric_limits< float >::max(), bool clampalpha01=false, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API fixNonFinite(const ImageBuf &src, NonFiniteFixMode mode=NONFINITE_BOX3, int *pixelsFixed=nullptr, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder scale
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API polar_to_complex(const ImageBuf &src, ROI roi={}, int nthreads=0)
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
ImageBuf OIIO_API fit(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, string_view fillmode="letterbox", bool exact=false, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API fillholes_pushpull(const ImageBuf &src, ROI roi={}, int nthreads=0)
GLfloat f
Definition: glcorearb.h:1926
ImageBuf OIIO_API flop(const ImageBuf &src, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API sub(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
PixelStats(int nchannels)
ImageBuf OIIO_API make_kernel(string_view name, float width, float height, float depth=1.0f, bool normalize=true)
GLboolean reset
Definition: glad.h:5138
ImageBuf OIIO_API deep_merge(const ImageBuf &A, const ImageBuf &B, bool occlusion_cull=true, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API ociodisplay(const ImageBuf &src, string_view display, string_view view, string_view fromspace="", string_view looks="", bool unpremult=true, string_view context_key="", string_view context_value="", ColorConfig *colorconfig=nullptr, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API deepen(const ImageBuf &src, float zvalue=1.0f, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API premult(const ImageBuf &src, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API dilate(const ImageBuf &src, int width=3, int height=-1, ROI roi={}, int nthreads=0)
ROI OIIO_API text_size(string_view text, int fontsize=16, string_view fontname="")
ImageBuf OIIO_API rotate180(const ImageBuf &src, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API erode(const ImageBuf &src, int width=3, int height=-1, ROI roi={}, int nthreads=0)
GLdouble y1
Definition: glad.h:2349
ImageBuf OIIO_API invert(const ImageBuf &A, ROI roi={}, int nthreads=0)
cspan< float > val() const
Definition: imagebufalgo.h:174
ImageBuf OIIO_API maxchan(const ImageBuf &A, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API color_map(const ImageBuf &src, int srcchannel, int nknots, int channels, cspan< float > knots, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API circular_shift(const ImageBuf &src, int xshift, int yshift, int zshift=0, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API over(const ImageBuf &A, const ImageBuf &B, ROI roi={}, int nthreads=0)
OIIO_API ImageBuf contrast_remap(const ImageBuf &src, cspan< float > black=0.0f, cspan< float > white=1.0f, cspan< float > min=0.0f, cspan< float > max=1.0f, cspan< float > scontrast=1.0f, cspan< float > sthresh=0.5f, ROI={}, int nthreads=0)
ImageBuf OIIO_API ociofiletransform(const ImageBuf &src, string_view name, bool unpremult=true, bool inverse=false, ColorConfig *colorconfig=nullptr, ROI roi={}, int nthreads=0)
std::vector< imagesize_t > nancount
void swap(Image_or_Const &other)
Definition: imagebufalgo.h:176
GLint GLint xoffset
Definition: glcorearb.h:411
ImageBuf OIIO_API saturate(const ImageBuf &src, float scale=0.0f, int firstchannel=0, ROI roi={}, int nthreads=0)
GLuint const GLchar * name
Definition: glcorearb.h:786
Image_or_Const(const float &val)
Definition: imagebufalgo.h:163
ImageBuf OIIO_API fft(const ImageBuf &src, ROI roi={}, int nthreads=0)
GLint GLenum GLint x
Definition: glcorearb.h:409
ImageBuf OIIO_API repremult(const ImageBuf &src, ROI roi={}, int nthreads=0)
GLint void * img
Definition: glcorearb.h:556
ImageBuf OIIO_API rotate(const ImageBuf &src, float angle, string_view filtername=string_view(), float filterwidth=0.0f, bool recompute_roi=false, ROI roi={}, int nthreads=0)
bool is_val() const
Definition: imagebufalgo.h:170
Image_or_Const(const ImageBuf &img)
Definition: imagebufalgo.h:160
ImageBuf OIIO_API div(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool OIIO_API make_texture(MakeTextureMode mode, const ImageBuf &input, string_view outputfilename, const ImageSpec &config, std::ostream *outstream=nullptr)
Version of make_texture that starts with an ImageBuf.
ImageBuf OIIO_API capture_image(int cameranum=0, TypeDesc convert=TypeUnknown)
std::vector< float > max
GLenum mode
Definition: glcorearb.h:99
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
GLint GLint bottom
Definition: glcorearb.h:2005
Image_or_Const(const ImageBuf *img)
Definition: imagebufalgo.h:161
ImageBuf OIIO_API noise(string_view noisetype, float A=0.0f, float B=0.1f, bool mono=false, int seed=0, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API flip(const ImageBuf &src, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API unpremult(const ImageBuf &src, ROI roi={}, int nthreads=0)
bool OIIO_API min(ImageBuf &dst, Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Write to an existing image dst (allocating if it is uninitialized).
bool OIIO_API render_line(ImageBuf &dst, int x1, int y1, int x2, int y2, cspan< float > color=1.0f, bool skip_first_point=false, ROI roi={}, int nthreads=0)
GLenum GLenum dst
Definition: glcorearb.h:1793
Definition: imageio.h:85
ImageBuf OIIO_API cut(const ImageBuf &src, ROI roi={}, int nthreads=0)
OIIO_API const ImageBuf & bluenoise_image()
Image_or_Const(None)
Definition: imagebufalgo.h:159
OIIO_API bool isConstantColor(const ImageBuf &src, float threshold=0.0f, span< float > color={}, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
int OIIO_API compare_Yee(const ImageBuf &A, const ImageBuf &B, CompareResults &result, float luminance=100, float fov=45, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API colormatrixtransform(const ImageBuf &src, const Imath::M44f &M, bool unpremult=true, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API rotate90(const ImageBuf &src, ROI roi={}, int nthreads=0)
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
Replace non-finite values with 0.0.
GLuint color
Definition: glcorearb.h:1261
ImageBuf OIIO_API median_filter(const ImageBuf &src, int width=3, int height=-1, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API absdiff(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
LeafData & operator=(const LeafData &)=delete
std::vector< float > min
bool OIIO_API render_text(ImageBuf &dst, int x, int y, string_view text, int fontsize=16, string_view fontname="", cspan< float > textcolor=1.0f, TextAlignX alignx=TextAlignX::Left, TextAlignY aligny=TextAlignY::Baseline, int shadow=0, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint GLfloat * val
Definition: glcorearb.h:1608
ImageBuf OIIO_API colorconvert(const ImageBuf &src, string_view fromspace, string_view tospace, bool unpremult=true, string_view context_key="", string_view context_value="", ColorConfig *colorconfig=nullptr, ROI roi={}, int nthreads=0)
Transform between named color spaces, returning an ImageBuf result.
Image_or_Const(const float *v, size_t s)
Definition: imagebufalgo.h:166
ImageBuf OIIO_API channel_sum(const ImageBuf &src, cspan< float > weights=1.0f, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API rangeexpand(const ImageBuf &src, bool useluma=false, ROI roi={}, int nthreads=0)
GLint GLsizei width
Definition: glcorearb.h:103
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
Definition: core.h:982
ImageBuf OIIO_API unsharp_mask(const ImageBuf &src, string_view kernel="gaussian", float width=3.0f, float contrast=1.0f, float threshold=0.0f, ROI roi={}, int nthreads=0)
OIIO_API ROI nonzero_region(const ImageBuf &src, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API warp(const ImageBuf &src, const Imath::M33f &M, string_view filtername=string_view(), float filterwidth=0.0f, bool recompute_roi=false, ImageBuf::WrapMode wrap=ImageBuf::WrapDefault, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Image_or_Const(const float *v, int s)
Definition: imagebufalgo.h:167
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
ImageBuf OIIO_API deep_holdout(const ImageBuf &src, const ImageBuf &holdout, ROI roi={}, int nthreads=0)
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
std::vector< float > avg
ImageBuf OIIO_API crop(const ImageBuf &src, ROI roi={}, int nthreads=0)
bool OIIO_API histogram_draw(ImageBuf &dst, const std::vector< imagesize_t > &histogram)
ImageBuf OIIO_API resample(const ImageBuf &src, bool interpolate=true, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API zero(ROI roi, int nthreads=0)
uint64_t imagesize_t
Definition: imageio.h:52
ImageBuf OIIO_API convolve(const ImageBuf &src, const ImageBuf &kernel, bool normalize=true, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API minchan(const ImageBuf &src, ROI roi={}, int nthreads=0)
Image_or_Const(cspan< float > val)
Definition: imagebufalgo.h:162
bool is_empty() const
Definition: imagebufalgo.h:171
ImageBuf OIIO_API zover(const ImageBuf &A, const ImageBuf &B, bool z_zeroisinf=false, ROI roi={}, int nthreads=0)
GLint GLint GLint GLint zoffset
Definition: glcorearb.h:477
GLint GLsizei count
Definition: glcorearb.h:405
PixelStats OIIO_API computePixelStats(const ImageBuf &src, ROI roi={}, int nthreads=0)
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
bool OIIO_API color_range_check(const ImageBuf &src, imagesize_t *lowcount, imagesize_t *highcount, imagesize_t *inrangecount, cspan< float > low, cspan< float > high, ROI roi={}, int nthreads=0)
OIIO_API bool isConstantChannel(const ImageBuf &src, int channel, float val, float threshold=0.0f, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)
Image_or_Const(std::initializer_list< const float > val)
Definition: imagebufalgo.h:165
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93
ImageBuf OIIO_API mul(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int nchannels() const
#define OIIO_API
Definition: export.h:65
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GLenum src
Definition: glcorearb.h:1793
bool is_img() const
Definition: imagebufalgo.h:169