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