HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG_FileParms.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: IMG_FileParm.h ( IMG Library, C++)
7  *
8  * COMMENTS:
9  * Parameter class for options to IMG_File::open() and IMG_File::create()
10  */
11 #ifndef __IMG_FILE_PARMS_H__
12 #define __IMG_FILE_PARMS_H__
13 
14 #include "IMG_API.h"
15 
16 #include <SYS/SYS_Types.h>
17 #include <UT/UT_FilterType.h>
18 #include <UT/UT_StringArray.h>
19 #include <UT/UT_IntArray.h>
20 #include <UT/UT_Rect.h>
21 #include <UT/UT_SharedPtr.h>
22 #include <PXL/PXL_LumFuncs.h>
23 
24 #include "IMG_FileTypes.h"
25 #include "IMG_Metadata.h"
26 
27 class UT_Options;
28 class UT_OptionEntry;
29 class UT_JSONWriter;
30 class IMG_TileOptions;
31 class IMG_Stat;
32 class IMG_Format;
33 class img_MipCache;
34 
35 /// @brief File options for manipulating image data on load or save.
36 /// This class allows you to modify the incoming or outgoing image data by
37 /// scaling, flipping, converting or cropping the data. It can be optionally
38 /// passed to IMG_File::open() or IMG_File::create()
40 {
41 public:
42  IMG_FileParms();
43 
44  /// This method turns off any option that would result in image
45  /// translation.
46  void readAsIs();
47 
48  // DATA ORGANIZATION ----------------------------------------------------
49 
50  /// @brief Convert to a different data type
51  /// convert the image to this data type, if needed (default = use native)
52  void setDataType(IMG_DataType dt);
53 
54  /// @brief Convert to a different number of pixel components
55  /// convert to a standard color model, if needed (RGB, RGBA, single).
56  /// When moving from fewer components to more components, the
57  /// data is either duplicated (1chan->RGB) or generated (RGB-RGBA, A=1).
58  void setColorModel(IMG_ColorModel cm);
59 
60  /// @brief Convert to either an RGBA or ABGR ordering
61  /// converts the component ordering to RGBA or ABGR (or RGB/BGR, RG/GR)
62  /// without forcing the color model to a specific number of components.
63  void setComponentOrder(IMG_ComponentOrder order);
64 
65 
66  /// @brief Interleaves or deinterleaves pixel data
67  /// Determines how to format the data.
68  /// - IMG_INTERLEAVE_AS_IS - leave it interleaved or non, as in the file.
69  /// - IMG_INTERLEAVED - always interleave (rgbrgbrgb). Default.
70  /// - IMG_NON_INTERLEAVED - always non-interleaved (rrrgggbbb)
71  void setInterleaved(IMG_Interleave i);
72 
73  /// is RGB or higher, this method determines how to convert the vector
74  /// into a scalar. By default, the luminance is taken.
75  void setLuminanceFunc(PXL_LumFunction f);
76 
77  /// If true, alpha will be read into its own plane, instead of an RGBA
78  /// color plane. Color will be read as its own plane as well, RGB.
79  void readAlphaAsPlane();
80 
81  /// If demoting from a deep raster to an RGB(A) image, these methods
82  /// allow you to specify the plane(s) to copy to RGB(A), by name or index.
83  /// Selects a plane by index. Indices are specified from 1 to # planes.
84  void selectPlanes(const UT_IntArray &planeindices);
85 
86  /// If demoting from a deep raster to an RGB(A) image, these methods
87  /// allow you to specify the plane(s) to copy to RGB(A), by name or index.
88  /// Selects several planes by numeric pattern, ie. "1", "1 3 4", "[1-3] 5"
89  void selectPlanes(const char *pattern);
90 
91  /// If demoting from a deep raster to an RGB(A) image, these methods
92  /// allow you to specify the plane(s) to copy to RGB(A), by name or index.
93  /// Selects serveral planes by name pattern, such as "C", "C A Pz" "P? C*"
94  void selectPlaneNames(const char *name, const char *separators=", ");
95 
96  /// Isolate mip level to load (0 being base resolution). IMG_File::open()
97  /// may return nullptr if invalid mip level is specified. If the file
98  /// doesn't have pre-generated mipmaps, IMG_File::open() will generate
99  /// mipmap level on the fly. This object holds the cache for intermediate
100  /// mip levels if they're being generated, so if you're opening the same
101  /// file multiple times with different mip level selected, it's recommended
102  /// that you reuse this parm object (as long as it's within the same
103  /// thread).
104  void selectMipLevel(int level);
105 
106  /// optimizes mipmap generation by caching level0
107  void setEnableMipLevel0Cache(bool val);
108 
109  /// mipmap rounding mode (ie how next resolution down is calculated)
110  void setMipRoundMode(IMG_MipRoundMode mode);
111 
112  void setPreserveDataWindow(bool preserve) { myPreserveDataWindow = preserve; }
113 
114  /// @{
115  /// Accessors
116  IMG_DataType dataType() const { return myDataType; }
117  IMG_ColorModel colorModel() const { return myColorModel; }
118  IMG_ComponentOrder componentOrder() const { return myComponentOrder; }
119  IMG_Interleave interleaved() const { return myInterleaved; }
121  { return mySelectPlaneName; }
123  { return mySelectPlaneIndex; }
124  bool alphaSplit() const { return myAlphaSplit; }
125  bool alphaDetect() const { return myAlphaDetect; }
126  PXL_LumFunction lumFunc() const { return myLumFunc; }
127  IMG_XOrientation orientX() const { return myOrientX; }
128  IMG_YOrientation orientY() const { return myOrientY; }
129  bool flipVertical() const { return myFlipVertical; }
130  bool flipHorizontal() const { return myFlipHorizontal; }
131  bool flopImage() const { return myFlopImage; }
132  bool useTiles() const { return myUseTiles; }
133  exint xres() const {return myResX; }
134  exint yres() const {return myResY; }
135  fpreal xscale() const { return myScaleX; }
136  fpreal yscale() const { return myScaleY; }
137  bool preserveAspect() const { return myPreserveAspect; }
138  bool resLimit() const { return myResLimit; }
139  exint maxXres() const {return myMaxX; }
140  exint maxYres() const {return myMaxY; }
141  bool powerTwoRes() const { return myPowerTwoRes; }
142  UT_FilterType filterType() const { return myFilterType; }
143 
144  bool enableMipLevel0Cache() const
145  { return myEnableMipLevel0Cache; }
146  bool readDataWindowOnly() const
147  { return myReadDataWindowOnly; }
148  bool isReadArea() const
149  { return myReadAreaFlag; }
150  const UT_DimRect getReadArea() const { return myReadArea; }
151  bool isReadUVArea() const
152  { return myReadUVAreaFlag; }
153  const fpreal *getReadUVArea() const { return myReadUVArea; }
154 
155  bool preserveDataWindow() const { return myPreserveDataWindow; }
156  /// @}
157 
158  /// If the color model is set to IMG_1CHAN, and the actual color model
159 
160  /// RESOLUTION -----------------------------------------------------------
161  /// using these methods always scales. To crop, use the data window methods
162  /// Note that the filter is shared, so if more than one of these is called,
163  /// the last filter setting is used.
164 
165  /// Scale the image to resolution (x,y). (0 = use original dimension)
166  void scaleImageTo(int x, int y, UT_FilterType ft=UT_FILTER_BOX);
167 
168  /// scale the image by scaling factors (x,y).
169  void scaleImageBy(fpreal x, fpreal y, UT_FilterType ft=UT_FILTER_BOX);
170 
171  /// limit the image to a maximum resolution. Scale to this res, preserving
172  /// the aspect ratio if requested.
173  void limitImageRes(int x, int y, UT_FilterType ft=UT_FILTER_BOX,
174  bool preserve_aspect = true);
175 
176  /// images must be read as powers of two. Does not preserve aspect ratio.
177  void powerTwoOnly();
178 
179  // DATA WINDOW ---------------------------------------------------------
180 
181  /// Normally, a data window is expanded or cropped to the image resolution.
182  /// calling this will always read only the data window.
183  /// Used only for reading.
184  void setDataWindowOnly();
185 
186  /// read the image region in 'area' only (even if we need to crop or expand
187  /// the image to fill it). Used only for reading.
188  void setWindow(const UT_DimRect &area);
189 
190  /// read the image region in 'area' in UV coords. Used only for reading.
191  void setWindow(float u1, float v1, float u2, float v2);
192 
193  // ORIENTATION ----------------------------------------------------------
194 
195  /// options for orienting and flipping the image. Default orientation is
196  /// LEFT_FIRST, BOTTOM_FIRST. You can set each to 'none' if you don't care.
197  void orientImage(IMG_XOrientation x, IMG_YOrientation y);
198 
199  /// @brief Flip the image in either direction.
200  /// flip the images in either direction. May cancel out any orientation
201  /// flipping.
202  /// @{
203  void flipImageVertical();
204  void flipImageHorizontal();
205  /// @}
206 
207  /// rotate the image 90', flopping it on its side.
208  void flopImage();
209 
210 
211  // COLOR CORRECTION -----------------------------------------------------
212 
213  /// @brief Color correct an image using a LUT
214  /// apply a lookup table to the data, but only those planes that match the
215  /// scope (ie, "C spec diff", "C*", "*beauty*")
216  /// If no @c plane_scope is specified, "*" is used.
217  void applyLUT(const char *lut,
218  const UT_StringHolder &plane_scope = UT_StringHolder(),
219  bool ocio = false);
220 
221  /// @brief Color correct an image using a gamma setting
222  /// Apply gamma to the planes matching the scope (ie, "C spec diff", "C*",
223  /// "*beauty*") If no @c gamma_scope is specified, "*" is ued.
224  void applyGamma(fpreal gamma,
225  const UT_StringHolder &gamma_scope = UT_StringHolder());
226 
227  /// Set the gamma and scope to apply any needed gamma correction to planes
228  /// being written. This overwrites any applyGamma() changes.
229  void adjustGammaForFormat(IMG_Stat &stat,
230  const IMG_Format *format,
231  IMG_DataType override_type = IMG_DT_ANY);
232 
233  /// Specifies the destination colorspace when reading, and the source
234  /// colorspace when writing (ie, the colorspace the raster is in, not the
235  /// file contents). Default colorspace is the scene linear role.
236  /// Only active if an OCIO LUT is used.
237  void setOCIODestColorSpace(const UT_StringHolder &ocio_colorspace);
238 
239  /// One or more looks (color transforms) that are applied to the image
240  /// after reading or before writing, in order of specification (whitespace
241  /// separated list).
242  void setOCIOLooks(const UT_StringHolder &looks);
243 
244  /// Set OCIO Source display/view (if the image data already has tone
245  /// mapping baked in).
246  void setOCIOSourceDisplay(const UT_StringHolder &display,
247  const UT_StringHolder &view);
248 
249  /// @{
250  /// Set up OCIO information fully
251  void setOCIOTransform(const UT_StringHolder &sspace,
252  const UT_StringHolder &dspace,
253  const UT_StringHolder &looks,
254  const UT_StringHolder &lut_scope = UT_StringHolder());
255  void setOCIOTransformView(const UT_StringHolder &sspace,
256  const UT_StringHolder &display,
257  const UT_StringHolder &view,
258  bool forward,
259  const UT_StringHolder &lut_scope = UT_StringHolder());
260  /// @}
261 
262  // INFORMATION ----------------------------------------------------------
263 
264  /// @brief Returns information about the image's alpha channel
265  /// Checks to see if the alpha plane is constant 1, cutout 0/1,
266  /// constant valued, varying, out-of-range (>1 or <0) or absent. Load only.
267  void detectAlphaDetails();
268 
269  // FORMAT SPECIFIC OPTIONS ----------------------------------------------
270 
271  /// set an input/output tag option for the format.
272  void setOption(const char *option, const char *value);
273 
274  /// options are a list of argument pairs, such as "artist", "Tom Smith".
275  /// The options list is terminated by a NULL.
276  void setOptions(const char **options);
277 
278  /// options are in a whitespace separated string "Artist 'Tom Jones'"
279  void setOptionsString(const char *option_pair_string);
280 
281  /// options are specified in the IMG_TileOptions structure
282  void setOptions(const IMG_TileOptions &info_with_options);
283 
284  /// set options based on a UT_Options (this is similar to using
285  /// IMG_TileOptions)
286  void setOptions(const UT_Options &options);
287 
288  /// Set metadata option
289  void setOption(const UT_StringHolder &key,
290  const IMG_MetadataItem &item)
291  { myMetadata.add(key, item); }
292 
293  /// @{
294  /// Set metadata
295  void setFileParm(const UT_StringHolder &key, const UT_JSONValue &val)
296  { myMetadata.add(key, IMG_MetadataItem(val)); }
297  void setFileParm(const UT_StringHolder &key, bool val)
298  { myMetadata.add(key, UT_JSONValue(val)); }
299  void setFileParm(const UT_StringHolder &key, int64 val)
300  { myMetadata.add(key, UT_JSONValue(val)); }
301  void setFileParm(const UT_StringHolder &key, fpreal64 val)
302  { myMetadata.add(key, UT_JSONValue(val)); }
303  void setFileParm(const UT_StringHolder &key,
304  const UT_StringHolder &val)
305  { myMetadata.add(key, UT_JSONValue(val)); }
306  void setFileParm(const UT_StringHolder &key,
307  const UT_OptionEntry &val)
308  { myMetadata.add(key, val); }
309  /// @}
310 
311  /// @{
312  /// Access to options
313  UT_StringArray SYS_DEPRECATED(20.0) options() const;
314  UT_StringArray SYS_DEPRECATED(20.0) optionValues() const;
315  IMG_Metadata &metadata() { return myMetadata; }
316  const IMG_Metadata &metadata() const { return myMetadata; }
317  void merge(const IMG_Metadata &opts, bool overwrite=true)
318  { myMetadata.merge(opts, overwrite); }
319  /// @}
320 
321  /// @{
322  /// Import an option
323  bool import(const UT_StringRef &name, bool &val) const
324  { return myMetadata.import(name, val); }
325  bool import(const UT_StringRef &name, int32 &val) const
326  { return myMetadata.import(name, val); }
327  bool import(const UT_StringRef &name, int64 &val) const
328  { return myMetadata.import(name, val); }
329  bool import(const UT_StringRef &name, fpreal32 &val) const
330  { return myMetadata.import(name, val); }
331  bool import(const UT_StringRef &name, fpreal64 &val) const
332  { return myMetadata.import(name, val); }
333  bool import(const UT_StringRef &name, UT_StringHolder &val) const
334  { return myMetadata.import(name, val); }
335  /// @}
336 
337  /// @brief Enable the tile inteface for reading or writing
338  /// If called, we're reading or writing tiles using IMG_File::readTile
339  /// and IMG_File::writeTile. The scanline versions will not work.
340  void useTileInterface();
341 
342  /// If set, files will not report errors and subsequent scanlines
343  /// will be returned as black.
345  { myContinueOnError = true; }
347  { return myContinueOnError; }
348 
349  /// @{
350  /// @private
351  void setIsNormal(bool f=true) { myIsNormal = f; }
352  bool isNormal() const { return myIsNormal; }
353  const UT_SharedPtr<img_MipCache> &mipCache() const { return myMipCache; }
355  { myMipCache = c; }
356  /// @}
357 
358 
359  /// @{
360  /// Debug
361  void dump() const;
362  void dump(UT_JSONWriter &w) const;
363  /// @}
364 
365  /// @{
366  /// LUT Accessors
367  const UT_StringHolder &lutFilename() const { return myLUTFilename; }
368  const UT_StringHolder &lutScope() const { return myLUTScope; }
369  bool lutIsOCIO() const { return myLutIsOCIO; }
370  fpreal gamma() const { return myGamma; }
371  const UT_StringHolder &gammaScope() const { return myGammaScope; }
372  const UT_StringHolder &ocioDestSpace() const { return myOCIODestSpace; }
373  const UT_StringHolder &ocioLooks() const { return myOCIOLooks; }
374  const UT_StringHolder &ocioView() const { return myOCIOView; }
375  const UT_StringHolder &ocioSourceDisplay() const { return myOCIOSourceDisplay; }
376  const UT_StringHolder &ocioSourceView() const { return myOCIOSourceView; }
377  bool ocioForward() const { return myOCIOForward; }
378 
380  {
381  myGain = gain;
382  myOffset = offset;
383  }
384  fpreal gain() const { return myGain; }
385  fpreal offset() const { return myOffset; }
386  /// @}
387 
388 private:
389  IMG_ImageType myImageType;
390  IMG_DataType myDataType;
391  IMG_ColorModel myColorModel;
392  IMG_ComponentOrder myComponentOrder;
393  IMG_XOrientation myOrientX;
394  IMG_YOrientation myOrientY;
395  int myMaxX, myMaxY;
396  int myResX, myResY;
397  fpreal myScaleX, myScaleY;
398  UT_FilterType myFilterType;
399  fpreal myGamma;
400  IMG_Interleave myInterleaved;
401  PXL_LumFunction myLumFunc;
402  fpreal myGain;
403  fpreal myOffset;
404 
405  bool myFlipHorizontal : 1,
406  myFlipVertical : 1,
407  myFlopImage : 1,
408  myReadDataWindowOnly :1,
409  myReadAreaFlag :1,
410  myReadUVAreaFlag : 1,
411  myUseTiles :1,
412  myUseLUT : 1,
413  myPowerTwoRes :1,
414  myResLimit:1,
415  myPreserveAspect : 1,
416  myAlphaSplit : 1,
417  myContinueOnError : 1,
418  myAlphaDetect: 1,
419  myIsNormal: 1,
420  myLutIsOCIO : 1,
421  myEnableMipLevel0Cache : 1,
422  myPreserveDataWindow : 1;
423 
424  UT_DimRect myReadArea;
425  fpreal myReadUVArea[4];
426  UT_StringHolder myLUTFilename;
427  UT_StringHolder myLUTScope;
428  UT_StringHolder myGammaScope;
429  UT_StringHolder mySelectPlaneName;
430  UT_IntArray mySelectPlaneIndex;
431  UT_StringHolder myOCIODestSpace; // Doubles as display for view xforms
432  UT_StringHolder myOCIOLooks;
433  UT_StringHolder myOCIOView;
434  UT_StringHolder myOCIOSourceDisplay; // Source display/view
435  UT_StringHolder myOCIOSourceView;
436  bool myOCIOForward;
437 
438  IMG_Metadata myMetadata;
439 
440  UT_SharedPtr<img_MipCache> myMipCache;
441 };
442 
443 #endif
IMG_Interleave interleaved() const
const UT_StringHolder & ocioSourceView() const
const UT_StringHolder & ocioLooks() const
bool isNormal() const
int int32
Definition: SYS_Types.h:39
bool flipVertical() const
bool readDataWindowOnly() const
bool isReadArea() const
#define SYS_DEPRECATED(__V__)
const UT_IntArray & selectPlaneIndex() const
void setGainOffset(fpreal gain, fpreal offset)
IMG_ImageType
Type of image we want to create or have opened.
IMG_XOrientation
exint maxYres() const
IMG_ComponentOrder componentOrder() const
const UT_StringHolder & selectPlaneName() const
exint yres() const
const UT_StringHolder & lutScope() const
fpreal gamma() const
fpreal offset() const
const UT_StringHolder & ocioView() const
GLsizei const GLfloat * value
Definition: glcorearb.h:824
bool flopImage() const
int64 exint
Definition: SYS_Types.h:125
GLint level
Definition: glcorearb.h:108
IMG_MipRoundMode
fpreal xscale() const
const fpreal * getReadUVArea() const
GLint y
Definition: glcorearb.h:103
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
exint xres() const
IMG_ColorModel colorModel() const
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
UT_FilterType
Definition: UT_FilterType.h:16
float fpreal32
Definition: SYS_Types.h:200
GLdouble u1
Definition: glad.h:2676
void setFileParm(const UT_StringHolder &key, fpreal64 val)
void setFileParm(const UT_StringHolder &key, const UT_JSONValue &val)
IMG_DataType dataType() const
double fpreal64
Definition: SYS_Types.h:201
PXL_LumFunction
Definition: PXL_LumFuncs.h:18
#define IMG_API
Definition: IMG_API.h:10
const UT_SharedPtr< img_MipCache > & mipCache() const
fpreal yscale() const
void setMipCache(const UT_SharedPtr< img_MipCache > &c)
GLfloat f
Definition: glcorearb.h:1926
const UT_StringHolder & ocioDestSpace() const
GLintptr offset
Definition: glcorearb.h:665
void setFileParm(const UT_StringHolder &key, const UT_OptionEntry &val)
bool flipHorizontal() const
bool preserveDataWindow() const
const UT_StringHolder & gammaScope() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
void setFileParm(const UT_StringHolder &key, int64 val)
IMG_DataType
Definition: IMG_FileTypes.h:17
void merge(const IMG_Metadata &opts, bool overwrite=true)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
IMG_XOrientation orientX() const
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
long long int64
Definition: SYS_Types.h:116
#define SYS_NO_DISCARD_RESULT
Definition: SYS_Compiler.h:86
bool enableMipLevel0Cache() const
void setPreserveDataWindow(bool preserve)
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble GLdouble u2
Definition: glad.h:2676
SYS_NO_DISCARD_RESULT bool continueOnError() const
GLushort pattern
Definition: glad.h:2583
bool useTiles() const
GLint GLenum GLint x
Definition: glcorearb.h:409
GLenum mode
Definition: glcorearb.h:99
const UT_DimRect getReadArea() const
IMG_YOrientation
A map of string to various well defined value types.
Definition: UT_Options.h:87
bool powerTwoRes() const
bool isReadUVArea() const
const UT_StringHolder & ocioSourceDisplay() const
IMG_YOrientation orientY() const
PXL_LumFunction lumFunc() const
const UT_StringHolder & lutFilename() const
fpreal64 fpreal
Definition: SYS_Types.h:283
IMG_Interleave
Definition: IMG_FileTypes.h:76
bool alphaSplit() const
void setContinueOnError()
File options for manipulating image data on load or save. This class allows you to modify the incomin...
Definition: IMG_FileParms.h:39
bool ocioForward() const
IMG_ColorModel
Definition: IMG_FileTypes.h:52
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLuint GLfloat * val
Definition: glcorearb.h:1608
void setOption(const UT_StringHolder &key, const IMG_MetadataItem &item)
Set metadata option.
bool lutIsOCIO() const
void setFileParm(const UT_StringHolder &key, const UT_StringHolder &val)
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
IMG_ComponentOrder
Definition: IMG_FileTypes.h:94
Contains the details of a specific image file, used by IMG_File. This class contains all the high-lev...
Definition: IMG_Stat.h:38
bool alphaDetect() const
Map of metadata items.
Definition: IMG_Metadata.h:217
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
exint maxXres() const
fpreal gain() const
bool resLimit() const
bool preserveAspect() const
const IMG_Metadata & metadata() const
UT_FilterType filterType() const
GA_API const UT_StringHolder area
void setFileParm(const UT_StringHolder &key, bool val)