OpenImageIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
imagebufalgo.h
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
3  All Rights Reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
32 #ifndef OPENIMAGEIO_IMAGEBUFALGO_H
33 #define OPENIMAGEIO_IMAGEBUFALGO_H
34 
35 #if defined(_MSC_VER)
36 // Ignore warnings about DLL exported classes with member variables that are template classes.
37 // This happens with the std::vector<T> members of PixelStats below.
38 # pragma warning (disable : 4251)
39 #endif
40 
41 #include "imageio.h"
42 #include "imagebuf.h"
43 #include "fmath.h"
44 #include "color.h"
45 #include "thread.h"
46 
47 #include <limits>
48 
49 #ifndef __OPENCV_CORE_TYPES_H__
50 struct IplImage; // Forward declaration; used by Intel Image lib & OpenCV
51 #endif
52 
53 
54 
55 OIIO_NAMESPACE_ENTER
56 {
57 
58 class Filter2D; // forward declaration
59 
60 
61 
88 
89 
90 
91 namespace ImageBufAlgo {
92 
111 bool OIIO_API zero (ImageBuf &dst, ROI roi=ROI::All(), int nthreads=0);
112 
113 
134 bool OIIO_API fill (ImageBuf &dst, const float *values,
135  ROI roi=ROI::All(), int nthreads=0);
136 
138 inline bool OIIO_API fill (ImageBuf &dst, const float *pixel,
139  int xbegin, int xend, int ybegin, int yend,
140  int zbegin=0, int zend=1) {
141  return fill (dst, pixel, ROI(xbegin,xend,ybegin,yend,zbegin,zend));
142 }
143 
144 
145 
168 bool OIIO_API checker (ImageBuf &dst, int width, int height, int depth,
169  const float *color1, const float *color2,
170  int xoffset, int yoffset, int zoffset,
171  ROI roi=ROI::All(), int nthreads=0);
172 
174 bool OIIO_API checker (ImageBuf &dst, int width,
175  const float *color1, const float *color2,
176  int xbegin, int xend, int ybegin, int yend,
177  int zbegin=0, int zend=1);
178 
179 
180 
205 bool OIIO_API channels (ImageBuf &dst, const ImageBuf &src,
206  int nchannels, const int *channelorder,
207  const float *channelvalues=NULL,
208  const std::string *newchannelnames=NULL,
209  bool shuffle_channel_names=false);
210 
213 bool OIIO_API channels (ImageBuf &dst, const ImageBuf &src,
214  int nchannels, const int *channelorder,
215  bool shuffle_channel_names);
216 
219 bool OIIO_API setNumChannels(ImageBuf &dst, const ImageBuf &src, int numChannels);
220 
221 
227 bool OIIO_API channel_append (ImageBuf &dst, const ImageBuf &A,
228  const ImageBuf &B, ROI roi=ROI::All(),
229  int nthreads=0);
230 
231 
243 bool OIIO_API crop (ImageBuf &dst, const ImageBuf &src,
244  ROI roi = ROI::All(), int nthreads = 0);
245 
246 
261 bool OIIO_API paste (ImageBuf &dst, int xbegin, int ybegin,
262  int zbegin, int chbegin,
263  const ImageBuf &src, ROI srcroi=ROI::All(),
264  int nthreads = 0);
265 
266 
285 bool OIIO_API flip (ImageBuf &dst, const ImageBuf &src,
286  ROI roi=ROI::All(), int nthreads=0);
287 
306 bool OIIO_API flop (ImageBuf &dst, const ImageBuf &src,
307  ROI roi=ROI::All(), int nthreads=0);
308 
328 bool OIIO_API flipflop (ImageBuf &dst, const ImageBuf &src,
329  ROI roi=ROI::All(), int nthreads=0);
330 
350 bool OIIO_API transpose (ImageBuf &dst, const ImageBuf &src,
351  ROI roi=ROI::All(), int nthreads=0);
352 
353 
373 bool OIIO_API circular_shift (ImageBuf &dst, const ImageBuf &src,
374  int xshift, int yshift, int zshift=0,
375  ROI roi=ROI::All(), int nthreads=0);
376 
377 
396 bool OIIO_API clamp (ImageBuf &dst,
397  const float *min=NULL, const float *max=NULL,
398  bool clampalpha01 = false,
399  ROI roi = ROI::All(), int nthreads = 0);
400 
416 bool OIIO_API clamp (ImageBuf &dst,
417  float min=-std::numeric_limits<float>::max(),
418  float max=std::numeric_limits<float>::max(),
419  bool clampalpha01 = false,
420  ROI roi = ROI::All(), int nthreads = 0);
421 
439 bool OIIO_API add (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
440  ROI roi=ROI::All(), int nthreads=0);
441 
454 bool OIIO_API add (ImageBuf &dst, float val,
455  ROI roi=ROI::All(), int nthreads=0);
456 
470 bool OIIO_API add (ImageBuf &dst, const float *val,
471  ROI roi=ROI::All(), int nthreads=0);
472 
473 
475 bool OIIO_API add (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B, int options);
476 
479 enum OIIO_API AddOptions
480 {
481  ADD_DEFAULT = 0,
482  ADD_RETAIN_DST = 1,
483  ADD_CLEAR_DST = 0,
484  ADD_RETAIN_WINDOWS = 2,
485  ADD_ALIGN_WINDOWS = 0,
486 };
487 
488 
505 bool OIIO_API sub (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
506  ROI roi=ROI::All(), int nthreads=0);
507 
524 bool OIIO_API mul (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
525  ROI roi=ROI::All(), int nthreads=0);
526 
527 
540 bool OIIO_API mul (ImageBuf &dst, float val,
541  ROI roi=ROI::All(), int nthreads=0);
542 
556 bool OIIO_API mul (ImageBuf &dst, const float *val,
557  ROI roi=ROI::All(), int nthreads=0);
558 
575 bool OIIO_API channel_sum (ImageBuf &dst, const ImageBuf &src,
576  const float *weights=NULL, ROI roi=ROI::All(),
577  int nthreads=0);
578 
608 bool OIIO_API rangecompress (ImageBuf &dst, bool useluma = true,
609  ROI roi = ROI::All(), int nthreads=0);
610 
614 bool OIIO_API rangeexpand (ImageBuf &dst, bool useluma = true,
615  ROI roi = ROI::All(), int nthreads=0);
616 
617 
634 bool OIIO_API colorconvert (ImageBuf &dst, const ImageBuf &src,
635  const ColorProcessor *processor,
636  bool unpremult,
637  ROI roi=ROI::All(), int nthreads=0);
638 
646 bool OIIO_API colorconvert (float *color, int nchannels,
647  const ColorProcessor *processor, bool unpremult);
648 
649 
663 bool OIIO_API unpremult (ImageBuf &dst, ROI roi = ROI::All(), int nthreads = 0);
664 
680 bool OIIO_API premult (ImageBuf &dst, ROI roi = ROI::All(), int nthreads = 0);
681 
682 
683 
684 struct OIIO_API PixelStats {
685  std::vector<float> min;
686  std::vector<float> max;
687  std::vector<float> avg;
688  std::vector<float> stddev;
689  std::vector<imagesize_t> nancount;
690  std::vector<imagesize_t> infcount;
691  std::vector<imagesize_t> finitecount;
692  std::vector<double> sum, sum2; // for intermediate calculation
693 };
694 
695 
708 bool OIIO_API computePixelStats (PixelStats &stats, const ImageBuf &src,
709  ROI roi=ROI::All(), int nthreads=0);
710 
711 
718  double meanerror, rms_error, PSNR, maxerror;
719  int maxx, maxy, maxz, maxc;
720  imagesize_t nwarn, nfail;
721 };
722 
740 bool OIIO_API compare (const ImageBuf &A, const ImageBuf &B,
741  float failthresh, float warnthresh,
742  CompareResults &result,
743  ROI roi = ROI::All(), int nthreads=0);
744 
765 int OIIO_API compare_Yee (const ImageBuf &A, const ImageBuf &B,
766  CompareResults &result,
767  float luminance = 100, float fov = 45,
768  ROI roi = ROI::All(), int nthreads = 0);
769 
771 int OIIO_API compare_Yee (const ImageBuf &A, const ImageBuf &B,
772  float luminance = 100, float fov = 45);
773 
774 
787 bool OIIO_API isConstantColor (const ImageBuf &src, float *color = NULL,
788  ROI roi = ROI::All(), int nthreads=0);
789 
802 bool OIIO_API isConstantChannel (const ImageBuf &src, int channel, float val,
803  ROI roi = ROI::All(), int nthreads = 0);
804 
816 bool OIIO_API isMonochrome (const ImageBuf &src,
817  ROI roi = ROI::All(), int nthreads = 0);
818 
842 bool OIIO_API color_count (const ImageBuf &src,
843  imagesize_t *count,
844  int ncolors, const float *color,
845  const float *eps=NULL,
846  ROI roi=ROI::All(), int nthreads=0);
847 
868 bool OIIO_API color_range_check (const ImageBuf &src,
869  imagesize_t *lowcount,
870  imagesize_t *highcount,
871  imagesize_t *inrangecount,
872  const float *low, const float *high,
873  ROI roi=ROI::All(), int nthreads=0);
874 
887 OIIO_API ROI nonzero_region (const ImageBuf &src,
888  ROI roi=ROI::All(), int nthreads=0);
889 
900 std::string OIIO_API computePixelHashSHA1 (const ImageBuf &src,
901  const std::string &extrainfo = "",
902  ROI roi = ROI::All(),
903  int blocksize = 0, int nthreads=0);
904 
905 
906 
927 bool OIIO_API resize (ImageBuf &dst, const ImageBuf &src,
928  Filter2D *filter=NULL,
929  ROI roi = ROI::All(), int nthreads = 0);
930 
932 bool OIIO_API resize (ImageBuf &dst, const ImageBuf &src,
933  int xbegin, int xend, int ybegin, int yend,
934  Filter2D *filter=NULL);
935 
936 
957 bool OIIO_API resample (ImageBuf &dst, const ImageBuf &src,
958  bool interpolate = true,
959  ROI roi = ROI::All(), int nthreads = 0);
960 
978 bool OIIO_API convolve (ImageBuf &dst, const ImageBuf &src,
979  const ImageBuf &kernel, bool normalize = true,
980  ROI roi = ROI::All(), int nthreads = 0);
981 
1000 bool OIIO_API make_kernel (ImageBuf &dst, const char *name,
1001  float width, float height, float depth = 1.0f,
1002  bool normalize = true);
1003 
1032 bool OIIO_API unsharp_mask (ImageBuf &dst, const ImageBuf &src,
1033  const char *kernel="gaussian", float width = 3.0f,
1034  float contrast = 1.0f, float threshold = 0.0f,
1035  ROI roi = ROI::All(), int nthreads = 0);
1036 
1037 
1058 bool OIIO_API fft (ImageBuf &dst, const ImageBuf &src,
1059  ROI roi = ROI::All(), int nthreads = 0);
1060 
1080 bool OIIO_API ifft (ImageBuf &dst, const ImageBuf &src,
1081  ROI roi = ROI::All(), int nthreads = 0);
1082 
1083 
1084 enum OIIO_API NonFiniteFixMode
1085 {
1086  NONFINITE_NONE = 0,
1087  NONFINITE_BLACK = 1,
1088  NONFINITE_BOX3 = 2,
1089 };
1090 
1114 bool OIIO_API fixNonFinite (ImageBuf &dst, NonFiniteFixMode mode=NONFINITE_BOX3,
1115  int *pixelsFixed = NULL,
1116  ROI roi = ROI::All(), int nthreads = 0);
1117 
1121 bool OIIO_API fixNonFinite (ImageBuf &dst, const ImageBuf &src,
1122  NonFiniteFixMode mode = NONFINITE_BOX3,
1123  int *pixelsFixed = NULL);
1124 
1125 
1141 bool OIIO_API fillholes_pushpull (ImageBuf &dst, const ImageBuf &src,
1142  ROI roi = ROI::All(), int nthreads = 0);
1143 
1144 
1152 bool OIIO_API from_IplImage (ImageBuf &dst, const IplImage *ipl,
1153  TypeDesc convert=TypeDesc::UNKNOWN);
1154 
1160 OIIO_API IplImage* to_IplImage (const ImageBuf &src);
1161 
1167 bool OIIO_API capture_image (ImageBuf &dst, int cameranum = 0,
1168  TypeDesc convert=TypeDesc::UNKNOWN);
1169 
1170 
1171 
1207 bool OIIO_API over (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
1208  ROI roi = ROI::All(), int threads = 0);
1209 
1210 
1216 bool OIIO_API zover (ImageBuf &dst, const ImageBuf &A, const ImageBuf &B,
1217  bool z_zeroisinf = false,
1218  ROI roi = ROI::All(), int threads = 0);
1219 
1221 bool OIIO_API zover (ImageBuf &R, const ImageBuf &A, const ImageBuf &B,
1222  ROI roi, int threads = 0);
1223 
1224 
1234 bool OIIO_API render_text (ImageBuf &R, int x, int y,
1235  const std::string &text,
1236  int fontsize=16, const std::string &fontname="",
1237  const float *textcolor = NULL);
1238 
1239 
1257 bool OIIO_API histogram (const ImageBuf &A, int channel,
1258  std::vector<imagesize_t> &histogram, int bins=256,
1259  float min=0, float max=1, imagesize_t *submin=NULL,
1260  imagesize_t *supermax=NULL, ROI roi=ROI::All());
1261 
1262 
1263 
1271 bool OIIO_API histogram_draw (ImageBuf &R,
1272  const std::vector<imagesize_t> &histogram);
1273 
1274 
1275 
1276 enum OIIO_API MakeTextureMode {
1277  MakeTxTexture, MakeTxShadow, MakeTxEnvLatl,
1278  MakeTxEnvLatlFromLightProbe,
1279  _MakeTxLast
1280 };
1281 
1409 bool OIIO_API make_texture (MakeTextureMode mode,
1410  const ImageBuf &input,
1411  const std::string &outputfilename,
1412  const ImageSpec &config,
1413  std::ostream *outstream = NULL);
1414 
1417 bool OIIO_API make_texture (MakeTextureMode mode,
1418  const std::string &filename,
1419  const std::string &outputfilename,
1420  const ImageSpec &config,
1421  std::ostream *outstream = NULL);
1422 
1425 bool OIIO_API make_texture (MakeTextureMode mode,
1426  const std::vector<std::string> &filenames,
1427  const std::string &outputfilename,
1428  const ImageSpec &config,
1429  std::ostream *outstream = NULL);
1430 
1431 
1432 
1433 
1434 } // end namespace ImageBufAlgo
1435 
1436 }
1437 OIIO_NAMESPACE_EXIT
1438 
1439 #endif // OPENIMAGEIO_IMAGEBUFALGO_H