Path: blob/master/3rdparty/openexr/IlmImf/ImfCompressor.cpp
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////33343536//-----------------------------------------------------------------------------37//38// class Compressor39//40//-----------------------------------------------------------------------------4142#include <ImfCompressor.h>43#include <ImfRleCompressor.h>44#include <ImfZipCompressor.h>45#include <ImfPizCompressor.h>46#include <ImfPxr24Compressor.h>47#include <ImfB44Compressor.h>48#include <ImfCheckedArithmetic.h>4950namespace Imf {5152using Imath::Box2i;535455Compressor::Compressor (const Header &hdr): _header (hdr) {}565758Compressor::~Compressor () {}596061Compressor::Format62Compressor::format () const63{64return XDR;65}666768int69Compressor::compressTile (const char *inPtr,70int inSize,71Box2i range,72const char *&outPtr)73{74return compress (inPtr, inSize, range.min.y, outPtr);75}767778int79Compressor::uncompressTile (const char *inPtr,80int inSize,81Box2i range,82const char *&outPtr)83{84return uncompress (inPtr, inSize, range.min.y, outPtr);85}868788bool89isValidCompression (Compression c)90{91switch (c)92{93case NO_COMPRESSION:94case RLE_COMPRESSION:95case ZIPS_COMPRESSION:96case ZIP_COMPRESSION:97case PIZ_COMPRESSION:98case PXR24_COMPRESSION:99case B44_COMPRESSION:100case B44A_COMPRESSION:101102return true;103104default:105106return false;107}108}109110111Compressor *112newCompressor (Compression c, size_t maxScanLineSize, const Header &hdr)113{114switch (c)115{116case RLE_COMPRESSION:117118return new RleCompressor (hdr, maxScanLineSize);119120case ZIPS_COMPRESSION:121122return new ZipCompressor (hdr, maxScanLineSize, 1);123124case ZIP_COMPRESSION:125126return new ZipCompressor (hdr, maxScanLineSize, 16);127128case PIZ_COMPRESSION:129130return new PizCompressor (hdr, maxScanLineSize, 32);131132case PXR24_COMPRESSION:133134return new Pxr24Compressor (hdr, maxScanLineSize, 16);135136case B44_COMPRESSION:137138return new B44Compressor (hdr, maxScanLineSize, 32, false);139140case B44A_COMPRESSION:141142return new B44Compressor (hdr, maxScanLineSize, 32, true);143144default:145146return 0;147}148}149150151Compressor *152newTileCompressor (Compression c,153size_t tileLineSize,154size_t numTileLines,155const Header &hdr)156{157switch (c)158{159case RLE_COMPRESSION:160161return new RleCompressor (hdr, uiMult (tileLineSize, numTileLines));162163case ZIPS_COMPRESSION:164case ZIP_COMPRESSION:165166return new ZipCompressor (hdr, tileLineSize, numTileLines);167168case PIZ_COMPRESSION:169170return new PizCompressor (hdr, tileLineSize, numTileLines);171172case PXR24_COMPRESSION:173174return new Pxr24Compressor (hdr, tileLineSize, numTileLines);175176case B44_COMPRESSION:177178return new B44Compressor (hdr, tileLineSize, numTileLines, false);179180case B44A_COMPRESSION:181182return new B44Compressor (hdr, tileLineSize, numTileLines, true);183184default:185186return 0;187}188}189190191} // namespace Imf192193194