00001 /* 00002 /-------------------------------------------------------------------- 00003 | 00004 | $Id: plpictdec_8h-source.html,v 1.1 2004/06/06 12:56:41 uzadow Exp $ 00005 | 00006 | Copyright (c) 1996-2002 Ulrich von Zadow 00007 | 00008 \-------------------------------------------------------------------- 00009 */ 00010 00011 #ifndef INCL_PLPICTDEC 00012 #define INCL_PLPICTDEC 00013 00014 #ifndef INCL_PLPICDEC 00015 #include "plpicdec.h" 00016 #endif 00017 00018 #include "qdraw.h" 00019 00020 class PLJPEGDecoder; 00021 00022 //! This class decodes macintosh PICT files with 1,2,4,8,16 and 32 00023 //! bits per pixel as well as PICT/JPEG. If an alpha channel is 00024 //! present in a 32-bit-PICT, it is decoded as well. 00025 //! The PICT format is a general picture file format and can 00026 //! contain a lot of other elements besides bitmaps. These elements 00027 //! are ignored. 00028 class PLPictDecoder : public PLPicDecoder 00029 { 00030 00031 public: 00032 //! Creates a decoder. A JPEG decoder is needed to decode PICT 00033 //! files containing JPEGs. 00034 PLPictDecoder 00035 ( PLJPEGDecoder * pJPEGDecoder 00036 ); 00037 00038 //! Destroys a decoder. 00039 virtual ~PLPictDecoder 00040 (); 00041 00042 //! 00043 virtual void Open (PLDataSource * pDataSrc); 00044 00045 //! Fills the bitmap with the image. 00046 virtual void GetImage (PLBmp & Bmp); 00047 00048 private: 00049 // Decodes header and version information. 00050 // Sets m_Version. 00051 // Performs checks to make sure the data is really a pict file. 00052 void readHeader 00053 ( PLDataSource * pDataSrc, 00054 int& Version 00055 ); 00056 00057 // This is the main decoder loop. The functions reads opcodes, 00058 // skips some of them, and hands the rest to opcode-specific 00059 // functions. It stops decoding after the first opcode containing 00060 // bitmapped data. 00061 void interpretOpcodes 00062 ( PLDataSource * pDataSrc, 00063 int& Version 00064 ); 00065 00066 // Moves to an even byte position in the file and returns the 00067 // opcode found there. 00068 PLWORD readOpcode 00069 ( int Version, 00070 PLDataSource * pDataSrc 00071 ); 00072 00073 // Opcode functions 00074 00075 // Skips clipping rectangle or region opcode. 00076 void clip 00077 ( PLDataSource * pDataSrc 00078 ); 00079 00080 // Skips pattern definition opcode. 00081 // Untested!! 00082 void pixPat 00083 ( PLDataSource * pDataSrc 00084 ); 00085 00086 // Skips polygon/region opcodes. 00087 // Untested!! 00088 void skipPolyOrRegion 00089 ( PLDataSource * pDataSrc 00090 ); 00091 00092 // Opcode: Bitmap/pixmap data clipped by a rectangle. 00093 void bitsRect 00094 ( PLDataSource * pDataSrc 00095 ); 00096 00097 // Opcode: Bitmap/pixmap data clipped by a region. 00098 void bitsRegion 00099 ( PLDataSource * pDataSrc 00100 ); 00101 00102 // DirectBitsRect opcode. 00103 void opcode9a 00104 ( PLDataSource * pDataSrc 00105 ); 00106 00107 void DecodeOp9a 00108 ( PLBmp * pBmp, 00109 PLDataSource * pDataSrc 00110 ); 00111 00112 // Long comment opcode. Skipped. 00113 void longComment 00114 ( PLDataSource * pDataSrc 00115 ); 00116 00117 // Header opcode. Contains resolution information. 00118 void headerOp 00119 ( PLDataSource * pDataSrc 00120 ); 00121 00122 // JPEG opcode. Invoke the JPEG decoder for this PICT. 00123 void jpegOp 00124 ( PLDataSource * pDataSrc 00125 ); 00126 00127 void DecodeJPEG 00128 ( PLBmp * pBmp, 00129 PLDataSource * pDataSrc 00130 ); 00131 00132 // Bitmap & Pixmap functions. 00133 00134 // Allocates the output bitmap. 00135 void setBmpInfo 00136 ( MacpixMap PixMap 00137 ); 00138 00139 // Decode version 1 bitmap: 1 bpp. 00140 void doBitmap 00141 ( PLDataSource * pDataSrc 00142 ); 00143 00144 void DecodeBitmap 00145 ( PLBmp * pBmp, 00146 PLDataSource * pDataSrc 00147 ); 00148 00149 // Decode version 2 pixmap. 00150 void doPixmap 00151 ( PLDataSource * pDataSrc 00152 ); 00153 00154 void DecodePixmap 00155 ( PLBmp * pBmp, 00156 PLDataSource * pDataSrc 00157 ); 00158 00159 00160 // This routine decompresses BitsRects with a packType of 4 (and 00161 // 32 bits per pixel). In this format, each line is separated 00162 // into 8-bit-bitplanes and then compressed via RLE. To decode, 00163 // the routine decompresses each line & then juggles the bytes 00164 // around to get pixel-oriented data. 00165 void unpack32bits 00166 ( MacRect* pBounds, 00167 PLWORD rowBytes, 00168 int NumBitPlanes, // 3 if RGB, 4 if RGBA 00169 PLBmp * pBmp, 00170 PLDataSource * pDataSrc 00171 ); 00172 00173 // Decompression routine for 8 bpp. rowBytes is the number of 00174 // bytes each source row would take if it were uncompressed. 00175 // This _isn't_ equal to the number of pixels in the row - apple 00176 // pads the data to a word boundary and then compresses it. Of 00177 // course, we have to decompress the excess data and then throw it 00178 // away. 00179 void unpack8bits 00180 ( MacRect* pBounds, 00181 PLWORD rowBytes, 00182 PLBmp * pBmp, 00183 PLDataSource * pDataSrc 00184 ); 00185 00186 // Decompression routine for everything but 32 bpp. This routine 00187 // is slower than the two routines above since it has to deal 00188 // with a lot of special cases. 00189 void unpackbits 00190 ( MacRect* pBounds, 00191 PLWORD rowBytes, 00192 int pixelSize, // Source bits per pixel. 00193 PLBmp * pBmp, 00194 PLDataSource * pDataSrc 00195 ); 00196 00197 // Skips unneeded packbits. 00198 void skipBits 00199 ( MacRect* pBounds, 00200 PLWORD rowBytes, 00201 int pixelSize, // Source bits per pixel. 00202 PLDataSource * pDataSrc 00203 ); 00204 00205 // Expands one RLE unit to 32-bit pixel data. 00206 void expandBuf 00207 ( PLBYTE * pDestBuf, 00208 PLBYTE * pSrcBuf, 00209 int Width, // Width in bytes for 8 bpp or less. 00210 // Width in pixels for 16 bpp. 00211 int bpp // bits per pixel 00212 ); 00213 00214 // Expands Width units to 8-bit pixel data. 00215 // Max. 8 bpp source format. 00216 void expandBuf8 00217 ( PLBYTE * pDestBuf, 00218 PLBYTE * pSrcBuf, 00219 int Width, // Width in bytes. 00220 int bpp // bits per pixel. 00221 ); 00222 00223 void readPixmap 00224 ( MacpixMap * pPixMap, 00225 PLDataSource * pDataSrc 00226 ); 00227 00228 // Reads a mac colour table into a windows palette. 00229 void readColourTable 00230 ( PLWORD * pNumColors, 00231 PLDataSource * pDataSrc, 00232 PLPixel32 * pPal 00233 ); 00234 00235 void readRect 00236 ( MacRect * pr, 00237 PLDataSource * pDataSrc 00238 ); 00239 00240 void dumpRect 00241 ( char * psz, 00242 MacRect * pr 00243 ); 00244 00245 void tracePixMapHeader 00246 ( int Level, 00247 MacpixMap * pPixMap 00248 ); 00249 00250 00251 PLJPEGDecoder * m_pJPEGDecoder; // Used if a pict file contains a JPEG. 00252 00253 enum PICTType {none, op9a, jpeg, pixmap, bitmap}; 00254 PICTType m_PictType; 00255 00256 // Pixmap header. 00257 MacpixMap m_PixMap; 00258 00259 // pixmap/bitmap stuff 00260 int m_rowBytes; 00261 MacRect m_Bounds; 00262 bool m_bIsRegion; 00263 }; 00264 00265 #endif 00266 /* 00267 /-------------------------------------------------------------------- 00268 | 00269 | $Log: plpictdec_8h-source.html,v $ 00269 | Revision 1.1 2004/06/06 12:56:41 uzadow 00269 | Doxygenified documentation. 00269 | 00270 | Revision 1.8 2002/08/04 21:20:41 uzadow 00271 | no message 00272 | 00273 | Revision 1.7 2002/08/04 20:08:01 uzadow 00274 | Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support. 00275 | 00276 | Revision 1.6 2002/03/31 13:36:42 uzadow 00277 | Updated copyright. 00278 | 00279 | Revision 1.5 2001/10/21 17:12:40 uzadow 00280 | Added PSD decoder beta, removed BPPWanted from all decoders, added PLFilterPixel. 00281 | 00282 | Revision 1.4 2001/10/16 17:12:26 uzadow 00283 | Added support for resolution information (Luca Piergentili) 00284 | 00285 | Revision 1.3 2001/10/06 22:03:26 uzadow 00286 | Added PL prefix to basic data types. 00287 | 00288 | Revision 1.2 2001/10/03 13:58:21 uzadow 00289 | Removed references to config.h 00290 | 00291 | Revision 1.1 2001/09/16 19:03:22 uzadow 00292 | Added global name prefix PL, changed most filenames. 00293 | 00294 | 00295 \-------------------------------------------------------------------- 00296 */