/src/FreeImage/Source/OpenEXR/IlmImf/ImfMisc.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 255 lines · 46 code · 38 blank · 171 comment · 0 complexity · 17a154409fecfc2d536af28973cc9f12 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. #ifndef INCLUDED_IMF_MISC_H
  35. #define INCLUDED_IMF_MISC_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // Miscellaneous helper functions for OpenEXR image file I/O
  39. //
  40. //-----------------------------------------------------------------------------
  41. #include <ImfPixelType.h>
  42. #include <vector>
  43. #include <ImfCompressor.h>
  44. namespace Imf {
  45. class Header;
  46. //
  47. // Return the size of a single value of the indicated type,
  48. // in the machine's native format.
  49. //
  50. int pixelTypeSize (PixelType type);
  51. //
  52. // Return the number of samples a channel with subsampling rate
  53. // s has in the interval [a, b]. For example, a channel with
  54. // subsampling rate 2 (and samples at 0, 2, 4, 6, 8, etc.) has
  55. // 2 samples in the interval [1, 5] and three samples in the
  56. // interval [2, 6].
  57. //
  58. int numSamples (int s, int a, int b);
  59. //
  60. // Build a table that lists, for each scanline in a file's
  61. // data window, how many bytes are required to store all
  62. // pixels in all channels in that scanline (assuming that
  63. // the pixel data are tightly packed).
  64. //
  65. size_t bytesPerLineTable (const Header &header,
  66. std::vector<size_t> &bytesPerLine);
  67. //
  68. // For scanline-based files, pixels are read or written in
  69. // in multi-scanline blocks. Internally, class OutputFile
  70. // and class ScanLineInputFile store a block of scan lines
  71. // in a "line buffer". Function offsetInLineBufferTable()
  72. // builds a table that lists, for each scan line in a file's
  73. // data window, the location of the pixel data for the scanline
  74. // relative to the beginning of the line buffer.
  75. //
  76. void offsetInLineBufferTable (const std::vector<size_t> &bytesPerLine,
  77. int linesInLineBuffer,
  78. std::vector<size_t> &offsetInLineBuffer);
  79. //
  80. // For a scanline-based file, compute the range of scanlines
  81. // that occupy the same line buffer as a given scanline, y.
  82. // (minY is the minimum y coordinate of the file's data window.)
  83. //
  84. int lineBufferMinY (int y, int minY, int linesInLineBuffer);
  85. int lineBufferMaxY (int y, int minY, int linesInLineBuffer);
  86. //
  87. // Return a compressor's data format (Compressor::NATIVE or Compressor::XDR).
  88. // If compressor is 0, return Compressor::XDR.
  89. //
  90. Compressor::Format defaultFormat (Compressor *compressor);
  91. //
  92. // Return the number of scan lines a compressor wants to compress
  93. // or uncompress at once. If compressor is 0, return 1.
  94. //
  95. int numLinesInBuffer (Compressor *compressor);
  96. //
  97. // Copy a single channel of a horizontal row of pixels from an
  98. // input file's internal line buffer or tile buffer into a
  99. // frame buffer slice. If necessary, perform on-the-fly data
  100. // type conversion.
  101. //
  102. // readPtr initially points to the beginning of the
  103. // data in the line or tile buffer. readPtr
  104. // is advanced as the pixel data are copied;
  105. // when copyIntoFrameBuffer() returns,
  106. // readPtr points just past the end of the
  107. // copied data.
  108. //
  109. // writePtr, endPtr point to the lefmost and rightmost pixels
  110. // in the frame buffer slice
  111. //
  112. // xStride the xStride for the frame buffer slice
  113. //
  114. // format indicates if the line or tile buffer is
  115. // in NATIVE or XDR format.
  116. //
  117. // typeInFrameBuffer the pixel data type of the frame buffer slice
  118. //
  119. // typeInFile the pixel data type in the input file's channel
  120. //
  121. void copyIntoFrameBuffer (const char *&readPtr,
  122. char *writePtr,
  123. char *endPtr,
  124. size_t xStride,
  125. bool fill,
  126. double fillValue,
  127. Compressor::Format format,
  128. PixelType typeInFrameBuffer,
  129. PixelType typeInFile);
  130. //
  131. // Given a pointer into a an input file's line buffer or tile buffer,
  132. // skip over the data for xSize pixels of type typeInFile.
  133. // readPtr initially points to the beginning of the data to be skipped;
  134. // when skipChannel() returns, readPtr points just past the end of the
  135. // skipped data.
  136. //
  137. void skipChannel (const char *&readPtr,
  138. PixelType typeInFile,
  139. size_t xSize);
  140. //
  141. // Convert an array of pixel data from the machine's native
  142. // representation to XDR format.
  143. //
  144. // toPtr, fromPtr initially point to the beginning of the input
  145. // and output pixel data arrays; when convertInPlace()
  146. // returns, toPtr and fromPtr point just past the
  147. // end of the input and output arrays.
  148. // If the native representation of the data has the
  149. // same size as the XDR data, then the conversion
  150. // can take in place, without an intermediate
  151. // temporary buffer (toPtr and fromPtr can point
  152. // to the same location).
  153. //
  154. // type the pixel data type
  155. //
  156. // numPixels number of pixels in the input and output arrays
  157. //
  158. void convertInPlace (char *&toPtr,
  159. const char *&fromPtr,
  160. PixelType type,
  161. size_t numPixels);
  162. //
  163. // Copy a single channel of a horizontal row of pixels from a
  164. // a frame buffer into an output file's internal line buffer or
  165. // tile buffer.
  166. //
  167. // writePtr initially points to the beginning of the
  168. // data in the line or tile buffer. writePtr
  169. // is advanced as the pixel data are copied;
  170. // when copyFromFrameBuffer() returns,
  171. // writePtr points just past the end of the
  172. // copied data.
  173. //
  174. // readPtr, endPtr point to the lefmost and rightmost pixels
  175. // in the frame buffer slice
  176. //
  177. // xStride the xStride for the frame buffer slice
  178. //
  179. // format indicates if the line or tile buffer is
  180. // in NATIVE or XDR format.
  181. //
  182. // type the pixel data type in the frame buffer
  183. // and in the output file's channel (function
  184. // copyFromFrameBuffer() doesn't do on-the-fly
  185. // data type conversion)
  186. //
  187. void copyFromFrameBuffer (char *&writePtr,
  188. const char *&readPtr,
  189. const char *endPtr,
  190. size_t xStride,
  191. Compressor::Format format,
  192. PixelType type);
  193. //
  194. // Fill part of an output file's line buffer or tile buffer with
  195. // zeroes. This routine is called when an output file contains
  196. // a channel for which the frame buffer contains no corresponding
  197. // slice.
  198. //
  199. // writePtr initially points to the beginning of the
  200. // data in the line or tile buffer. When
  201. // fillChannelWithZeroes() returns, writePtr
  202. // points just past the end of the zeroed
  203. // data.
  204. //
  205. // format indicates if the line or tile buffer is
  206. // in NATIVE or XDR format.
  207. //
  208. // type the pixel data type in the line or frame buffer.
  209. //
  210. // xSize number of pixels to be filled with zeroes.
  211. //
  212. void fillChannelWithZeroes (char *&writePtr,
  213. Compressor::Format format,
  214. PixelType type,
  215. size_t xSize);
  216. } // namespace Imf
  217. #endif