Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members

plpicdec.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: plpicdec.h,v 1.10 2003/08/03 12:54:10 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 
00011 #ifndef INCL_PLPICDEC
00012 #define INCL_PLPICDEC
00013 
00014 #ifndef INCL_PLBITMAP
00015 #include "plbitmap.h"
00016 #endif
00017 
00018 #ifndef INCL_PLDATASRC
00019 #include "pldatasrc.h"
00020 #endif
00021 
00022 //! PLPicDecoder is an abstract base class. It defines common routines
00023 //! for all decoders. Decoders for specific file formats can be
00024 //! derived from this class. Objects of this class interact with a
00025 //! PLDataSource to decode bitmaps.
00026 class PLPicDecoder : public PLBmpInfo
00027 {
00028 
00029 public:
00030   //! Empty constructor. The actual initialization takes place in a
00031   //! derived class.
00032   PLPicDecoder
00033     ();
00034 
00035   //! Destructor. Frees memory allocated.
00036   virtual ~PLPicDecoder
00037     ();
00038 
00039   //! Decodes a picture in a file and stores the results in pBmp.
00040   //! BPPWanted is the number of bits per pixel in the bitmap
00041   //! returned. Valid values for BPPWanted are 8, 24, and 0.
00042   //! 0 means 'keep the input format'. Decoding a true-color image
00043   //! to 8 bpp is not supported. As an exception, BPPWanted can be
00044   //! 1 for b/w tiff files.
00045   virtual void MakeBmpFromFile
00046     ( const char * pszFName,
00047       PLBmp * pBmp,
00048       int BPPWanted = 0,
00049       PLIProgressNotification * pProgNot = NULL
00050     );
00051 
00052 #ifdef _WINDOWS  
00053   //! Decodes a picture in a file and stores the results in pBmp.
00054   //! Wide-Character version (windows only). 
00055   virtual void MakeBmpFromFileW
00056     ( const wchar_t * pszwFName,
00057       PLBmp * pBmp,
00058       int BPPWanted = 0,
00059       PLIProgressNotification * pProgNot = NULL
00060     );
00061 #endif
00062 
00063 
00064   //! BPPWanted is the number of bits per pixel in the bitmap
00065   //! returned. Valid values for BPPWanted are 8, 24, and 0.
00066   //! 0 means 'keep the input format'. Decoding a true-color image
00067   //! to 8 bpp is not supported. As an exception, BPPWanted can be
00068   //! 1 for b/w tiff files.
00069   virtual void MakeBmpFromURL
00070     ( const char * pszURL,
00071       PLBmp * pBmp,
00072       int BPPWanted = 0,
00073       PLIProgressNotification * pProgNot = NULL
00074     );
00075 
00076 #ifdef _WINDOWS
00077   //! Decodes a picture in a windows resource by creating a resource data
00078   //! source and calling MakeBmp with this data source.
00079   //! BPPWanted is the number of bits per pixel in the bitmap
00080   //! returned. Valid values for BPPWanted are 8, 24, and 0.
00081   //! 0 means 'keep the input format'. Decoding a true-color image
00082   //! to 8 bpp is not supported. As an exception, BPPWanted can be
00083   //! 1 for b/w tiff files.
00084   //! ResType is the windows resource type (e.g. "JPEG") to be used.
00085   //! If a module handle is passed as hResModule, then the resource
00086   //! will be loaded from this module, otherwise, the resource
00087   //! will be searched for by AfxFindResourceHandle (! MFC dependent!)
00088   virtual void MakeBmpFromResource
00089     ( HINSTANCE hInstResource, int ResourceID,
00090       PLBmp * pBmp,
00091       int BPPWanted = 0,
00092       const char* ResType = NULL,
00093       HMODULE hResModule = 0
00094           );
00095 #endif
00096 
00097   //! Decodes a picture from a memory location which directly resembles
00098   //! the image file as it would be on disc. The result is stored in pBmp.
00099   //! BPPWanted is the number of bits per pixel in the bitmap
00100   //! returned. Valid values for BPPWanted are 8, 24, and 0.
00101   //! 0 means 'keep the input format'. Decoding a true-color image
00102   //! to 8 bpp is not supported. As an exception, BPPWanted can be
00103   //! 1 for b/w tiff files.
00104   virtual void MakeBmpFromMemory
00105     ( unsigned char * ucMemSrc,
00106       int MemSrcSize,
00107       PLBmp * pBmp,
00108       int BPPWanted = 0,
00109       PLIProgressNotification * pProgNot = NULL
00110     );
00111 
00112 #ifdef _WINDOWS
00113   void OpenFileW
00114     ( const wchar_t * pszwFName, 
00115       PLIProgressNotification * pProgNot = NULL
00116     );
00117 #endif
00118   //! Stores the results in pBmp. BPPWanted is the number of bits
00119   //! per pixel in the bitmap returned. Valid values for BPPWanted
00120   //! are 8, 24, and 0. 0 means 'keep the input format'. Decoding a
00121   //! true-color image to 8 bpp is not supported.
00122   virtual void MakeBmp
00123     ( PLBmp * pBmp,
00124       int BPPWanted = 0
00125     );
00126 
00127   //! Decodes a picture by getting the encoded data from pDataSrc.
00128   //! Open should be called before, close after this routine is called.
00129   void OpenFile
00130     ( const char * pszFName, 
00131       PLIProgressNotification * pProgNot = NULL
00132     );
00133   
00134   //!
00135   virtual void Close
00136     ();
00137 
00138   //! Sets the amount and destination of debug traces output by the
00139   //! debug version. pszFName contains either a valid file name or is
00140   //! NULL. If it contains a file name, this file is used to store
00141   //! debug information. If pszFName is NULL, the destination is
00142   //! either the MSVC debug console or stderr depending on the
00143   //! version of the library. Valid values for Level are: <BR>
00144   //! <BR>
00145   //! 0: Trace only errors.<BR>
00146   //! 1: Trace top-level calls.<BR>
00147   //! 2: Trace picture format information<BR>
00148   //! 3: Trace all miscellaneous info.<BR>
00149   //! <BR>
00150   //! The trace configuration is global to all decoders.
00151   static void SetTraceConfig
00152     ( int Level,
00153       char * pszFName
00154     );
00155 
00156   //!
00157   virtual void Open (PLDataSource * pDataSrc)=0;
00158 
00159   //!
00160   virtual void GetImage (PLBmp & Bmp) = 0;
00161 
00162   // Used only by PLAnyPicDecoder
00163   void SetDataSrc (PLDataSource * pDataSrc);
00164 
00165   // This function is needed by callbacks outside of any object,
00166   // so it's public and static. It should not be called from
00167   // outside of the library.
00168   static void raiseError
00169     ( int Code,
00170       char * pszErr
00171     );
00172 
00173   //! Called to output status messages to the current debug console
00174   static void Trace
00175     ( int TraceLevel,
00176       const char * pszMessage
00177     );
00178 
00179 protected:
00180   // TODO: What is this doing here?!
00181   PLBYTE * unpackPictRow
00182     ( PLBYTE * pLineBuf,
00183       PLDataSource * pDataSrc,
00184       int Width,
00185       int rowBytes,
00186       int SrcBytes
00187     );
00188 
00189   PLBYTE ReadByte
00190     ( PLDataSource * pDataSrc
00191     );
00192 
00193   // Machine-independent routines for byte-order conversion.
00194 
00195   PLWORD ReadIWord
00196     ( PLDataSource * pDataSrc
00197     );
00198 
00199   PLWORD ReadMWord
00200     ( PLDataSource * pDataSrc
00201     );
00202 
00203   PLLONG ReadILong
00204     ( PLDataSource * pDataSrc
00205     );
00206 
00207   PLLONG ReadMLong
00208     ( PLDataSource * pDataSrc
00209     );
00210 
00211   PLDataSource * m_pDataSrc;
00212 
00213 private:
00214   ///////////////////////////////////////////////////////////////////
00215   // Member variables.
00216 
00217   static int    m_TraceLevel;    // 0: Trace only errors.
00218                                  // 1: Trace top-level calls.
00219                                  // 2: Trace picture format info.
00220                                  // 3: Trace misc. info.
00221   static char * m_pszTraceFName; // Name of trace file. NULL if trace to
00222                                  // MSVC debug console.
00223 };
00224 
00225 
00226 inline PLBYTE PLPicDecoder::ReadByte
00227     ( PLDataSource * pDataSrc
00228     )
00229 {
00230 
00231   return *(pDataSrc->ReadNBytes (1));
00232 }
00233 
00234 
00235 inline PLWORD PLPicDecoder::ReadIWord
00236     ( PLDataSource * pDataSrc
00237     )
00238 {
00239   PLBYTE * pData = pDataSrc->Read2Bytes ();
00240   // This should work regardless of the destination byte order ;-)
00241   return pData[0] + (pData[1]<<8);
00242 }
00243 
00244 
00245 inline PLWORD PLPicDecoder::ReadMWord
00246     ( PLDataSource * pDataSrc
00247     )
00248 {
00249   PLBYTE * pData = pDataSrc->Read2Bytes ();
00250   return pData[1] + (pData[0]<<8);
00251 }
00252 
00253 
00254 inline PLLONG PLPicDecoder::ReadILong
00255     ( PLDataSource * pDataSrc
00256     )
00257 {
00258   PLBYTE * pData = pDataSrc->Read4Bytes ();
00259   return pData[0] + (pData[1]<<8) + (pData[2]<<16) + (pData[3]<<24);
00260 }
00261 
00262 inline PLLONG PLPicDecoder::ReadMLong
00263     ( PLDataSource * pDataSrc
00264     )
00265 {
00266   PLBYTE * pData = pDataSrc->Read4Bytes ();
00267   return pData[3] + (pData[2]<<8) + (pData[1]<<16) + (pData[0]<<24);
00268 }
00269 
00270 #endif
00271 /*
00272 /--------------------------------------------------------------------
00273 |
00274 |      $Log: plpicdec.h,v $
00275 |      Revision 1.10  2003/08/03 12:54:10  uzadow
00276 |      Fixed broken linux build.
00277 |
00278 |      Revision 1.9  2003/08/03 12:03:20  uzadow
00279 |      Added unicode support; fixed some header includes.
00280 |
00281 |      Revision 1.8  2003/03/19 14:33:13  uzadow
00282 |      Added Rect.Contains
00283 |
00284 |      Revision 1.7  2003/02/15 21:26:58  uzadow
00285 |      Added win32 version of url data source.
00286 |
00287 |      Revision 1.6  2002/08/04 20:08:01  uzadow
00288 |      Added PLBmpInfo class, ability to extract metainformation from images without loading the whole image and proper greyscale support.
00289 |
00290 |      Revision 1.5  2002/03/06 22:46:54  uzadow
00291 |      Fixed major PLAnyDec bug
00292 |
00293 |      Revision 1.4  2002/03/03 16:29:55  uzadow
00294 |      Re-added BPPWanted.
00295 |
00296 |      Revision 1.3  2001/10/21 17:12:40  uzadow
00297 |      Added PSD decoder beta, removed BPPWanted from all decoders, added PLFilterPixel.
00298 |
00299 |      Revision 1.2  2001/10/06 22:03:26  uzadow
00300 |      Added PL prefix to basic data types.
00301 |
00302 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00303 |      Added global name prefix PL, changed most filenames.
00304 |
00305 |      Revision 1.8  2000/12/18 22:42:52  uzadow
00306 |      Replaced RGBAPIXEL with PLPixel32.
00307 |
00308 |      Revision 1.7  2000/03/30 21:24:15  Ulrich von Zadow
00309 |      Added MakeBmpFromMemory() function by Markus Ewald
00310 |
00311 |      Revision 1.6  2000/01/16 20:43:14  anonymous
00312 |      Removed MFC dependencies
00313 |
00314 |      Revision 1.5  2000/01/11 21:40:30  Ulrich von Zadow
00315 |      Added instance handle parameter to LoadFromResource()
00316 |
00317 |      Revision 1.4  2000/01/08 15:51:30  Ulrich von Zadow
00318 |      Misc. modifications to png encoder.
00319 |
00320 |      Revision 1.3  1999/11/08 22:12:51  Ulrich von Zadow
00321 |      Andreas Koepf: Added resource type as parameter to
00322 |      MakeBmpFromResource
00323 |
00324 |
00325 \--------------------------------------------------------------------
00326 */

Generated on Sun Jun 6 13:42:22 2004 for paintlib by doxygen 1.3.2