ImfDwaCompressor.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2009-2014 DreamWorks Animation LLC.
  4. //
  5. // All rights reserved.
  6. //
  7. // Redistribution and use in source and binary forms, with or without
  8. // modification, are permitted provided that the following conditions are
  9. // met:
  10. // * Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. // * Redistributions in binary form must reproduce the above
  13. // copyright notice, this list of conditions and the following disclaimer
  14. // in the documentation and/or other materials provided with the
  15. // distribution.
  16. // * Neither the name of DreamWorks Animation nor the names of
  17. // its contributors may be used to endorse or promote products derived
  18. // from this software without specific prior written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. //
  32. ///////////////////////////////////////////////////////////////////////////
  33. #ifndef INCLUDED_IMF_DWA_COMRESSOR_H
  34. #define INCLUDED_IMF_DWA_COMRESSOR_H
  35. //------------------------------------------------------------------------------
  36. //
  37. // class DwaCompressor -- Store lossy RGB data by quantizing DCT components.
  38. //
  39. //------------------------------------------------------------------------------
  40. #include <vector>
  41. #include <half.h>
  42. #include "ImfInt64.h"
  43. #include "ImfZip.h"
  44. #include "ImfChannelList.h"
  45. #include "ImfCompressor.h"
  46. #include "ImfNamespace.h"
  47. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  48. class DwaCompressor: public Compressor
  49. {
  50. public:
  51. enum AcCompression
  52. {
  53. STATIC_HUFFMAN,
  54. DEFLATE,
  55. };
  56. IMF_EXPORT
  57. DwaCompressor (const Header &hdr,
  58. int maxScanLineSize,
  59. int numScanLines, // ideally is a multiple of 8
  60. AcCompression acCompression);
  61. IMF_EXPORT
  62. virtual ~DwaCompressor ();
  63. IMF_EXPORT
  64. virtual int numScanLines () const;
  65. IMF_EXPORT
  66. virtual OPENEXR_IMF_NAMESPACE::Compressor::Format format () const;
  67. IMF_EXPORT
  68. virtual int compress (const char *inPtr,
  69. int inSize,
  70. int minY,
  71. const char *&outPtr);
  72. IMF_EXPORT
  73. virtual int compressTile (const char *inPtr,
  74. int inSize,
  75. IMATH_NAMESPACE::Box2i range,
  76. const char *&outPtr);
  77. IMF_EXPORT
  78. virtual int uncompress (const char *inPtr,
  79. int inSize,
  80. int minY,
  81. const char *&outPtr);
  82. IMF_EXPORT
  83. virtual int uncompressTile (const char *inPtr,
  84. int inSize,
  85. IMATH_NAMESPACE::Box2i range,
  86. const char *&outPtr);
  87. IMF_EXPORT
  88. static void initializeFuncs ();
  89. private:
  90. struct ChannelData;
  91. struct CscChannelSet;
  92. struct Classifier;
  93. class LossyDctDecoderBase;
  94. class LossyDctDecoder;
  95. class LossyDctDecoderCsc;
  96. class LossyDctEncoderBase;
  97. class LossyDctEncoder;
  98. class LossyDctEncoderCsc;
  99. enum CompressorScheme
  100. {
  101. UNKNOWN = 0,
  102. LOSSY_DCT,
  103. RLE,
  104. NUM_COMPRESSOR_SCHEMES
  105. };
  106. //
  107. // Per-chunk compressed data sizes, one value per chunk
  108. //
  109. enum DataSizesSingle
  110. {
  111. VERSION = 0, // Version number:
  112. // 0: classic
  113. // 1: adds "end of block" to the AC RLE
  114. UNKNOWN_UNCOMPRESSED_SIZE, // Size of leftover data, uncompressed.
  115. UNKNOWN_COMPRESSED_SIZE, // Size of leftover data, zlib compressed.
  116. AC_COMPRESSED_SIZE, // AC RLE + Huffman size
  117. DC_COMPRESSED_SIZE, // DC + Deflate size
  118. RLE_COMPRESSED_SIZE, // RLE + Deflate data size
  119. RLE_UNCOMPRESSED_SIZE, // RLE'd data size
  120. RLE_RAW_SIZE, // Un-RLE'd data size
  121. AC_UNCOMPRESSED_COUNT, // AC RLE number of elements
  122. DC_UNCOMPRESSED_COUNT, // DC number of elements
  123. AC_COMPRESSION, // AC compression strategy
  124. NUM_SIZES_SINGLE
  125. };
  126. AcCompression _acCompression;
  127. int _maxScanLineSize;
  128. int _numScanLines;
  129. int _min[2], _max[2];
  130. ChannelList _channels;
  131. std::vector<ChannelData> _channelData;
  132. std::vector<CscChannelSet> _cscSets;
  133. std::vector<Classifier> _channelRules;
  134. char *_packedAcBuffer;
  135. size_t _packedAcBufferSize;
  136. char *_packedDcBuffer;
  137. size_t _packedDcBufferSize;
  138. char *_rleBuffer;
  139. size_t _rleBufferSize;
  140. char *_outBuffer;
  141. size_t _outBufferSize;
  142. char *_planarUncBuffer[NUM_COMPRESSOR_SCHEMES];
  143. size_t _planarUncBufferSize[NUM_COMPRESSOR_SCHEMES];
  144. Zip *_zip;
  145. float _dwaCompressionLevel;
  146. int compress (const char *inPtr,
  147. int inSize,
  148. IMATH_NAMESPACE::Box2i range,
  149. const char *&outPtr);
  150. int uncompress (const char *inPtr,
  151. int inSize,
  152. IMATH_NAMESPACE::Box2i range,
  153. const char *&outPtr);
  154. void initializeBuffers (size_t&);
  155. void initializeDefaultChannelRules ();
  156. void initializeLegacyChannelRules ();
  157. void relevantChannelRules( std::vector<Classifier> &) const;
  158. //
  159. // Populate our cached version of the channel data with
  160. // data from the real channel list. We want to
  161. // copy over attributes, determine compression schemes
  162. // releveant for the channel type, and find sets of
  163. // channels to be compressed from Y'CbCr data instead
  164. // of R'G'B'.
  165. //
  166. void classifyChannels (ChannelList channels,
  167. std::vector<ChannelData> &chanData,
  168. std::vector<CscChannelSet> &cscData);
  169. //
  170. // Compute various buffer pointers for each channel
  171. //
  172. void setupChannelData (int minX, int minY, int maxX, int maxY);
  173. };
  174. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  175. #endif