ImfCompressor.h 8.0 KB

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