HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openexr_attr.h
Go to the documentation of this file.
1 /*
2 ** SPDX-License-Identifier: BSD-3-Clause
3 ** Copyright Contributors to the OpenEXR Project.
4 */
5 
6 #ifndef OPENEXR_ATTR_H
7 #define OPENEXR_ATTR_H
8 
9 #include "openexr_context.h"
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /** @file */
19 
20 /**
21  * @defgroup AttributeTypes Attribute/metadata value types and struct declarations
22  *
23  * @brief These are a group of enum values defining valid values for
24  * some attributes and then associated structs for other types.
25  *
26  * Some of these types will be directly representable/storable in
27  * the file, some not. There is some overlap here with Imath, and they
28  * should be kept in the same order for compatibility. However do note
29  * that these are just the raw data, and no useful functions are
30  * declared at this layer, that is what Imath is for.
31  *
32  * @{
33  */
34 
35 /** Enum declaring allowed values for \c uint8_t value stored in built-in compression type. */
36 typedef enum
37 {
50  EXR_COMPRESSION_LAST_TYPE /**< Invalid value, provided for range checking. */
52 
53 /** Enum declaring allowed values for \c uint8_t value stored in built-in env map type. */
54 typedef enum
55 {
58  EXR_ENVMAP_LAST_TYPE /**< Invalid value, provided for range checking. */
59 } exr_envmap_t;
60 
61 /** Enum declaring allowed values for \c uint8_t value stored in \c lineOrder type. */
62 typedef enum
63 {
67  EXR_LINEORDER_LAST_TYPE /**< Invalid value, provided for range checking. */
69 
70 /** Enum declaring allowed values for part type. */
71 typedef enum
72 {
73  EXR_STORAGE_SCANLINE = 0, /**< Corresponds to type of \c scanlineimage. */
74  EXR_STORAGE_TILED, /**< Corresponds to type of \c tiledimage. */
75  EXR_STORAGE_DEEP_SCANLINE, /**< Corresponds to type of \c deepscanline. */
76  EXR_STORAGE_DEEP_TILED, /**< Corresponds to type of \c deeptile. */
77  EXR_STORAGE_LAST_TYPE, /**< Invalid value, provided for range checking. */
78  EXR_STORAGE_UNKNOWN /**< An unknown type, provided for future proofing. */
80 
81 /** @brief Enum representing what type of tile information is contained. */
82 typedef enum
83 {
84  EXR_TILE_ONE_LEVEL = 0, /**< Single level of image data. */
85  EXR_TILE_MIPMAP_LEVELS = 1, /**< Mipmapped image data. */
86  EXR_TILE_RIPMAP_LEVELS = 2, /**< Ripmapped image data. */
87  EXR_TILE_LAST_TYPE /**< Invalid value, provided for range checking. */
89 
90 /** @brief Enum representing how to scale positions between levels. */
91 typedef enum
92 {
97 
98 /** @brief Enum capturing the underlying data type on a channel. */
99 typedef enum
100 {
106 
107 /** Enum declaring allowed values for \c uint8_t value stored in \c deepImageState type. */
108 typedef enum
109 {
114  EXR_DIS_LAST_TYPE /**< Invalid value, provided for range checking. */
116 
117 /* /////////////////////////////////////// */
118 /* First set of structs are data where we can read directly with no allocation needed... */
119 
120 /* Most are naturally aligned, but force some of these
121  * structs to be tightly packed
122  */
123 #pragma pack(push, 1)
124 
125 /** @brief Struct to hold color chromaticities to interpret the tristimulus color values in the image data. */
126 typedef struct
127 {
128  float red_x;
129  float red_y;
130  float green_x;
131  float green_y;
132  float blue_x;
133  float blue_y;
134  float white_x;
135  float white_y;
137 
138 /** @brief Struct to hold keycode information. */
139 typedef struct
140 {
141  int32_t film_mfc_code;
142  int32_t film_type;
143  int32_t prefix;
144  int32_t count;
145  int32_t perf_offset;
149 
150 /** @brief struct to hold a 32-bit floating-point 3x3 matrix. */
151 typedef struct
152 {
153  float m[9];
155 
156 /** @brief struct to hold a 64-bit floating-point 3x3 matrix. */
157 typedef struct
158 {
159  double m[9];
161 
162 /** @brief Struct to hold a 32-bit floating-point 4x4 matrix. */
163 typedef struct
164 {
165  float m[16];
167 
168 /** @brief Struct to hold a 64-bit floating-point 4x4 matrix. */
169 typedef struct
170 {
171  double m[16];
173 
174 /** @brief Struct to hold an integer ratio value. */
175 typedef struct
176 {
177  int32_t num;
178  uint32_t denom;
180 
181 /** @brief Struct to hold timecode information. */
182 typedef struct
183 {
184  uint32_t time_and_flags;
185  uint32_t user_data;
187 
188 /** @brief Struct to hold a 2-element integer vector. */
189 typedef struct
190 {
191  int32_t x, y;
193 
194 /** @brief Struct to hold a 2-element 32-bit float vector. */
195 typedef struct
196 {
197  float x, y;
199 
200 /** @brief Struct to hold a 2-element 64-bit float vector. */
201 typedef struct
202 {
203  double x, y;
205 
206 /** @brief Struct to hold a 3-element integer vector. */
207 typedef struct
208 {
209  int32_t x, y, z;
211 
212 /** @brief Struct to hold a 3-element 32-bit float vector. */
213 typedef struct
214 {
215  float x, y, z;
217 
218 /** @brief Struct to hold a 3-element 64-bit float vector. */
219 typedef struct
220 {
221  double x, y, z;
223 
224 /** @brief Struct to hold an integer box/region definition. */
225 typedef struct
226 {
230 
231 /** @brief Struct to hold a floating-point box/region definition. */
232 typedef struct
233 {
237 
238 /** @brief Struct holding base tiledesc attribute type defined in spec
239  *
240  * NB: This is in a tightly packed area so it can be read directly, be
241  * careful it doesn't become padded to the next \c uint32_t boundary.
242  */
243 typedef struct
244 {
245  uint32_t x_size;
246  uint32_t y_size;
249 
250 /** @brief Macro to access type of tiling from packed structure. */
251 #define EXR_GET_TILE_LEVEL_MODE(tiledesc) \
252  ((exr_tile_level_mode_t) (((tiledesc).level_and_round) & 0xF))
253 /** @brief Macro to access the rounding mode of tiling from packed structure. */
254 #define EXR_GET_TILE_ROUND_MODE(tiledesc) \
255  ((exr_tile_round_mode_t) ((((tiledesc).level_and_round) >> 4) & 0xF))
256 /** @brief Macro to pack the tiling type and rounding mode into packed structure. */
257 #define EXR_PACK_TILE_LEVEL_ROUND(lvl, mode) \
258  ((uint8_t) ((((uint8_t) ((mode) & 0xF) << 4)) | ((uint8_t) ((lvl) & 0xF))))
259 
260 #pragma pack(pop)
261 
262 /* /////////////////////////////////////// */
263 /* Now structs that involve heap allocation to store data. */
264 
265 /** Storage for a string. */
266 typedef struct
267 {
268  int32_t length;
269  /** If this is non-zero, the string owns the data, if 0, is a const ref to a static string. */
270  int32_t alloc_size;
271 
272  const char* str;
274 
275 /** Storage for a string vector. */
276 typedef struct
277 {
278  int32_t n_strings;
279  /** If this is non-zero, the string vector owns the data, if 0, is a const ref. */
280  int32_t alloc_size;
281 
284 
285 /** Float vector storage struct. */
286 typedef struct
287 {
288  int32_t length;
289  /** If this is non-zero, the float vector owns the data, if 0, is a const ref. */
290  int32_t alloc_size;
291 
292  const float* arr;
294 
295 /** Hint for lossy compression methods about how to treat values
296  * (logarithmic or linear), meaning a human sees values like R, G, B,
297  * luminance difference between 0.1 and 0.2 as about the same as 1.0
298  * to 2.0 (logarithmic), where chroma coordinates are closer to linear
299  * (0.1 and 0.2 is about the same difference as 1.0 and 1.1).
300  */
301 typedef enum
302 {
306 
307 /** Individual channel information. */
308 typedef struct
309 {
311  /** Data representation for these pixels: uint, half, float. */
313  /** Possible values are 0 and 1 per docs exr_perceptual_treatment_t. */
314  uint8_t p_linear;
315  uint8_t reserved[3];
316  int32_t x_sampling;
317  int32_t y_sampling;
319 
320 /** List of channel information (sorted alphabetically). */
321 typedef struct
322 {
325 
328 
329 /** @brief Struct to define attributes of an embedded preview image. */
330 typedef struct
331 {
332  uint32_t width;
333  uint32_t height;
334  /** If this is non-zero, the preview owns the data, if 0, is a const ref. */
335  size_t alloc_size;
336 
337  const uint8_t* rgba;
339 
340 /** @brief Struct to define bytes attributes */
341 typedef struct
342 {
343  size_t size;
344  uint8_t* data;
345  // The type hint is not null terminated when serialized. The length
346  // is instead determined by the hint_length attribute.
347  uint32_t hint_length;
348  const char *type_hint;
350 
351 /** Custom storage structure for opaque data.
352  *
353  * Handlers for opaque types can be registered, then when a
354  * non-builtin type is encountered with a registered handler, the
355  * function pointers to unpack/pack it will be set up.
356  *
357  * @sa exr_register_attr_type_handler
358  */
359 typedef struct
360 {
361  int32_t size;
362  int32_t unpacked_size;
363  /** If this is non-zero, the struct owns the data, if 0, is a const ref. */
365  uint8_t pad[4];
366 
367  void* packed_data;
368 
369  /** When an application wants to have custom data, they can store
370  * an unpacked form here which will be requested to be destroyed
371  * upon destruction of the attribute.
372  */
374 
375  /** An application can register an attribute handler which then
376  * fills in these function pointers. This allows a user to delay
377  * the expansion of the custom type until access is desired, and
378  * similarly, to delay the packing of the data until write time.
379  */
380  exr_result_t (*unpack_func_ptr) (
381  exr_context_t ctxt,
382  const void* data,
383  int32_t attrsize,
384  int32_t* outsize,
385  void** outbuffer);
386  exr_result_t (*pack_func_ptr) (
387  exr_context_t ctxt,
388  const void* data,
389  int32_t datasize,
390  int32_t* outsize,
391  void* outbuffer);
392  void (*destroy_unpacked_func_ptr) (
393  exr_context_t ctxt, void* data, int32_t attrsize);
395 
396 /* /////////////////////////////////////// */
397 
398 /** @brief Built-in/native attribute type enum.
399  *
400  * This will enable us to do a tagged type struct to generically store
401  * attributes.
402  */
403 typedef enum
404 {
406  0, /**< Type indicating an error or uninitialized attribute. */
407  EXR_ATTR_BOX2I, /**< Integer region definition. @see exr_attr_box2i_t. */
408  EXR_ATTR_BOX2F, /**< Float region definition. @see exr_attr_box2f_t. */
409  EXR_ATTR_BYTES, /**< Bytes definition. @see exr_attr_bytes_t. */
410  EXR_ATTR_CHLIST, /**< Definition of channels in file @see exr_chlist_entry. */
411  EXR_ATTR_CHROMATICITIES, /**< Values to specify color space of colors in file @see exr_attr_chromaticities_t. */
412  EXR_ATTR_COMPRESSION, /**< ``uint8_t`` declaring compression present. */
413  EXR_ATTR_DOUBLE, /**< Double precision floating point number. */
414  EXR_ATTR_ENVMAP, /**< ``uint8_t`` declaring environment map type. */
415  EXR_ATTR_FLOAT, /**< Normal (4 byte) precision floating point number. */
416  EXR_ATTR_FLOAT_VECTOR, /**< List of normal (4 byte) precision floating point numbers. */
417  EXR_ATTR_INT, /**< 32-bit signed integer value. */
418  EXR_ATTR_KEYCODE, /**< Struct recording keycode @see exr_attr_keycode_t. */
419  EXR_ATTR_LINEORDER, /**< ``uint8_t`` declaring scanline ordering. */
420  EXR_ATTR_M33F, /**< 9 32-bit floats representing a 3x3 matrix. */
421  EXR_ATTR_M33D, /**< 9 64-bit floats representing a 3x3 matrix. */
422  EXR_ATTR_M44F, /**< 16 32-bit floats representing a 4x4 matrix. */
423  EXR_ATTR_M44D, /**< 16 64-bit floats representing a 4x4 matrix. */
424  EXR_ATTR_PREVIEW, /**< 2 ``unsigned ints`` followed by 4 x w x h ``uint8_t`` image. */
425  EXR_ATTR_RATIONAL, /**< \c int followed by ``unsigned int`` */
426  EXR_ATTR_STRING, /**< ``int`` (length) followed by char string data. */
427  EXR_ATTR_STRING_VECTOR, /**< 0 or more text strings (int + string). number is based on attribute size. */
428  EXR_ATTR_TILEDESC, /**< 2 ``unsigned ints`` ``xSize``, ``ySize`` followed by mode. */
429  EXR_ATTR_TIMECODE, /**< 2 ``unsigned ints`` time and flags, user data. */
430  EXR_ATTR_V2I, /**< Pair of 32-bit integers. */
431  EXR_ATTR_V2F, /**< Pair of 32-bit floats. */
432  EXR_ATTR_V2D, /**< Pair of 64-bit floats. */
433  EXR_ATTR_V3I, /**< Set of 3 32-bit integers. */
434  EXR_ATTR_V3F, /**< Set of 3 32-bit floats. */
435  EXR_ATTR_V3D, /**< Set of 3 64-bit floats. */
436  EXR_ATTR_DEEP_IMAGE_STATE, /**< ``uint8_t`` declaring deep image state. */
437  EXR_ATTR_OPAQUE, /**< User/unknown provided type. */
440 
441 /** @brief Storage, name and type information for an attribute.
442  *
443  * Attributes (metadata) for the file cause a surprising amount of
444  * overhead. It is not uncommon for a production-grade EXR to have
445  * many attributes. As such, the attribute struct is designed in a
446  * slightly more complicated manner. It is optimized to have the
447  * storage for that attribute: the struct itself, the name, the type,
448  * and the data all allocated as one block. Further, the type and
449  * standard names may use a static string to avoid allocating space
450  * for those as necessary with the pointers pointing to static strings
451  * (not to be freed). Finally, small values are optimized for.
452  */
453 typedef struct
454 {
455  /** Name of the attribute. */
456  const char* name;
457  /** String type name of the attribute. */
458  const char* type_name;
459  /** Length of name string (short flag is 31 max, long allows 255). */
460  uint8_t name_length;
461  /** Length of type string (short flag is 31 max, long allows 255). */
463 
464  uint8_t pad[2];
465 
466  /** Enum of the attribute type. */
468 
469  /** Union of pointers of different types that can be used to type
470  * pun to an appropriate type for builtins. Do note that while
471  * this looks like a big thing, it is only the size of a single
472  * pointer. These are all pointers into some other data block
473  * storing the value you want, with the exception of the pod types
474  * which are just put in place (i.e. small value optimization).
475  *
476  * The attribute type \c type should directly correlate to one
477  * of these entries.
478  */
479  union
480  {
481  // NB: not pointers for POD types
482  uint8_t uc;
483  double d;
484  float f;
485  int32_t i;
486 
511  uint8_t* rawptr;
512  };
514 
515 /** @} */
516 
517 #ifdef __cplusplus
518 } /* extern "C" */
519 #endif
520 
521 #endif /* OPENEXR_ATTR_H */
exr_attr_bytes_t * bytes
Definition: openexr_attr.h:489
exr_attr_timecode_t * timecode
Definition: openexr_attr.h:503
exr_attr_v2f_t max
Definition: openexr_attr.h:235
exr_attr_v2f_t * v2f
Definition: openexr_attr.h:505
Struct to hold a floating-point box/region definition.
Definition: openexr_attr.h:232
uint8_t name_length
Definition: openexr_attr.h:460
Struct to hold an integer box/region definition.
Definition: openexr_attr.h:225
const char * str
Definition: openexr_attr.h:272
Struct holding base tiledesc attribute type defined in spec.
Definition: openexr_attr.h:243
exr_attr_v3f_t * v3f
Definition: openexr_attr.h:508
exr_pixel_type_t pixel_type
Definition: openexr_attr.h:312
void
Definition: png.h:1083
GLboolean * data
Definition: glcorearb.h:131
Struct to define bytes attributes.
Definition: openexr_attr.h:341
exr_attr_v2f_t min
Definition: openexr_attr.h:234
Struct to hold an integer ratio value.
Definition: openexr_attr.h:175
uint32_t hint_length
Definition: openexr_attr.h:347
exr_attr_m33f_t * m33f
Definition: openexr_attr.h:494
exr_attr_float_vector_t * floatvector
Definition: openexr_attr.h:493
Struct to hold a 3-element integer vector.
Definition: openexr_attr.h:207
exr_perceptual_treatment_t
Definition: openexr_attr.h:301
Struct to hold a 3-element 32-bit float vector.
Definition: openexr_attr.h:213
GLint y
Definition: glcorearb.h:103
Struct to hold a 64-bit floating-point 4x4 matrix.
Definition: openexr_attr.h:169
exr_lineorder_t
Definition: openexr_attr.h:62
void pad(T &out, int n)
Definition: ImfXdr.h:407
const exr_attr_string_t * strings
Definition: openexr_attr.h:282
uint8_t p_linear
Definition: openexr_attr.h:314
uint8_t type_name_length
Definition: openexr_attr.h:462
const char * name
Definition: openexr_attr.h:456
exr_attr_v2i_t * v2i
Definition: openexr_attr.h:504
uint8_t * rawptr
Definition: openexr_attr.h:511
Struct to hold a 32-bit floating-point 4x4 matrix.
Definition: openexr_attr.h:163
const uint8_t * rgba
Definition: openexr_attr.h:337
exr_attr_v3i_t * v3i
Definition: openexr_attr.h:507
exr_attr_tiledesc_t * tiledesc
Definition: openexr_attr.h:502
exr_attr_preview_t * preview
Definition: openexr_attr.h:498
exr_attr_m44d_t * m44d
Definition: openexr_attr.h:497
int32_t exr_result_t
exr_deep_image_state_t
Definition: openexr_attr.h:108
exr_tile_level_mode_t
Enum representing what type of tile information is contained.
Definition: openexr_attr.h:82
struct _priv_exr_context_t * exr_context_t
struct to hold a 64-bit floating-point 3x3 matrix.
Definition: openexr_attr.h:157
exr_attr_v2i_t max
Definition: openexr_attr.h:228
exr_attr_keycode_t * keycode
Definition: openexr_attr.h:492
const exr_attr_chlist_entry_t * entries
Definition: openexr_attr.h:326
Struct to hold a 2-element 64-bit float vector.
Definition: openexr_attr.h:201
exr_attr_m33d_t * m33d
Definition: openexr_attr.h:495
GLint GLenum GLint x
Definition: glcorearb.h:409
exr_attr_string_vector_t * stringvector
Definition: openexr_attr.h:501
exr_attr_box2i_t * box2i
Definition: openexr_attr.h:487
exr_compression_t
Definition: openexr_attr.h:36
exr_attr_m44f_t * m44f
Definition: openexr_attr.h:496
exr_attr_chlist_t * chlist
Definition: openexr_attr.h:490
exr_attr_string_t * string
Definition: openexr_attr.h:500
Struct to define attributes of an embedded preview image.
Definition: openexr_attr.h:330
struct to hold a 32-bit floating-point 3x3 matrix.
Definition: openexr_attr.h:151
exr_tile_round_mode_t
Enum representing how to scale positions between levels.
Definition: openexr_attr.h:91
exr_attr_box2f_t * box2f
Definition: openexr_attr.h:488
exr_storage_t
Definition: openexr_attr.h:71
exr_attr_rational_t * rational
Definition: openexr_attr.h:499
exr_envmap_t
Definition: openexr_attr.h:54
exr_attr_v2d_t * v2d
Definition: openexr_attr.h:506
const char * type_hint
Definition: openexr_attr.h:348
Struct to hold timecode information.
Definition: openexr_attr.h:182
int32_t x_sampling
Definition: openexr_attr.h:316
Storage, name and type information for an attribute.
Definition: openexr_attr.h:453
Struct to hold a 2-element integer vector.
Definition: openexr_attr.h:189
Struct to hold a 2-element 32-bit float vector.
Definition: openexr_attr.h:195
int32_t y_sampling
Definition: openexr_attr.h:317
exr_attr_v2i_t min
Definition: openexr_attr.h:227
exr_attr_v3d_t * v3d
Definition: openexr_attr.h:509
exr_attr_chromaticities_t * chromaticities
Definition: openexr_attr.h:491
Struct to hold keycode information.
Definition: openexr_attr.h:139
Struct to hold color chromaticities to interpret the tristimulus color values in the image data...
Definition: openexr_attr.h:126
const char * type_name
Definition: openexr_attr.h:458
Definition: openexr_attr.h:308
exr_attribute_type_t type
Definition: openexr_attr.h:467
exr_attribute_type_t
Built-in/native attribute type enum.
Definition: openexr_attr.h:403
exr_attr_string_t name
Definition: openexr_attr.h:310
exr_pixel_type_t
Enum capturing the underlying data type on a channel.
Definition: openexr_attr.h:99
Struct to hold a 3-element 64-bit float vector.
Definition: openexr_attr.h:219
exr_attr_opaquedata_t * opaque
Definition: openexr_attr.h:510