Path: blob/master/3rdparty/openexr/IlmImf/ImfCompressor.h
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2002, 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#ifndef INCLUDED_IMF_COMPRESSOR_H37#define INCLUDED_IMF_COMPRESSOR_H3839//-----------------------------------------------------------------------------40//41// class Compressor42//43//-----------------------------------------------------------------------------4445#include <ImfCompression.h>46#include "ImathBox.h"47#include <stdlib.h>4849namespace Imf {5051class Header;525354class Compressor55{56public:5758//---------------------------------------------59// Constructor -- hdr is the header of the file60// that will be compressed or uncompressed61//---------------------------------------------6263Compressor (const Header &hdr);646566//-----------67// Destructor68//-----------6970virtual ~Compressor ();717273//----------------------------------------------74// Maximum number of scan lines processed by75// a single call to compress() and uncompress().76//----------------------------------------------7778virtual int numScanLines () const = 0;798081//--------------------------------------------82// Format of the pixel data read and written83// by the compress() and uncompress() methods.84// The default implementation of format()85// returns XDR.86//--------------------------------------------8788enum Format89{90NATIVE, // the machine's native format91XDR // Xdr format92};9394virtual Format format () const;959697//----------------------------98// Access to the file's header99//----------------------------100101const Header & header () const {return _header;}102103104//-------------------------------------------------------------------------105// Compress an array of bytes that represents the contents of up to106// numScanLines() scan lines:107//108// inPtr Input buffer (uncompressed data).109//110// inSize Number of bytes in the input buffer111//112// minY Minimum y coordinate of the scan lines to113// be compressed114//115// outPtr Pointer to output buffer116//117// return value Size of compressed data in output buffer118//119// Arrangement of uncompressed pixel data in the input buffer:120//121// Before calling122//123// compress (buf, size, minY, ...);124//125// the InputFile::writePixels() method gathers pixel data from the126// frame buffer, fb, and places them in buffer buf, like this:127//128// char *endOfBuf = buf;129//130// for (int y = minY;131// y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);132// ++y)133// {134// for (ChannelList::ConstIterator c = header().channels().begin();135// c != header().channels().end();136// ++c)137// {138// if (modp (y, c.channel().ySampling) != 0)139// continue;140//141// for (int x = header().dataWindow().min.x;142// x <= header().dataWindow().max.x;143// ++x)144// {145// if (modp (x, c.channel().xSampling) != 0)146// continue;147//148// Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));149// }150// }151// }152//153// int size = endOfBuf - buf;154//155//-------------------------------------------------------------------------156157virtual int compress (const char *inPtr,158int inSize,159int minY,160const char *&outPtr) = 0;161162virtual int compressTile (const char *inPtr,163int inSize,164Imath::Box2i range,165const char *&outPtr);166167//-------------------------------------------------------------------------168// Uncompress an array of bytes that has been compressed by compress():169//170// inPtr Input buffer (compressed data).171//172// inSize Number of bytes in the input buffer173//174// minY Minimum y coordinate of the scan lines to175// be uncompressed176//177// outPtr Pointer to output buffer178//179// return value Size of uncompressed data in output buffer180//181//-------------------------------------------------------------------------182183virtual int uncompress (const char *inPtr,184int inSize,185int minY,186const char *&outPtr) = 0;187188virtual int uncompressTile (const char *inPtr,189int inSize,190Imath::Box2i range,191const char *&outPtr);192193private:194195const Header & _header;196};197198199//--------------------------------------200// Test if c is a valid compression type201//--------------------------------------202203bool isValidCompression (Compression c);204205206//-----------------------------------------------------------------207// Construct a Compressor for compression type c:208//209// maxScanLineSize Maximum number of bytes per uncompressed210// scan line.211//212// header Header of the input or output file whose213// pixels will be compressed or uncompressed.214//215// return value A pointer to a new Compressor object (it216// is the caller's responsibility to delete217// the object), or 0 (if c is NO_COMPRESSION).218//219//-----------------------------------------------------------------220221Compressor * newCompressor (Compression c,222size_t maxScanLineSize,223const Header &hdr);224225226//-----------------------------------------------------------------227// Construct a Compressor for compression type c for a tiled image:228//229// tileLineSize Maximum number of bytes per uncompressed230// line in a tile.231//232// numTileLines Maximum number of lines in a tile.233//234// header Header of the input or output file whose235// pixels will be compressed or uncompressed.236//237// return value A pointer to a new Compressor object (it238// is the caller's responsibility to delete239// the object), or 0 (if c is NO_COMPRESSION).240//241//-----------------------------------------------------------------242243Compressor * newTileCompressor (Compression c,244size_t tileLineSize,245size_t numTileLines,246const Header &hdr);247248249} // namespace Imf250251#endif252253254