PBRT
|
00001 00002 // 00003 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas 00004 // Digital Ltd. LLC 00005 // 00006 // All rights reserved. 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are 00010 // met: 00011 // * Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // * Redistributions in binary form must reproduce the above 00014 // copyright notice, this list of conditions and the following disclaimer 00015 // in the documentation and/or other materials provided with the 00016 // distribution. 00017 // * Neither the name of Industrial Light & Magic nor the names of 00018 // its contributors may be used to endorse or promote products derived 00019 // from this software without specific prior written permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00025 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00029 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00030 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00034 00035 00036 00037 #ifndef INCLUDED_IMF_COMPRESSOR_H 00038 #define INCLUDED_IMF_COMPRESSOR_H 00039 00040 //----------------------------------------------------------------------------- 00041 // 00042 // class Compressor 00043 // 00044 //----------------------------------------------------------------------------- 00045 00046 #include <ImfCompression.h> 00047 #include "ImathBox.h" 00048 #include <stdlib.h> 00049 00050 namespace Imf { 00051 00052 class Header; 00053 00054 00055 class Compressor 00056 { 00057 public: 00058 00059 //--------------------------------------------- 00060 // Constructor -- hdr is the header of the file 00061 // that will be compressed or uncompressed 00062 //--------------------------------------------- 00063 00064 Compressor (const Header &hdr); 00065 00066 00067 //----------- 00068 // Destructor 00069 //----------- 00070 00071 virtual ~Compressor (); 00072 00073 00074 //---------------------------------------------- 00075 // Maximum number of scan lines processed by 00076 // a single call to compress() and uncompress(). 00077 //---------------------------------------------- 00078 00079 virtual int numScanLines () const = 0; 00080 00081 00082 //-------------------------------------------- 00083 // Format of the pixel data read and written 00084 // by the compress() and uncompress() methods. 00085 // The default implementation of format() 00086 // returns XDR. 00087 //-------------------------------------------- 00088 00089 enum Format 00090 { 00091 NATIVE, // the machine's native format 00092 XDR // Xdr format 00093 }; 00094 00095 virtual Format format () const; 00096 00097 00098 //---------------------------- 00099 // Access to the file's header 00100 //---------------------------- 00101 00102 const Header & header () const {return _header;} 00103 00104 00105 //------------------------------------------------------------------------- 00106 // Compress an array of bytes that represents the contents of up to 00107 // numScanLines() scan lines: 00108 // 00109 // inPtr Input buffer (uncompressed data). 00110 // 00111 // inSize Number of bytes in the input buffer 00112 // 00113 // minY Minimum y coordinate of the scan lines to 00114 // be compressed 00115 // 00116 // outPtr Pointer to output buffer 00117 // 00118 // return value Size of compressed data in output buffer 00119 // 00120 // Arrangement of uncompressed pixel data in the input buffer: 00121 // 00122 // Before calling 00123 // 00124 // compress (buf, size, minY, ...); 00125 // 00126 // the InputFile::writePixels() method gathers pixel data from the 00127 // frame buffer, fb, and places them in buffer buf, like this: 00128 // 00129 // char *endOfBuf = buf; 00130 // 00131 // for (int y = minY; 00132 // y <= min (minY + numScanLines() - 1, header().dataWindow().max.y); 00133 // ++y) 00134 // { 00135 // for (ChannelList::ConstIterator c = header().channels().begin(); 00136 // c != header().channels().end(); 00137 // ++c) 00138 // { 00139 // if (modp (y, c.channel().ySampling) != 0) 00140 // continue; 00141 // 00142 // for (int x = header().dataWindow().min.x; 00143 // x <= header().dataWindow().max.x; 00144 // ++x) 00145 // { 00146 // if (modp (x, c.channel().xSampling) != 0) 00147 // continue; 00148 // 00149 // Xdr::write<CharPtrIO> (endOfBuf, fb.pixel (c, x, y)); 00150 // } 00151 // } 00152 // } 00153 // 00154 // int size = endOfBuf - buf; 00155 // 00156 //------------------------------------------------------------------------- 00157 00158 virtual int compress (const char *inPtr, 00159 int inSize, 00160 int minY, 00161 const char *&outPtr) = 0; 00162 00163 virtual int compressTile (const char *inPtr, 00164 int inSize, 00165 Imath::Box2i range, 00166 const char *&outPtr); 00167 00168 //------------------------------------------------------------------------- 00169 // Uncompress an array of bytes that has been compressed by compress(): 00170 // 00171 // inPtr Input buffer (compressed data). 00172 // 00173 // inSize Number of bytes in the input buffer 00174 // 00175 // minY Minimum y coordinate of the scan lines to 00176 // be uncompressed 00177 // 00178 // outPtr Pointer to output buffer 00179 // 00180 // return value Size of uncompressed data in output buffer 00181 // 00182 //------------------------------------------------------------------------- 00183 00184 virtual int uncompress (const char *inPtr, 00185 int inSize, 00186 int minY, 00187 const char *&outPtr) = 0; 00188 00189 virtual int uncompressTile (const char *inPtr, 00190 int inSize, 00191 Imath::Box2i range, 00192 const char *&outPtr); 00193 00194 private: 00195 00196 const Header & _header; 00197 }; 00198 00199 00200 //-------------------------------------- 00201 // Test if c is a valid compression type 00202 //-------------------------------------- 00203 00204 bool isValidCompression (Compression c); 00205 00206 00207 //----------------------------------------------------------------- 00208 // Construct a Compressor for compression type c: 00209 // 00210 // maxScanLineSize Maximum number of bytes per uncompressed 00211 // scan line. 00212 // 00213 // header Header of the input or output file whose 00214 // pixels will be compressed or uncompressed. 00215 // 00216 // return value A pointer to a new Compressor object (it 00217 // is the caller's responsibility to delete 00218 // the object), or 0 (if c is NO_COMPRESSION). 00219 // 00220 //----------------------------------------------------------------- 00221 00222 Compressor * newCompressor (Compression c, 00223 size_t maxScanLineSize, 00224 const Header &hdr); 00225 00226 00227 //----------------------------------------------------------------- 00228 // Construct a Compressor for compression type c for a tiled image: 00229 // 00230 // tileLineSize Maximum number of bytes per uncompressed 00231 // line in a tile. 00232 // 00233 // numTileLines Maximum number of lines in a tile. 00234 // 00235 // header Header of the input or output file whose 00236 // pixels will be compressed or uncompressed. 00237 // 00238 // return value A pointer to a new Compressor object (it 00239 // is the caller's responsibility to delete 00240 // the object), or 0 (if c is NO_COMPRESSION). 00241 // 00242 //----------------------------------------------------------------- 00243 00244 Compressor * newTileCompressor (Compression c, 00245 size_t tileLineSize, 00246 size_t numTileLines, 00247 const Header &hdr); 00248 00249 00250 } // namespace Imf 00251 00252 #endif