home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 20.3 KB | 743 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWWinDIB.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifdef FW_BUILD_WIN
-
- #ifndef FWWINDIB_H
- #include "FWWinDIB.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWBITMAP_H
- #include "FWBitmap.h"
- #endif
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // Local helper functions
- //----------------------------------------------------------------------------------------
-
- static DWORD RoundToDWord(DWORD number)
- {
- return ((number + 31) & (~31)) / 8;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::ConvertToBitmap
- //----------------------------------------------------------------------------------------
-
- HBITMAP FW_CPrivWinDIB::ConvertToBitmap(HDIB dib, HPALETTE hPal)
- {
- // we will use the screen device as the source for color depth information
- HDC dc = ::GetDC(NULL);
-
- // select the palette, if any
- HPALETTE hPalOld = NULL;
- if (hPal != NULL)
- {
- hPalOld = ::SelectPalette(dc, hPal, FALSE);
- ::RealizePalette(dc);
- }
-
- // lock DIB bits
- FW_CAcquireLockedSystemHandle lock(dib);
- const BITMAPINFO* biPtr = (BITMAPINFO*)lock.GetPointer();
- const BITMAPINFOHEADER* bmiHeader = &biPtr->bmiHeader;
-
- // determine bitmap dimensions
- short width, height;
- if(bmiHeader->biSize == sizeof(BITMAPCOREHEADER))
- {
- // this is an OS/2 bitmap
- const BITMAPCOREHEADER* bcHeader = (const BITMAPCOREHEADER*) bmiHeader;
- width = bcHeader->bcWidth;
- height = bcHeader->bcHeight;
- }
- else
- {
- width = bmiHeader->biWidth;
- height = bmiHeader->biHeight;
- }
-
- // get the pixel buffer and perform the conversion
- PixelBufferPtr pixelBuffer = GetPixelBuffer(biPtr);
- HBITMAP bitmapHandle = ::CreateDIBitmap(dc, bmiHeader, CBM_INIT, pixelBuffer, biPtr, DIB_RGB_COLORS);
-
- // clean up
- if (hPalOld != NULL)
- ::SelectPalette(dc, hPalOld, TRUE);
-
- ::ReleaseDC(NULL, dc);
-
- // check errors and return
- if(bitmapHandle == 0)
- FW_Failure(FW_xMemoryExhausted);
-
- return bitmapHandle;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::ConvertFromBitmap
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinDIB::HDIB FW_CPrivWinDIB::ConvertFromBitmap(
- HBITMAP bitmapHandle,
- short bitDepth /* = 0 */,
- HPALETTE hPal /* = NULL */)
- {
- BITMAPINFOHEADER bmiHeader;
-
- // get information about the DDB
- BITMAP bitmapInfo;
- ::GetObject(bitmapHandle, sizeof(bitmapInfo), &bitmapInfo);
-
- // Determine bit depth
- if(bitDepth == 0)
- bitDepth = bitmapInfo.bmPlanes * bitmapInfo.bmBitsPixel;
-
- FW_ASSERT(bitDepth == 1 || bitDepth == 4 || bitDepth == 8 || bitDepth == 16 || bitDepth == 24);
-
- // Initilaize the header
- PrivInitHeader(bmiHeader, bitmapInfo.bmWidth, bitmapInfo.bmHeight, bitDepth);
-
- // allocate memory for the header and the palette
- unsigned long paletteSize = GetPaletteSize(&bmiHeader);
- unsigned long memSize = bmiHeader.biSize + paletteSize;
- FW_CAcquireTemporarySystemHandle dibMemory(memSize);
- BITMAPINFO* biPtr = (BITMAPINFO*)dibMemory.GetPointer();
-
- // stick the header in
- biPtr->bmiHeader = bmiHeader;
-
- // get image size from the video driver, by calling GetDIBits with NULL
- // parameter for the storage
- HDC hdc = ::GetDC(NULL);
- HPALETTE hPalOld = NULL;
- if (hPal != NULL)
- {
- hPalOld = ::SelectPalette(hdc, hPal, FALSE);
- ::RealizePalette(hdc);
- }
-
- ::GetDIBits(hdc, bitmapHandle, 0, bmiHeader.biHeight, NULL, biPtr, DIB_RGB_COLORS);
-
- bmiHeader = biPtr->bmiHeader;
-
- // for RGB bitmaps, it is valid for biSizeImage to be 0,
- // so we need to calculate it outselves
- if (bmiHeader.biSizeImage == 0)
- {
- bmiHeader.biSizeImage = RoundToDWord(bitmapInfo.bmWidth *
- bitmapInfo.bmPlanes * bitmapInfo.bmBitsPixel) * bitmapInfo.bmHeight;
- }
-
- // reallocate the buffer to hold the bits
- memSize = bmiHeader.biSize + paletteSize + bmiHeader.biSizeImage;
- FW_TRY
- {
- dibMemory.Resize(memSize);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (hPalOld != NULL)
- {
- ::SelectPalette(hdc, hPalOld, FALSE);
- ::RealizePalette(hdc);
- }
-
- ::ReleaseDC(NULL, hdc);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- biPtr = (BITMAPINFO*) dibMemory.GetPointer();
-
- // now get the bits by calling GetDIBits again, this time with a non-NULL pixel buffer
- PixelBufferPtr pixelBuffer = GetPixelBuffer(biPtr);
- ::GetDIBits(hdc, bitmapHandle, 0, bmiHeader.biHeight, pixelBuffer, biPtr, DIB_RGB_COLORS);
-
- // clean up and return the handle
- if (hPalOld != NULL)
- {
- ::SelectPalette(hdc, hPalOld, FALSE);
- ::RealizePalette(hdc);
- }
- ::ReleaseDC(NULL, hdc);
- dibMemory.Orphan();
- return (HDIB) dibMemory.GetPlatformHandle();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::GetPalette
- //----------------------------------------------------------------------------------------
-
- HPALETTE FW_CPrivWinDIB::GetPalette(HDIB dib)
- {
- FW_CAcquireLockedSystemHandle lock(dib);
- const BITMAPINFOHEADER* bmiHeader = (const BITMAPINFOHEADER*) lock.GetPointer();
-
- // It only makes sense to support palettes for 8-bit DIBs.
- // For Windows, I also check ClrImportant and ClrUsed which
- // both may be set in HiColor or TrueColor DIBs.
-
- // RGBQUAD and RGBTRIPLE both begin with 3 BYTE's that specify
- // Blue, Green and Red components in that exact order
-
- // ----- Determine color count
- short colorCount, colorStep;
- LOGPALETTE* pLogPal = NULL;
- BYTE* colorTable;
-
- if (bmiHeader->biSize == sizeof(BITMAPINFOHEADER))
- {
- // Windows DIB
- colorCount = bmiHeader->biClrImportant;
-
- if (colorCount == 0)
- colorCount = bmiHeader->biClrUsed;
-
- if (colorCount == 0)
- colorCount = bmiHeader->biBitCount == 8 ? 256 : 0;
-
- colorStep = sizeof(RGBQUAD);
- colorTable = (BYTE*) (bmiHeader + 1);
- }
- else
- {
- // OS/2 DIB
- const BITMAPCOREHEADER* bcHeader = (const BITMAPCOREHEADER*) bmiHeader;
- colorCount = bcHeader->bcBitCount == 8 ? 256 : 0;
-
- colorStep = sizeof(RGBTRIPLE);
- colorTable = (BYTE*) (bcHeader + 1);
- }
-
- // Create a palette
- HPALETTE hPal = NULL;
- if (colorCount != 0)
- {
- pLogPal = (LOGPALETTE*) new char[sizeof(LOGPALETTE) + colorCount * sizeof(PALETTEENTRY)];
- pLogPal->palVersion = 0x300;
- pLogPal->palNumEntries = colorCount;
-
- for (short i = 0; i < colorCount; ++ i, colorTable += colorStep)
- {
- pLogPal->palPalEntry[i].peBlue = colorTable[0];
- pLogPal->palPalEntry[i].peGreen = colorTable[1];
- pLogPal->palPalEntry[i].peRed = colorTable[2];
- pLogPal->palPalEntry[i].peFlags = 0;
- }
-
- hPal = ::CreatePalette(pLogPal);
-
- delete[] (char*) pLogPal;
- }
-
- return hPal;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::GetPaletteSize
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CPrivWinDIB::GetPaletteSize(const BITMAPINFOHEADER* bmiHeader)
- {
- short bits; // bitmap depth, in bits
- short numColors = 0; // number of colors
- short colorEntrySize; // size of each color entry in the palette
-
- if(bmiHeader->biSize == sizeof(BITMAPCOREHEADER))
- {
- // OS/2 bitmap header
- const BITMAPCOREHEADER* bcHeader = (const BITMAPCOREHEADER*) bmiHeader;
- bits = bcHeader->bcBitCount;
- colorEntrySize = sizeof(RGBTRIPLE);
- }
- else
- {
- numColors = bmiHeader->biClrUsed;
- bits = bmiHeader->biBitCount;
- colorEntrySize = sizeof(RGBQUAD);
- }
-
- if(numColors == 0)
- {
- switch(bits)
- {
- case 1:
- numColors = 2;
- break;
- case 4:
- numColors = 16;
- break;
- case 8:
- numColors = 256;
- break;
- default:
- numColors = 0;
- break;
- }
- }
-
- return colorEntrySize * numColors;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::GetPixelBuffer
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinDIB::PixelBufferPtr FW_CPrivWinDIB::GetPixelBuffer(const BITMAPINFO* biPtr)
- {
- const BITMAPINFOHEADER* bmiHeader = &biPtr->bmiHeader;
- unsigned long paletteSize = GetPaletteSize(bmiHeader);
-
- return (PixelBufferPtr) biPtr + paletteSize + bmiHeader->biSize;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::LoadFromStream
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinDIB::HDIB FW_CPrivWinDIB::LoadFromStream(const FW_CReadableStream& stream, FW_Boolean bFileHeader)
- {
- // read the header first
- if (bFileHeader)
- {
- BITMAPFILEHEADER bmfh;
- stream.Read((void*) &bmfh, sizeof(bmfh));
-
- // verify the header
- if(bmfh.bfType != kWinBitmapFileSignature || bmfh.bfSize == 0)
- FW_Failure(FW_xInvalidBitmapData);
- }
-
- // Start reading the DIB header
- FW_Boolean bIsWindowsBitmap;
-
- BITMAPINFOHEADER bmih;
- BITMAPCOREHEADER bmch;
-
- int bitDepth;
- int colorCount;
- int width, height;
- int headerSize;
- int paletteSize;
-
- stream.Read((void*) &bmih.biSize, sizeof(bmih.biSize));
-
- if(bmih.biSize == sizeof(BITMAPINFOHEADER)) // Windows bitmap
- {
- stream.Read((void*) &bmih.biWidth, sizeof(bmih) - sizeof(bmih.biSize));
- bIsWindowsBitmap = TRUE;
-
- width = bmih.biWidth;
- height = bmih.biHeight;
- headerSize = sizeof(bmih);
- }
- else if(bmih.biSize == sizeof(BITMAPCOREHEADER)) // OS/2 bitmap
- {
- bmch.bcSize = bmih.biSize;
- stream.Read((void* )&bmch.bcWidth, sizeof(bmch) - sizeof(bmch.bcSize));
- bIsWindowsBitmap = FALSE;
-
- width = bmch.bcWidth;
- height = bmch.bcHeight;
- headerSize = sizeof(bmch);
- }
- else
- FW_Failure(FW_xInvalidBitmapData);
-
- PrivGetColorInfo(bmih, bitDepth, colorCount, paletteSize);
-
- // Determine the image size
- short rowBytes = ((width * bitDepth + 31) & ~31) / 8;
- long bitsSize = height * rowBytes;
-
- // allocate memory for the DIB
- FW_CAcquireTemporarySystemHandle dibMemory(headerSize + paletteSize + bitsSize);
- BITMAPINFOHEADER* biPtr = (BITMAPINFOHEADER*) dibMemory.GetPointer();
- BITMAPCOREHEADER* bcPtr = (BITMAPCOREHEADER*) dibMemory.GetPointer();
-
- // Stick the header in
- void* palettePtr;
- if(bIsWindowsBitmap)
- {
- *biPtr = bmih;
- palettePtr = biPtr + 1;
- }
- else
- {
- *bcPtr = bmch;
- palettePtr = bcPtr + 1;
- }
-
- // Read the palette
- if(paletteSize != 0)
- stream.Read(palettePtr, paletteSize);
-
- // Read the bits
- void* bitsPtr = (char*) palettePtr + paletteSize;
- stream.Read(bitsPtr, bitsSize);
-
- // Clean up and return
- dibMemory.Orphan();
- return (HDIB) dibMemory.GetPlatformHandle();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::SaveToStream
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinDIB::SaveToStream(const FW_CWritableStream& stream, HDIB dib, FW_Boolean bFileHeader)
- {
- // lock DIB bits
- FW_CAcquireLockedSystemHandle lock(dib);
- BITMAPINFO* biPtr = (BITMAPINFO*) lock.GetPointer();
- BITMAPINFOHEADER* bmiHeader = &biPtr->bmiHeader;
-
- unsigned long headerSize;
- unsigned long imageSize;
-
- if(bmiHeader->biSize == sizeof(BITMAPCOREHEADER))
- {
- // this is an OS/2 bitmap
- const BITMAPCOREHEADER* bcHeader = (const BITMAPCOREHEADER*) bmiHeader;
- headerSize = bcHeader->bcSize;
- imageSize = RoundToDWord(bcHeader->bcWidth *
- bcHeader->bcPlanes * bcHeader->bcBitCount) * bcHeader->bcHeight;
- }
- else
- {
- // this is a Windows bitmap
- headerSize = bmiHeader->biSize;
- imageSize = bmiHeader->biSizeImage;
- }
-
- // calculate file size and image offset
- unsigned long paletteSize = GetPaletteSize(bmiHeader);
- unsigned long fullSize = paletteSize + headerSize + imageSize;
-
- // Write the file header
- if(bFileHeader)
- {
- BITMAPFILEHEADER bmfh;
- bmfh.bfType = kWinBitmapFileSignature;
- bmfh.bfSize = fullSize + sizeof(BITMAPFILEHEADER);
- bmfh.bfReserved1 = 0;
- bmfh.bfReserved2 = 0;
- bmfh.bfOffBits = paletteSize + headerSize + sizeof(BITMAPFILEHEADER);
-
- stream.Write((void*) &bmfh, sizeof(BITMAPFILEHEADER));
- }
-
- // Write the bits
- stream.Write((void*) biPtr, fullSize);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::Free
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinDIB::Free(HDIB dib)
- {
- FW_CMemoryManager::FreeSystemHandle(dib);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::CreateDIB
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinDIB::HDIB FW_CPrivWinDIB::CreateDIB(short bitDepth, short width, short height,
- short nbColors, const FW_CColor* colorTable,
- const void* pixels /* = NULL */)
- {
- FW_ASSERT(bitDepth == 1 || bitDepth == 4 || bitDepth == 8);
-
- // Calculate the sizes
- unsigned short colorCount = 1 << bitDepth;
- unsigned long paletteSize = colorCount * sizeof(RGBQUAD);
- unsigned long imageSize = RoundToDWord(width * bitDepth) * height;
- unsigned long size = sizeof(BITMAPINFOHEADER) + paletteSize + imageSize;
-
- FW_ASSERT(nbColors <= colorCount);
-
- // Allocate DIB memory
- FW_CAcquireTemporarySystemHandle dibMemory(size);
- BITMAPINFO* biPtr = (BITMAPINFO*)dibMemory.GetPointer();
-
- // Initiliaze the header
- PrivInitHeader(biPtr->bmiHeader, width, height, bitDepth);
- biPtr->bmiHeader.biClrImportant = nbColors;
-
- // Copy the color table
- for(int i = 0; i < nbColors; i ++)
- biPtr->bmiColors[i] = colorTable[i];
-
- if(nbColors != colorCount)
- ::memset(biPtr->bmiColors + nbColors, 0, sizeof(RGBQUAD) * (colorCount - nbColors));
-
- // Copy the bits
- if(pixels != NULL)
- {
- PixelBufferPtr pixelBuffer = GetPixelBuffer(biPtr);
- FW_CMemoryManager::CopyMemory(pixels, pixelBuffer, imageSize);
- }
-
- dibMemory.Orphan();
- return (HDIB) dibMemory.GetPlatformHandle();
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::CreateCopy
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinDIB::HDIB FW_CPrivWinDIB::CreateCopy(HDIB dib)
- {
- FW_ASSERT(dib != NULL);
- return (HDIB) FW_CMemoryManager::CopySystemHandle(dib);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::GetColorTable
- //----------------------------------------------------------------------------------------
-
- unsigned short FW_CPrivWinDIB::GetColorTable(HDIB dib, FW_CColor*& colors)
- {
- colors = NULL;
-
- FW_CAcquireLockedSystemHandle lock(dib);
- const BITMAPINFO* bmi = (const BITMAPINFO*) lock.GetPointer();
-
- int i, bitDepth, colorCount, paletteSize;
- PrivGetColorInfo(bmi->bmiHeader, bitDepth, colorCount, paletteSize);
-
- if(bmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
- {
- // this is an OS/2 bitmap
- const BITMAPCOREINFO* bmci = (const BITMAPCOREINFO*) bmi;
- if(colorCount != 0)
- {
- colors = new FW_CColor[colorCount];
- for(i = 0; i < colorCount; i ++)
- colors[i] = bmci->bmciColors[i];
- }
- }
- else
- {
- // this is a Windows bitmap
- if(bmi->bmiHeader.biClrImportant != 0)
- colorCount = bmi->bmiHeader.biClrImportant;
-
- if(colorCount != 0)
- {
- colors = new FW_CColor[colorCount];
- for(i = 0; i < colorCount; i ++)
- colors[i] = bmi->bmiColors[i];
- }
- }
-
- return colorCount;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::PrivInitHeader
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinDIB::PrivInitHeader(BITMAPINFOHEADER& header, int width, int height, int bitDepth)
- {
- header.biSize = sizeof(BITMAPINFOHEADER);
- header.biWidth = width;
- header.biHeight = height;
- header.biPlanes = 1;
- header.biBitCount = bitDepth;
- header.biCompression = BI_RGB;
- header.biSizeImage = 0;
- header.biXPelsPerMeter = 0;
- header.biYPelsPerMeter = 0;
- header.biClrUsed = 0;
- header.biClrImportant = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinDIB::PrivGetColorInfo
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinDIB::PrivGetColorInfo(
- const BITMAPINFOHEADER& biHeader,
- int& bitDepth,
- int& colorCount,
- int& paletteSize)
- {
- if(biHeader.biSize == sizeof(BITMAPINFOHEADER))
- {
- bitDepth = biHeader.biBitCount;
- colorCount = biHeader.biClrUsed != 0 ? biHeader.biClrUsed :
- biHeader.biBitCount == 24 ? 0 : 1 << biHeader.biBitCount;
- paletteSize = colorCount * sizeof(RGBQUAD);
- }
- else
- {
- const BITMAPCOREHEADER& bcHeader = (const BITMAPCOREHEADER&) biHeader;
- bitDepth = bcHeader.bcBitCount;
- colorCount = bcHeader.bcBitCount == 24 ? 0 : 1 << bcHeader.bcBitCount;
- paletteSize = colorCount * sizeof(RGBTRIPLE);
- }
- }
-
- //========================================================================================
- // class FW_CPrivWinBitmap
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinBitmap::GetColorDepth
- //----------------------------------------------------------------------------------------
-
- short FW_CPrivWinBitmap::GetColorDepth(HBITMAP hBitmap)
- {
- BITMAP bm;
- ::GetObject(hBitmap, sizeof(bm), &bm);
-
- if(bm.bmPlanes != 1)
- return bm.bmPlanes;
-
- return bm.bmBitsPixel;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinBitmap::CopyImage
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinBitmap::CopyImage(
- HBITMAP hBmpDst, HPALETTE hPalDst, const RECT& rectDst,
- HBITMAP hBmpSrc, HPALETTE hPalSrc, const RECT& rectSrc,
- short options)
- {
- FW_ASSERT(hBmpSrc != NULL);
- FW_ASSERT(hBmpDst != NULL);
-
- HDC hDCDst = ::CreateCompatibleDC(NULL);
- HDC hDCSrc = ::CreateCompatibleDC(NULL);
-
- if(hDCDst != NULL && hDCSrc != NULL)
- {
- HBITMAP hBmpDstOld = (HBITMAP) ::SelectObject(hDCDst, hBmpDst);
- HBITMAP hBmpSrcOld = (HBITMAP) ::SelectObject(hDCSrc, hBmpSrc);
-
- if(hBmpDstOld != NULL && hBmpSrcOld != NULL)
- {
- // Select the palettes
- HPALETTE hPalOldDst = NULL;
- if (hPalDst != NULL)
- {
- hPalOldDst = ::SelectPalette(hDCDst, hPalDst, FALSE);
- ::RealizePalette(hDCDst);
- }
-
- HPALETTE hPalOldSrc = NULL;
- if (hPalSrc != NULL)
- {
- hPalOldSrc = ::SelectPalette(hDCSrc, hPalSrc, FALSE);
- ::RealizePalette(hDCSrc);
- }
-
- if(options == kScale)
- {
- // Stretch the bits
- ::StretchBlt(
- hDCDst,
- rectDst.left, rectDst.top,
- rectDst.right - rectDst.left, rectDst.bottom - rectDst.top,
- hDCSrc,
- rectSrc.left, rectSrc.top,
- rectSrc.right - rectSrc.left, rectSrc.bottom - rectSrc.top,
- SRCCOPY);
- }
- else
- {
- // Determine the size of image we can copy
- short copyWidth = rectSrc.right - rectSrc.left;
- if(copyWidth > rectDst.right - rectDst.left)
- copyWidth = rectDst.right - rectDst.left;
-
- short copyHeight = rectSrc.bottom - rectSrc.top;
- if(copyHeight > rectDst.bottom - rectDst.top)
- copyHeight = rectDst.bottom - rectDst.top;
-
- // Copy the bits
- ::BitBlt(
- hDCDst,
- rectDst.left, rectDst.top,
- copyWidth, copyHeight,
- hDCSrc,
- rectSrc.left, rectSrc.top,
- SRCCOPY);
-
- // Erase any space to the right of the copied image piece
- if(copyWidth < rectDst.right - rectDst.left)
- ::PatBlt(
- hDCDst,
- rectDst.left + copyWidth,
- rectDst.top,
- rectDst.right - rectDst.left - copyWidth,
- rectDst.bottom - rectDst.top,
- WHITENESS);
-
- // Erase any space to the bottom of the copied image piece
- if(copyHeight < rectDst.bottom - rectDst.top)
- ::PatBlt(
- hDCDst,
- rectDst.left,
- rectDst.top + copyHeight,
- rectDst.right - rectDst.left,
- rectDst.bottom - rectDst.top - copyHeight,
- WHITENESS);
- }
-
- // Clean up the palettes
- if (hPalOldDst != NULL)
- ::SelectPalette(hDCDst, hPalOldDst, FALSE);
-
- if (hPalOldSrc != NULL)
- ::SelectPalette(hDCSrc, hPalOldSrc, FALSE);
- }
-
- if(hBmpDstOld != NULL)
- ::SelectObject(hDCDst, hBmpDstOld);
-
- if(hBmpSrcOld != NULL)
- ::SelectObject(hDCSrc, hBmpSrcOld);
- }
-
- if(hDCDst != NULL)
- ::DeleteDC(hDCDst);
-
- if(hDCSrc != NULL)
- ::DeleteDC(hDCSrc);
- }
-
- #endif
-