1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
37
#ifndef INCLUDED_IMF_COMPRESSOR_H
38
#define INCLUDED_IMF_COMPRESSOR_H
40
//-----------------------------------------------------------------------------
44
//-----------------------------------------------------------------------------
46
#include <ImfCompression.h>
58
//---------------------------------------------
59
// Constructor -- hdr is the header of the file
60
// that will be compressed or uncompressed
61
//---------------------------------------------
63
Compressor (const Header &hdr);
70
virtual ~Compressor ();
73
//----------------------------------------------
74
// Maximum number of scan lines processed by
75
// a single call to compress() and uncompress().
76
//----------------------------------------------
78
virtual int numScanLines () const = 0;
81
//--------------------------------------------
82
// Format of the pixel data read and written
83
// by the compress() and uncompress() methods.
84
// The default implementation of format()
86
//--------------------------------------------
90
NATIVE, // the machine's native format
94
virtual Format format () const;
97
//----------------------------
98
// Access to the file's header
99
//----------------------------
101
const Header & header () const {return _header;}
104
//-------------------------------------------------------------------------
105
// Compress an array of bytes that represents the contents of up to
106
// numScanLines() scan lines:
108
// inPtr Input buffer (uncompressed data).
110
// inSize Number of bytes in the input buffer
112
// minY Minimum y coordinate of the scan lines to
115
// outPtr Pointer to output buffer
117
// return value Size of compressed data in output buffer
119
// Arrangement of uncompressed pixel data in the input buffer:
123
// compress (buf, size, minY, ...);
125
// the InputFile::writePixels() method gathers pixel data from the
126
// frame buffer, fb, and places them in buffer buf, like this:
128
// char *endOfBuf = buf;
130
// for (int y = minY;
131
// y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);
134
// for (ChannelList::ConstIterator c = header().channels().begin();
135
// c != header().channels().end();
138
// if (modp (y, c.channel().ySampling) != 0)
141
// for (int x = header().dataWindow().min.x;
142
// x <= header().dataWindow().max.x;
145
// if (modp (x, c.channel().xSampling) != 0)
148
// Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));
153
// int size = endOfBuf - buf;
155
//-------------------------------------------------------------------------
157
virtual int compress (const char *inPtr,
160
const char *&outPtr) = 0;
162
virtual int compressTile (const char *inPtr,
165
const char *&outPtr);
167
//-------------------------------------------------------------------------
168
// Uncompress an array of bytes that has been compressed by compress():
170
// inPtr Input buffer (compressed data).
172
// inSize Number of bytes in the input buffer
174
// minY Minimum y coordinate of the scan lines to
177
// outPtr Pointer to output buffer
179
// return value Size of uncompressed data in output buffer
181
//-------------------------------------------------------------------------
183
virtual int uncompress (const char *inPtr,
186
const char *&outPtr) = 0;
188
virtual int uncompressTile (const char *inPtr,
191
const char *&outPtr);
195
const Header & _header;
199
//--------------------------------------
200
// Test if c is a valid compression type
201
//--------------------------------------
203
bool isValidCompression (Compression c);
206
//-----------------------------------------------------------------
207
// Construct a Compressor for compression type c:
209
// maxScanLineSize Maximum number of bytes per uncompressed
212
// header Header of the input or output file whose
213
// pixels will be compressed or uncompressed.
215
// return value A pointer to a new Compressor object (it
216
// is the caller's responsibility to delete
217
// the object), or 0 (if c is NO_COMPRESSION).
219
//-----------------------------------------------------------------
221
Compressor * newCompressor (Compression c,
226
//-----------------------------------------------------------------
227
// Construct a Compressor for compression type c for a tiled image:
229
// tileLineSize Maximum number of bytes per uncompressed
232
// numTileLines Maximum number of lines in a tile.
234
// header Header of the input or output file whose
235
// pixels will be compressed or uncompressed.
237
// return value A pointer to a new Compressor object (it
238
// is the caller's responsibility to delete
239
// the object), or 0 (if c is NO_COMPRESSION).
241
//-----------------------------------------------------------------
243
Compressor * newTileCompressor (Compression c,
1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
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
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.
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.
33
///////////////////////////////////////////////////////////////////////////
37
#ifndef INCLUDED_IMF_COMPRESSOR_H
38
#define INCLUDED_IMF_COMPRESSOR_H
40
//-----------------------------------------------------------------------------
44
//-----------------------------------------------------------------------------
46
#include <ImfCompression.h>
58
//---------------------------------------------
59
// Constructor -- hdr is the header of the file
60
// that will be compressed or uncompressed
61
//---------------------------------------------
63
Compressor (const Header &hdr);
70
virtual ~Compressor ();
73
//----------------------------------------------
74
// Maximum number of scan lines processed by
75
// a single call to compress() and uncompress().
76
//----------------------------------------------
78
virtual int numScanLines () const = 0;
81
//--------------------------------------------
82
// Format of the pixel data read and written
83
// by the compress() and uncompress() methods.
84
// The default implementation of format()
86
//--------------------------------------------
90
NATIVE, // the machine's native format
94
virtual Format format () const;
97
//----------------------------
98
// Access to the file's header
99
//----------------------------
101
const Header & header () const {return _header;}
104
//-------------------------------------------------------------------------
105
// Compress an array of bytes that represents the contents of up to
106
// numScanLines() scan lines:
108
// inPtr Input buffer (uncompressed data).
110
// inSize Number of bytes in the input buffer
112
// minY Minimum y coordinate of the scan lines to
115
// outPtr Pointer to output buffer
117
// return value Size of compressed data in output buffer
119
// Arrangement of uncompressed pixel data in the input buffer:
123
// compress (buf, size, minY, ...);
125
// the InputFile::writePixels() method gathers pixel data from the
126
// frame buffer, fb, and places them in buffer buf, like this:
128
// char *endOfBuf = buf;
130
// for (int y = minY;
131
// y <= min (minY + numScanLines() - 1, header().dataWindow().max.y);
134
// for (ChannelList::ConstIterator c = header().channels().begin();
135
// c != header().channels().end();
138
// if (modp (y, c.channel().ySampling) != 0)
141
// for (int x = header().dataWindow().min.x;
142
// x <= header().dataWindow().max.x;
145
// if (modp (x, c.channel().xSampling) != 0)
148
// Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y));
153
// int size = endOfBuf - buf;
155
//-------------------------------------------------------------------------
157
virtual int compress (const char *inPtr,
160
const char *&outPtr) = 0;
162
virtual int compressTile (const char *inPtr,
165
const char *&outPtr);
167
//-------------------------------------------------------------------------
168
// Uncompress an array of bytes that has been compressed by compress():
170
// inPtr Input buffer (compressed data).
172
// inSize Number of bytes in the input buffer
174
// minY Minimum y coordinate of the scan lines to
177
// outPtr Pointer to output buffer
179
// return value Size of uncompressed data in output buffer
181
//-------------------------------------------------------------------------
183
virtual int uncompress (const char *inPtr,
186
const char *&outPtr) = 0;
188
virtual int uncompressTile (const char *inPtr,
191
const char *&outPtr);
195
const Header & _header;
199
//--------------------------------------
200
// Test if c is a valid compression type
201
//--------------------------------------
203
bool isValidCompression (Compression c);
206
//-----------------------------------------------------------------
207
// Construct a Compressor for compression type c:
209
// maxScanLineSize Maximum number of bytes per uncompressed
212
// header Header of the input or output file whose
213
// pixels will be compressed or uncompressed.
215
// return value A pointer to a new Compressor object (it
216
// is the caller's responsibility to delete
217
// the object), or 0 (if c is NO_COMPRESSION).
219
//-----------------------------------------------------------------
221
Compressor * newCompressor (Compression c,
226
//-----------------------------------------------------------------
227
// Construct a Compressor for compression type c for a tiled image:
229
// tileLineSize Maximum number of bytes per uncompressed
232
// numTileLines Maximum number of lines in a tile.
234
// header Header of the input or output file whose
235
// pixels will be compressed or uncompressed.
237
// return value A pointer to a new Compressor object (it
238
// is the caller's responsibility to delete
239
// the object), or 0 (if c is NO_COMPRESSION).
241
//-----------------------------------------------------------------
243
Compressor * newTileCompressor (Compression c,