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 <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 {
81  TIL_TI_SAMPLE_COUNT = IMG_TI_SAMPLE_COUNT // Deep sample count pseudo-plane
82 };
83 
85 {
90 };
91 
93 {
96  ODD_ONLY = 2,
98 };
99 
100 
101 // spatial & temporal extend conditions
103 {
109 };
110 
112 {
118 };
119 
121 {
136 };
137 
139 {
157 };
158 
159 #define TILE_WHITE_8 UCHAR_MAX
160 #define TILE_WHITE_16 USHRT_MAX
161 #define TILE_WHITE_32 UINT_MAX
162 
163 #define TILE_CACHE_MANAGER_MAX_LOCKS 4096
164 
165 #define PLANE_MAX_ARRAY_SIZE 4096
166 #define PLANE_MAX_VECTOR_SIZE 4
167 
168 #define PROXY_TABLE_SIZE 309
169 #define POOL_TABLE_SIZE 509
170 
171 
172 // Tile list manipulation
173 
174 // list = (TIL_TileList *), tile = (TIL_Tile *)
175 #define FOR_EACH_TILE(list,tile, i) \
176  for(i=0, tile=list->myItems[0]; i<PLANE_MAX_VECTOR_SIZE; \
177  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)])\
178  if(tile)
179 
180 #define GET_TILE(list,tile,i) \
181  for(tile=0, i=0, tile=list->myItems[0]; i<PLANE_MAX_VECTOR_SIZE; \
182  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)]) \
183  if(tile) break;
184 
185 #define GET_UNCOOKED_TILE(list,tile,i) \
186  for(tile=0, i=0, tile=list->myItems[0]; \
187  i<PLANE_MAX_VECTOR_SIZE; \
188  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)])\
189  if(tile && !tile->isCooked()) break;
190 
191 #define FOR_EACH_UNCOOKED_TILE(list,tile,i) \
192  for(i=0, tile=list->myItems[0]; i<PLANE_MAX_VECTOR_SIZE; \
193  i++, tile=list->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)])\
194  if(tile && !tile->isCooked())
195 
196 #define FOR_EACH_UNCOOKED_PAIR(outlist, inlist, out, in, i) \
197  for(i=0, out=outlist->myItems[0], in=inlist->myItems[0]; \
198  i<PLANE_MAX_VECTOR_SIZE; \
199  i++, out=outlist->myItems[SYSmin(i,PLANE_MAX_VECTOR_SIZE-1)],\
200  in=inlist->myItems[SYSmin(i, PLANE_MAX_VECTOR_SIZE-1)]) \
201  if(out && in && !out->isCooked())
202 
203 // Expands an input tile list into tiles.
204 #define TILE_INPUT1(list,a) { \
205  a = list->myItems[0]; }
206 
207 #define TILE_INPUT2(list,a,b) { \
208  a = list->myItems[0]; \
209  b = list->myItems[1]; }
210 
211 #define TILE_INPUT3(list,a,b,c) { \
212  a = list->myItems[0]; \
213  b = list->myItems[1]; \
214  c = list->myItems[2]; }
215 
216 #define TILE_INPUT4(list,a,b,c,d) { \
217  a = list->myItems[0]; \
218  b = list->myItems[1]; \
219  c = list->myItems[2]; \
220  d = list->myItems[3]; }
221 
222 
223 // expands an output tile list into tiles, if they aren't cooked already.
224 #define TILE_SCALAR(list,a) { \
225  a = list->myItems[0]; \
226  if(a && a->isCooked()) a = 0; \
227  }
228 
229 #define TILE_VECTOR2(list,a,b) { \
230  a = list->myItems[0]; \
231  b = list->myItems[1]; \
232  if(a && a->isCooked()) a = 0; \
233  if(b && b->isCooked()) b = 0; \
234  }
235 
236 #define TILE_VECTOR3(list,a,b,c) { \
237  a = list->myItems[0]; \
238  b = list->myItems[1]; \
239  c = list->myItems[2]; \
240  if(a && a->isCooked()) a = 0; \
241  if(b && b->isCooked()) b = 0; \
242  if(c && c->isCooked()) c = 0; \
243  }
244 
245 #define TILE_VECTOR4(list,a,b,c,d){ \
246  a = list->myItems[0]; \
247  b = list->myItems[1]; \
248  c = list->myItems[2]; \
249  d = list->myItems[3]; \
250  if(a && a->isCooked()) a = 0; \
251  if(b && b->isCooked()) b = 0; \
252  if(c && c->isCooked()) c = 0; \
253  if(d && d->isCooked()) d = 0; \
254  }
255 
256 //#define TIL_DEBUG_LOCK_BLOCKING
257 
258 #ifdef TIL_DEBUG_LOCK_BLOCKING
259 #define TIL_LOCK(loc) TILlock(loc, __FILE__ ":", __LINE__)
260 #define TIL_UNLOCK(loc) loc.unlock()
261 #define TILwait(n) TILwaitF(n, __FILE__ ":", __LINE__)
262 #else
263 #define TIL_LOCK(loc) loc.lock()
264 #define TIL_UNLOCK(loc) loc.unlock()
265 #define TILwait(n) TILwaitF(n)
266 #endif
267 
269  { return PXLformatDepth(d); }
270 
272  { return PXLpackingComponents(p); }
273 
275  { return PXLpackingDepth(p); }
276 
277 inline unsigned int TILwhitePoint(PXL_DataFormat dt)
278  { return PXLwhitePoint(dt); }
279 
280 // functions defined in TIL_Tile.C.
283 TIL_API void TILparsePlaneName(const char *name, UT_String &pname,
284  int &arrayindex);
285 TIL_API void TILgetBWPoints(TIL_DataFormat d, float b, float w,
286  unsigned &ib, unsigned &iw, bool &fast);
288  unsigned ib, unsigned iw,
289  float &b, float &w);
290 TIL_API void TILgetBestFormat(TIL_DataFormat d1, float b1, float w1,
291  TIL_DataFormat d2, float b2, float w2,
292  TIL_DataFormat &best,
293  float &black, float &white);
294 
295 // Lock & wait functions (with debug support)
296 TIL_API void TILlock(UT_Lock &lock,const char *file=0, int line=0);
299 TIL_API void TILwaitF(int n, const char *file=0, int line=0);
300 TIL_API double TILgetTotalWait();
301 
302 // common plane name and component referencing (return 'true' if the name
303 // had to be allocated with strdup, false if referenced).
304 TIL_API bool TILcopyOrRefPlaneName(const char *&dname,
305  const char *name);
306 TIL_API bool TILcopyOrRefCompName(const char *&dname,
307  const char *name);
308 TIL_API void TILinitNameRefs();
309 
310 
311 // returns true if the image data is constant-valued.
313  int xres,int yres);
314 
315 TIL_API bool TILemulationNeeded(int comp, float b, float w,
316  float sc, float sh, float gamma,
317  const char *lut, float aspect,
319  bool use8bit, bool hard_accel,
320  bool hardlut, bool frag_shader);
321 
322 // Properly aligned memory blocks, since memalign seems to have problems.
324 {
325 public:
326  // The specified alignment must be a power of 2, ie:
327  // 1, 2, 4, 8, 16, etc.
328  // Non powers of two will not only not work, but may crash, etc
329  static til_AlignedBlock *allocBlock(int size, int alignment);
330 
331  // set-it-up yourself version. Ensure that your block is aligned the way
332  // you like! Note that this memory is not owned, and will not be freed
333  // when this instance is destroyed.
334  static til_AlignedBlock *allocBlock(void *aligned);
335 
336  static void freeBlock(til_AlignedBlock *&block);
337 
338  operator void *() { return myAligned; }
339  operator const void *() { return myAligned; }
340 
341 private:
343  ~til_AlignedBlock();
344 
345  void reset();
346 
347  // myReal is the actual allocated data.
348  // myAligned is guaranteed to be aligned to the given
349  // alignment amount.
350  // myNext is used by the allocators when this block is not in
351  // circulation.
352  void *myReal;
353  union {
354  void *myAligned;
356  };
357 };
358 
359 
360 // This define causes ever tile alloced to be striped with alternating
361 // scanlines of white and grey, so that uncooked portions can be easily
362 // identified. This causes a fairly big performance hit.
363 // #define TIL_STRIPE_UNCOOKED_TILES
364 
365 // This define causes regions to be cleared to 33% grey (integer only
366 // - floating point looks white) so that unfilled regions can be quickly
367 // identified. This causes even more of a performance hit than the STRIPE
368 // define above.
369 // #define TIL_CLEAR_REGIONS_TO_GREY
370 
371 #endif // TIL_DEFINES_H
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
int PXLpackingComponents(PXL_Packing p)
Definition: PXL_Common.h:118
TIL_Storage
Definition: TIL_Defines.h:111
TIL_API void TILgetBWPoints(TIL_DataFormat d, float b, float w, unsigned &ib, unsigned &iw, bool &fast)
int TILpackingComponents(PXL_Packing p)
Definition: TIL_Defines.h:271
unsigned int PXLwhitePoint(PXL_DataFormat dt)
Definition: PXL_Common.h:124
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:84
TIL_API bool TILcopyOrRefPlaneName(const char *&dname, const char *name)
int TILpackingDepth(PXL_Packing p)
Definition: TIL_Defines.h:274
GLuint const GLchar * name
Definition: glcorearb.h:786
TIL_API bool TILcheckConstant(void *idata, TIL_DataFormat format, int xres, int yres)
GLsizeiptr size
Definition: glcorearb.h:664
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
unsigned int TILwhitePoint(PXL_DataFormat dt)
Definition: TIL_Defines.h:277
#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:92
int PXLpackingDepth(PXL_Packing p)
Definition: PXL_Common.h:121
PXL_Packing
Definition: PXL_Common.h:30
TIL_API void TILclearTotalWait()
GLfloat GLfloat p
Definition: glew.h:16656
TIL_API void TILgetFloatBWPoints(TIL_DataFormat d, unsigned ib, unsigned iw, float &b, float &w)
GLboolean reset
Definition: glew.h:4989
int TILformatDepth(PXL_DataFormat d)
Definition: TIL_Defines.h:268
PXL_DataFormat
Definition: PXL_Common.h:20
GLenum pname
Definition: glcorearb.h:104
TIL_ViewerType
Definition: TIL_Defines.h:138
TIL_API void TILwaitF(int n, const char *file=0, int line=0)
GLdouble n
Definition: glcorearb.h:2008
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
TIL_API double TILgetTotalWait()
TIL_HistogramType
Definition: TIL_Defines.h:120
int PXLformatDepth(PXL_DataFormat d)
Definition: PXL_Common.h:115
TIL_API void TILprintLockBlockStats()
TIL_API void TILparsePlaneName(const char *name, UT_String &pname, int &arrayindex)
TIL_TypeInfo
Definition: TIL_Defines.h:74
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:355
TIL_Extend
Definition: TIL_Defines.h:102
TIL_API void TILlock(UT_Lock &lock, const char *file=0, int line=0)