HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_Defines.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_Defines.h (Tile Image Library, C++)
7  *
8  * COMMENTS:
9  * Some common stuff for tiles.
10  */
11 #ifndef TIL_DEFINES_H
12 #define TIL_DEFINES_H
13 
14 #include "TIL_API.h"
15 #include <IMG/IMG_FileTypes.h>
16 #include <PXL/PXL_Common.h>
17 #include <UT/UT_Lock.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_SysClone.h>
20 #include <SYS/SYS_Math.h>
21 #include <SYS/SYS_Types.h>
22 #include <limits.h>
23 
24 #define TIL_Lookup PXL_Lookup
25 #define TIL_Fill PXL_Fill
26 #define TIL_FillParms PXL_FillParms
27 #define TIL_Pixel PXL_Pixel
28 #define TIL_Convert PXL_Convert
29 
30 class UT_String;
31 
32 
33 // Use a maximum of 32 threads because:
34 // 1. COPs still uses locks, and this cap helps prevent slowdowns due to lock
35 // contention
36 // 2. A 32b bitmask is used to store per-thread information (though this can
37 // easily be changed if the above condition is fixed).
38 #define TIL_MAX_THREADS 32
39 
40 #define TIL_DEFAULT_TILE_SIZE 320
41 
42 #define TIL_DEFAULT_INT8_SIZE (TIL_DEFAULT_TILE_SIZE*TIL_DEFAULT_TILE_SIZE)
43 #define TIL_DEFAULT_INT16_SIZE (TIL_DEFAULT_INT8_SIZE * 2)
44 #define TIL_DEFAULT_FLOAT32_SIZE (TIL_DEFAULT_INT8_SIZE * 4)
45 
46 
47 #define TILE_LOCK_WRITE 0
48 #define TILE_LOCK_READ_ONLY 1
49 
50 // For Linux, PThread locks are faster than spin locks.
51 #ifdef WIN32
52 #include <UT/UT_SpinLock.h>
54 #else
56 #endif
57 
58 // how the data is stored.
59 //
60 // INT8 8 bit unsigned, 0.0 = 0, 1.0 = 255.
61 // INT16 16 bit unsigned, 0.0 = 0, 1.0 = variable (likely 65535)
62 // INT32 32 bit unsigned, 0.0 = variable, 1.0 = variable.
63 // FLOAT32 32 bit floating point 0.0 = 0.0, 1.0 = 1.0.
64 
65 #define TIL_DataFormat PXL_DataFormat
66 #define TILE_INT8 PXL_INT8
67 #define TILE_INT16 PXL_INT16
68 #define TILE_INT32 PXL_INT32
69 #define TILE_FLOAT32 PXL_FLOAT32
70 #define TILE_FLOAT16 PXL_FLOAT16
71 #define TILE_MAX_DATA_FORMAT PXL_MAX_DATA_FORMAT
72 
73 #define TIL_Packing PXL_Packing
74 
76 {
82  TIL_TI_SAMPLE_COUNT = IMG_TI_SAMPLE_COUNT // Deep sample count pseudo-plane
83 };
84 
86 {
91 };
92 
94 {
97  ODD_ONLY = 2,
99 };
100 
101 
102 // spatial & temporal extend conditions
104 {
110 };
111 
113 {
119 };
120 
122 {
137 };
138 
140 {
158 };
159 
160 #define TILE_WHITE_8 UCHAR_MAX
161 #define TILE_WHITE_16 USHRT_MAX
162 #define TILE_WHITE_32 UINT_MAX
163 
164 #define TILE_CACHE_MANAGER_MAX_LOCKS 4096
165 
166 #define PLANE_MAX_ARRAY_SIZE 4096
167 #define PLANE_MAX_VECTOR_SIZE 4
168 
169 #define PROXY_TABLE_SIZE 309
170 #define POOL_TABLE_SIZE 509
171 
172 
173 // Tile list manipulation
174 
175 // list = (TIL_TileList *), tile = (TIL_Tile *)
176 #define FOR_EACH_TILE(list,tile, i) \
177  for(i=0, tile=list->myItems[0]; i<PLANE_MAX_VECTOR_SIZE; \
178  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)])\
179  if(tile)
180 
181 #define GET_TILE(list,tile,i) \
182  for(tile=0, i=0, tile=list->myItems[0]; i<PLANE_MAX_VECTOR_SIZE; \
183  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)]) \
184  if(tile) break;
185 
186 #define GET_UNCOOKED_TILE(list,tile,i) \
187  for(tile=0, i=0, tile=list->myItems[0]; \
188  i<PLANE_MAX_VECTOR_SIZE; \
189  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)])\
190  if(tile && !tile->isCooked()) break;
191 
192 #define FOR_EACH_UNCOOKED_TILE(list,tile,i) \
193  for(i=0, tile=list->myItems[0]; i<PLANE_MAX_VECTOR_SIZE; \
194  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)])\
195  if(tile && !tile->isCooked())
196 
197 #define FOR_EACH_UNCOOKED_PAIR(outlist, inlist, out, in, i) \
198  for(i=0, out=outlist->myItems[0], in=inlist->myItems[0]; \
199  i<PLANE_MAX_VECTOR_SIZE; \
200  i++, out=outlist->myItems[SYSmin(i,PLANE_MAX_VECTOR_SIZE-1)],\
201  in=inlist->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)]) \
202  if(out && in && !out->isCooked())
203 
204 // Expands an input tile list into tiles.
205 #define TILE_INPUT1(list,a) { \
206  a = list->myItems[0]; }
207 
208 #define TILE_INPUT2(list,a,b) { \
209  a = list->myItems[0]; \
210  b = list->myItems[1]; }
211 
212 #define TILE_INPUT3(list,a,b,c) { \
213  a = list->myItems[0]; \
214  b = list->myItems[1]; \
215  c = list->myItems[2]; }
216 
217 #define TILE_INPUT4(list,a,b,c,d) { \
218  a = list->myItems[0]; \
219  b = list->myItems[1]; \
220  c = list->myItems[2]; \
221  d = list->myItems[3]; }
222 
223 
224 // expands an output tile list into tiles, if they aren't cooked already.
225 #define TILE_SCALAR(list,a) { \
226  a = list->myItems[0]; \
227  if(a && a->isCooked()) a = 0; \
228  }
229 
230 #define TILE_VECTOR2(list,a,b) { \
231  a = list->myItems[0]; \
232  b = list->myItems[1]; \
233  if(a && a->isCooked()) a = 0; \
234  if(b && b->isCooked()) b = 0; \
235  }
236 
237 #define TILE_VECTOR3(list,a,b,c) { \
238  a = list->myItems[0]; \
239  b = list->myItems[1]; \
240  c = list->myItems[2]; \
241  if(a && a->isCooked()) a = 0; \
242  if(b && b->isCooked()) b = 0; \
243  if(c && c->isCooked()) c = 0; \
244  }
245 
246 #define TILE_VECTOR4(list,a,b,c,d){ \
247  a = list->myItems[0]; \
248  b = list->myItems[1]; \
249  c = list->myItems[2]; \
250  d = list->myItems[3]; \
251  if(a && a->isCooked()) a = 0; \
252  if(b && b->isCooked()) b = 0; \
253  if(c && c->isCooked()) c = 0; \
254  if(d && d->isCooked()) d = 0; \
255  }
256 
257 //#define TIL_DEBUG_LOCK_BLOCKING
258 
259 #ifdef TIL_DEBUG_LOCK_BLOCKING
260 #define TIL_LOCK(loc) TILlock(loc, __FILE__ ":", __LINE__)
261 #define TIL_UNLOCK(loc) loc.unlock()
262 #define TILwait(n) TILwaitF(n, __FILE__ ":", __LINE__)
263 #else
264 #define TIL_LOCK(loc) loc.lock()
265 #define TIL_UNLOCK(loc) loc.unlock()
266 #define TILwait(n) TILwaitF(n)
267 #endif
268 
270  { return PXLformatDepth(d); }
271 
273  { return PXLpackingComponents(p); }
274 
276  { return PXLpackingDepth(p); }
277 
278 inline unsigned int TILwhitePoint(PXL_DataFormat dt)
279  { return PXLwhitePoint(dt); }
280 
281 // functions defined in TIL_Tile.C.
284 TIL_API void TILparsePlaneName(const char *name, UT_String &pname,
285  int &arrayindex);
286 TIL_API void TILgetBWPoints(TIL_DataFormat d, float b, float w,
287  unsigned &ib, unsigned &iw, bool &fast);
289  unsigned ib, unsigned iw,
290  float &b, float &w);
291 TIL_API void TILgetBestFormat(TIL_DataFormat d1, float b1, float w1,
292  TIL_DataFormat d2, float b2, float w2,
293  TIL_DataFormat &best,
294  float &black, float &white);
295 
296 // Lock & wait functions (with debug support)
297 TIL_API void TILlock(UT_Lock &lock,const char *file=0, int line=0);
300 TIL_API void TILwaitF(int n, const char *file=0, int line=0);
301 TIL_API double TILgetTotalWait();
302 
303 // common plane name and component referencing (return 'true' if the name
304 // had to be allocated with strdup, false if referenced).
305 TIL_API bool TILcopyOrRefPlaneName(const char *&dname,
306  const char *name);
307 TIL_API bool TILcopyOrRefCompName(const char *&dname,
308  const char *name);
309 TIL_API void TILinitNameRefs();
310 
311 
312 // returns true if the image data is constant-valued.
314  int xres,int yres);
315 
316 TIL_API bool TILemulationNeeded(int comp, float b, float w,
317  float sc, float sh, float gamma,
318  const char *lut, float aspect,
320  bool use8bit, bool hard_accel,
321  bool hardlut, bool frag_shader);
322 
323 // Properly aligned memory blocks, since memalign seems to have problems.
325 {
326 public:
327  // The specified alignment must be a power of 2, ie:
328  // 1, 2, 4, 8, 16, etc.
329  // Non powers of two will not only not work, but may crash, etc
330  static til_AlignedBlock *allocBlock(int size, int alignment);
331 
332  // set-it-up yourself version. Ensure that your block is aligned the way
333  // you like! Note that this memory is not owned, and will not be freed
334  // when this instance is destroyed.
335  static til_AlignedBlock *allocBlock(void *aligned);
336 
337  static void freeBlock(til_AlignedBlock *&block);
338 
339  operator void *() { return myAligned; }
340  operator const void *() { return myAligned; }
341 
342 private:
344  ~til_AlignedBlock();
346 
347  void reset();
348 
349  // myReal is the actual allocated data.
350  // myAligned is guaranteed to be aligned to the given
351  // alignment amount.
352  // myNext is used by the allocators when this block is not in
353  // circulation.
354  void *myReal;
355  union {
356  void *myAligned;
358  };
359 };
360 
361 
362 // This define causes ever tile alloced to be striped with alternating
363 // scanlines of white and grey, so that uncooked portions can be easily
364 // identified. This causes a fairly big performance hit.
365 // #define TIL_STRIPE_UNCOOKED_TILES
366 
367 // This define causes regions to be cleared to 33% grey (integer only
368 // - floating point looks white) so that unfilled regions can be quickly
369 // identified. This causes even more of a performance hit than the STRIPE
370 // define above.
371 // #define TIL_CLEAR_REGIONS_TO_GREY
372 
373 #endif // TIL_DEFINES_H
int PXLpackingComponents(PXL_Packing p)
Definition: PXL_Common.h:126
TIL_Storage
Definition: TIL_Defines.h:112
TIL_API void TILgetBWPoints(TIL_DataFormat d, float b, float w, unsigned &ib, unsigned &iw, bool &fast)
void
Definition: png.h:1083
int TILpackingComponents(PXL_Packing p)
Definition: TIL_Defines.h:272
unsigned int PXLwhitePoint(PXL_DataFormat dt)
Definition: PXL_Common.h:132
TIL_API bool TILemulationNeeded(int comp, float b, float w, float sc, float sh, float gamma, const char *lut, float aspect, TIL_DataFormat type, bool use8bit, bool hard_accel, bool hardlut, bool frag_shader)
UT_Lock TIL_FastLock
Definition: TIL_Defines.h:55
TIL_API bool TILcopyOrRefCompName(const char *&dname, const char *name)
TIL_Interlace
Definition: TIL_Defines.h:85
TIL_API bool TILcopyOrRefPlaneName(const char *&dname, const char *name)
int TILpackingDepth(PXL_Packing p)
Definition: TIL_Defines.h:275
TIL_API bool TILcheckConstant(void *idata, TIL_DataFormat format, int xres, int yres)
unsigned int TILwhitePoint(PXL_DataFormat dt)
Definition: TIL_Defines.h:278
GLdouble n
Definition: glcorearb.h:2008
#define TIL_DataFormat
Definition: TIL_Defines.h:65
GLboolean reset
Definition: glad.h:5138
TIL_API void TILinitNameRefs()
IMG_DataType
Definition: IMG_FileTypes.h:17
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
TIL_Dominance
Definition: TIL_Defines.h:93
int PXLpackingDepth(PXL_Packing p)
Definition: PXL_Common.h:129
PXL_Packing
Definition: PXL_Common.h:32
TIL_API void TILclearTotalWait()
TIL_API void TILgetFloatBWPoints(TIL_DataFormat d, unsigned ib, unsigned iw, float &b, float &w)
GLuint const GLchar * name
Definition: glcorearb.h:786
int TILformatDepth(PXL_DataFormat d)
Definition: TIL_Defines.h:269
PXL_DataFormat
Definition: PXL_Common.h:20
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLenum pname
Definition: glcorearb.h:104
TIL_ViewerType
Definition: TIL_Defines.h:139
TIL_API void TILwaitF(int n, const char *file=0, int line=0)
GLsizeiptr size
Definition: glcorearb.h:664
TIL_API double TILgetTotalWait()
TIL_HistogramType
Definition: TIL_Defines.h:121
int PXLformatDepth(PXL_DataFormat d)
Definition: PXL_Common.h:123
TIL_API void TILprintLockBlockStats()
TIL_API void TILparsePlaneName(const char *name, UT_String &pname, int &arrayindex)
TIL_TypeInfo
Definition: TIL_Defines.h:75
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
TIL_API TIL_DataFormat TILformatConvert(IMG_DataType)
type
Definition: core.h:1059
#define TIL_API
Definition: TIL_API.h:10
TIL_API void TILgetBestFormat(TIL_DataFormat d1, float b1, float w1, TIL_DataFormat d2, float b2, float w2, TIL_DataFormat &best, float &black, float &white)
til_AlignedBlock * myNext
Definition: TIL_Defines.h:357
TIL_Extend
Definition: TIL_Defines.h:103
TIL_API void TILlock(UT_Lock &lock, const char *file=0, int line=0)