win32dib.c
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:17k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. // Swarm library. Copyright (C) 1996-2000 Swarm Development Group.
  2. // This library is distributed without any warranty; without even the
  3. // implied warranty of merchantability or fitness for a particular purpose.
  4. // See file LICENSE for details and terms of copying.
  5. #include "win32dib.h"
  6. #ifdef _WIN32
  7. #include <windows.h>
  8. #define BOOL w32BOOL
  9. #include <misc.h>
  10. #undef BOOL
  11. dib_t *
  12. dib_create (void)
  13. {
  14.   dib_t *dib = xmalloc (sizeof (dib_t));
  15.   
  16.   dib->window = NULL;
  17.   dib->colormapBlocks = 0;
  18.   dib->colormapSize = 0;
  19.   dib->colormap = NULL;
  20.   memset (dib->colormapOffsets, 0, sizeof (dib->colormapOffsets));
  21.   memset (dib->colormapObjects, 0, sizeof (dib->colormapObjects));
  22.   dib->sourceDC = NULL;
  23.   dib->destDC = NULL;
  24.   dib->dibInfo = xmalloc (sizeof (CDIB_BITMAP));
  25.   dib->bitmap = NULL;
  26.   dib->oldBitmap = NULL;
  27.   dib->bits = NULL;
  28.   dib->palette = NULL;
  29.   dib->oldPalette = NULL;
  30.   dib->xBitmapOffset = 0;
  31.   dib->yBitmapOffset = 0;
  32.   return dib;
  33. }
  34. void
  35. dib_destroy (dib_t *dib)
  36. {
  37.   XFREE (dib->dibInfo);
  38.   dib->dibInfo = NULL;
  39.   if (dib->colormap)
  40.     XFREE (dib->colormap);
  41.   if (dib->bitmap)
  42.     {
  43.       if (dib->window)
  44.         {
  45.           HDC hdc = GetDC (dib->window);
  46.           SelectObject (hdc, dib->oldBitmap);
  47.           DeleteObject (dib->bitmap);
  48.           ReleaseDC (dib->window, hdc);
  49.         }
  50.       else
  51.         {
  52.           HDC hdc = CreateCompatibleDC (NULL);
  53.           SelectObject (hdc, dib->oldBitmap);
  54.           DeleteObject (dib->bitmap);
  55.           DeleteDC (hdc);
  56.         }
  57.     }
  58.   else if (dib->bits != NULL)
  59.     XFREE (dib->bits);
  60.   dib->bitmap = NULL;
  61.   dib->oldBitmap = NULL;
  62.   dib->bits = NULL;
  63.   if (dib->palette)
  64.     {
  65.       DeleteObject (dib->palette);
  66.       dib->palette = NULL;
  67.     }
  68.   dib->oldPalette = NULL;
  69.   if (dib->sourceDC)
  70.     {
  71.       DeleteDC (dib->sourceDC);
  72.       dib->sourceDC = NULL;
  73.     }
  74.   if (dib->destDC)
  75.     {
  76.       if (dib->window)
  77.         ReleaseDC (dib->window, dib->destDC);
  78.       else
  79.         DeleteDC (dib->destDC);
  80.       dib->destDC = NULL;
  81.     }
  82.   dib->window = NULL;
  83.   dib->xBitmapOffset = 0;
  84.   dib->yBitmapOffset = 0;
  85. }
  86. void
  87. dib_createBitmap (dib_t *dib, HWND window, unsigned width, unsigned height)
  88. {
  89.   HDC hdc;
  90.   if (window)
  91.     hdc = GetDC (window);
  92.   else
  93.     hdc = CreateCompatibleDC (NULL);
  94.   
  95.   dib->window = window;
  96.   if (width & 3)
  97.     width += 4 - (width & 3);
  98.   dib->dibInfo->bmiHead.biSize = sizeof (BITMAPINFOHEADER);
  99.   dib->dibInfo->bmiHead.biWidth = width;
  100.   if (TOP_DOWN_DIB)
  101.     dib->dibInfo->bmiHead.biHeight = -height;
  102.   else
  103.     dib->dibInfo->bmiHead.biHeight = height;
  104.   dib->dibInfo->bmiHead.biPlanes = 1;
  105.   dib->dibInfo->bmiHead.biBitCount = 24;
  106.   dib->dibInfo->bmiHead.biCompression = BI_RGB;
  107.   dib->dibInfo->bmiHead.biSizeImage = 0;
  108.   dib->dibInfo->bmiHead.biClrUsed = 0;
  109.   dib->dibInfo->bmiHead.biClrImportant = 0;
  110.   dib->bitmap = CreateDIBSection (hdc,
  111.   (BITMAPINFO *) dib->dibInfo,
  112.   DIB_RGB_COLORS,
  113.   &dib->bits,
  114.   NULL,
  115.   0 /* ignored if above is NULL */ );
  116.   if (window)
  117.     ReleaseDC (window, hdc);
  118.   else
  119.     DeleteDC (hdc);
  120. }
  121. #define SNAPSHOTPALETTE ((void *)0xdeaf)
  122. void
  123. dib_snapshot (dib_t *dib, BOOL windowDCFlag)
  124. {
  125.   HDC hdc = windowDCFlag ? GetWindowDC (dib->window) : GetDC (dib->window);
  126.   HDC hmemdc = CreateCompatibleDC (hdc);
  127.   HDC hbmmem;
  128.   RECT rect;
  129.   unsigned width, height, newWidth;
  130.   int caps;
  131.   HGDIOBJ hb1;
  132.   HPALETTE holdPal = NULL;
  133.   unsigned pixelCount, bufsize;
  134.   LPBYTE bits;
  135.   WORD depth;
  136.   LPBITMAPINFOHEADER pbmp = &dib->dibInfo->bmiHead;
  137.   LOGPALETTE *plp = NULL;
  138.   depth = (GetDeviceCaps (hdc, BITSPIXEL) <= 8) ? 8 : 24;
  139.   GetWindowRect (dib->window, &rect);
  140.   dib->bitmap = NULL;
  141.   if (dib->window == HWND_DESKTOP)
  142.     {
  143.       height = GetDeviceCaps (hdc, VERTRES);
  144.       width = GetDeviceCaps (hdc, HORZRES);
  145.     }
  146.   else
  147.     {
  148.       height = rect.bottom - rect.top;
  149.       width = rect.right - rect.left;
  150.     }
  151.   if (width & 3)
  152.     newWidth = width + 4 - (width & 3);
  153.   else
  154.     newWidth = width;
  155.   hbmmem = CreateCompatibleBitmap (hdc, newWidth, height);
  156.   hb1 = SelectObject (hmemdc, hbmmem);
  157.   caps = GetDeviceCaps (hdc, RASTERCAPS);
  158.   if (caps & RC_PALETTE)
  159.     {
  160.       UINT cnt;
  161.       HPALETTE hpal;
  162.       
  163.       cnt = GetDeviceCaps (hdc, SIZEPALETTE);
  164.       plp = xmalloc (sizeof (LOGPALETTE) + sizeof (PALETTEENTRY) * cnt);
  165.       plp->palVersion = 0x0300;
  166.       plp->palNumEntries = cnt;
  167.       cnt = GetSystemPaletteEntries (hdc, 0, cnt, plp->palPalEntry);
  168.       if (cnt == 0)
  169. abort ();
  170.       hpal = CreatePalette (plp);
  171.       SelectPalette (hmemdc, hpal, FALSE);
  172.       holdPal = SelectPalette (hdc, hpal, FALSE);
  173.     }
  174.   if (BitBlt (hmemdc, 0, 0, width, height, hdc, 0, 0, SRCCOPY) == FALSE)
  175.     abort ();
  176.   pixelCount = newWidth * height;
  177.   bufsize = pixelCount * (depth >> 3);
  178.   pbmp->biSize = sizeof (BITMAPINFOHEADER);
  179.   pbmp->biWidth = newWidth;
  180.   pbmp->biHeight = -height;
  181.   pbmp->biPlanes = 1;
  182.   pbmp->biBitCount = depth;
  183.   pbmp->biCompression = BI_RGB;
  184.   bits = xmalloc (bufsize);
  185.   hbmmem = SelectObject (hmemdc, hb1);
  186.   if (depth == 8)
  187.     {
  188.       if (GetDIBits (hmemdc, hbmmem, 0, height,
  189.      bits,
  190.                      (LPBITMAPINFO) pbmp,
  191.                      DIB_PAL_COLORS) != (int) height)
  192. abort ();
  193.       
  194.       {
  195. unsigned i;
  196. BYTE max = 0;
  197. LPBYTE colors = (PVOID) pbmp + sizeof (BITMAPINFOHEADER);
  198. LPBYTE pixels = bits;
  199. for (i = 0; i < pixelCount; i++)
  200.   if (pixels[i] > max)
  201.     max = pixels[i];
  202. {
  203.   unsigned colorCount = max + 1;
  204.   unsigned long map[colorCount];
  205.         
  206.   for (i = 0; i < colorCount; i++)
  207.             {
  208.               PALETTEENTRY *pe = &plp->palPalEntry[i];
  209.               
  210.               map[i] = (pe->peRed) | (pe->peGreen << 8) | (pe->peBlue << 16);
  211.             }
  212.   dib_augmentPalette (dib, SNAPSHOTPALETTE, colorCount, map);
  213. }
  214.       }
  215.     }
  216.   else if (depth == 24)
  217.     {
  218.       if (GetDIBits (hmemdc, hbmmem, 0, height,
  219.      bits,
  220.                      (LPBITMAPINFO) pbmp,
  221.                      DIB_RGB_COLORS) != (int) height)
  222. abort ();
  223.     }
  224.   else
  225.     abort ();
  226.   DeleteObject (hbmmem);
  227.   dib->bits = bits;
  228.   if (holdPal)
  229.     SelectObject (hdc, holdPal);
  230.   if (plp)
  231.     XFREE (plp);
  232.   ReleaseDC (dib->window, hdc);
  233.   DeleteDC (hmemdc);
  234. }
  235. int
  236. dib_paletteIndexForObject (dib_t *dib, void *object)
  237. {
  238.   unsigned i;
  239.   for (i = 0; i < dib->colormapBlocks; i++)
  240.     if (object == dib->colormapObjects[i])
  241.       return i;
  242.   return -1;
  243. }
  244. void
  245. dib_get_color (dib_t *dib, void *object, unsigned color, BYTE *red, BYTE *green, BYTE *blue)
  246. {
  247.   WORD depth = dib->dibInfo->bmiHead.biBitCount;
  248.   
  249.   if (depth == 8)
  250.     {
  251.       RGBQUAD *rgb = &dib->dibInfo->rgb[color];
  252.       *red = rgb->rgbRed;
  253.       *green = rgb->rgbGreen;
  254.       *blue = rgb->rgbBlue;
  255.     }
  256.   else if (depth == 24)
  257.     {
  258.       unsigned colorValue;
  259.       int index = dib_paletteIndexForObject (dib, object);
  260.       unsigned colorOffset = (index == -1) ? 0 : dib->colormapOffsets[index];
  261.       if (colorOffset + color < dib->colormapSize)
  262.         colorValue = dib->colormap[colorOffset + color];
  263.       else
  264.         {
  265. #if 0
  266.           fprintf (stderr, "color %u out of range (>= %u + %u = %un",
  267.                    color, colorOffset, color, dib->colormapSize);
  268. #endif
  269.           colorValue = 0;
  270.         }
  271.       *blue = colorValue >> 16;
  272.       *green = (colorValue >> 8) & 0xff;
  273.       *red = colorValue & 0xff;
  274.     }
  275.   else
  276.     abort ();
  277. }
  278. void
  279. dib_augmentPalette (dib_t *dib,
  280.     void *object,
  281.     unsigned colormapSize,
  282.     unsigned long *colormap)
  283. {
  284.   unsigned lastSize = dib->colormapSize;
  285.   WORD depth = dib->dibInfo->bmiHead.biBitCount;
  286.   unsigned bi;
  287.   for (bi = 0; bi < dib->colormapBlocks; bi++)
  288.     if (object == dib->colormapObjects[bi])
  289.       break;
  290.   if (bi < dib->colormapBlocks)
  291.     {
  292.       unsigned offset = dib->colormapOffsets[bi];
  293.       unsigned next = ((bi == dib->colormapBlocks - 1)
  294.        ? dib->colormapSize
  295.        : dib->colormapOffsets[bi + 1]);
  296.       unsigned size = next - offset;
  297.       if (size == dib->colormapSize)
  298. {
  299.   unsigned i;
  300.   for (i = 0; i < size; i++)
  301.     if (dib->colormap[i + offset] != colormap[i])
  302.       break;
  303.   if (i == size)
  304.     return;
  305. }
  306.     }
  307.   
  308.   dib->colormapObjects[bi] = object;
  309.   dib->colormapOffsets[bi] = lastSize;
  310.   dib->colormapSize += colormapSize;
  311.   dib->colormapBlocks++;
  312.   
  313.   if (depth == 8)
  314.     {
  315.       unsigned i;
  316.       RGBQUAD *rgb = &dib->dibInfo->rgb[lastSize];
  317.       
  318.       for (i = 0; i < colormapSize; i++)
  319.         {
  320.           rgb[i].rgbRed = colormap[i] & 0xff;
  321.           rgb[i].rgbGreen = (colormap[i] & 0xff00) >> 8;
  322.           rgb[i].rgbBlue = (colormap[i] & 0xff0000) >> 16;
  323.         }  
  324.       if (dib->bitmap)
  325. {
  326.   HDC shdc = CreateCompatibleDC (NULL);
  327.   UINT ret;
  328.   
  329.   dib->oldBitmap = SelectObject (shdc, dib->bitmap);
  330.   ret = SetDIBColorTable (shdc, 0, dib->colormapSize,
  331.   dib->dibInfo->rgb);
  332.   SelectObject (shdc, dib->oldBitmap);
  333.   DeleteDC (shdc);
  334. }
  335.     }
  336.   else if (depth == 24)
  337.     {
  338.       unsigned long *newcolormap;
  339.       unsigned i;
  340.       unsigned newSize = dib->colormapSize * sizeof (unsigned long);
  341.       
  342.       dib->colormap = dib->colormap
  343. ? xrealloc (dib->colormap, newSize)
  344. : xmalloc (newSize);
  345.       newcolormap = &dib->colormap[lastSize];
  346.       
  347.       for (i = 0; i < colormapSize; i++)
  348. newcolormap[i] = colormap[i];
  349.     }
  350. }
  351. void
  352. dib_fill (dib_t *dib,
  353.   int x, int y,
  354.   unsigned width, unsigned height,
  355.   void *object,
  356.   unsigned color)
  357. {
  358.   unsigned frameWidth = dib->dibInfo->bmiHead.biWidth;
  359.   unsigned frameHeight = (dib->dibInfo->bmiHead.biHeight < 0
  360.   ? -dib->dibInfo->bmiHead.biHeight
  361.   : dib->dibInfo->bmiHead.biHeight);
  362.   unsigned yoff;
  363.   int wdiff, hdiff;
  364.   int clipx, clipy;
  365.   WORD depth = dib->dibInfo->bmiHead.biBitCount;
  366.   unsigned row_width;
  367.   if (x < 0)
  368.     {
  369.       if (-x > (int)width)
  370.         return;
  371.       width -= (-x);
  372.       clipx = 0;
  373.     }
  374.   else if (x > (int)frameWidth)
  375.     return;
  376.   else clipx = x;
  377.   if (y < 0)
  378.     {
  379.       if (-y > (int)height)
  380.         return;
  381.       height -= (-y);
  382.       clipy = 0;
  383.     }
  384.   else if (y > (int)frameHeight)
  385.     return;
  386.   else clipy = y;
  387.   wdiff = clipx + width - frameWidth;
  388.   if (wdiff > 0)
  389.     width -= wdiff;
  390.   hdiff = clipy + height - frameHeight;
  391.   if (hdiff > 0)
  392.     height -= hdiff;
  393.    
  394.   if (frameWidth & 3)
  395.     frameWidth += 4 - (frameWidth & 3);
  396.   row_width = frameWidth * ((depth == 24) ? 3 : 1);
  397.       
  398.   if (row_width & 3)
  399.     row_width += 4 - (row_width & 3);
  400.   if (depth == 8)
  401.     {
  402.       LPBYTE base = (LPBYTE) dib->bits + (clipy * row_width);
  403.       for (yoff = 0; yoff < height; yoff++)
  404. {
  405.   unsigned xoff;
  406.   LPBYTE ybase = &base[yoff * row_width + clipx];
  407.   
  408.   for (xoff = 0; xoff < width; xoff++)
  409.     ybase[xoff] =  color;
  410. }
  411.     }
  412.   else if (depth == 24)
  413.     {
  414.       LPBYTE base = ((LPBYTE) dib->bits) + (clipy * row_width);
  415.       BYTE red, green, blue;
  416.       unsigned fsize = frameWidth * 3;
  417.       if (fsize & 3)
  418. fsize += (4 - (fsize & 3));
  419.       dib_get_color (dib, object, color, &red, &green, &blue);
  420.       for (yoff = 0; yoff < height; yoff++)
  421. {
  422.   unsigned xoff;
  423.   LPBYTE ybase = base + ((yoff * fsize) + (clipx * 3));
  424.   for (xoff = 0; xoff < width; xoff++)
  425.     {
  426.       LPBYTE xbase = ybase + xoff * 3;
  427.       xbase[0] = blue;
  428.       xbase[1] = green;
  429.       xbase[2] = red;
  430.     }
  431. }
  432.     }
  433.   else
  434.     abort ();
  435. }
  436. void
  437. dib_ellipse (dib_t *dib,
  438.      int x, int y,
  439.      unsigned width, unsigned height,
  440.      unsigned pixels,
  441.      void *object,
  442.      unsigned color)
  443. {
  444.   HPEN oldPen, pen;
  445.   HBRUSH oldBrush;
  446.   BYTE red, green, blue;
  447.   dib_get_color (dib, object, color, &red, &green, &blue);
  448.   pen = CreatePen (PS_SOLID, pixels, RGB (red, green, blue));
  449.   dib_lock (dib);
  450.   
  451.   oldPen = SelectObject (dib->sourceDC, pen);
  452.   oldBrush = SelectObject (dib->sourceDC, GetStockObject (NULL_BRUSH));
  453.   Ellipse (dib->sourceDC, x, y, x + width, y + height);
  454.   
  455.   DeleteObject (SelectObject (dib->sourceDC, oldPen));
  456.   SelectObject (dib->sourceDC, oldBrush);
  457.   dib_unlock (dib);
  458. }
  459. void
  460. dib_line (dib_t *dib,
  461.           int x0, int y0,
  462.           int x1, int y1,
  463.           unsigned pixels,
  464.   void *object,
  465.           unsigned color)
  466. {
  467.   HPEN oldPen, pen;
  468.   HBRUSH oldBrush;
  469.   BYTE red, green, blue;
  470.   dib_get_color (dib, object, color, &red, &green, &blue);
  471.   pen = CreatePen (PS_SOLID, pixels, RGB (red, green, blue));
  472.   dib_lock (dib);
  473.   
  474.   oldPen = SelectObject (dib->sourceDC, pen);
  475.   oldBrush = SelectObject (dib->sourceDC, GetStockObject (NULL_BRUSH));
  476.   MoveToEx (dib->sourceDC, x0, y0, NULL);
  477.   LineTo (dib->sourceDC, x1, y1);
  478.   
  479.   DeleteObject (SelectObject (dib->sourceDC, oldPen));
  480.   SelectObject (dib->sourceDC, oldBrush);
  481.   dib_unlock (dib);
  482. }
  483. void
  484. dib_rectangle (dib_t *dib,
  485.                int x, int y,
  486.                unsigned width, unsigned height,
  487.                unsigned pixels,
  488.        void *object,
  489.                unsigned color)
  490. {
  491.   HPEN oldPen, pen;
  492.   HBRUSH oldBrush;
  493.   BYTE red, green, blue;
  494.   dib_get_color (dib, object, color, &red, &green, &blue);
  495.   pen = CreatePen (PS_SOLID, pixels, RGB (red, green, blue));
  496.   dib_lock (dib);
  497.   
  498.   oldPen = SelectObject (dib->sourceDC, pen);
  499.   oldBrush = SelectObject (dib->sourceDC, GetStockObject (NULL_BRUSH));
  500.   Rectangle (dib->sourceDC, x, y, x + width, y + height);
  501.   
  502.   DeleteObject (SelectObject (dib->sourceDC, oldPen));
  503.   SelectObject (dib->sourceDC, oldBrush);
  504.   dib_unlock (dib);
  505. }
  506. BOOL
  507. dib_paintBlit (dib_t *dib,
  508.        HDC destDC,
  509.        int destX, int destY,
  510.        int sourceX, int sourceY,
  511.        unsigned sourceWidth, unsigned sourceHeight)
  512. {
  513.   unsigned frameWidth = dib->dibInfo->bmiHead.biWidth;
  514.   int diff;
  515.   diff = (destX + sourceWidth) - frameWidth;
  516.   if (diff > 0)
  517.     sourceWidth -= diff;
  518.   GdiFlush ();
  519.   {
  520.     /* Lock */
  521.     HDC sourceDC = CreateCompatibleDC (destDC);
  522.     dib->oldBitmap = SelectObject (sourceDC, dib->bitmap);
  523.     
  524.     /* Blit */
  525.     {
  526.       BOOL result;
  527.       
  528.       SelectPalette (destDC, dib->palette, FALSE);
  529.       RealizePalette (destDC);
  530.       result = BitBlt (destDC, 
  531.        destX, destY,
  532.        sourceWidth, sourceHeight,
  533.        sourceDC, 
  534.        sourceX + dib->xBitmapOffset,
  535.        sourceY + dib->yBitmapOffset,
  536.        SRCCOPY);
  537.       
  538.       /* Unlock */
  539.       SelectObject (sourceDC, dib->oldBitmap);
  540.       DeleteDC (sourceDC);
  541.       
  542.       return result;
  543.     }
  544.   }
  545. }
  546. void
  547. dib_copy_metadata (dib_t *source, dib_t *dest)
  548. {
  549.   memcpy (dest->dibInfo, source->dibInfo, sizeof (CDIB_BITMAP));
  550.   dest->colormapBlocks = source->colormapBlocks;
  551.   dest->colormapSize = source->colormapSize;
  552.   if (source->colormap)
  553.     {
  554.       size_t size = source->colormapSize * sizeof (unsigned long);
  555.       dest->colormap = xmalloc (size);
  556.       memcpy (dest->colormap, source->colormap, size);
  557.     }
  558.   else
  559.     dest->colormap = NULL;
  560.   memcpy (dest->colormapOffsets,
  561.   source->colormapOffsets,
  562.   sizeof (source->colormapOffsets));
  563.   memcpy (dest->colormapObjects,
  564.   source->colormapObjects,
  565.   sizeof (source->colormapObjects));
  566.   memcpy (dest->dibInfo->rgb,
  567.   source->dibInfo->rgb,
  568.   sizeof (RGBQUAD) * source->colormapSize);
  569. #if 0
  570.   {
  571.     HDC shdc = CreateCompatibleDC (NULL);
  572.     
  573.     dest->oldBitmap = SelectObject (shdc, dest->bitmap);
  574.     SetDIBColorTable (shdc, 0, dest->colormapSize, dest->dibInfo->rgb);
  575.     SelectObject (shdc, dest->oldBitmap);
  576.     DeleteDC (shdc);
  577.   }
  578. #endif
  579. }
  580. BOOL
  581. dib_copy (dib_t *source, dib_t *dest,
  582.           int destx, int desty,
  583.           unsigned width, unsigned height)
  584. {
  585.   BOOL result;
  586.   if (dib_lock (dest) == NULL)
  587.     return FALSE;
  588.   if (dib_lock (source) == NULL)
  589.     return FALSE;
  590.   result = BitBlt (dest->sourceDC, destx, desty,
  591.    width, height,
  592.    source->sourceDC, 0, 0,
  593.    SRCCOPY);
  594.   dib_unlock (source);
  595.   dib_unlock (dest);
  596.   return result;
  597. }
  598. LPBYTE
  599. dib_lock (dib_t *dib)
  600. {
  601.   GdiFlush ();
  602.   
  603.   dib->destDC = GetDC (dib->window);
  604.   dib->sourceDC = CreateCompatibleDC (dib->destDC);
  605.   dib->oldBitmap = SelectObject (dib->sourceDC, dib->bitmap);
  606.   
  607.   return dib->bits;
  608. }
  609. void
  610. dib_unlock (dib_t *dib)
  611. {
  612.   SelectObject (dib->sourceDC, dib->oldBitmap);
  613.   
  614.   DeleteDC (dib->sourceDC);
  615.   dib->sourceDC = NULL;
  616.   ReleaseDC (dib->window, dib->destDC);
  617.   dib->destDC = NULL;
  618. }
  619. #if 0
  620. void
  621. dib_setPaintOffset (dib_t *dib, int xOffset, int yOffset)
  622. {
  623.   dib->xBitmapOffset = xOffset;
  624.   dib->yBitmapOffset = yOffset;
  625. }
  626. LPBYTE
  627. dib_getSurface (dib_t *dib)
  628. {
  629.   if (dib->bitmap == NULL)
  630.     return NULL;
  631.   return (PIXEL_TYPE *)dib->bits;
  632. }
  633. int
  634. dib_getWidth (dib_t *dib)
  635. {
  636.   if (dib->bitmap == NULL)
  637.     return -1;
  638.   
  639.   return dib->dibInfo->bmiHead.biWidth;
  640. }
  641. int
  642. dib_getHeight (dib_t *dib)
  643. {
  644.   if (dib->bitmap == NULL)
  645.     return -1;
  646.   {
  647.     int height = dib->dibInfo->bmiHead.biHeight;
  648.     return height < 0 ? -height : height;
  649.   }
  650. }
  651. BOOL
  652. dib_blit (dib_t *dib,
  653.   int destX, int destY,
  654.   int sourceX, int sourceY,
  655.   unsigned sourceWidth, unsigned sourceHeight)
  656. {
  657.   int diff = destX + sourceWidth - dib->dibInfo->bmiHead.biWidth;
  658.   
  659.   if (diff > 0)
  660.     sourceWidth -= diff;
  661.   SelectPalette (dib->destDC, dib->palette, FALSE);
  662.   RealizePalette (dib->destDC);
  663.   return BitBlt (dib->destDC,
  664.                  destX, destY,
  665.                  sourceWidth, sourceHeight,
  666.                  dib->sourceDC,
  667.                  sourceX, sourceY,
  668.                  SRCCOPY);
  669. }
  670. #endif
  671. #endif