HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_MakeTexture.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: TIL_MakeTexture.h (TIL Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __TIL_MakeTexture__
12 #define __TIL_MakeTexture__
13 
14 #include "TIL_API.h"
15 
16 #include <PXL/PXL_OCIO.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_UniquePtr.h>
19 #include <UT/UT_Set.h>
20 #include <UT/UT_StringHolder.h>
21 #include <UT/UT_WorkBuffer.h>
22 #include <IMG/IMG_Metadata.h>
23 
24 class FS_DiskCache;
25 class IMG_File;
26 class IMG_Stat;
27 
29  : public UT_NonCopyable
30 {
31 public:
32  static constexpr exint DEFAULT_CACHE_SIZE = 2 * 1024; // In MB
33  enum SRGB_MODE
34  {
35  SRGB_DISABLE, // No sRGB conversions
36  SRGB_FORCE, // Always apply SRGB convresion
37  SRGB_AUTO // Use the file type information for sRGB
38  };
39 
41  : myOutputFormat() // Defaults to determining from file extension
42  , myFilter()
43  , myAOV()
44  , mySRGBMode(SRGB_AUTO)
45  , myOCIO()
46  , mySanitize(true)
47  , myStoreColorSpace(true)
48  , myLinearizeMips(linearizeMipDefault())
49  , myConstantRes(0)
50  , myStripOpaqueAlpha(false)
51  , myDeepSource(false)
52  , myMetadata(nullptr)
53  {
54  }
55 
56  virtual ~TIL_MakeTexture();
57 
59 
60  static void initDiskCache();
61  static const UT_StringHolder &fastRemap(const UT_StringRef &name,
62  bool force);
63  static UT_StringHolder remapFile(const UT_StringHolder &name,
64  bool force);
65  static bool clearRemapCache(bool out_of_date);
66  static FS_DiskCache &diskCache();
67 
69  : public UT_NonCopyable
70  {
72  ~CacheErrorFiles();
74  };
75 
76  /// Number of cached files found and used
77  static int64 cacheFilesFound();
78  /// Number of local files created
79  static int64 cacheLocalCreated();
80  /// Number of temp files created
81  static int64 cacheTempCreated();
82  /// Number of errors while trying to create cache files
83  static CacheErrorFiles cacheErrorFiles();
84 
85  // Defaults to computing the output format from the file extension on the
86  // output file.
87  void setOutputFormat(const UT_StringHolder &v) { myOutputFormat = v; }
88  void setFilter(const UT_StringHolder &f) { myFilter = f; }
89  void setAOV(const UT_StringHolder &s) { myAOV = s; }
90  void setSRGBMode(SRGB_MODE mode) { mySRGBMode = mode; };
91  void setOCIO(const UT_StringRef &sspace, const UT_StringRef &infile,
92  const UT_StringRef &dspace, const UT_StringRef &outfile,
93  bool allowparse);
95  {
96  mySWrapMode = s;
97  myTWrapMode = t;
98  }
99  void setMetadata(UT_UniquePtr<IMG_Metadata> md) { myMetadata = std::move(md); }
100  void setSanitize(bool v) { mySanitize = v; }
101  void setStoreColorSpace(bool v) { myStoreColorSpace = v; }
102  void setConstantRes(int res) { myConstantRes = res; }
103  void setStripOpaqueAlpha(bool f) { myStripOpaqueAlpha = f; }
104  void setLinearizeMips(bool v) { myLinearizeMips = v; }
105 
106  // Perform the texture map creation
107  bool makeTexture(const UT_StringRef &infile,
108  const UT_StringRef &outfile,
109  int tile_width=64,
110  int tile_height=64) const;
111 
112  bool deepSource() const { return myDeepSource; }
113 
114  template <typename... Args>
115  void message(const char *fmt, const Args &...args) const
116  {
117  UT_WorkBuffer tmp;
118  tmp.format(fmt, args...);
119  doMessage(tmp.buffer());
120  }
121  template <typename... Args>
122  void warning(const char *fmt, const Args &...args) const
123  {
124  UT_WorkBuffer tmp;
125  tmp.format(fmt, args...);
126  doWarning(tmp.buffer());
127  }
128  template <typename... Args>
129  void error(const char *fmt, const Args &...args) const
130  {
131  UT_WorkBuffer tmp;
132  tmp.format(fmt, args...);
133  doError(tmp.buffer());
134  }
135 
136  struct TextureFiles;
137 
138 protected:
139  virtual void doMessage(const char *msg) const {}
140  virtual void doWarning(const char *msg) const {}
141  virtual void doError(const char *msg) const {}
142 
143 private:
144  static bool linearizeMipDefault();
145 
146  bool makeEXR(TextureFiles &files,
147  const UT_StringRef &infile,
148  const UT_StringRef &outfile,
149  IMG_File *img,
150  int tileWidth,
151  int tileHeight,
152  const UT_StringRef &swrap,
153  const UT_StringRef &twrap) const;
154  // Compute the OCIO color space associated. This uses the @c sspace token
155  // if it's defined (and not "default"). Otherwise, it will inspect the
156  // image file to determine it's color space (when not in @c write_mode).
157  // The @c allowparse will enable/disable OCIO filename color space parsing.
158  UT_StringHolder computeOCIOSpace(const UT_StringRef &sspace,
159  const UT_StringRef &filename,
160  bool write_mode,
161  bool allowparse,
162  bool is_output) const;
163 
164  UT_StringHolder myOutputFormat;
165  UT_StringHolder myOutputSpace;
166  UT_StringHolder myFilter;
167  UT_StringHolder myAOV;
168  PXL_OCIO::PHandle myOCIO;
169  PXL_OCIO::PHandle myOCIOToLinear;
170  PXL_OCIO::PHandle myOCIOFromLinear;
171  UT_StringHolder mySWrapMode;
172  UT_StringHolder myTWrapMode;
173  UT_UniquePtr<IMG_Metadata> myMetadata;
174  SRGB_MODE mySRGBMode;
175  int myConstantRes;
176  bool myStripOpaqueAlpha;
177  bool mySanitize;
178  bool myStoreColorSpace;
179  bool myLinearizeMips;
180  mutable bool myDeepSource;
181 };
182 
183 #endif
184 
virtual void doError(const char *msg) const
virtual void doWarning(const char *msg) const
GT_API const UT_StringHolder filename
bool deepSource() const
const GLdouble * v
Definition: glcorearb.h:837
void setLinearizeMips(bool v)
void setConstantRes(int res)
void setStoreColorSpace(bool v)
void setFilter(const UT_StringHolder &f)
int64 exint
Definition: SYS_Types.h:125
SYS_FORCE_INLINE const char * buffer() const
GLdouble s
Definition: glad.h:3009
void setOutputFormat(const UT_StringHolder &v)
void setWrapModes(const UT_StringHolder &s, const UT_StringHolder &t)
void setStripOpaqueAlpha(bool f)
void warning(const char *fmt, const Args &...args) const
void setAOV(const UT_StringHolder &s)
void setSanitize(bool v)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLfloat f
Definition: glcorearb.h:1926
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLint void * img
Definition: glcorearb.h:556
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
size_t format(const char *fmt, const Args &...args)
SIM_API const UT_StringHolder force
virtual void doMessage(const char *msg) const
**If you just want to fire and args
Definition: thread.h:618
Contains the details of a specific image file, used by IMG_File. This class contains all the high-lev...
Definition: IMG_Stat.h:38
void message(const char *fmt, const Args &...args) const
void setSRGBMode(SRGB_MODE mode)
void setMetadata(UT_UniquePtr< IMG_Metadata > md)
#define TIL_API
Definition: TIL_API.h:10
void error(const char *fmt, const Args &...args) const
const UT_Set< UT_StringHolder > * myFiles