Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.5 KiB

  1. // cdib.h
  2. #ifndef _INC_DIB
  3. #define _INC_DIB
  4. #define BMP_IMAGE 0
  5. #define TIFF_IMAGE 1
  6. //////////////////////////////////////////
  7. //////// DIB/BMP HEADER DEFINES //////////
  8. //////////////////////////////////////////
  9. #define PALVERSION 0x300
  10. #define DIB_HEADER_MARKER ((WORD) ('M' << 8) | 'B')
  11. // macros
  12. #define RECTWIDTH(lpRect) ((lpRect)->right - (lpRect)->left)
  13. #define RECTHEIGHT(lpRect) ((lpRect)->bottom - (lpRect)->top)
  14. // WIDTHBYTES performs DWORD-aligning of DIB scanlines. The "bits"
  15. // parameter is the bit count for the scanline (biWidth * biBitCount),
  16. // and this macro returns the number of DWORD-aligned bytes needed
  17. // to hold those bits.
  18. #define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
  19. //////////////////////////////////////////
  20. //////////////////////////////////////////
  21. //////////////////////////////////////////
  22. ////////// TIFF HEADER DEFINES ///////////
  23. //////////////////////////////////////////
  24. typedef struct TIFFFILEHEADERtag {
  25. char tfByteOrder[2];
  26. short tfType;
  27. long tfOffset;
  28. }TIFFFILEHEADER;
  29. typedef struct TIFFTAGtag {
  30. short ttTag;
  31. short ttType;
  32. long ttCount;
  33. long ttOffset;
  34. }TIFFTAG;
  35. #define TIFFBYTE unsigned int
  36. #define TIFFASCII char*
  37. typedef struct TIFFRATIONALtag {
  38. long trNumerator;
  39. long trDenominator;
  40. }TIFFRATIONAL;
  41. typedef struct TIFFTODIBDATAtag {
  42. BITMAPINFOHEADER bmiHeader;
  43. TIFFRATIONAL xResolution;
  44. TIFFRATIONAL yResolution;
  45. long ResolutionUnit;
  46. long RowsPerStrip;
  47. long StripOffsets;
  48. long StripByteCounts;
  49. long ColorsUsed;
  50. char Software[30];
  51. char Author[30];
  52. char Description[30];
  53. long CompressionType;
  54. long *pStripOffsets;
  55. long *pStripByteCountsOffsets;
  56. int OffsetCount;
  57. }TIFFTODIBDATA;
  58. #define TIFF_NEWSUBFILETYPE 254 // long
  59. #define TIFF_IMAGEWIDTH 256 // short or long
  60. #define TIFF_LENGTH 257 // short or long
  61. #define TIFF_BITSPERSAMPLE 258 // short
  62. #define TIFF_COMPRESSION 259 // short
  63. #define TIFF_PHOTOINTERP 262 // short
  64. #define TIFF_IMAGEDESCRIPTION 270 // ASCII
  65. #define TIFF_STRIPOFFSETS 273 // short or long
  66. #define TIFF_ORIENTATION 274 // short
  67. #define TIFF_SAMPLESPERPIXEL 277 // short
  68. #define TIFF_ROWSPERSTRIP 278 // short or long
  69. #define TIFF_STRIPBYTECOUNTS 279 // short or long
  70. #define TIFF_XRESOLUTION 282 // TIFFRATIONAL
  71. #define TIFF_YRESOLUTION 283 // TIFFRATIONAL
  72. #define TIFF_RESOLUTIONUNIT 296 // short
  73. #define TIFF_SOFTWARE 305 // ASCII
  74. //////////////////////////////////////////
  75. //////////////////////////////////////////
  76. class CDib : public CObject
  77. {
  78. DECLARE_DYNAMIC(CDib)
  79. // Constructors
  80. public:
  81. CDib();
  82. int change;
  83. // Attributes
  84. protected:
  85. LPBYTE m_pBits;
  86. LPBITMAPINFO m_pBMI;
  87. public:
  88. CPalette* m_pPalette;
  89. public:
  90. DWORD Width() const;
  91. DWORD Height() const;
  92. WORD NumColors() const;
  93. BOOL IsValid() const { return (m_pBMI != NULL); }
  94. // Operations
  95. public:
  96. BOOL Paint(HDC, LPRECT, LPRECT) const;
  97. HGLOBAL CopyToHandle() const;
  98. DWORD Save(CFile& file) const;
  99. DWORD Read(CFile& file,int FileType);
  100. DWORD ReadFromHandle(HGLOBAL hGlobal);
  101. void Invalidate() { Free(); }
  102. virtual void Serialize(CArchive& ar);
  103. // Implementation
  104. public:
  105. virtual ~CDib();
  106. protected:
  107. BOOL CreatePalette();
  108. WORD PaletteSize() const;
  109. void Free();
  110. BOOL Flip(BYTE* pSrcData);
  111. public:
  112. void ReadFromTIFFFile(CString filename);
  113. void ReadFromBMPFile(LPSTR filename);
  114. void ReadFromBMPFile(CString filename);
  115. BOOL GotImage();
  116. BOOL ReadFromHGLOBAL(HGLOBAL hGlobal,int FileType);
  117. #ifdef _DEBUG
  118. virtual void Dump(CDumpContext& dc) const;
  119. #endif
  120. protected:
  121. CDib& operator = (CDib& dib);
  122. };
  123. #endif //!_INC_DIB