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