DIB.h
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:5k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   Dib.h
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Interface for the CDib class.
  11. *                       
  12. *                                                                             
  13. *   Authors: Eran Yariv - 28484475                                           
  14. *            Moshe Zur  - 24070856                                           
  15. *                                                                            
  16. *                                                                            
  17. *   Date: 23/09/98                                                           
  18. *                                                                            
  19. ******************************************************************************/
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Copyright (C) 1998 by Jorge Lodos
  22. // All rights reserved
  23. //
  24. // Distribute and use freely, except:
  25. // 1. Don't alter or remove this notice.
  26. // 2. Mark the changes you made
  27. //
  28. // Send bug reports, bug fixes, enhancements, requests, etc. to:
  29. //    lodos@cigb.edu.cu
  30. /////////////////////////////////////////////////////////////////////////////
  31. // dib.h
  32. #ifndef _INC_DIB
  33. #define _INC_DIB
  34. /* DIB constants */
  35. #define PALVERSION   0x300
  36. /* Dib Header Marker - used in writing DIBs to files */
  37. #define DIB_HEADER_MARKER   ((WORD) ('M' << 8) | 'B')
  38. /* DIB Macros*/
  39. #define RECTWIDTH(lpRect)     ((lpRect)->right - (lpRect)->left)
  40. #define RECTHEIGHT(lpRect)    ((lpRect)->bottom - (lpRect)->top)
  41. // WIDTHBYTES performs DWORD-aligning of DIB scanlines.  The "bits"
  42. // parameter is the bit count for the scanline (biWidth * biBitCount),
  43. // and this macro returns the number of DWORD-aligned bytes needed
  44. // to hold those bits.
  45. #define WIDTHBYTES(bits)    (((bits) + 31) / 32 * 4)
  46. typedef BYTE PIXEL, *PPIXEL;
  47. class CDIB : public CObject
  48. {
  49.     DECLARE_DYNAMIC(CDIB)
  50. // Constructors
  51. public:
  52.     CDIB();
  53. // Attributes
  54.     LPBYTE m_pBits;
  55.     LPBITMAPINFO m_pBMI;
  56.     CPalette* m_pPalette;
  57.     DWORD           Width()     const;
  58.     DWORD           Height()    const;
  59.     CSize           Size()      const;
  60.     WORD            NumColors() const;
  61.     BOOL            IsValid()   const;
  62. // Operations
  63.     BOOL            ReadFromResource (UINT);
  64.     PIXEL&          ColorAt (UINT uX, UINT uY);
  65.     void            FillSolidColor (BYTE R, BYTE G, BYTE B);
  66.     void            FillRect (int x, int y, int w, int h, int R, int G, int B );
  67.     BOOL            CreateEmpty (UINT uXSize, UINT uYSize);
  68.     BOOL            CreateRotated (
  69.                         CDIB *pSrc, 
  70.                         UINT uAngle /* 0, 90, 180 or 270 only */, 
  71.                         BOOL bFlipHoriz, 
  72.                         BOOL bFlipVert);
  73.     BOOL            Paint(CDC *pDC, LPRECT p1=NULL, LPRECT p2=NULL) const;
  74.     HGLOBAL         CopyToHandle();
  75.     DWORD           Save(CFile& file);
  76.     DWORD           Read(CFile& file);
  77.     DWORD           ReadFromHandle(HGLOBAL hGlobal);
  78.     BOOL            CopyFrom (CDIB *pSrc);
  79.     BOOL            CopyPalette (CDIB *pSrc);
  80.     BOOL            CopyPalette (CPalette *pSrc);
  81.     BOOL            GetPaletteFromResourceBitmap (UINT uResID);
  82.     void            PasteCKRect (   CDIB *Dib, 
  83.                                     int x, 
  84.                                     int y, 
  85.                                     PIXEL ColorKey);
  86.     BOOL            CopyRectFrom (  CDIB *pSrcDIB, 
  87.                                     int SrcX, 
  88.                                     int SrcY, 
  89.                                     UINT SrcWidth, 
  90.                                     UINT SrcHeight,
  91.                                     int DstX, int DstY); 
  92.     void            Invalidate();
  93.     virtual void    Serialize(CArchive& ar);
  94. // Implementation
  95.     virtual         ~CDIB();
  96. protected:
  97.     BOOL            CreatePalette();
  98.     DWORD           CalcImageSize();
  99.     WORD            PaletteSize()               const;
  100.     void            Free();
  101.     PPIXEL          FindPixel(UINT x, UINT y)   const;
  102. public:
  103. #ifdef _DEBUG
  104.     virtual void    Dump(CDumpContext& dc)      const;
  105. #endif
  106. };
  107. #include "dib.inl"
  108. #endif //!_INC_DIB