1 /////////////////////////////////////////////////////////////////////////// 2 // 3 // Copyright (c) 2002, 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 37 #ifndef INCLUDED_IMF_COMPRESSOR_H 38 #define INCLUDED_IMF_COMPRESSOR_H 39 40 //----------------------------------------------------------------------------- 41 // 42 // class Compressor 43 // 44 //----------------------------------------------------------------------------- 45 46 #include "ImfCompression.h" 47 #include "ImathBox.h" 48 #include "ImfNamespace.h" 49 #include "ImfExport.h" 50 #include "ImfForward.h" 51 52 #include <stdlib.h> 53 54 55 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER 56 57 58 class IMF_EXPORT Compressor 59 { 60 public: 61 62 //--------------------------------------------- 63 // Constructor -- hdr is the header of the file 64 // that will be compressed or uncompressed 65 //--------------------------------------------- 66 67 Compressor (const Header &hdr); 68 69 70 //----------- 71 // Destructor 72 //----------- 73 74 virtual ~Compressor (); 75 76 77 //---------------------------------------------- 78 // Maximum number of scan lines processed by 79 // a single call to compress() and uncompress(). 80 //---------------------------------------------- 81 82 virtual int numScanLines () const = 0; 83 84 85 //-------------------------------------------- 86 // Format of the pixel data read and written 87 // by the compress() and uncompress() methods. 88 // The default implementation of format() 89 // returns XDR. 90 //-------------------------------------------- 91 92 enum Format 93 { 94 NATIVE, // the machine's native format 95 XDR // Xdr format 96 }; 97 98 virtual Format format () const; 99 100 101 //---------------------------- 102 // Access to the file's header 103 //---------------------------- 104 header()105 const Header & header () const {return _header;} 106 107 108 //------------------------------------------------------------------------- 109 // Compress an array of bytes that represents the contents of up to 110 // numScanLines() scan lines: 111 // 112 // inPtr Input buffer (uncompressed data). 113 // 114 // inSize Number of bytes in the input buffer 115 // 116 // minY Minimum y coordinate of the scan lines to 117 // be compressed 118 // 119 // outPtr Pointer to output buffer 120 // 121 // return value Size of compressed data in output buffer 122 // 123 // Arrangement of uncompressed pixel data in the input buffer: 124 // 125 // Before calling 126 // 127 // compress (buf, size, minY, ...); 128 // 129 // the InputFile::writePixels() method gathers pixel data from the 130 // frame buffer, fb, and places them in buffer buf, like this: 131 // 132 // char *endOfBuf = buf; 133 // 134 // for (int y = minY; 135 // y <= min (minY + numScanLines() - 1, header().dataWindow().max.y); 136 // ++y) 137 // { 138 // for (ChannelList::ConstIterator c = header().channels().begin(); 139 // c != header().channels().end(); 140 // ++c) 141 // { 142 // if (modp (y, c.channel().ySampling) != 0) 143 // continue; 144 // 145 // for (int x = header().dataWindow().min.x; 146 // x <= header().dataWindow().max.x; 147 // ++x) 148 // { 149 // if (modp (x, c.channel().xSampling) != 0) 150 // continue; 151 // 152 // Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y)); 153 // } 154 // } 155 // } 156 // 157 // int size = endOfBuf - buf; 158 // 159 //------------------------------------------------------------------------- 160 161 virtual int compress (const char *inPtr, 162 int inSize, 163 int minY, 164 const char *&outPtr) = 0; 165 166 virtual int compressTile (const char *inPtr, 167 int inSize, 168 IMATH_NAMESPACE::Box2i range, 169 const char *&outPtr); 170 171 //------------------------------------------------------------------------- 172 // Uncompress an array of bytes that has been compressed by compress(): 173 // 174 // inPtr Input buffer (compressed data). 175 // 176 // inSize Number of bytes in the input buffer 177 // 178 // minY Minimum y coordinate of the scan lines to 179 // be uncompressed 180 // 181 // outPtr Pointer to output buffer 182 // 183 // return value Size of uncompressed data in output buffer 184 // 185 //------------------------------------------------------------------------- 186 187 virtual int uncompress (const char *inPtr, 188 int inSize, 189 int minY, 190 const char *&outPtr) = 0; 191 192 virtual int uncompressTile (const char *inPtr, 193 int inSize, 194 IMATH_NAMESPACE::Box2i range, 195 const char *&outPtr); 196 197 private: 198 199 const Header & _header; 200 }; 201 202 203 //-------------------------------------- 204 // Test if c is a valid compression type 205 //-------------------------------------- 206 207 IMF_EXPORT 208 bool isValidCompression (Compression c); 209 210 //-------------------------------------- 211 // Test if c is valid for deep data 212 //-------------------------------------- 213 214 IMF_EXPORT 215 bool isValidDeepCompression (Compression c); 216 217 218 //----------------------------------------------------------------- 219 // Construct a Compressor for compression type c: 220 // 221 // maxScanLineSize Maximum number of bytes per uncompressed 222 // scan line. 223 // 224 // header Header of the input or output file whose 225 // pixels will be compressed or uncompressed. 226 // 227 // return value A pointer to a new Compressor object (it 228 // is the caller's responsibility to delete 229 // the object), or 0 (if c is NO_COMPRESSION). 230 // 231 //----------------------------------------------------------------- 232 233 IMF_EXPORT 234 Compressor * newCompressor (Compression c, 235 size_t maxScanLineSize, 236 const Header &hdr); 237 238 239 //----------------------------------------------------------------- 240 // Construct a Compressor for compression type c for a tiled image: 241 // 242 // tileLineSize Maximum number of bytes per uncompressed 243 // line in a tile. 244 // 245 // numTileLines Maximum number of lines in a tile. 246 // 247 // header Header of the input or output file whose 248 // pixels will be compressed or uncompressed. 249 // 250 // return value A pointer to a new Compressor object (it 251 // is the caller's responsibility to delete 252 // the object), or 0 (if c is NO_COMPRESSION). 253 // 254 //----------------------------------------------------------------- 255 256 IMF_EXPORT 257 Compressor * newTileCompressor (Compression c, 258 size_t tileLineSize, 259 size_t numTileLines, 260 const Header &hdr); 261 262 263 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT 264 265 #endif 266