home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / misc / vfwdk / samples / icmapp / dib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-31  |  3.6 KB  |  71 lines

  1. /*----------------------------------------------------------------------------*\
  2. |
  3. |   DIB.H
  4. |
  5. |   Routines for dealing with Device independent bitmaps                       
  6. |
  7. |    (C) Copyright Microsoft Corp. 1991, 1992, 1993.  All rights reserved.
  8. |
  9. |    You have a royalty-free right to use, modify, reproduce and
  10. |    distribute the Sample Files (and/or any modified version) in
  11. |    any way you find useful, provided that you agree that
  12. |    Microsoft has no warranty obligations or liability for any
  13. |    Sample Application Files.
  14. |
  15. \*----------------------------------------------------------------------------*/
  16.  
  17. typedef HANDLE HDIB;
  18.  
  19. HDIB        ReadDibBitmapInfo   (int fh);
  20. HDIB        OpenDIB             (LPSTR szFile);
  21. BOOL        WriteDIB            (LPSTR szFile,HDIB hdib);
  22. HPALETTE    CreateBIPalette     (LPBITMAPINFOHEADER lpbi);
  23. HDIB        DibFromBitmap       (HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal, WORD wUsage);
  24. HBITMAP     BitmapFromDib       (HDIB hdib, HPALETTE hpal, WORD wUsage);
  25. BOOL        SetDibUsage         (HDIB hdib, HPALETTE hpal,WORD wUsage);
  26. HDIB        CreateDib           (int bits, int dx, int dy);
  27. BOOL        StretchDib          (HDC hdc, int x, int y, int dx, int dy, HDIB hdib, HPALETTE hpal, int x0, int y0, int dx0, int dy0, LONG rop, WORD wUsage);
  28. HDIB        CopyDib             (HDIB hdib);
  29. HDIB        CopyPalette         (HPALETTE hpal);
  30.  
  31. /*----------------------------------------------------------------------------*\
  32. |   Macros                                                                     |
  33. \*----------------------------------------------------------------------------*/
  34.  
  35. #define DrawDib(hdc,x,y,hdib,hpal,wUsage)  StretchDib(hdc,x,y,-1,-1,hdib,hpal,0,0,-1,-1,SRCCOPY,wUsage)
  36. #define CreateDibPalette(hdib)  CreateBIPalette(GlobalLock(hdib))
  37.  
  38. #define ALIGNULONG(i)           ((i+3)/4*4)        /* ULONG aligned ! */
  39. #define WIDTHBYTES(i)           ((unsigned)((i+31)&(~31))/8)  /* ULONG aligned ! */
  40.  
  41. #define DIBWIDTHBYTES(bi)       DibWidthBytes(&bi)
  42.  
  43. #define DibWidthBytesN(lpbi, n) (UINT)WIDTHBYTES((UINT)(lpbi)->biWidth * (UINT)(n))
  44. #define DibWidthBytes(lpbi)     DibWidthBytesN(lpbi, (lpbi)->biBitCount)
  45.  
  46. #define DibSizeImage(lpbi)      ((lpbi)->biSizeImage == 0 \
  47.                                     ? ((DWORD)(UINT)DibWidthBytes(lpbi) * (DWORD)(UINT)(lpbi)->biHeight) \
  48.                                     : (lpbi)->biSizeImage)
  49.  
  50. #define DibSize(lpbi)           ((lpbi)->biSize + (lpbi)->biSizeImage + (int)(lpbi)->biClrUsed * sizeof(RGBQUAD))
  51.  
  52. #define DibPtr(lpbi)            (LPVOID)(DibColors(lpbi) + (UINT)(lpbi)->biClrUsed)
  53. #define DibColors(lpbi)         ((LPRGBQUAD)((LPBYTE)(lpbi) + (int)(lpbi)->biSize))
  54.  
  55. #define DibNumColors(lpbi)      ((lpbi)->biClrUsed == 0 && (lpbi)->biBitCount <= 8 \
  56.                                     ? (int)(1 << (int)(lpbi)->biBitCount)          \
  57.                                     : (int)(lpbi)->biClrUsed)
  58.  
  59. #define DibXYN(lpbi,pb,x,y,n)   (LPVOID)(                                     \
  60.                                 (PBYTE)(pb) +                                 \
  61.                                 (UINT)((UINT)(x) * (UINT)(n) / 8u) +          \
  62.                                 ((DWORD)DibWidthBytesN(lpbi,n) * (DWORD)(UINT)(y)))
  63.  
  64. #define DibXY(lpbi,x,y)         DibXYN(lpbi,DibPtr(lpbi),x,y,(lpbi)->biBitCount)
  65.  
  66.  
  67. #define FixBitmapInfo(lpbi)     if ((lpbi)->biSizeImage == 0)                 \
  68.                                     (lpbi)->biSizeImage = DibSizeImage(lpbi); \
  69.                                 if ((lpbi)->biClrUsed == 0)                   \
  70.                                     (lpbi)->biClrUsed = DibNumColors(lpbi);
  71.