/src/FreeImage/Source/OpenEXR/IlmImf/ImfCompressor.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 192 lines · 99 code · 55 blank · 38 comment · 3 complexity · 5dc2255bdd2a59f020d7df3f1f98f3d8 MD5 · raw file

  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 <ImfCheckedArithmetic.h>
  46. namespace Imf {
  47. using Imath::Box2i;
  48. Compressor::Compressor (const Header &hdr): _header (hdr) {}
  49. Compressor::~Compressor () {}
  50. Compressor::Format
  51. Compressor::format () const
  52. {
  53. return XDR;
  54. }
  55. int
  56. Compressor::compressTile (const char *inPtr,
  57. int inSize,
  58. Box2i range,
  59. const char *&outPtr)
  60. {
  61. return compress (inPtr, inSize, range.min.y, outPtr);
  62. }
  63. int
  64. Compressor::uncompressTile (const char *inPtr,
  65. int inSize,
  66. Box2i range,
  67. const char *&outPtr)
  68. {
  69. return uncompress (inPtr, inSize, range.min.y, outPtr);
  70. }
  71. bool
  72. isValidCompression (Compression c)
  73. {
  74. switch (c)
  75. {
  76. case NO_COMPRESSION:
  77. case RLE_COMPRESSION:
  78. case ZIPS_COMPRESSION:
  79. case ZIP_COMPRESSION:
  80. case PIZ_COMPRESSION:
  81. case PXR24_COMPRESSION:
  82. case B44_COMPRESSION:
  83. case B44A_COMPRESSION:
  84. return true;
  85. default:
  86. return false;
  87. }
  88. }
  89. Compressor *
  90. newCompressor (Compression c, size_t maxScanLineSize, const Header &hdr)
  91. {
  92. switch (c)
  93. {
  94. case RLE_COMPRESSION:
  95. return new RleCompressor (hdr, maxScanLineSize);
  96. case ZIPS_COMPRESSION:
  97. return new ZipCompressor (hdr, maxScanLineSize, 1);
  98. case ZIP_COMPRESSION:
  99. return new ZipCompressor (hdr, maxScanLineSize, 16);
  100. case PIZ_COMPRESSION:
  101. return new PizCompressor (hdr, maxScanLineSize, 32);
  102. case PXR24_COMPRESSION:
  103. return new Pxr24Compressor (hdr, maxScanLineSize, 16);
  104. case B44_COMPRESSION:
  105. return new B44Compressor (hdr, maxScanLineSize, 32, false);
  106. case B44A_COMPRESSION:
  107. return new B44Compressor (hdr, maxScanLineSize, 32, true);
  108. default:
  109. return 0;
  110. }
  111. }
  112. Compressor *
  113. newTileCompressor (Compression c,
  114. size_t tileLineSize,
  115. size_t numTileLines,
  116. const Header &hdr)
  117. {
  118. switch (c)
  119. {
  120. case RLE_COMPRESSION:
  121. return new RleCompressor (hdr, uiMult (tileLineSize, numTileLines));
  122. case ZIPS_COMPRESSION:
  123. case ZIP_COMPRESSION:
  124. return new ZipCompressor (hdr, tileLineSize, numTileLines);
  125. case PIZ_COMPRESSION:
  126. return new PizCompressor (hdr, tileLineSize, numTileLines);
  127. case PXR24_COMPRESSION:
  128. return new Pxr24Compressor (hdr, tileLineSize, numTileLines);
  129. case B44_COMPRESSION:
  130. return new B44Compressor (hdr, tileLineSize, numTileLines, false);
  131. case B44A_COMPRESSION:
  132. return new B44Compressor (hdr, tileLineSize, numTileLines, true);
  133. default:
  134. return 0;
  135. }
  136. }
  137. } // namespace Imf