Blame IlmImf/ImfCompressor.h

Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
//
Packit 0d464f
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
Packit 0d464f
// Digital Ltd. LLC
Packit 0d464f
// 
Packit 0d464f
// All rights reserved.
Packit 0d464f
// 
Packit 0d464f
// Redistribution and use in source and binary forms, with or without
Packit 0d464f
// modification, are permitted provided that the following conditions are
Packit 0d464f
// met:
Packit 0d464f
// *       Redistributions of source code must retain the above copyright
Packit 0d464f
// notice, this list of conditions and the following disclaimer.
Packit 0d464f
// *       Redistributions in binary form must reproduce the above
Packit 0d464f
// copyright notice, this list of conditions and the following disclaimer
Packit 0d464f
// in the documentation and/or other materials provided with the
Packit 0d464f
// distribution.
Packit 0d464f
// *       Neither the name of Industrial Light & Magic nor the names of
Packit 0d464f
// its contributors may be used to endorse or promote products derived
Packit 0d464f
// from this software without specific prior written permission. 
Packit 0d464f
// 
Packit 0d464f
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 0d464f
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 0d464f
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 0d464f
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 0d464f
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 0d464f
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 0d464f
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 0d464f
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 0d464f
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 0d464f
//
Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
Packit 0d464f
Packit 0d464f
Packit 0d464f
#ifndef INCLUDED_IMF_COMPRESSOR_H
Packit 0d464f
#define INCLUDED_IMF_COMPRESSOR_H
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
//
Packit 0d464f
//	class Compressor
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
#include "ImfCompression.h"
Packit 0d464f
#include "ImathBox.h"
Packit 0d464f
#include "ImfNamespace.h"
Packit 0d464f
#include "ImfExport.h"
Packit 0d464f
#include "ImfForward.h"
Packit 0d464f
Packit 0d464f
#include <stdlib.h>
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit 0d464f
Packit 0d464f
Packit 0d464f
class IMF_EXPORT Compressor
Packit 0d464f
{
Packit 0d464f
  public:
Packit 0d464f
Packit 0d464f
    //---------------------------------------------
Packit 0d464f
    // Constructor -- hdr is the header of the file
Packit 0d464f
    // that will be compressed or uncompressed
Packit 0d464f
    //---------------------------------------------
Packit 0d464f
Packit 0d464f
    Compressor (const Header &hdr);
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-----------
Packit 0d464f
    // Destructor
Packit 0d464f
    //-----------
Packit 0d464f
Packit 0d464f
    virtual ~Compressor ();
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //----------------------------------------------
Packit 0d464f
    // Maximum number of scan lines processed by
Packit 0d464f
    // a single call to compress() and uncompress().
Packit 0d464f
    //----------------------------------------------
Packit 0d464f
Packit 0d464f
    virtual int		numScanLines () const = 0;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //--------------------------------------------
Packit 0d464f
    // Format of the pixel data read and written
Packit 0d464f
    // by the compress() and uncompress() methods.
Packit 0d464f
    // The default implementation of format()
Packit 0d464f
    // returns XDR.
Packit 0d464f
    //--------------------------------------------
Packit 0d464f
Packit 0d464f
    enum Format
Packit 0d464f
    {
Packit 0d464f
	NATIVE,		// the machine's native format
Packit 0d464f
	XDR		// Xdr format
Packit 0d464f
    };
Packit 0d464f
Packit 0d464f
    virtual Format	format () const;
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //----------------------------
Packit 0d464f
    // Access to the file's header
Packit 0d464f
    //----------------------------
Packit 0d464f
Packit 0d464f
    const Header &	header () const		{return _header;}
Packit 0d464f
Packit 0d464f
Packit 0d464f
    //-------------------------------------------------------------------------
Packit 0d464f
    // Compress an array of bytes that represents the contents of up to
Packit 0d464f
    // numScanLines() scan lines:
Packit 0d464f
    //
Packit 0d464f
    //	    inPtr		Input buffer (uncompressed data).
Packit 0d464f
    //
Packit 0d464f
    //	    inSize		Number of bytes in the input buffer
Packit 0d464f
    //
Packit 0d464f
    //	    minY		Minimum y coordinate of the scan lines to
Packit 0d464f
    //				be compressed
Packit 0d464f
    //
Packit 0d464f
    //	    outPtr		Pointer to output buffer
Packit 0d464f
    //
Packit 0d464f
    //	    return value	Size of compressed data in output buffer
Packit 0d464f
    //
Packit 0d464f
    // Arrangement of uncompressed pixel data in the input buffer:
Packit 0d464f
    //
Packit 0d464f
    //	Before calling
Packit 0d464f
    //
Packit 0d464f
    //	        compress (buf, size, minY, ...);
Packit 0d464f
    //
Packit 0d464f
    //	the InputFile::writePixels() method gathers pixel data from the
Packit 0d464f
    // 	frame buffer, fb, and places them in buffer buf, like this:
Packit 0d464f
    //
Packit 0d464f
    //  char *endOfBuf = buf;
Packit 0d464f
    //
Packit 0d464f
    //	for (int y = minY;
Packit 0d464f
    //	     y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);
Packit 0d464f
    //	     ++y)
Packit 0d464f
    //	{
Packit 0d464f
    //	    for (ChannelList::ConstIterator c = header().channels().begin();
Packit 0d464f
    //		 c != header().channels().end();
Packit 0d464f
    //		 ++c)
Packit 0d464f
    //	    {
Packit 0d464f
    //		if (modp (y, c.channel().ySampling) != 0)
Packit 0d464f
    //		    continue;
Packit 0d464f
    //
Packit 0d464f
    //		for (int x = header().dataWindow().min.x;
Packit 0d464f
    //		     x <= header().dataWindow().max.x;
Packit 0d464f
    //		     ++x)
Packit 0d464f
    //		{
Packit 0d464f
    //		    if (modp (x, c.channel().xSampling) != 0)
Packit 0d464f
    //			continue;
Packit 0d464f
    //
Packit 0d464f
    //		    Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));
Packit 0d464f
    //		}
Packit 0d464f
    //	    }
Packit 0d464f
    //	}
Packit 0d464f
    //
Packit 0d464f
    //	int size = endOfBuf - buf;
Packit 0d464f
    //
Packit 0d464f
    //-------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    virtual int		compress (const char *inPtr,
Packit 0d464f
				  int inSize,
Packit 0d464f
				  int minY,
Packit 0d464f
				  const char *&outPtr) = 0;
Packit 0d464f
Packit 0d464f
    virtual int		compressTile (const char *inPtr,
Packit 0d464f
				      int inSize,
Packit 0d464f
				      IMATH_NAMESPACE::Box2i range,
Packit 0d464f
				      const char *&outPtr);
Packit 0d464f
Packit 0d464f
    //-------------------------------------------------------------------------
Packit 0d464f
    // Uncompress an array of bytes that has been compressed by compress():
Packit 0d464f
    //
Packit 0d464f
    //	    inPtr		Input buffer (compressed data).
Packit 0d464f
    //
Packit 0d464f
    //	    inSize		Number of bytes in the input buffer
Packit 0d464f
    //
Packit 0d464f
    //	    minY		Minimum y coordinate of the scan lines to
Packit 0d464f
    //				be uncompressed
Packit 0d464f
    //
Packit 0d464f
    //	    outPtr		Pointer to output buffer
Packit 0d464f
    //
Packit 0d464f
    //	    return value	Size of uncompressed data in output buffer
Packit 0d464f
    //
Packit 0d464f
    //-------------------------------------------------------------------------
Packit 0d464f
Packit 0d464f
    virtual int		uncompress (const char *inPtr,
Packit 0d464f
				    int inSize,
Packit 0d464f
				    int minY,
Packit 0d464f
				    const char *&outPtr) = 0;
Packit 0d464f
Packit 0d464f
    virtual int		uncompressTile (const char *inPtr,
Packit 0d464f
					int inSize,
Packit 0d464f
					IMATH_NAMESPACE::Box2i range,
Packit 0d464f
					const char *&outPtr);
Packit 0d464f
Packit 0d464f
  private:
Packit 0d464f
Packit 0d464f
    const Header &	_header;
Packit 0d464f
};
Packit 0d464f
Packit 0d464f
Packit 0d464f
//--------------------------------------
Packit 0d464f
// Test if c is a valid compression type
Packit 0d464f
//--------------------------------------
Packit 0d464f
Packit 0d464f
IMF_EXPORT 
Packit 0d464f
bool isValidCompression (Compression c);
Packit 0d464f
Packit 0d464f
//--------------------------------------
Packit 0d464f
// Test if c is valid for deep data
Packit 0d464f
//--------------------------------------
Packit 0d464f
Packit 0d464f
IMF_EXPORT
Packit 0d464f
bool            isValidDeepCompression (Compression c);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------
Packit 0d464f
// Construct a Compressor for compression type c:
Packit 0d464f
//
Packit 0d464f
//  maxScanLineSize	Maximum number of bytes per uncompressed
Packit 0d464f
//			scan line.
Packit 0d464f
//
Packit 0d464f
//  header		Header of the input or output file whose
Packit 0d464f
//			pixels will be compressed or uncompressed.
Packit 0d464f
//			
Packit 0d464f
//  return value	A pointer to a new Compressor object (it
Packit 0d464f
//			is the caller's responsibility to delete
Packit 0d464f
//			the object), or 0 (if c is NO_COMPRESSION).
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------
Packit 0d464f
Packit 0d464f
IMF_EXPORT 
Packit 0d464f
Compressor *	newCompressor (Compression c,
Packit 0d464f
			       size_t maxScanLineSize,
Packit 0d464f
			       const Header &hdr);
Packit 0d464f
Packit 0d464f
Packit 0d464f
//-----------------------------------------------------------------
Packit 0d464f
// Construct a Compressor for compression type c for a tiled image:
Packit 0d464f
//
Packit 0d464f
//  tileLineSize	Maximum number of bytes per uncompressed
Packit 0d464f
//			line in a tile.
Packit 0d464f
//
Packit 0d464f
//  numTileLines	Maximum number of lines in a tile.
Packit 0d464f
//
Packit 0d464f
//  header		Header of the input or output file whose
Packit 0d464f
//			pixels will be compressed or uncompressed.
Packit 0d464f
//
Packit 0d464f
//  return value	A pointer to a new Compressor object (it
Packit 0d464f
//			is the caller's responsibility to delete
Packit 0d464f
//			the object), or 0 (if c is NO_COMPRESSION).
Packit 0d464f
//
Packit 0d464f
//-----------------------------------------------------------------
Packit 0d464f
Packit 0d464f
IMF_EXPORT 
Packit 0d464f
Compressor *    newTileCompressor (Compression c,
Packit 0d464f
				   size_t tileLineSize,
Packit 0d464f
				   size_t numTileLines,
Packit 0d464f
				   const Header &hdr);
Packit 0d464f
Packit 0d464f
Packit 0d464f
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit 0d464f
Packit 0d464f
#endif