openexr_chunkio.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ** SPDX-License-Identifier: BSD-3-Clause
  3. ** Copyright Contributors to the OpenEXR Project.
  4. */
  5. #ifndef OPENEXR_CORE_CHUNKIO_H
  6. #define OPENEXR_CORE_CHUNKIO_H
  7. #include "openexr_part.h"
  8. #include <stdint.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** @file */
  13. /**
  14. * Struct describing raw data information about a chunk.
  15. *
  16. * A chunk is the generic term for a pixel data block in an EXR file,
  17. * as described in the OpenEXR File Layout documentation. This is
  18. * common between all different forms of data that can be stored.
  19. */
  20. typedef struct
  21. {
  22. int32_t idx;
  23. /** For tiles, this is the tilex; for scans it is the x. */
  24. int32_t start_x;
  25. /** For tiles, this is the tiley; for scans it is the scanline y. */
  26. int32_t start_y;
  27. int32_t height; /**< For this chunk. */
  28. int32_t width; /**< For this chunk. */
  29. uint8_t level_x; /**< For tiled files. */
  30. uint8_t level_y; /**< For tiled files. */
  31. uint8_t type;
  32. uint8_t compression;
  33. uint64_t data_offset;
  34. uint64_t packed_size;
  35. uint64_t unpacked_size;
  36. uint64_t sample_count_data_offset;
  37. uint64_t sample_count_table_size;
  38. } exr_chunk_info_t;
  39. EXR_EXPORT
  40. exr_result_t exr_read_scanline_chunk_info (
  41. exr_const_context_t ctxt, int part_index, int y, exr_chunk_info_t* cinfo);
  42. EXR_EXPORT
  43. exr_result_t exr_read_tile_chunk_info (
  44. exr_const_context_t ctxt,
  45. int part_index,
  46. int tilex,
  47. int tiley,
  48. int levelx,
  49. int levely,
  50. exr_chunk_info_t* cinfo);
  51. /** Read the packed data block for a chunk.
  52. *
  53. * This assumes that the buffer pointed to by @p packed_data is
  54. * large enough to hold the chunk block info packed_size bytes.
  55. */
  56. EXR_EXPORT
  57. exr_result_t exr_read_chunk (
  58. exr_const_context_t ctxt,
  59. int part_index,
  60. const exr_chunk_info_t* cinfo,
  61. void* packed_data);
  62. /**
  63. * Read chunk for deep data.
  64. *
  65. * This allows one to read the packed data, the sample count data, or both.
  66. * \c exr_read_chunk also works to read deep data packed data,
  67. * but this is a routine to get the sample count table and the packed
  68. * data in one go, or if you want to pre-read the sample count data,
  69. * you can get just that buffer.
  70. */
  71. EXR_EXPORT
  72. exr_result_t exr_read_deep_chunk (
  73. exr_const_context_t ctxt,
  74. int part_index,
  75. const exr_chunk_info_t* cinfo,
  76. void* packed_data,
  77. void* sample_data);
  78. /**************************************/
  79. /** Initialize a \c exr_chunk_info_t structure when encoding scanline
  80. * data (similar to read but does not do anything with a chunk
  81. * table).
  82. */
  83. EXR_EXPORT
  84. exr_result_t exr_write_scanline_chunk_info (
  85. exr_context_t ctxt, int part_index, int y, exr_chunk_info_t* cinfo);
  86. /** Initialize a \c exr_chunk_info_t structure when encoding tiled data
  87. * (similar to read but does not do anything with a chunk table).
  88. */
  89. EXR_EXPORT
  90. exr_result_t exr_write_tile_chunk_info (
  91. exr_context_t ctxt,
  92. int part_index,
  93. int tilex,
  94. int tiley,
  95. int levelx,
  96. int levely,
  97. exr_chunk_info_t* cinfo);
  98. /**
  99. * @p y must the appropriate starting y for the specified chunk.
  100. */
  101. EXR_EXPORT
  102. exr_result_t exr_write_scanline_chunk (
  103. exr_context_t ctxt,
  104. int part_index,
  105. int y,
  106. const void* packed_data,
  107. uint64_t packed_size);
  108. /**
  109. * @p y must the appropriate starting y for the specified chunk.
  110. */
  111. EXR_EXPORT
  112. exr_result_t exr_write_deep_scanline_chunk (
  113. exr_context_t ctxt,
  114. int part_index,
  115. int y,
  116. const void* packed_data,
  117. uint64_t packed_size,
  118. uint64_t unpacked_size,
  119. const void* sample_data,
  120. uint64_t sample_data_size);
  121. EXR_EXPORT
  122. exr_result_t exr_write_tile_chunk (
  123. exr_context_t ctxt,
  124. int part_index,
  125. int tilex,
  126. int tiley,
  127. int levelx,
  128. int levely,
  129. const void* packed_data,
  130. uint64_t packed_size);
  131. EXR_EXPORT
  132. exr_result_t exr_write_deep_tile_chunk (
  133. exr_context_t ctxt,
  134. int part_index,
  135. int tilex,
  136. int tiley,
  137. int levelx,
  138. int levely,
  139. const void* packed_data,
  140. uint64_t packed_size,
  141. uint64_t unpacked_size,
  142. const void* sample_data,
  143. uint64_t sample_data_size);
  144. #ifdef __cplusplus
  145. } /* extern "C" */
  146. #endif
  147. #endif /* OPENEXR_CORE_CHUNKIO_H */