HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMG_FileTTMap.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_FileTTMap.h ( IMG Library, C++)
7  *
8  * COMMENTS: Tiled Texture Maps
9  */
10 
11 #ifndef __IMG_FileTTMap__
12 #define __IMG_FileTTMap__
13 
14 #include "IMG_API.h"
15 #include "IMG_File.h"
16 #include "IMG_TextureFilter.h"
17 #include <UT/UT_Array.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_UniquePtr.h>
20 #include <SYS/SYS_Inline.h>
21 
22 class UT_Filter;
23 class UT_FilterWindow;
24 class UT_Options;
25 class IMG_TTMipSampler;
26 class IMG_Raster;
27 
28 /// An IMG_TTChannel is used to retrieve pixel data from the image.
29 /// Each image owns an array of IMG_TTChannel objects that could
30 /// represent environment map rasters or mipmap levels.
32 {
33 public:
34  IMG_TTChannel();
35  virtual ~IMG_TTChannel();
36 
38 
39  virtual void getRes(int &xres, int &yres,
40  int &tile_xres, int &tile_yres) const = 0;
41 
42  virtual int64 getMemoryUsage(bool inclusive) const = 0;
43 
44  virtual void filterPixels(float *rgba, int nchan,
45  int first_x, int first_y,
47  const float *xweights,
48  const float *yweights,
49  int usize, int vsize) = 0;
50 
51  virtual void getPixel(float *rgba, int nchan, int iu, int iv,
52  const IMG_TextureFilter &filter) = 0;
53 
54  /// This method returns the raw pixel data.
55  virtual void getPixel(void *pixel, int iu, int iv) = 0;
56  /// Return raw scanline data
57  virtual void getScanline(void *scanline,
58  int y, int xres, size_t bpp);
59 
60  /// Return raw tile data
61  virtual void getTile(const UT_DimRect &region,
62  void *data,
63  int bytes_per_pixel,
64  int bytes_per_scanline);
65 
66  /// This method is called when the channel is destroyed
67  virtual void closeChannel() {};
68 
69  // Check color statistics
70  virtual bool getMinMaxColor(UT_Vector4 &min_color,
71  UT_Vector4 &max_color,
73  virtual const UT_StringHolder &getChecksum() const;
74 };
75 
76 /// A IMG_TTMap represents a tiled texture format that can be
77 /// sampled for texture mapping or for environment mapping. This class
78 /// supports methods for sampling and filtering the texture data.
79 /// This class is pure virtual and so derived classes must override the
80 /// image file and format operations.
81 class IMG_API IMG_FileTTMap : public IMG_File
82 {
83 public:
84  IMG_FileTTMap();
85  ~IMG_FileTTMap() override;
86 
88 
89  const char *className() const override { return "IMG_FileTTMap"; }
90 
91  /// Return true if texture evaluation of this format is enabled
92  virtual bool textureEnabled() const;
93 
94  int getOGLRaster(void *data, int xres, int yres,
96  int raster_number=0);
97 
98  /// Lookup information about the raster specified by the IMG_TextureFilter
99  /// This returns the resolution for each MIP map as well as the data format
100  /// and the number of image channels.
101  bool getMipInfo(int aov_channel,
103  IMG_DataType &data_type,
104  int &nchannels) const;
105 
106  /// Read pixels for a given MIP level
107  bool getMipData(int aov_channel, int mip_level,
108  const UT_DimRect &region,
109  void *data) const;
110 
111  // Perform unfiltered evaluation at a specified uv. This operation
112  // will not even perform filtering on pixels, so the caller is
113  // responsible for all filtering and antialiasing.
114  void unfilteredSample(
115  float *result, int tuple_size, float u, float v,
116  const IMG_TextureFilter &info,
117  int channel, int raster);
118 
119  // Sample with filtering at the specified uv.
120  void sample(float *result, int tuple_size, float u, float v,
121  const IMG_TextureFilter &info,
122  int channel, int raster)
123  {
124  float ua[4] = {u,u,u,u};
125  float va[4] = {v,v,v,v};
126 
127  sample(result, tuple_size,
128  ua, va, 1, info, channel, raster);
129  }
130 
131 
132  // Sample the map within a quadrilateral in texture space. When
133  // specifying four corners of the map, the order of the coordinates is
134  // very important:
135  //
136  // BAD GOOD GOOD
137  // 2--3 3--2 2--3
138  // \/ | | | |
139  // /\ | | | |
140  // 0--1 0--1 1--0
141  void sample(float *result, float &visible, int tuple_size,
142  const float u[4], const float v[4],
143  float quality,
144  const IMG_TextureFilter &info,
145  int channel, int raster);
146  void sample(float *result, int tuple_size,
147  const float u[4], const float v[4],
148  float quality,
149  const IMG_TextureFilter &info,
150  int channel, int raster)
151  {
152  float visible;
153  sample(result, visible,
154  tuple_size, u, v, quality,
155  info, channel, raster);
156  }
157 
158  // Only call the envLookup functions if this RAT is really a cubic
159  // environment map.
160  void envLookup(float *result, int tuple_size,
161  const UT_Vector3 &r, float angle,
162  const IMG_TextureFilter &info, int channel);
163 
164  void envLookup(float *result, int tuple_size,
165  const UT_Vector3 &r00, const UT_Vector3 &r01,
166  const UT_Vector3 &r11, const UT_Vector3 &r10,
167  const IMG_TextureFilter &info,
168  int channel);
169 
170  fpreal getUPixelSize() const { return myDx; }
171  fpreal getVPixelSize() const { return myDy; }
172 
173  int64 getMemoryUsage(bool inclusive) const override;
174  virtual int getRasterCount() const { return 0; }
175  int getChannelTupleSize(int ch) const;
176  virtual int getNumChannels() const { return getStat().getNumPlanes(); }
177  const UT_StringHolder &ocioColorSpace(int channel) const;
178 
179  const UT_StringHolder &swrapMode() const { return mySWrapMode; }
180  const UT_StringHolder &twrapMode() const { return myTWrapMode; }
181 
182  // Return the channel index to use for lookups that haven't specified a
183  // particular channel.
184  virtual int getDefaultChannelIndex() const
185  { return 0; }
186  int findChannelIndex(const char *name) const;
187 
188  // TODO: Remove this method and replace with calls to IMG_Stat::getImageType
189  // Add IMG_TYPE_ENVMAP to the IMG_ImageType enum.
190  virtual int isReflMap() const { return 0; }
191 
193  { return myTTChannels(i).get(); }
194 
195 protected:
196  void initialize(int mipcount,
198 
199  int closeFile() override;
200 
202  exint numTTChannels() const { return myTTChannels.size(); }
204  IMG_TTChannel *getTTChannel(exint i) { return myTTChannels(i).get(); }
205 
206 protected:
207  // Mipmap level to start reading from the file.
209 
210 private:
211  void initScaleAndSize();
212 
213  //
214  // Data used in lookup of pixel values. These members MUST be
215  // initialized by derived classes before this class is used for
216  // sampling, by calling the initialize() method above.
217  //
218  void clearMips();
219 
220  // We have MIPs for each channel and raster
221  int getMipOffset(int aov, int image, int mip=0) const
222  {
223  // Each image AOV has myMipCount mip levels, so
224  // there are myMipCount IMG_TTChannel's for every
225  // AOV.
226  //
227  // Textures can contain multiple images (6-pack
228  // environment maps for example). To the texture
229  // library, each of these images is considered as
230  // an AOV (it shows up as a separate AOV in the
231  // IMG_Stat). Right now, there's no way for
232  // sub-images to contain multiple AOVs.
233  //
234  // These are flattened to a linear array:
235  // image0.aov0.mip0 [4x4]
236  // image0.aov0.mip1 [2x2]
237  // image0.aov0.mip2 [1x1]
238  // image1.aov0.mip0 [4x4]
239  // image1.aov0.mip1
240  // image1.aov0.mip2
241  // image2.aov0.mip0
242  // image2.aov0.mip1
243  // image2.aov0.mip2
244  // image0.aov1.mip0
245  // image0.aov1.mip1
246  // ...
247  return (aov+image)*myMipCount + mip;
248  }
249 
250  float myDx, myDy; // Inverse pixel sizes
251 
252  UT_Array<int> myColorSize;
253  UT_StringArray myOCIOColorSpace;
254  UT_StringHolder mySWrapMode;
255  UT_StringHolder myTWrapMode;
256 
257  // Mipmap samplers are stored as an array of pointers, with each
258  // entry representing one mipmap level. If this class is an
259  // environment map, multiple sets of mipmaps may be stored sequentially
260  // in this array.
261  UT_Array<UT_UniquePtr<IMG_TTMipSampler>> myMips; // Mip Maps
263  int myMipCount;
264  int myDSMComponentCount;
265  int myDepthComplexityPlane;
266  bool myFixMipFilterWidth;
267 };
268 
269 #endif
SYS_FORCE_INLINE IMG_TTChannel * getTTChannel(exint i)
const UT_StringHolder & swrapMode() const
virtual int isReflMap() const
SIM_API const UT_StringHolder angle
virtual int getNumChannels() const
const GLdouble * v
Definition: glcorearb.h:837
int64 exint
Definition: SYS_Types.h:125
GLenum GLenum GLsizei void * image
Definition: glad.h:5132
GLint y
Definition: glcorearb.h:103
**But if you need a result
Definition: thread.h:622
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define IMG_API
Definition: IMG_API.h:10
virtual int getRasterCount() const
IMG_DataType
Definition: IMG_FileTypes.h:17
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
fpreal getVPixelSize() const
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
HUSD_API const char * raster()
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
Modes for filtering.
A map of string to various well defined value types.
Definition: UT_Options.h:87
fpreal64 fpreal
Definition: SYS_Types.h:283
virtual void closeChannel()
This method is called when the channel is destroyed.
Definition: IMG_FileTTMap.h:67
void sample(float *result, int tuple_size, const float u[4], const float v[4], float quality, const IMG_TextureFilter &info, int channel, int raster)
IMG_ColorModel
Definition: IMG_FileTypes.h:52
const IMG_TTChannel * getChannel(exint i) const
fpreal getUPixelSize() const
void sample(float *result, int tuple_size, float u, float v, const IMG_TextureFilter &info, int channel, int raster)
IMG_ColorSpace
Modes for how to translate colors in images for texture lookups.
GLboolean r
Definition: glcorearb.h:1222
virtual int getDefaultChannelIndex() const
SYS_FORCE_INLINE exint numTTChannels() const
Definition: format.h:1821
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)
const UT_StringHolder & twrapMode() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297