HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_Tile.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_Tile.h (Tile Image Library, C++)
7  *
8  * COMMENTS:
9  * Defines the structure of an image tile.
10  */
11 #ifndef TIL_TILE_H
12 #define TIL_TILE_H
13 
14 #include "TIL_API.h"
15 #include "TIL_Defines.h"
16 #include "TIL_HoldingQueue.h"
17 #include <SYS/SYS_Types.h>
18 
19 #include <iosfwd>
20 
21 
22 class UT_TokenString;
23 class TIL_TileCache;
24 
26 {
27 public:
28  // Constructor and Destructor are private; only TIL_CacheManager can create
29  // and destroy tiles.
30 
31  // resets all the information for re-allocation.
32  void reset();
33 
34  // utility functions ****
35  void clear(float value = 0.0F, int scanstep=1,
36  int scanoff =0);
37  // odd means double the odd scanlines to the even ones.
38  void lineDouble(bool odd);
39 
40  int matches(const UT_TokenString *image_id,
41  int tilex, int tiley) const;
42  // like strcmp.
43  int compare(const UT_TokenString *image_id,
44  int tilex, int tiley) const;
45 
46 
47  // Accesser functions *****
48 
49  // plane name and vector index (0-3).
50  void setVectorName(const char *name, int vector =0);
51  const char * getVectorName() const {return myVectorName;}
52  void setCompName(const char *name);
53  const char * getCompName() const { return myCompName; }
54  int getVectorIndex() const {return myVectorIndex;}
55 
56  // format of the tile (int8,int16,int32,float32)
57  void setFormat(TIL_DataFormat f);
58  TIL_DataFormat getFormat() const { return myFormat; }
59 
60  // storage type of this type (locked, proxy, nocache, cached).
61  void setStorage(TIL_Storage storage) { myStorage = storage;}
62  TIL_Storage getStorage() const { return myStorage; }
63 
64  // the "frame" number; first image is always 0 regardless of time offset.
65  void setImageNum(int n) { myImageNum = n; }
66  int getImageNum() const { return myImageNum; }
67 
68  // black/white support for integer formats.
69  void setBlackWhitePoints(int black,int white);
70  int usesBlackWhitePoints() const;
71  void getBlackWhitePoints(unsigned int &black,
72  unsigned int &white) const
73  { black = myBlackLevel; white = myWhiteLevel; }
74 
75  // tile offset in the main image (in pixels).
76  void setOffset(int x,int y) { myXOffset=x; myYOffset=y; }
77  void getOffset(int &x, int &y) const
78  { x=myXOffset; y=myYOffset; }
79 
80  // the size of the tile (from 1 to theTileX/YSize)
81  void setSize(int x, int y);
82  void getSize(int &x, int &y) const
83  { x = myXSize; y = myYSize; }
84 
85  int getNumPixels() const;
86 
87  // the COP this tile belongs to (void * due to lib linking).
88  void setParent(void *parent) { myParent = parent; }
89  void * getParent() const { return myParent; }
90 
91 
92  // the full path of the COP this tile belongs to.
93  void setNodePath(const char *path);
94  const char * getNodePath() const { return myNodePath;}
95 
96  // the image id; guarenteed to be unique if the tiles are different.
98  { myImageIdentifier = token; }
100  { return myImageIdentifier; }
101 
102  // has this tile been cooked yet?
103  void setCooked(bool done = true) { myCookedFlag =done; }
104  bool isCooked() const { return myCookedFlag;}
105 
106  bool isCheckpoint() const { return myCheckpointCount != 0; }
107  int getCheckpointCount() const { return myCheckpointCount; }
108  void incrementCheckpointCount();
109  void decrementCheckpointCount();
110 
111  bool determineIfConstant();
112  bool isConstantTile() const { return myConstantTileFlag; }
113  float getConstantColor() const;
114 
115  // When flagging a tile as constant, ensure that you've already
116  // initialized the data as this method will read it.
117  void setConstantTile(bool constant);
118 
119  // used to access this tile in a multithreaded environment
120  // access can be TILE_LOCK_READ_ONLY or TILE_LOCK_WRITE
121  int lock(int access, int block = 1);
122  // used when cooking is done. score is the priority score for the tile.
123  void lockWriteToRead(int score);
124  void unlock(int access);
125 
126  // if on, this tile is being held for proxy writing.
127  void setProxyHold(bool on) { myProxyHoldFlag = on; }
128 
129  // the amount of memory the tile's image takes up (not including overhead).
130  int getMemSize() const { return myMemSize; }
131 
132  // the amount of memory the tile takes up (including overhead)
133  int64 getMemoryUsage(bool inclusive) const;
134 
135  // Image data accessor functions; returns NULL if the data type doesn't
136  // match the function called. the void * functions always return non-null.
138  { myImageData = data; }
139 
140  void getImageData(const unsigned char *&data) const;
141  void getImageData(const unsigned short *&data) const;
142  void getImageData(const unsigned int *&data) const;
143  void getImageData(const float *&data) const;
144  void getImageData(const fpreal16 *&data) const;
145  const void * getImageData() const { return (void *) *myImageData; }
146 
147  void getImageData(unsigned char *&data);
148  void getImageData(unsigned short *&data);
149  void getImageData(unsigned int *&data);
150  void getImageData(float *&data);
151  void getImageData(fpreal16 *&data);
152  void * getImageData() { return (void *) *myImageData; }
153 
154  TIL_AlignedBlock *getImageBlock() { return myImageData; }
155 
156  // caching functions *****
157 
158  // the priority of this tile.
159  void setPriority(unsigned int p) { myPriority = p; }
160  int getPriority() const { return myPriority; }
161 
162  // returns 1 if this tile is locked in any way
163  int isCacheLocked() const;
164  bool isReadLocked() const;
165  bool isWriteLocked() const;
166 
167  bool isBorrowedImage() const { return myBorrowedImageFlag; }
168  void setBorrowedImage(bool b) { myBorrowedImageFlag = b;
169  myMemSize = 0; }
170 
171  // Static tile functions.
172 
173  // selects a new tile size. Must be called before the Cache Manager is
174  // initialized (or re-initialized). Use with extreme care.
175  static void setNewTileSize(int xsize, int ysize);
176 
177  // query tiles sizes and memory requirements.
178  static int getTileSizeX();
179  static int getTileSizeY();
180  static int getTile8Mem();
181  static int getTile16Mem();
182  static int getTile32Mem();
183 
184  static void setTileCachePtr(TIL_TileCache *tc);
185 
186  // DEBUG
187  void print(std::ostream &os) const;
188  static void setCop2PrintCallback(void(*callback)(void *,std::ostream &));
189 
190 private:
191  // Only the Tile Cache can create and destroy tiles.
192  TIL_Tile();
193  ~TIL_Tile();
194 
195  // TIL_HoldingNode (12)
196  // identification (16)
197  const char *myVectorName;
198  const char *myCompName;
199  int myVectorIndex;
200  int myImageNum;
201 
202  // description (40)
203  TIL_DataFormat myFormat;
204  unsigned int myBlackLevel;
205  unsigned int myWhiteLevel;
206  int myXSize;
207  int myYSize;
208  int myXOffset;
209  int myYOffset;
210  int myMemSize;
211  TIL_Storage myStorage;
212  char *myNodePath;
213 
214  // caching (16)
215  unsigned int myPriority;
216  void * myParent;
217  UT_TokenString * myImageIdentifier;
218  int myCheckpointCount; // num planes checkpointing tile
219 
220  // flags (4)
221  unsigned int myCompNameAlloc : 1,
222  myConstantTileFlag : 1,
223  myBorrowedImageFlag : 1,
224  myCookedFlag : 1,
225  myProxyHoldFlag : 1,
226  myVectorNameAlloc : 1;
227 
228  // constant value, if const (4)
229  union {
230  unsigned char myConstantVal8;
231  unsigned short myConstantVal16;
232  unsigned int myConstantVal32;
234  };
235  fpreal16 myConstantValFP16;
236 
237  // locking (24)
238  TIL_FastLock myMainLock;
239  int myReadLocks;
240  int myWriteLock;
241 
242  // actual image data: not owned by this object (4)
243  TIL_AlignedBlock *myImageData;
244 
245  friend class TIL_TileCache;
246 };
247 
248 
249 #endif // TIL_TILE_H
int getVectorIndex() const
Definition: TIL_Tile.h:54
void * getParent() const
Definition: TIL_Tile.h:89
unsigned int myConstantVal32
Definition: TIL_Tile.h:232
const char * getVectorName() const
Definition: TIL_Tile.h:51
unsigned short myConstantVal16
Definition: TIL_Tile.h:231
TIL_Storage
Definition: TIL_Defines.h:111
int getPriority() const
Definition: TIL_Tile.h:160
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GLboolean * data
Definition: glcorearb.h:131
GLsizei const GLfloat * value
Definition: glcorearb.h:824
CompareResults OIIO_API compare(const ImageBuf &A, const ImageBuf &B, float failthresh, float warnthresh, float failrelative, float warnrelative, ROI roi={}, int nthreads=0)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
**And then you can **find out if it s done
Definition: thread.h:631
void setParent(void *parent)
Definition: TIL_Tile.h:88
int getCheckpointCount() const
Definition: TIL_Tile.h:107
bool isCooked() const
Definition: TIL_Tile.h:104
GLint y
Definition: glcorearb.h:103
int getMemSize() const
Definition: TIL_Tile.h:130
void setBorrowedImage(bool b)
Definition: TIL_Tile.h:168
void getBlackWhitePoints(unsigned int &black, unsigned int &white) const
Definition: TIL_Tile.h:71
TIL_Storage getStorage() const
Definition: TIL_Tile.h:62
TIL_DataFormat getFormat() const
Definition: TIL_Tile.h:58
void getOffset(int &x, int &y) const
Definition: TIL_Tile.h:77
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
TIL_AlignedBlock * getImageBlock()
Definition: TIL_Tile.h:154
#define TIL_DataFormat
Definition: TIL_Defines.h:64
GLboolean reset
Definition: glad.h:5138
GLuint GLint GLboolean GLint GLenum access
Definition: glcorearb.h:2222
const UT_TokenString * getImageIdentifier() const
Definition: TIL_Tile.h:99
void setImageData(TIL_AlignedBlock *data)
Definition: TIL_Tile.h:137
long long int64
Definition: SYS_Types.h:116
void setProxyHold(bool on)
Definition: TIL_Tile.h:127
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
void getSize(int &x, int &y) const
Definition: TIL_Tile.h:82
float myConstantValFP
Definition: TIL_Tile.h:233
void setCooked(bool done=true)
Definition: TIL_Tile.h:103
const void * getImageData() const
Definition: TIL_Tile.h:145
const char * getCompName() const
Definition: TIL_Tile.h:53
void setImageIdentifier(UT_TokenString *token)
Definition: TIL_Tile.h:97
int getImageNum() const
Definition: TIL_Tile.h:66
bool isBorrowedImage() const
Definition: TIL_Tile.h:167
void setStorage(TIL_Storage storage)
Definition: TIL_Tile.h:61
void * getImageData()
Definition: TIL_Tile.h:152
void setPriority(unsigned int p)
Definition: TIL_Tile.h:159
const char * getNodePath() const
Definition: TIL_Tile.h:94
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2903
#define TIL_API
Definition: TIL_API.h:10
bool isConstantTile() const
Definition: TIL_Tile.h:112
unsigned char myConstantVal8
Definition: TIL_Tile.h:230
Definition: format.h:1821
void setOffset(int x, int y)
Definition: TIL_Tile.h:76
void setImageNum(int n)
Definition: TIL_Tile.h:65
bool isCheckpoint() const
Definition: TIL_Tile.h:106