home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM User 1995 January / CDuser6Jan95.iso / WING / DIB.H_ / DIB.H
C/C++ Source or Header  |  1994-06-19  |  5KB  |  121 lines

  1. /*
  2.  *    DIB.H
  3.  *
  4.  *    (C) Copyright Microsoft Corp. 1993.  All rights reserved.
  5.  *
  6.  *    You have a royalty-free right to use, modify, reproduce and 
  7.  *    distribute the Sample Files (and/or any modified version) in 
  8.  *    any way you find useful, provided that you agree that 
  9.  *    Microsoft has no warranty obligations or liability for any 
  10.  *    Sample Application Files which are modified. 
  11.  */
  12.  
  13.  
  14. #if defined(__cplusplus)
  15. extern "C" {
  16. #endif
  17.  
  18. /*----------------------------------------------------------------------------*\
  19. |   Routines for dealing with Device independent bitmaps                       |
  20. |                                           |
  21. \*----------------------------------------------------------------------------*/
  22.  
  23. typedef     LPBITMAPINFOHEADER PDIB;
  24. typedef     HANDLE             HDIB;
  25.  
  26. PDIB        DibOpenFile(LPSTR szFile);
  27. BOOL        DibWriteFile(PDIB pdib, LPSTR szFile);
  28. PDIB        DibReadBitmapInfo(HFILE fh);
  29. HPALETTE    DibCreatePalette(PDIB pdib);
  30. BOOL        DibSetUsage(PDIB pdib, HPALETTE hpal,UINT wUsage);
  31. BOOL        DibDraw(HDC hdc, int x, int y, int dx, int dy, PDIB pdib, int x0, int y0, int dx0, int dy0, LONG rop, UINT wUsage);
  32. PDIB        DibCreate(int bits, int dx, int dy);
  33. PDIB        DibCopy(PDIB pdib);
  34. void        DibMapToPalette(PDIB pdib, HPALETTE hpal);  
  35. PDIB         DibConvert(PDIB pdib, int BitCount, DWORD biCompression);
  36.  
  37. PDIB        DibFromBitmap(HBITMAP hbm, DWORD biStyle, UINT biBits, HPALETTE hpal, UINT wUsage);
  38. HBITMAP     BitmapFromDib(PDIB pdib, HPALETTE hpal, UINT wUsage);
  39.  
  40. void        MakeIdentityPalette(HPALETTE hpal); 
  41. HPALETTE    CopyPalette(HPALETTE hpal);
  42.  
  43. /****************************************************************************
  44.  DIB macros.
  45.  ***************************************************************************/
  46.  
  47. #ifdef  WIN32
  48.     #define HandleFromDib(lpbi) GlobalHandle(lpbi)
  49. #else
  50.     #define HandleFromDib(lpbi) (HANDLE)GlobalHandle(SELECTOROF(lpbi))
  51. #endif
  52.  
  53. #define DibFromHandle(h)        (PDIB)GlobalLock(h)
  54.  
  55. #define DibFree(pdib)           GlobalFreePtr(pdib)
  56.  
  57. #define WIDTHBYTES(i)           ((unsigned)((i+31)&(~31))/8)  /* ULONG aligned ! */
  58.  
  59. #define DibWidth(lpbi)          (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biWidth)
  60. #define DibHeight(lpbi)         (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biHeight)
  61. #define DibBitCount(lpbi)       (UINT)(((LPBITMAPINFOHEADER)(lpbi))->biBitCount)
  62. #define DibCompression(lpbi)    (DWORD)(((LPBITMAPINFOHEADER)(lpbi))->biCompression)
  63.  
  64. #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
  65. #define DibWidthBytes(lpbi)     DibWidthBytesN(lpbi, (lpbi)->biBitCount)
  66.  
  67. #define DibSizeImage(lpbi)      ((lpbi)->biSizeImage == 0 \
  68.                                     ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
  69.                                     : (lpbi)->biSizeImage)
  70.  
  71. #define DibSize(lpbi)           ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
  72. #define DibPaletteSize(lpbi)    (DibNumColors(lpbi) * sizeof(RGBQUAD))
  73.  
  74. #define DibFlipY(lpbi, y)       ((int)(lpbi)->biHeight-1-(y))
  75.  
  76. //HACK for NT BI_BITFIELDS DIBs
  77. #ifdef WIN32
  78.     #define DibPtr(lpbi)            ((lpbi)->biCompression == BI_BITFIELDS \
  79.                                        ? (LPVOID)(DibColors(lpbi) + 3) \
  80.                                        : (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed))
  81. #else
  82.     #define DibPtr(lpbi)            (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
  83. #endif
  84.  
  85. #define DibColors(lpbi)         ((RGBQUAD FAR *)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
  86.  
  87. #define DibNumColors(lpbi)      ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
  88.                                     ? (int)(1 << (int)(lpbi)->biBitCount)          \
  89.                                     : (int)(lpbi)->biClrUsed)
  90.  
  91. #define DibXYN(lpbi,pb,x,y,n)   (LPVOID)(                                     \
  92.                                 (BYTE _huge *)(pb) +                          \
  93.                                 (UINT)((UINT)(x) * (UINT)(n) / 8u) +          \
  94.                                 ((DWORD)DibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
  95.  
  96. #define DibXY(lpbi,x,y)         DibXYN(lpbi,DibPtr(lpbi),x,y,(lpbi)->biBitCount)
  97.  
  98. #define FixBitmapInfo(lpbi)     if ((lpbi)->biSizeImage == 0)                 \
  99.                                     (lpbi)->biSizeImage = DibSizeImage(lpbi); \
  100.                                 if ((lpbi)->biClrUsed == 0)                   \
  101.                                     (lpbi)->biClrUsed = DibNumColors(lpbi);   \
  102.                                 if ((lpbi)->biCompression == BI_BITFIELDS && (lpbi)->biClrUsed == 0) \
  103.                                     ; // (lpbi)->biClrUsed = 3;                    
  104.  
  105. #define DibInfo(pDIB) ((BITMAPINFO far *)(pDIB))
  106.  
  107. /****************************************************************************
  108.  ***************************************************************************/
  109.  
  110. #ifndef BI_BITFIELDS
  111.     #define BI_BITFIELDS 3
  112. #endif  
  113.  
  114. #ifndef HALFTONE
  115.     #define HALFTONE COLORONCOLOR
  116. #endif
  117.  
  118. #if defined(__cplusplus)
  119. }
  120. #endif
  121.