openexr_coding.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. ** SPDX-License-Identifier: BSD-3-Clause
  3. ** Copyright Contributors to the OpenEXR Project.
  4. */
  5. #ifndef OPENEXR_CORE_CODING_H
  6. #define OPENEXR_CORE_CODING_H
  7. #include <stdint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /** @file */
  12. /**
  13. * Enum for use in a custom allocator in the encode/decode pipelines
  14. * (that is, so the implementor knows whether to allocate on which
  15. * device based on the buffer disposition).
  16. */
  17. typedef enum exr_transcoding_pipeline_buffer_id
  18. {
  19. EXR_TRANSCODE_BUFFER_PACKED,
  20. EXR_TRANSCODE_BUFFER_UNPACKED,
  21. EXR_TRANSCODE_BUFFER_COMPRESSED,
  22. EXR_TRANSCODE_BUFFER_SCRATCH1,
  23. EXR_TRANSCODE_BUFFER_SCRATCH2,
  24. EXR_TRANSCODE_BUFFER_PACKED_SAMPLES,
  25. EXR_TRANSCODE_BUFFER_SAMPLES
  26. } exr_transcoding_pipeline_buffer_id_t;
  27. /** @brief Struct for negotiating buffers when decoding/encoding
  28. * chunks of data.
  29. *
  30. * This is generic and meant to negotiate exr data bi-directionally,
  31. * in that the same structure is used for both decoding and encoding
  32. * chunks for read and write, respectively.
  33. *
  34. * The first half of the structure will be filled by the library, and
  35. * the caller is expected to fill the second half appropriately.
  36. */
  37. typedef struct
  38. {
  39. /**************************************************
  40. * Elements below are populated by the library when
  41. * decoding is initialized/updated and must be left
  42. * untouched when using the default decoder routines.
  43. **************************************************/
  44. /** Channel name.
  45. *
  46. * This is provided as a convenient reference. Do not free, this
  47. * refers to the internal data structure in the context.
  48. */
  49. const char* channel_name;
  50. /** Number of lines for this channel in this chunk.
  51. *
  52. * May be 0 or less than overall image height based on sampling
  53. * (i.e. when in 4:2:0 type sampling)
  54. */
  55. int32_t height;
  56. /** Width in pixel count.
  57. *
  58. * May be 0 or less than overall image width based on sampling
  59. * (i.e. 4:2:2 will have some channels have fewer values).
  60. */
  61. int32_t width;
  62. /** Horizontal subsampling information. */
  63. int32_t x_samples;
  64. /** Vertical subsampling information. */
  65. int32_t y_samples;
  66. /** Linear flag from channel definition (used by b44). */
  67. uint8_t p_linear;
  68. /** How many bytes per pixel this channel consumes (2 for float16,
  69. * 4 for float32/uint32).
  70. */
  71. int8_t bytes_per_element;
  72. /** Small form of exr_pixel_type_t enum (EXR_PIXEL_UINT/HALF/FLOAT). */
  73. uint16_t data_type;
  74. /**************************************************
  75. * Elements below must be edited by the caller
  76. * to control encoding/decoding.
  77. **************************************************/
  78. /** How many bytes per pixel the input is or output should be
  79. * (2 for float16, 4 for float32/uint32). Defaults to same
  80. * size as input.
  81. */
  82. int16_t user_bytes_per_element;
  83. /** Small form of exr_pixel_type_t enum
  84. * (EXR_PIXEL_UINT/HALF/FLOAT). Defaults to same type as input.
  85. */
  86. uint16_t user_data_type;
  87. /** Increment to get to next pixel.
  88. *
  89. * This is in bytes. Must be specified when the decode pointer is
  90. * specified (and always for encode).
  91. *
  92. * This is useful for implementing transcoding generically of
  93. * planar or interleaved data. For planar data, where the layout
  94. * is RRRRRGGGGGBBBBB, you can pass in 1 * bytes per component.
  95. */
  96. int32_t user_pixel_stride;
  97. /** When \c lines > 1 for a chunk, this is the increment used to get
  98. * from beginning of line to beginning of next line.
  99. *
  100. * This is in bytes. Must be specified when the decode pointer is
  101. * specified (and always for encode).
  102. */
  103. int32_t user_line_stride;
  104. /** This data member has different requirements reading vs
  105. * writing. When reading, if this is left as `NULL`, the channel
  106. * will be skipped during read and not filled in. During a write
  107. * operation, this pointer is considered const and not
  108. * modified. To make this more clear, a union is used here.
  109. */
  110. union
  111. {
  112. uint8_t* decode_to_ptr;
  113. const uint8_t* encode_from_ptr;
  114. };
  115. } exr_coding_channel_info_t;
  116. #ifdef __cplusplus
  117. } /* extern "C" */
  118. #endif
  119. #endif /* OPENEXR_CORE_CODING_H */