ImfCompressor.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2004, 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. //-----------------------------------------------------------------------------
  35. //
  36. // class Compressor
  37. //
  38. //-----------------------------------------------------------------------------
  39. #include "ImfCompressor.h"
  40. #include "ImfRleCompressor.h"
  41. #include "ImfZipCompressor.h"
  42. #include "ImfPizCompressor.h"
  43. #include "ImfPxr24Compressor.h"
  44. #include "ImfB44Compressor.h"
  45. #include "ImfDwaCompressor.h"
  46. #include "ImfCheckedArithmetic.h"
  47. #include "ImfNamespace.h"
  48. OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
  49. using IMATH_NAMESPACE::Box2i;
  50. Compressor::Compressor (const Header &hdr): _header (hdr) {}
  51. Compressor::~Compressor () {}
  52. Compressor::Format
  53. Compressor::format () const
  54. {
  55. return XDR;
  56. }
  57. int
  58. Compressor::compressTile (const char *inPtr,
  59. int inSize,
  60. Box2i range,
  61. const char *&outPtr)
  62. {
  63. return compress (inPtr, inSize, range.min.y, outPtr);
  64. }
  65. int
  66. Compressor::uncompressTile (const char *inPtr,
  67. int inSize,
  68. Box2i range,
  69. const char *&outPtr)
  70. {
  71. return uncompress (inPtr, inSize, range.min.y, outPtr);
  72. }
  73. bool
  74. isValidCompression (Compression c)
  75. {
  76. switch (c)
  77. {
  78. case NO_COMPRESSION:
  79. case RLE_COMPRESSION:
  80. case ZIPS_COMPRESSION:
  81. case ZIP_COMPRESSION:
  82. case PIZ_COMPRESSION:
  83. case PXR24_COMPRESSION:
  84. case B44_COMPRESSION:
  85. case B44A_COMPRESSION:
  86. case DWAA_COMPRESSION:
  87. case DWAB_COMPRESSION:
  88. return true;
  89. default:
  90. return false;
  91. }
  92. }
  93. bool isValidDeepCompression(Compression c)
  94. {
  95. switch(c)
  96. {
  97. case NO_COMPRESSION:
  98. case RLE_COMPRESSION:
  99. case ZIPS_COMPRESSION:
  100. return true;
  101. default :
  102. return false;
  103. }
  104. }
  105. Compressor *
  106. newCompressor (Compression c, size_t maxScanLineSize, const Header &hdr)
  107. {
  108. switch (c)
  109. {
  110. case RLE_COMPRESSION:
  111. return new RleCompressor (hdr, maxScanLineSize);
  112. case ZIPS_COMPRESSION:
  113. return new ZipCompressor (hdr, maxScanLineSize, 1);
  114. case ZIP_COMPRESSION:
  115. return new ZipCompressor (hdr, maxScanLineSize, 16);
  116. case PIZ_COMPRESSION:
  117. return new PizCompressor (hdr, maxScanLineSize, 32);
  118. case PXR24_COMPRESSION:
  119. return new Pxr24Compressor (hdr, maxScanLineSize, 16);
  120. case B44_COMPRESSION:
  121. return new B44Compressor (hdr, maxScanLineSize, 32, false);
  122. case B44A_COMPRESSION:
  123. return new B44Compressor (hdr, maxScanLineSize, 32, true);
  124. case DWAA_COMPRESSION:
  125. return new DwaCompressor (hdr, maxScanLineSize, 32,
  126. DwaCompressor::STATIC_HUFFMAN);
  127. case DWAB_COMPRESSION:
  128. return new DwaCompressor (hdr, maxScanLineSize, 256,
  129. DwaCompressor::STATIC_HUFFMAN);
  130. default:
  131. return 0;
  132. }
  133. }
  134. Compressor *
  135. newTileCompressor (Compression c,
  136. size_t tileLineSize,
  137. size_t numTileLines,
  138. const Header &hdr)
  139. {
  140. switch (c)
  141. {
  142. case RLE_COMPRESSION:
  143. return new RleCompressor (hdr, uiMult (tileLineSize, numTileLines));
  144. case ZIPS_COMPRESSION:
  145. case ZIP_COMPRESSION:
  146. return new ZipCompressor (hdr, tileLineSize, numTileLines);
  147. case PIZ_COMPRESSION:
  148. return new PizCompressor (hdr, tileLineSize, numTileLines);
  149. case PXR24_COMPRESSION:
  150. return new Pxr24Compressor (hdr, tileLineSize, numTileLines);
  151. case B44_COMPRESSION:
  152. return new B44Compressor (hdr, tileLineSize, numTileLines, false);
  153. case B44A_COMPRESSION:
  154. return new B44Compressor (hdr, tileLineSize, numTileLines, true);
  155. case DWAA_COMPRESSION:
  156. case DWAB_COMPRESSION:
  157. return new DwaCompressor (hdr, tileLineSize, numTileLines,
  158. DwaCompressor::DEFLATE);
  159. default:
  160. return 0;
  161. }
  162. }
  163. OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT