home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / win32 / include / cximage / ximabmp.h < prev    next >
C/C++ Source or Header  |  2004-02-29  |  3KB  |  95 lines

  1. /*
  2.  * File:    ximabmp.h
  3.  * Purpose:    BMP Image Class Loader and Writer
  4.  */
  5. /* === C R E D I T S  &  D I S C L A I M E R S ==============
  6.  * CxImageBMP (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
  7.  * Permission is given by the author to freely redistribute and include
  8.  * this code in any program as long as this credit is given where due.
  9.  *
  10.  * CxImage version 5.99a 08/Feb/2004
  11.  * See the file history.htm for the complete bugfix and news report.
  12.  *
  13.  * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
  14.  *
  15.  * original CImageBMP  and CImageIterator implementation are:
  16.  * Copyright:    (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
  17.  *
  18.  * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
  19.  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
  20.  * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
  21.  * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
  22.  * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
  23.  * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
  24.  * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
  25.  * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  26.  * THIS DISCLAIMER.
  27.  *
  28.  * Use at your own risk!
  29.  * ==========================================================
  30.  */
  31.  
  32. #if !defined(__ximaBMP_h)
  33. #define __ximaBMP_h
  34.  
  35. #include "ximage.h"
  36.  
  37. const int RLE_COMMAND     = 0;
  38. const int RLE_ENDOFLINE   = 0;
  39. const int RLE_ENDOFBITMAP = 1;
  40. const int RLE_DELTA       = 2;
  41.  
  42. #if !defined(BI_RLE8)
  43.  #define BI_RLE8  1L
  44. #endif
  45. #if !defined(BI_RLE4)
  46.  #define BI_RLE4  2L
  47. #endif
  48.  
  49. #if CXIMAGE_SUPPORT_BMP
  50.  
  51. class CxImageBMP: public CxImage
  52. {
  53. public:
  54.     CxImageBMP(): CxImage(CXIMAGE_FORMAT_BMP) {};
  55.  
  56.     bool Decode(CxFile * hFile);
  57.     bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
  58.  
  59. #if CXIMAGE_SUPPORT_ENCODE
  60.     bool Encode(CxFile * hFile);
  61.     bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
  62. #endif // CXIMAGE_SUPPORT_ENCODE
  63.  
  64. protected:
  65.     bool DibReadBitmapInfo(CxFile* fh, BITMAPINFOHEADER *pdib);
  66. };
  67.  
  68. #define BFT_ICON   0x4349   /* 'IC' */
  69. #define BFT_BITMAP 0x4d42   /* 'BM' */
  70. #define BFT_CURSOR 0x5450   /* 'PT' */
  71.  
  72. #ifndef WIDTHBYTES
  73. #define WIDTHBYTES(i)           ((unsigned)((i+31)&(~31))/8)  /* ULONG aligned ! */
  74. #endif
  75.  
  76. #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
  77. #define DibWidthBytes(lpbi)     DibWidthBytesN(lpbi, (lpbi)->biBitCount)
  78.  
  79. #define DibSizeImage(lpbi)      ((lpbi)->biSizeImage == 0 \
  80.                                     ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
  81.                                     : (lpbi)->biSizeImage)
  82.  
  83. #define DibNumColors(lpbi)      ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
  84.                                     ? (int)(1 << (int)(lpbi)->biBitCount)          \
  85.                                     : (int)(lpbi)->biClrUsed)
  86.  
  87. #define FixBitmapInfo(lpbi)     if ((lpbi)->biSizeImage == 0)                 \
  88.                                                 (lpbi)->biSizeImage = DibSizeImage(lpbi); \
  89.                                 if ((lpbi)->biClrUsed == 0)                   \
  90.                                     (lpbi)->biClrUsed = DibNumColors(lpbi);   \
  91.  
  92. #endif
  93.  
  94. #endif
  95.