/src/3rdparty/openexr-1.7.0/ImfCompressor.h

https://bitbucket.org/melbyruarus/pbrt · C Header · 252 lines · 49 code · 45 blank · 158 comment · 0 complexity · ffb469f4fb498a88e52d37977a6bb498 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_COMPRESSOR_H
  35. #define INCLUDED_IMF_COMPRESSOR_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // class Compressor
  39. //
  40. //-----------------------------------------------------------------------------
  41. #include <ImfCompression.h>
  42. #include "ImathBox.h"
  43. #include <stdlib.h>
  44. namespace Imf {
  45. class Header;
  46. class Compressor
  47. {
  48. public:
  49. //---------------------------------------------
  50. // Constructor -- hdr is the header of the file
  51. // that will be compressed or uncompressed
  52. //---------------------------------------------
  53. Compressor (const Header &hdr);
  54. //-----------
  55. // Destructor
  56. //-----------
  57. virtual ~Compressor ();
  58. //----------------------------------------------
  59. // Maximum number of scan lines processed by
  60. // a single call to compress() and uncompress().
  61. //----------------------------------------------
  62. virtual int numScanLines () const = 0;
  63. //--------------------------------------------
  64. // Format of the pixel data read and written
  65. // by the compress() and uncompress() methods.
  66. // The default implementation of format()
  67. // returns XDR.
  68. //--------------------------------------------
  69. enum Format
  70. {
  71. NATIVE, // the machine's native format
  72. XDR // Xdr format
  73. };
  74. virtual Format format () const;
  75. //----------------------------
  76. // Access to the file's header
  77. //----------------------------
  78. const Header & header () const {return _header;}
  79. //-------------------------------------------------------------------------
  80. // Compress an array of bytes that represents the contents of up to
  81. // numScanLines() scan lines:
  82. //
  83. // inPtr Input buffer (uncompressed data).
  84. //
  85. // inSize Number of bytes in the input buffer
  86. //
  87. // minY Minimum y coordinate of the scan lines to
  88. // be compressed
  89. //
  90. // outPtr Pointer to output buffer
  91. //
  92. // return value Size of compressed data in output buffer
  93. //
  94. // Arrangement of uncompressed pixel data in the input buffer:
  95. //
  96. // Before calling
  97. //
  98. // compress (buf, size, minY, ...);
  99. //
  100. // the InputFile::writePixels() method gathers pixel data from the
  101. // frame buffer, fb, and places them in buffer buf, like this:
  102. //
  103. // char *endOfBuf = buf;
  104. //
  105. // for (int y = minY;
  106. // y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);
  107. // ++y)
  108. // {
  109. // for (ChannelList::ConstIterator c = header().channels().begin();
  110. // c != header().channels().end();
  111. // ++c)
  112. // {
  113. // if (modp (y, c.channel().ySampling) != 0)
  114. // continue;
  115. //
  116. // for (int x = header().dataWindow().min.x;
  117. // x <= header().dataWindow().max.x;
  118. // ++x)
  119. // {
  120. // if (modp (x, c.channel().xSampling) != 0)
  121. // continue;
  122. //
  123. // Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));
  124. // }
  125. // }
  126. // }
  127. //
  128. // int size = endOfBuf - buf;
  129. //
  130. //-------------------------------------------------------------------------
  131. virtual int compress (const char *inPtr,
  132. int inSize,
  133. int minY,
  134. const char *&outPtr) = 0;
  135. virtual int compressTile (const char *inPtr,
  136. int inSize,
  137. Imath::Box2i range,
  138. const char *&outPtr);
  139. //-------------------------------------------------------------------------
  140. // Uncompress an array of bytes that has been compressed by compress():
  141. //
  142. // inPtr Input buffer (compressed data).
  143. //
  144. // inSize Number of bytes in the input buffer
  145. //
  146. // minY Minimum y coordinate of the scan lines to
  147. // be uncompressed
  148. //
  149. // outPtr Pointer to output buffer
  150. //
  151. // return value Size of uncompressed data in output buffer
  152. //
  153. //-------------------------------------------------------------------------
  154. virtual int uncompress (const char *inPtr,
  155. int inSize,
  156. int minY,
  157. const char *&outPtr) = 0;
  158. virtual int uncompressTile (const char *inPtr,
  159. int inSize,
  160. Imath::Box2i range,
  161. const char *&outPtr);
  162. private:
  163. const Header & _header;
  164. };
  165. //--------------------------------------
  166. // Test if c is a valid compression type
  167. //--------------------------------------
  168. bool isValidCompression (Compression c);
  169. //-----------------------------------------------------------------
  170. // Construct a Compressor for compression type c:
  171. //
  172. // maxScanLineSize Maximum number of bytes per uncompressed
  173. // scan line.
  174. //
  175. // header Header of the input or output file whose
  176. // pixels will be compressed or uncompressed.
  177. //
  178. // return value A pointer to a new Compressor object (it
  179. // is the caller's responsibility to delete
  180. // the object), or 0 (if c is NO_COMPRESSION).
  181. //
  182. //-----------------------------------------------------------------
  183. Compressor * newCompressor (Compression c,
  184. size_t maxScanLineSize,
  185. const Header &hdr);
  186. //-----------------------------------------------------------------
  187. // Construct a Compressor for compression type c for a tiled image:
  188. //
  189. // tileLineSize Maximum number of bytes per uncompressed
  190. // line in a tile.
  191. //
  192. // numTileLines Maximum number of lines in a tile.
  193. //
  194. // header Header of the input or output file whose
  195. // pixels will be compressed or uncompressed.
  196. //
  197. // return value A pointer to a new Compressor object (it
  198. // is the caller's responsibility to delete
  199. // the object), or 0 (if c is NO_COMPRESSION).
  200. //
  201. //-----------------------------------------------------------------
  202. Compressor * newTileCompressor (Compression c,
  203. size_t tileLineSize,
  204. size_t numTileLines,
  205. const Header &hdr);
  206. } // namespace Imf
  207. #endif