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_Set.h>
19 #include <UT/UT_StringHolder.h>
20 #include <UT/UT_WorkBuffer.h>
21 
22 class FS_DiskCache;
23 class IMG_File;
24 class IMG_Stat;
25 
27 {
28 public:
29  static constexpr exint DEFAULT_CACHE_SIZE = 2 * 1024; // In MB
30  enum SRGB_MODE
31  {
32  SRGB_DISABLE, // No sRGB conversions
33  SRGB_FORCE, // Always apply SRGB convresion
34  SRGB_AUTO // Use the file type information for sRGB
35  };
36 
38  : myOutputFormat() // Defaults to determining from file extension
39  , myFilter()
40  , myAOV()
41  , mySRGBMode(SRGB_AUTO)
42  , myOCIO()
43  , mySanitize(true)
44  , myStoreColorSpace(true)
45  , myDeepSource(false)
46  {
47  }
48 
49  virtual ~TIL_MakeTexture();
50 
52 
53  static void initDiskCache();
54  static const UT_StringHolder &fastRemap(const UT_StringRef &name,
55  bool force);
56  static UT_StringHolder remapFile(const UT_StringHolder &name,
57  bool force);
58  static bool clearRemapCache(bool out_of_date);
59  static FS_DiskCache &diskCache();
60 
62  : public UT_NonCopyable
63  {
65  ~CacheErrorFiles();
67  };
68 
69  /// Number of cached files found and used
70  static int64 cacheFilesFound();
71  /// Number of local files created
72  static int64 cacheLocalCreated();
73  /// Number of temp files created
74  static int64 cacheTempCreated();
75  /// Number of errors while trying to create cache files
76  static CacheErrorFiles cacheErrorFiles();
77 
78  // Defaults to computing the output format from the file extension on the
79  // output file.
80  void setOutputFormat(const UT_StringHolder &v) { myOutputFormat = v; }
81  void setFilter(const UT_StringHolder &f) { myFilter = f; }
82  void setAOV(const UT_StringHolder &s) { myAOV = s; }
83  void setSRGBMode(SRGB_MODE mode) { mySRGBMode = mode; };
84  void setOCIO(const UT_StringRef &sspace, const UT_StringRef &infile,
85  const UT_StringRef &dspace, const UT_StringRef &outfile,
86  bool allowparse);
88  {
89  mySWrapMode = s;
90  myTWrapMode = t;
91  }
92  void setSanitize(bool v) { mySanitize = v; }
93  void setStoreColorSpace(bool v) { myStoreColorSpace = v; }
94 
95  // Perform the texture map creation
96  bool makeTexture(const UT_StringRef &infile,
97  const UT_StringRef &outfile,
98  int tile_width=64,
99  int tile_height=64) const;
100 
101  bool deepSource() const { return myDeepSource; }
102 
103  template <typename... Args>
104  void message(const char *fmt, const Args &...args) const
105  {
106  UT_WorkBuffer tmp;
107  tmp.format(fmt, args...);
108  doMessage(tmp.buffer());
109  }
110  template <typename... Args>
111  void warning(const char *fmt, const Args &...args) const
112  {
113  UT_WorkBuffer tmp;
114  tmp.format(fmt, args...);
115  doWarning(tmp.buffer());
116  }
117  template <typename... Args>
118  void error(const char *fmt, const Args &...args) const
119  {
120  UT_WorkBuffer tmp;
121  tmp.format(fmt, args...);
122  doError(tmp.buffer());
123  }
124 
125  struct TextureFiles;
126 
127 protected:
128  virtual void doMessage(const char *msg) const {}
129  virtual void doWarning(const char *msg) const {}
130  virtual void doError(const char *msg) const {}
131 
132 private:
133  bool makeEXR(TextureFiles &files,
134  const UT_StringRef &infile,
135  const UT_StringRef &outfile,
136  IMG_File *img,
137  int tileWidth,
138  int tileHeight,
139  const UT_StringRef &swrap,
140  const UT_StringRef &twrap) const;
141  // Compute the OCIO color space associated. This uses the @c sspace token
142  // if it's defined (and not "default"). Otherwise, it will inspect the
143  // image file to determine it's color space (when not in @c write_mode).
144  // The @c allowparse will enable/disable OCIO filename color space parsing.
145  UT_StringHolder computeOCIOSpace(const UT_StringRef &sspace,
146  const UT_StringRef &filename,
147  bool write_mode,
148  bool allowparse) const;
149 
150  UT_StringHolder myOutputFormat;
151  UT_StringHolder myOutputSpace;
152  UT_StringHolder myFilter;
153  UT_StringHolder myAOV;
154  PXL_OCIO::PHandle myOCIO;
155  UT_StringHolder mySWrapMode;
156  UT_StringHolder myTWrapMode;
157  SRGB_MODE mySRGBMode;
158  bool mySanitize;
159  bool myStoreColorSpace;
160  mutable bool myDeepSource;
161 };
162 
163 #endif
164 
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 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 warning(const char *fmt, const Args &...args) const
void setAOV(const UT_StringHolder &s)
void setSanitize(bool v)
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)
#define TIL_API
Definition: TIL_API.h:10
void error(const char *fmt, const Args &...args) const
const UT_Set< UT_StringHolder > * myFiles