clipmap.cpp File Reference

(r1785/r1282)

#include "camtypes.h"
#include "clipext.h"
#include "clipint.h"
#include "clipmap.h"
#include "layer.h"
#include "nodetext.h"
#include "nodetxtl.h"
#include "nodetxts.h"
#include "unicdman.h"
#include "bitmpinf.h"
#include "nodebmp.h"
#include "wbitmap.h"
#include "scrcamvw.h"
#include "cmxifltr.h"

Go to the source code of this file.

Defines

#define new   CAM_DEBUG_NEW

Functions

static BOOL ConvertBMPToDIB (HBITMAP hSourceBmp, HPALETTE hSourcePal, LPBITMAPINFO *ResultHeader, LPBYTE *ResultBits)
 Converts a Windows HBITMAP GDI DDB into a DIB.
static HPALETTE CreateBMPPalette (LPBITMAPINFOHEADER lpbi)
 Given a DIB, creates a GDI HPALETTE based on the DIB's palette. If the DIB is 24 or 32 bit or whatever, this will return NULL, so it is a quite normal return value.
static KernelBitmapFindBitmapToExport (InternalClipboard *Source)
 Scans the clipboard for bitmap objects that can be exported, and returns the first one found.


Define Documentation

#define new   CAM_DEBUG_NEW
 

Definition at line 161 of file clipmap.cpp.


Function Documentation

static BOOL ConvertBMPToDIB HBITMAP  hSourceBmp,
HPALETTE  hSourcePal,
LPBITMAPINFO ResultHeader,
LPBYTE ResultBits
[static]
 

Converts a Windows HBITMAP GDI DDB into a DIB.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/5/95
Parameters:
hSourceBmp - The handle of the source bitmap GDI object [INPUTS] hSourcePal - NULL, or a handle of the palette to use
ResultHeader - Will be NULL or point at the resulting DIB header [OUTPUTS] ResultBits - Will be NULL or point at the resulting DIB body
Returns:
TRUE for success
Notes: Both returned pointers will be NULL unless the return value is TRUE. These pointers are CCMalloc'd blocks as used by other DIBUtil calls and WBitmaps.

If hSourcePal is not supplied, a default palette will be used

See also:
DibUtil::AloocDIB; DIBUtil::FreeDIB

Definition at line 1668 of file clipmap.cpp.

01670 {
01671     ERROR3IF(hSourceBmp == NULL || ResultHeader == NULL ||
01672                 ResultBits == NULL, "Illegal NULL params");
01673 
01674     // Safe results if we fail
01675     *ResultHeader   = NULL;
01676     *ResultBits     = NULL;
01677     
01678     BITMAPINFOHEADER *Header;
01679     LPBYTE Bits;
01680 
01681     // See if we can get a palette from the clipboard - if not, grab a default one
01682     if (hSourcePal == NULL)
01683         hSourcePal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);
01684 
01685     // Fill in the BITMAP info from the source bitmap
01686     BITMAP bm;
01687     GetObject(hSourceBmp, sizeof(bm), (LPSTR) &bm);
01688 
01689     UINT32 Depth = bm.bmPlanes * bm.bmBitsPixel;
01690     if (Depth > 8)      // DDBs can be 16bpp, but DIBs cannot -> convert it to 24bpp
01691         Depth = 24;
01692 
01693     INT32 PaletteSize = DIBUtil::CalcPaletteSize(Depth, FALSE);
01694 
01695     Header = (BITMAPINFOHEADER *) CCMalloc(sizeof(BITMAPINFOHEADER) + PaletteSize);
01696     if (Header == NULL)
01697         return(FALSE);      
01698 
01699     INT32 BitmapSize = DIBUtil::ScanlineSize(bm.bmWidth, Depth) * bm.bmHeight;
01700     if (BitmapSize == 0)    // Make sure we correctly handle zero width/height
01701         BitmapSize = 4;
01702 
01703     Header->biSize               = sizeof(BITMAPINFOHEADER);
01704     Header->biWidth              = bm.bmWidth;
01705     Header->biHeight             = bm.bmHeight;
01706     Header->biPlanes             = 1;
01707     Header->biBitCount           = Depth;
01708     Header->biCompression        = BI_RGB;
01709     Header->biSizeImage          = BitmapSize;
01710     Header->biXPelsPerMeter      = 0;
01711     Header->biYPelsPerMeter      = 0;
01712     Header->biClrUsed            = 0;
01713     Header->biClrImportant       = 0;
01714 
01715     // Add padding for Gavin rampancy etc
01716     BitmapSize += EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize(bm.bmWidth, Depth);
01717 
01718     Bits = (LPBYTE) CCMalloc(BitmapSize);
01719     if (Bits == NULL)
01720     {
01721         CCFree(Header);
01722         return(FALSE);
01723     }
01724 
01725     // Get a screen DC, and select in the palette
01726     HDC hDC = GetDC(NULL);
01727     if (Depth <= 8)
01728     {
01729         hSourcePal = SelectPalette(hDC, hSourcePal, FALSE);
01730         RealizePalette(hDC);
01731     }
01732 
01733     // Call GetDIBits to blit the bitmap data across
01734     INT32 result = GetDIBits(hDC, hSourceBmp,   0, (WORD)Header->biHeight,
01735                             Bits, (LPBITMAPINFO) Header, DIB_RGB_COLORS);
01736 
01737     // Restore the screen DC
01738     if (Depth <= 8)
01739         SelectPalette(hDC, hSourcePal, FALSE);
01740     ReleaseDC(NULL, hDC);
01741 
01742     // Result will be zero for failure, else the number of scanlines copied
01743     if (result == 0)
01744     {
01745         CCFree(Bits);
01746         CCFree(Header);
01747         return(FALSE);
01748     }
01749 
01750     if (Depth <= 8)
01751     {
01752         // If either of these fields are 0, they mean "The maximum number of colours"
01753         // and this doesn't export quite right, so we "fix" the value (eg 8bpp=>256 cols)
01754         if (Header->biClrUsed == 0)
01755             Header->biClrUsed = 1<<Depth;
01756 
01757         if (Header->biClrImportant == 0)
01758             Header->biClrImportant = 1<<Depth;
01759     }
01760 
01761     // And return successfully
01762     *ResultHeader   = (LPBITMAPINFO) Header;
01763     *ResultBits     = Bits;
01764     return(TRUE);
01765 }

static HPALETTE CreateBMPPalette LPBITMAPINFOHEADER  lpbi  )  [static]
 

Given a DIB, creates a GDI HPALETTE based on the DIB's palette. If the DIB is 24 or 32 bit or whatever, this will return NULL, so it is a quite normal return value.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/5/95
Parameters:
lpbi - A pointer to your DIB's header [INPUTS]
Returns:
NULL (failed, or no palette), or a windows handle of the GDI palette data

Definition at line 1898 of file clipmap.cpp.

01899 {
01900     ERROR3IF(lpbi == NULL, "Illegal NULL param");
01901 
01902     // Is it a windows DIB? If not, we can't get a palette out of it
01903     if (lpbi->biSize != sizeof(BITMAPINFOHEADER))
01904         return NULL;
01905 
01906     // Get a pointer to the colour table and the number of colours in it
01907     RGBQUAD *pRGB = (RGBQUAD *)((LPSTR)lpbi + (WORD)lpbi->biSize);
01908     INT32 NumColours = DIBUtil::CalcPaletteSize(lpbi->biBitCount, lpbi->biCompression == BI_BITFIELDS) / sizeof(RGBQUAD);
01909 
01910     HPALETTE hpal = NULL;
01911 
01912     if (NumColours > 0)
01913     {
01914         // Allocate temporary memory
01915         LOGPALETTE *pPal = (LOGPALETTE *) LocalAlloc(LPTR, sizeof(LOGPALETTE) + NumColours * sizeof(PALETTEENTRY));
01916         if (pPal == NULL)
01917             return NULL;
01918 
01919         // Set up the LOGPALETTE structure, copying the pal entries across
01920         pPal->palNumEntries = NumColours;
01921         pPal->palVersion    = 0x300;        // Palette structure Windows version number
01922 
01923         for (INT32 i = 0; i < NumColours; i++)
01924         {
01925             pPal->palPalEntry[i].peRed   = pRGB[i].rgbRed;
01926             pPal->palPalEntry[i].peGreen = pRGB[i].rgbGreen;
01927             pPal->palPalEntry[i].peBlue  = pRGB[i].rgbBlue;
01928             pPal->palPalEntry[i].peFlags = (BYTE)0;
01929         }
01930         hpal = CreatePalette(pPal);
01931         LocalFree((HANDLE)pPal);
01932     }
01933 
01934     return hpal;
01935 }

static KernelBitmap* FindBitmapToExport InternalClipboard Source  )  [static]
 

Scans the clipboard for bitmap objects that can be exported, and returns the first one found.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/5/95
Parameters:
Source - the internal clipboard (document) to be exported [INPUTS]
Returns:
NULL (if it failed), or a KernelBitmap to be exported
Used by the Bitmap, DIB, and Palette exporters to find the export data

Definition at line 1957 of file clipmap.cpp.

01958 {
01959     KernelBitmap *KernelBmp = NULL;
01960 
01961     // Scan the entire document tree, looking for a bitmap to export
01962     Node *pSubtree = InternalClipboard::GetInsertionLayer();
01963     Node *pNode = pSubtree->FindFirstDepthFirst();
01964 
01965     while (pNode != NULL && KernelBmp == NULL)
01966     {
01967         // Is this node a NodeBitmap?
01968         if (pNode->IsAnObject() && pNode->GetRuntimeClass() == CC_RUNTIME_CLASS(NodeBitmap))
01969         {
01970             NodeBitmap* pNodeBmp = (NodeBitmap*)pNode;
01971             KernelBitmapRef *BmpRef = pNodeBmp->GetBitmapRef();
01972             if (BmpRef != NULL)
01973                 KernelBmp = BmpRef->GetBitmap();
01974         }
01975 /*
01976         // How about a bitmap fill?
01977         else if (pNode->IsAnAttribute())
01978         {
01979             if (((NodeAttribute*)pNode)->IsABitmapFill())
01980             {
01981                 // We've found either a Bitmap or Fractal fill
01982                 AttrFillGeometry* pBmpFill = (AttrFillGeometry*)pNode;
01983                 KernelBitmapRef *BmpRef = pBmpFill->GetBitmapRef();
01984                 if (BmpRef != NULL)
01985                     KernelBmp = BmpRef->GetBitmap();
01986             }
01987         }
01988 */
01989         pNode = pNode->FindNextDepthFirst(pSubtree);
01990     }
01991 
01992     return(KernelBmp);
01993 }


Generated on Sat Nov 10 03:49:29 2007 for Camelot by  doxygen 1.4.4