CWxBitmap Class Reference

The Windows implementation of the OILBitmap class. Based on a non-compressed DIB. Kernel code should not call on functions in this class except via the OILBitmap interface. More...

#include <oilbitmap.h>

Inheritance diagram for CWxBitmap:

OILBitmap ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 CWxBitmap ()
 Constructor.
 CWxBitmap (LPBITMAPINFO, LPBYTE)
 Constructor. This must NOT be called from Kernel code.
 ~CWxBitmap ()
 Destructor. Frees up Windows resources for the bitmap.
virtual INT32 operator== (const OILBitmap &)
 Checks to see if one bitmap is the same as another.
void CacheGeometry ()
 Sets up the cached info in the header so the plot routines will work fast.
virtual BOOL GetInfo (BitmapInfo *Info, RenderRegion *pRegion=NULL)
 Kernel code can call this to obtain information about the bitmap in a platform- independent way. This function is implemented differently on different OIL layers.
virtual UINT32 GetWidth ()
 Retrieve information on this bitmap.
virtual UINT32 GetHeight ()
 Retrieve information on this bitmap.
virtual UINT32 GetBPP (RenderRegion *pRegion=NULL)
 Finds the colour resolution of this bitmap (or, if PRegion is specified, the colour resolution at which this bitmap should be output).
virtual UINT32 GetNumPaletteEntries ()
 Retrieve information on this bitmap.
virtual ADDR GetBitmapBits ()
virtual UINT32 GetScanlineSize ()
 To determine the memory allocation needed to hold a single scanline of this bitmap. This is a convenient interface onto DIBUtil::ScanlineSize.
virtual BOOL ExportBitmap (RenderRegion *pRegion)
virtual BOOL ExportBitmapPalette (RenderRegion *pRegion)
 Exports this bitmap's palette to the given RenderRegion.
virtual BOOL ExportBitmapData (RenderRegion *pRegion)
 Exports this bitmap's image data to the given RenderRegion.
virtual BOOL ExportSeparatedData (RenderRegion *pRegion, BYTE *SepTables)
 Exports this bitmap's image data to the given RenderRegion, colour separating to an 8bpp image as it does so.
virtual BOOL ExportSeparatedPalette (RenderRegion *pRegion)
 Exports a greyscale 8bpp palette suitable for use by the bitmaps output by ExportSeparatedData.
virtual BOOL GetScanline32bpp (UINT32 YPos, BOOL UsePalette, Pixel32bpp *Scanline)
 Copies a scanline out of this bitmap into the given 32bpp buffer. The buffer must be no less than CWxBitmap::GetWidth() entries wide.
virtual wxImage * MakewxImage (UINT32 ImageWidth=0, UINT32 ImageHeight=0, BOOL UsePalette=TRUE)
 Makes a wxBitmap, slowly.
virtual OILBitmapMakeCopy ()
 To make an exact duplicate of this bitmap.
virtual void ColourSeparate32to32 (ColourPlate *pPlate, BYTE *SepTables)
 Converts the bitmap in-place from full colour 32 bpp RGB to the relevant separation returning the result as 32 bpp with correct colours for the specified plate.
virtual OILBitmapMakeSeparatedCopy (ColourPlate *pPlate, BYTE *SepTables)
 To make an colour separated copy of this bitmap.
virtual INT32 GetRecommendedWidth ()
 Finds the recommended width of the bitmap.
virtual INT32 GetRecommendedHeight ()
 Finds the recommended height of the bitmap.
virtual void SetRecommendedWidth (INT32)
 Sets the recommended width of the bitmap.
virtual void SetRecommendedHeight (INT32)
 Sets the recommended height of the bitmap.
virtual BOOL SetTransparencyIndex (INT32)
 Finds the Transparent index colour of a bitmap if one exists.
virtual BOOL GetTransparencyIndex (INT32 *)
 Finds the Transparent index colour of a bitmap if one exists.
virtual BOOL IsTransparent ()
 Determines if a bitmap is not totally opaque.
virtual BOOL WritePalette (BaseCamelotFilter *pFilter)
 Function used when exporting an 8bpp JPEG into the web file and we need to squirt the palette information into the record ready for reuse when the file is loaded back in.
virtual BOOL Convert24To8 (RGBTRIPLE *pPalette, UINT32 NumberOfPaletteEntries)
 Converts the OILbitmap from its present 24bpp form into an 8bpp form which should closely match the one that was exported.
virtual BOOL ImportBitmap (CCLexFile *pFile, BaseBitmapFilter *pBitmapFilter, BaseCamelotFilter *pFilter, BOOL IsCompressed)
 Imports a bitmap object using the import filter provided. It is used by the web/native filters to pull out a bitmap definition from inside a bitmap definition record. IsCompressed is only used for BMP/BMPZIP type bitmaps at present. Assumes: pFile has already been opened up for reading pFilter has been set up for reading the data e.g. progress bar.
virtual BOOL ImportBitmap (Filter *, const BitmapInfo *, INT32)
 Import a bitmap object using the given bitmap specification and the import filter provided.
virtual BOOL LoadBitmap (UINT32 BitmapResourceID)
 Loads a bitmap from the resources.
virtual BOOL CreateFromwxBitmap (wxBitmap *pBitmap)
virtual BOOL CreateFromwxImage (wxImage *pImage)
virtual BOOL GetPaletteUsage (INT32 *)
 Find out how many times each palette entry is used in the bitmap. This is currently used when rendering paletted images to PostScript.
virtual BOOL PrepareMask (INT32 PaletteEntry)
virtual BOOL GetScanlineMaskBits (INT32 ScanlineY, LPBYTE ScanlineBuf)
 Given a palette.
virtual BOOL DestroyMask ()
virtual BOOL ExportContonePalette (RenderRegion *)
 Exports this bitmap's contone palette to the given RenderRegion.
virtual void PlotPixel (INT32 x, INT32 y, Pixel32bpp NewValue)
 Plots a 32bpp pixel to a deep bitmap (24, or 32bpp).
virtual void PlotPixel (INT32 x, INT32 y, PixelGreyscale NewValue)
 Plots an 8bpp (0..255) pixel to any type of bitmap The pixel is taken to be a greyscale, and is truncated or expanded as appropriate to fit the greyscale value into the destination bitmap pixel format.
virtual Pixel32bpp ReadPixel32bpp (INT32 x, INT32 y, BOOL UsePalette=TRUE)
 reads a pixel
virtual INT32 ReturnPaletteIndexUsed (INT32 x, INT32 y)
 When the user clicks in, or moves the mouse over a pixel in one of the preview images, this function is called to work out the actual palette index of the colour used.
virtual PixelGreyscale ReadPixelGreyscale (INT32 x, INT32 y)
 reads a pixel
virtual void DeleteData (BOOL bResetToDefault=TRUE)
 Deletes the actual bitmap data.
virtual BOOL HasBeenDeleted ()
 Returns whether or not the actual bitmap data has been deleted.
void ExtractBitsAndInfo (LPBYTE *, LPBITMAPINFO *)
 To extract the bitmap data for use elsewhere, sets them to null so that the CWxBitmap object can be deleted.
virtual void GenerateGreyscaleTable ()
 

virtual BOOL IsBrowserPalette ()
 To see if the palette attached to this bitmap is browser compatible. It runs through the colours in a browser palette and checks to see if they are all present. The ordering is not checked and so the palette may be different from the one that we actually use.
virtual BOOL ArePalettesTheSame (const LPLOGPALETTE pLogPalette, const INT32 TransColour=-1)
 To see if the palette attached to this bitmap is browser compatible. It runs through the colours in a browser palette and checks to see if they are all present. The ordering is not checked and so the palette may be different from the one that we actually use. Doesn't check the flags byte, just the RGB bytes.
virtual UINT32 GetHorizontalDPI ()
 Retrieve information on this bitmap.
virtual UINT32 GetVerticalDPI ()
 Retrieve information on this bitmap.
virtual void CopyFullyTransparentFrom (OILBitmap *pBitmap)
virtual LPBITMAPINFO GetBitmapInfo ()
 To get at the BITMAPINFO palette that this bitmap may have.
virtual LPRGBQUAD GetPaletteForBitmap ()
 To get at the RGBQUAD palette that this bitmap may have.
virtual LPBITMAPINFOHEADER GetBitmapInfoHeader ()
 To get at the BITMAPINFOHEADER that this bitmap should have.
virtual void ReplaceBitmap (LPBYTE pBytes, LPBITMAPINFO pInfo)
 To reset the bitmap stored in this CWxBitmap object.

Static Public Member Functions

static void ColourSeparateScanline32to8 (ColourContext *CurrentColContext, BYTE *SepTables, BYTE *DestBuffer, Pixel32bpp *SrcBuffer, INT32 PixelWidth)
 Copies the scanline of 32bpp BGR values from SrcBuffer to DestBuffer, running the pixels through colour separation tables en route. NOTE that Src and Dest may point at the same buffer to convert in-place.

Public Attributes

INT32 ScanLineByteWidth
INT32 BitmapSize
LPBITMAPINFO BMInfo
LPBYTE BMBytes

Protected Member Functions

BOOL ExportBitmapPaletteInternal (RenderRegion *pRegion, INT32 NumColours, RGBQUAD *pSrcCLUT)
 Exports the given palette data to the given RenderRegion Used as an internal shared function for ExportBitmapPalette and ExportContonePalette.

Friends

BOOL OILBitmap::Init ()
void OILBitmap::Deinit ()
OILBitmapOILBitmap::Create ()
OILBitmapOILBitmap::Create (UINT32, UINT32, UINT32, UINT32)

Detailed Description

The Windows implementation of the OILBitmap class. Based on a non-compressed DIB. Kernel code should not call on functions in this class except via the OILBitmap interface.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/8/94

Definition at line 125 of file oilbitmap.h.


Constructor & Destructor Documentation

CWxBitmap::CWxBitmap  ) 
 

Constructor.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
?/9/94

Definition at line 347 of file oilbitmap.cpp.

00348 {
00349     BMInfo = NULL;
00350     BMBytes = NULL;
00351 
00352     // Set up things for plotting
00353     ScanLineByteWidth = 0;
00354     BitmapSize = 0; // in bytes
00355 
00356     CacheGeometry();
00357 }

CWxBitmap::CWxBitmap LPBITMAPINFO  Info,
LPBYTE  Bytes
 

Constructor. This must NOT be called from Kernel code.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
?/9/94 Input: Windows bitmap pointers to an existing bitmap. Sets up the CWxBitmap to contain said bitmap.

Definition at line 371 of file oilbitmap.cpp.

00372 {
00373     BMInfo = Info;
00374     BMBytes = Bytes;
00375 
00376     ScanLineByteWidth = 0;
00377     BitmapSize = 0; // in bytes
00378 
00379     CacheGeometry();
00380 }

CWxBitmap::~CWxBitmap  ) 
 

Destructor. Frees up Windows resources for the bitmap.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
?/9/94

Definition at line 394 of file oilbitmap.cpp.

00395 {
00396     if (!HasBeenDeleted())
00397     {
00398         if (BMInfo != NULL && BMBytes != NULL)
00399         {
00400             FreeDIB( BMInfo, BMBytes );
00401             BMInfo = NULL;
00402             BMBytes = NULL;
00403         }
00404     }
00405 
00406     if (m_pGreyscaleTable)
00407         delete m_pGreyscaleTable;
00408 }


Member Function Documentation

BOOL CWxBitmap::ArePalettesTheSame const LPLOGPALETTE  pLogPalette,
const INT32  TransColour = -1
[virtual]
 

To see if the palette attached to this bitmap is browser compatible. It runs through the colours in a browser palette and checks to see if they are all present. The ordering is not checked and so the palette may be different from the one that we actually use. Doesn't check the flags byte, just the RGB bytes.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
03/07/97
Parameters:
pLogPalette A log palette to check the palette against [INPUTS] TransColour The transparent colour in the palette
Returns:
True if the bitmap has the same palette as the LOG palette.

Implements OILBitmap.

Definition at line 4160 of file oilbitmap.cpp.

04161 {
04162     ERROR2IF(pLogPalette == NULL,FALSE,"ArePalettesTheSame Bad LOGPALETTE param");
04163 
04164     // Not interested in deep bitmaps
04165     UINT32 bpp = GetBPP();
04166     if (bpp != 8)
04167         return FALSE;
04168 
04169 RebuildXPEBitmap();
04170     // Check the palette of this bitmap against this browser palette
04171     LPRGBQUAD pPalette = GetPaletteForBitmap();
04172     if (pPalette == NULL)
04173         return FALSE;
04174 
04175     UINT32 PaletteEntries = GetNumPaletteEntries();
04176     if (PaletteEntries != pLogPalette->palNumEntries)
04177         return FALSE;
04178 
04179     // Check this against our browser palette
04180     BOOL PaletteOk = TRUE;
04181     for (INT32 i = 0; i < pLogPalette->palNumEntries; i++)
04182     {
04183         // If it is the transparent colour then the entry must be white
04184         if (i == TransColour)
04185         {
04186             if (pPalette[i].rgbRed != 0xFF && 
04187                 pPalette[i].rgbGreen != 0xFF &&
04188                 pPalette[i].rgbBlue != 0xFF)
04189             {
04190                 PaletteOk = FALSE;
04191                 break;
04192             }
04193         }
04194         else if (pPalette[i].rgbRed != pLogPalette->palPalEntry[i].peRed &&
04195                  pPalette[i].rgbGreen != pLogPalette->palPalEntry[i].peGreen &&
04196                  pPalette[i].rgbBlue != pLogPalette->palPalEntry[i].peBlue)
04197         {
04198             PaletteOk = FALSE;
04199             break;
04200         }
04201     }
04202 
04203     return PaletteOk;
04204 }

void CWxBitmap::CacheGeometry  ) 
 

Sets up the cached info in the header so the plot routines will work fast.

Author:
Alex_Bligh (Xara Group Ltd) <camelotdev@xara.com>
Date:
14/9/94
Parameters:
None [INPUTS]
Caches scanline widths etc in the CWxBitmap [OUTPUTS]
Returns:
Nothing

Errors: -

See also:
-

Definition at line 3489 of file oilbitmap.cpp.

03490 {
03491     if (BMInfo)
03492     {
03493         // For now we need to restrict the size of the bitmaps
03494         // Hopefully a KernelBitmap member along the lines of PostProcessNewBitmap(pDocument)
03495         // will be provided at some stage to do something better
03496         // For now restrict it to the length of the shorter A0 side
03497         // The minimum size is the number of pixels as millipoints
03498         // This can probably done mathematically as well
03499         LPBITMAPINFOHEADER pHeader = &(BMInfo->bmiHeader);
03500 
03501         if (pHeader->biXPelsPerMeter != 0 || pHeader->biYPelsPerMeter != 0)
03502         {
03503             const double MaxSize    = 0.84;
03504 
03505             const double MaxWidth   = MaxSize;
03506             const double Width      = pHeader->biWidth;
03507             const double MinWidth   = Width / M_MP_VAL;
03508             const double XDensity   = pHeader->biXPelsPerMeter;
03509             const double RealWidth  = Width / XDensity;
03510             INT32 XRecommended = (INT32)(96 * (M_MP_VAL / IN_MP_VAL));
03511 
03512             const double MaxHeight  = MaxSize;
03513             const double Height     = pHeader->biHeight;
03514             const double MinHeight  = Height / M_MP_VAL;
03515             const double YDensity   = pHeader->biYPelsPerMeter;
03516             const double RealHeight = Height / YDensity;
03517             INT32 YRecommended = (INT32)(96 * (M_MP_VAL / IN_MP_VAL));
03518 
03519             const double AspectRatio = XDensity / YDensity;
03520 
03521             BOOL bIsTooBig      = FALSE;
03522             BOOL bIsTooSmall    = FALSE;
03523 
03524             // Check the width isn't too small or large
03525             if (pHeader->biXPelsPerMeter != 0)
03526             {
03527                 if (RealWidth > MaxWidth)
03528                 {
03529                     XRecommended = (INT32)(pHeader->biWidth / MaxWidth);
03530                     bIsTooBig = TRUE;
03531                 }
03532                 else if (RealWidth < MinWidth)
03533                 {
03534                     XRecommended = (INT32)(pHeader->biWidth / MinWidth);
03535                     bIsTooSmall = TRUE;
03536                 }
03537             }
03538 
03539             // Check the height is neither too large nor too small, but just right
03540             if (pHeader->biXPelsPerMeter != 0)
03541             {
03542                 if (RealHeight > MaxHeight)
03543                 {
03544                     YRecommended = (INT32)(pHeader->biHeight / MaxHeight);
03545                     bIsTooBig = TRUE;
03546                 }
03547                 else if (RealHeight < MinHeight)
03548                 {
03549                     YRecommended = (INT32)(pHeader->biHeight / MinHeight);
03550                     bIsTooSmall = TRUE;
03551                 }
03552             }
03553             // This is gorgeous...
03554             // If it's being awkward pick a density
03555             if (bIsTooBig || bIsTooSmall)
03556             {
03557                 if ((bIsTooBig && bIsTooSmall) || AspectRatio != 1.0)
03558                 {
03559                     // It's being really awkward so forget it and use the default
03560                     pHeader->biXPelsPerMeter = 0;
03561                     pHeader->biYPelsPerMeter = 0;
03562                 }
03563                 // From here on we know the original densities were the same.
03564                 // We'll pick the density that gives us the closest to the desired size
03565                 else if ((bIsTooBig && XRecommended > YRecommended) ||
03566                         (bIsTooSmall && XRecommended < YRecommended))
03567                 {
03568                     pHeader->biXPelsPerMeter = XRecommended;
03569                     pHeader->biYPelsPerMeter = XRecommended;
03570                 }
03571                 else
03572                 {
03573                     pHeader->biXPelsPerMeter = YRecommended;
03574                     pHeader->biYPelsPerMeter = YRecommended;
03575                 }
03576             }
03577         }
03578 
03579         ScanLineByteWidth = DIBUtil::ScanlineSize( pHeader->biWidth, pHeader->biBitCount );
03580         BitmapSize = ScanLineByteWidth*(pHeader->biHeight); // in bytes
03581     }
03582     else
03583     {
03584         ScanLineByteWidth = 0;
03585         BitmapSize = 0;
03586     }
03587 }

void CWxBitmap::ColourSeparate32to32 ColourPlate pPlate,
BYTE *  SepTables
[virtual]
 

Converts the bitmap in-place from full colour 32 bpp RGB to the relevant separation returning the result as 32 bpp with correct colours for the specified plate.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com> (from ColourSeparateScanline32to8)
Date:
02/03/2004
Parameters:
OutputContext - The context to get the separation plate from [INPUTS] SepTables - points to the separation tables

Definition at line 2395 of file oilbitmap.cpp.

02396 {
02397     ERROR3IF(SepTables == NULL, "No separation tables!?");
02398     ERROR3IF(pPlate == NULL, "The separation ColourPlate has gone missing!");
02399 
02400     RebuildXPEBitmap();
02401     
02402     ERROR3IF(GetBPP() != 32, "Bitmap not 32bpp!");
02403 
02404     DWORD NumPixels = GetWidth() * GetHeight();
02405     BGRT* pPixel = (BGRT*)GetBitmapBits();
02406 
02407     // --- A wee macro to find the Maximum of R,G,B, and place it into a variable called 
02408     // Temp, which we define right now in function scope so it's always available
02409     // (It's undefined at the end of this function)
02410     BYTE Temp;
02411     #define TEMPMAX(R,G,B)                  \
02412     {                                       \
02413         Temp = ((R) > (G))  ? (R) : (G);    \
02414         Temp = (Temp > (B)) ? Temp : (B);   \
02415     }
02416 
02417     // --- Izzy, Wizzy, let's get busy
02418     DWORD i;                                    // Loop Index
02419     BYTE Ink;                               // Temporary variable for storing the ink value in
02420 
02421     BYTE *UCR = SepTables + 768 + 255;      // UCR is the 4th table, but this points at the
02422                                             // END of the table for optimisation - precalcs (255 - Temp)
02423 
02424     ColourPlateType Plate = pPlate->GetType();
02425     ColourPlateType OutputPlate = pPlate->IsMonochrome() ? COLOURPLATE_KEY : Plate;
02426     BOOL bNegate = pPlate->IsNegative();
02427     BYTE *LUT = NULL;
02428 
02429     switch (Plate)
02430     {
02431         case COLOURPLATE_CYAN:
02432             LUT = SepTables + 0;                // Cyan table is the 1st table
02433             break;
02434 
02435         case COLOURPLATE_MAGENTA:
02436             LUT = SepTables + 256;              // Magenta table is the 2nd table
02437             break;
02438 
02439         case COLOURPLATE_YELLOW:
02440             LUT = SepTables + 512;              // Yellow table is the 3rd table
02441             break;
02442 
02443         default:
02444             LUT = SepTables + 1024;             // Black generation is the 5th table
02445             break;
02446     }
02447 
02448 PORTNOTE("cms", "Disabled XaraCMS")
02449 #ifndef EXCLUDE_FROM_XARALX
02450     BOOL PrintRGBBlackAsKey = XaraCMS::PrintRGBBlackAsKey;
02451 #else
02452     BOOL PrintRGBBlackAsKey = TRUE;
02453 #endif
02454 
02455     for (i = 0; i < NumPixels; i++)
02456     {
02457         // It's colour, so get the maximum of R,G,B into Temp
02458         TEMPMAX(pPixel[i].Red, pPixel[i].Green, pPixel[i].Blue);
02459 
02460         if (!PrintRGBBlackAsKey || Temp > 0)
02461         {
02462             switch (Plate)
02463             {
02464                 case COLOURPLATE_CYAN:
02465                     Ink = 255 - pPixel[i].Red;      // Cyan ink is (255 - Red)
02466                     if (Ink>UCR[-Temp])
02467                         Ink -= UCR[-Temp];
02468                     else
02469                         Ink=0;
02470                     break;
02471 
02472                 case COLOURPLATE_MAGENTA:
02473                     Ink = 255 - pPixel[i].Green;    // Magenta ink is (255 - Green)
02474                     if (Ink>UCR[-Temp])
02475                         Ink -= UCR[-Temp];
02476                     else
02477                         Ink=0;
02478                     break;
02479 
02480                 case COLOURPLATE_YELLOW:
02481                     Ink = 255 - pPixel[i].Blue;     // Yellow ink is (255 - Blue)
02482                     if (Ink>UCR[-Temp])
02483                         Ink -= UCR[-Temp];
02484                     else
02485                         Ink=0;
02486                     break;
02487 
02488                 default:
02489                     Ink = 255 - Temp;                   // Black ink is (255 - Temp)
02490                     break;
02491             }
02492 
02493             Ink = LUT[Ink];
02494         }
02495         else
02496         {
02497             Ink = (Plate == COLOURPLATE_KEY) ? 255 : 0;
02498         }
02499 
02500         if (bNegate)
02501             Ink = 255 - Ink;
02502 
02503         switch (OutputPlate)
02504         {
02505             case COLOURPLATE_CYAN:
02506                 pPixel[i].Red = 255 - Ink;
02507                 pPixel[i].Green = 255;
02508                 pPixel[i].Blue = 255;
02509                 break;
02510 
02511             case COLOURPLATE_MAGENTA:
02512                 pPixel[i].Red = 255;
02513                 pPixel[i].Green = 255 - Ink;
02514                 pPixel[i].Blue = 255;
02515                 break;
02516 
02517             case COLOURPLATE_YELLOW:
02518                 pPixel[i].Red = 255;
02519                 pPixel[i].Green = 255;
02520                 pPixel[i].Blue = 255 - Ink;
02521                 break;
02522 
02523             default:
02524                 pPixel[i].Red = 255 - Ink;
02525                 pPixel[i].Green = 255 - Ink;
02526                 pPixel[i].Blue = 255 - Ink;
02527                 break;
02528         }
02529     } 
02530     // And finally, vape our helper macro
02531     #undef TEMPMAX
02532 }

void CWxBitmap::ColourSeparateScanline32to8 ColourContext OutputContext,
BYTE *  SepTables,
BYTE *  DestBuffer,
Pixel32bpp SrcBuffer,
INT32  PixelWidth
[static]
 

Copies the scanline of 32bpp BGR values from SrcBuffer to DestBuffer, running the pixels through colour separation tables en route. NOTE that Src and Dest may point at the same buffer to convert in-place.

Parameters:
DestBuffer - points to a destination 24bpp RGB scanline buffer [INPUTS] SrcBuffer - points to a source 24bpp RGB scanline buffer PixelWidth - The number of pixels to copy from Src to Dest
The output pixels are produced in 8bpp greyscale (0=black, 255=white) format, and will occupy only the first PixelWidth bytes of the Dest buffer.

If you're not colour-separating, then you should replace this function call with a simple memcpy or equivalent.

Notes: ONLY handles Pixel32bpp scanlines, and expects that SepTables points at the separation tables.

The CMYK separation plates could have been written generically, but I have separated out the cases in order to squeeze a bit of speed out of the inner pixel conversion loop.

Definition at line 2260 of file oilbitmap.cpp.

02263 {
02264     ERROR3IF(DestBuffer == NULL || SrcBuffer == NULL || PixelWidth < 1, "Illegal params");
02265     ERROR3IF(SepTables == NULL, "No separation tables!?");
02266     ERROR3IF(OutputContext == NULL || OutputContext->GetColourPlate() == NULL,
02267                 "The separation ColourPlate has gone missing!");
02268 
02269 //RebuildXPEBitmap();
02270     // --- A wee macro to find the Maximum of R,G,B, and place it into a variable called 
02271     // Temp, which we define right now in function scope so it's always available
02272     // (It's undefined at the end of this function)
02273     BYTE Temp;
02274     #define TEMPMAX(R,G,B)                  \
02275     {                                       \
02276         Temp = ((R) > (G))  ? (R) : (G);    \
02277         Temp = (Temp > (B)) ? Temp : (B);   \
02278     }
02279 
02280 
02281     // --- Izzy, Wizzy, let's get busy
02282     INT32 i;                                    // Loop Index
02283     BYTE Ink;                               // Temporary variable for storing the ink value in
02284 
02285     BYTE *UCR = SepTables + 768 + 255;      // UCR is the 4th table, but this points at the
02286                                             // END of the table for optimisation - precalcs (255 - Temp)
02287 
02288     ColourPlateType Plate = OutputContext->GetColourPlate()->GetType();
02289     BOOL bNegate = OutputContext->GetColourPlate()->IsNegative();
02290     BYTE *LUT = NULL;
02291 
02292     switch (Plate)
02293     {
02294         case COLOURPLATE_SPOT:
02295             for (i = 0; i < PixelWidth; i++)
02296                 DestBuffer[i] = 255;
02297             return;
02298             break;
02299     
02300         case COLOURPLATE_CYAN:
02301             LUT = SepTables + 0;                // Cyan table is the 1st table
02302             break;
02303 
02304         case COLOURPLATE_MAGENTA:
02305             LUT = SepTables + 256;              // Magenta table is the 2nd table
02306             break;
02307 
02308         case COLOURPLATE_YELLOW:
02309             LUT = SepTables + 512;              // Yellow table is the 3rd table
02310             break;
02311 
02312         default:
02313             LUT = SepTables + 1024;             // Black generation is the 5th table
02314             break;
02315     }
02316 
02317 PORTNOTE("cms", "Disabled XaraCMS")
02318 #ifndef EXCLUDE_FROM_XARALX
02319     BOOL PrintRGBBlackAsKey = XaraCMS::PrintRGBBlackAsKey;
02320 #else
02321     BOOL PrintRGBBlackAsKey = TRUE;
02322 #endif
02323 
02324     for (i = 0; i < PixelWidth; i++)
02325     {
02326         // It's colour, so get the maximum of R,G,B into Temp
02327         TEMPMAX(SrcBuffer[i].Red, SrcBuffer[i].Green, SrcBuffer[i].Blue);
02328 
02329         if (!PrintRGBBlackAsKey || Temp > 0)
02330         {
02331             switch (Plate)
02332             {
02333                 case COLOURPLATE_CYAN:
02334                     Ink = 255 - SrcBuffer[i].Red;       // Cyan ink is (255 - Red)
02335                     if (Ink>UCR[-Temp])
02336                         Ink -= UCR[-Temp];
02337                     else
02338                         Ink=0;
02339                     break;
02340 
02341                 case COLOURPLATE_MAGENTA:
02342                     Ink = 255 - SrcBuffer[i].Green;     // Magenta ink is (255 - Green)
02343                     if (Ink>UCR[-Temp])
02344                         Ink -= UCR[-Temp];
02345                     else
02346                         Ink=0;
02347                     break;
02348 
02349                 case COLOURPLATE_YELLOW:
02350                     Ink = 255 - SrcBuffer[i].Blue;      // Yellow ink is (255 - Blue)
02351                     if (Ink>UCR[-Temp])
02352                         Ink -= UCR[-Temp];
02353                     else
02354                         Ink=0;
02355                     break;
02356 
02357                 default:
02358                     Ink = 255 - Temp;                   // Black ink is (255 - Temp)
02359                     break;
02360             }
02361 
02362             Ink = LUT[Ink];
02363         }
02364         else
02365         {
02366             Ink = (Plate == COLOURPLATE_KEY) ? 255 : 0;
02367         }
02368 
02369         if (bNegate)
02370             DestBuffer[i] = Ink;
02371         else
02372             DestBuffer[i] = 255 - Ink;
02373     } 
02374     // And finally, vape our helper macro
02375     #undef TEMPMAX
02376 }

BOOL CWxBitmap::Convert24To8 RGBTRIPLE pPalette,
UINT32  NumberOfPaletteEntries
[virtual]
 

Converts the OILbitmap from its present 24bpp form into an 8bpp form which should closely match the one that was exported.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/9/96
Parameters:
pPalette - pointer to the palette in RGBTIPLE format to use when converting [INPUTS] NumberOfPaletteEntries - entries in this palette
- [OUTPUTS]
Returns:
True if worked ok, False otherwise
Assumes that the bitmap is newly loaded in and hence can easily be deleted.

Implements OILBitmap.

Definition at line 2793 of file oilbitmap.cpp.

02794 {
02795     ERROR2IF(pPalette == NULL,FALSE,"KernelBitmap::Convert24To8 null pFilter");
02796     ERROR2IF(NumberOfPaletteEntries == 0,FALSE,"KernelBitmap::Convert24To8 NumberOfPaletteEntries = 0");
02797 RebuildXPEBitmap();
02798 
02799     BOOL ok = TRUE;
02800 TRACEUSER("Neville", wxT("CWxBitmap::Convert24To8 NumberOfPaletteEntries = %d\n"),NumberOfPaletteEntries);
02801 
02802     LPBITMAPINFO pDestBMInfo = NULL;
02803     LPBYTE pDestBMBytes = NULL;
02804 
02805     // Ask the DIB convert class to do the conversion for us
02806     ok = DIBUtil::Convert24to8( BMInfo, BMBytes, &pDestBMInfo, &pDestBMBytes, 
02807                                 pPalette, NumberOfPaletteEntries);
02808 
02809     if (ok)
02810     {
02811         // Free up the 24bpp version
02812         FreeDIB( BMInfo, BMBytes );
02813 
02814         // Hot swap it for the 8bpp version
02815         BMInfo = pDestBMInfo;
02816         BMBytes = pDestBMBytes;
02817 
02818         pDestBMInfo = NULL;
02819         pDestBMBytes = NULL;
02820 
02821         ScanLineByteWidth = 0;
02822         BitmapSize = 0; // in bytes
02823 
02824         CacheGeometry();
02825     }
02826 
02827     if (pDestBMInfo != NULL)
02828     {
02829         delete pDestBMInfo;
02830     }
02831 
02832     if (pDestBMBytes != NULL)
02833     {
02834         delete pDestBMBytes;
02835     }
02836 
02837     return ok;
02838 }

void CWxBitmap::CopyFullyTransparentFrom OILBitmap pBitmap  )  [virtual]
 

Implements OILBitmap.

Definition at line 4274 of file oilbitmap.cpp.

04275 {
04276     if (GetWidth() != pBitmap->GetWidth() ||
04277         GetHeight() != pBitmap->GetHeight() ||
04278         GetBPP() != 32 ||
04279         pBitmap->GetBPP() != 32)
04280     {
04281         ERROR3("Incompatible bitmaps passed to CopyFullyTransparentFrom");
04282         return;
04283     }
04284 
04285     // Pointers to the pixel we are dealing with
04286     UINT32* pMask = (UINT32*)(pBitmap->GetBitmapBits());
04287     UINT32* pDest = (UINT32*)GetBitmapBits();
04288 
04289     // Loop through all the pixels
04290     for (UINT32 j=0; j < pBitmap->GetHeight(); j++)
04291     {
04292         for (UINT32 i=0; i < pBitmap->GetWidth(); i++)
04293         {
04294             // If this bit is background then set the corresponding pixel 
04295             // in the output bitmap to fully transparent black
04296             if (*pMask == 0xFF000000)
04297                 *pDest = 0xFF000000;
04298 
04299             // Move to the next pixel
04300             pMask++;
04301             pDest++;
04302         }
04303     }
04304 }

BOOL CWxBitmap::CreateFromwxBitmap wxBitmap *  pBitmap  )  [virtual]
 

Definition at line 3741 of file oilbitmap.cpp.

03742 {
03743     wxImage i = pBitmap->ConvertToImage();
03744     return CreateFromwxImage(&i);
03745 }

BOOL CWxBitmap::CreateFromwxImage wxImage *  pImage  )  [virtual]
 

Definition at line 3747 of file oilbitmap.cpp.

03748 {
03749     LPBITMAPINFO bmInfo;
03750     LPBYTE bmBytes;
03751 
03752     bmInfo = AllocDIB( pImage->GetWidth(), pImage->GetHeight(), 32, &bmBytes );
03753     if (!bmInfo || !bmBytes)
03754         return FALSE;
03755 
03756     BMInfo=bmInfo;
03757     BMBytes=bmBytes;
03758 
03759     INT32 dpi=96;
03760 
03761     double xppm = ((double)dpi * 10000.0)/254.0;
03762     bmInfo->bmiHeader.biXPelsPerMeter = (INT32)(xppm + 0.5);
03763     bmInfo->bmiHeader.biYPelsPerMeter = bmInfo->bmiHeader.biXPelsPerMeter;
03764 
03765     CacheGeometry();
03766 
03767     unsigned char * pData=pImage->GetData();
03768     unsigned char * pAlpha=NULL;
03769     if (pImage->HasAlpha())
03770         pAlpha=pImage->GetAlpha();
03771 
03772     // Reasonably rapid conversion to internal format
03773     for (UINT32 YPos = 0; YPos < GetHeight(); YPos++)
03774     {
03775         // DIBs are the wrong way up
03776         BYTE *ScanlineStart = BMBytes + ((GetHeight()-YPos-1) * ScanLineByteWidth);
03777         INT32 off=0;
03778 
03779         for (UINT32 XPos = 0; XPos < GetWidth(); XPos++)
03780         {
03781             ScanlineStart[off++] = pData[2]; //Red
03782             ScanlineStart[off++] = pData[1]; //Green
03783             ScanlineStart[off++] = pData[0]; //Blue
03784             pData+=(UINT_PTR)3;
03785             ScanlineStart[off++] = pAlpha?(255-*(pAlpha++)):0; // Alpha
03786         }
03787     }
03788 
03789     return TRUE;
03790 }

void CWxBitmap::DeleteData BOOL  bResetToDefault = TRUE  )  [virtual]
 

Deletes the actual bitmap data.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/8/96

Implements OILBitmap.

Definition at line 3926 of file oilbitmap.cpp.

03927 {
03928 //  ERROR2IF(this == OILBitmap::Default, FALSE, "Someone is trying to delete the default bitmap data");
03929 
03930     FreeDIB( BMInfo, BMBytes );
03931     BMInfo = NULL;
03932     BMBytes = NULL;
03933 
03934     if (bResetToDefault)
03935     {
03936         BMInfo  = ((CWxBitmap*)OILBitmap::Default)->BMInfo;
03937         BMBytes = ((CWxBitmap*)OILBitmap::Default)->BMBytes;
03938         
03939         ScanLineByteWidth   = ((CWxBitmap*)OILBitmap::Default)->ScanLineByteWidth;
03940         BitmapSize          = ((CWxBitmap*)OILBitmap::Default)->BitmapSize;
03941 
03942         DestroyGreyscaleVersion();
03943         DestroyContonePalette();
03944     }
03945 
03946     return;
03947 }

BOOL CWxBitmap::DestroyMask  )  [virtual]
 

Implements OILBitmap.

Definition at line 3910 of file oilbitmap.cpp.

03911 {
03912     return FALSE;
03913 }

BOOL CWxBitmap::ExportBitmap RenderRegion pRegion  )  [virtual]
 

Implements OILBitmap.

Definition at line 1152 of file oilbitmap.cpp.

01153 {
01154 #if !defined(EXCLUDE_FROM_RALPH)
01155 RebuildXPEBitmap();
01156     // Check the render region type
01157     if (pRegion->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSRenderRegion)))
01158     {
01159         // It's Camelot EPS - export the bitmap.
01160         if (!ExportBitmapPalette(pRegion))
01161             // Error!
01162             return FALSE;
01163 
01164         if (!ExportBitmapData(pRegion))
01165             // Error!
01166             return FALSE;
01167     }
01168 PORTNOTE("cmx", "Disabled CMXRenderRegion")
01169 #ifndef EXCLUDE_FROM_XARALX
01170     else if (pRegion->IsKindOf(CC_RUNTIME_CLASS(CMXRenderRegion)))
01171     {
01172         // CMX render region... get the DC
01173         CMXExportDC *pDC = (CMXExportDC *) pRegion->GetRenderDC();
01174 
01175         // start the bitmap list thinguy
01176         if(!pDC->StartRIFFList(cmxRIFFLIST_ImageDesc))
01177             return FALSE;
01178 
01179         // start the bitmap info section
01180         if(!pDC->StartSection(CMXExportDC::CMXSECTION_IMAGINFO))
01181             return FALSE;
01182 
01183         // tag...
01184         if(!pDC->StartTag(cmxTAG_DescrSection_Image_ImageInfo))
01185             return FALSE;
01186 
01187         // non-palette flag
01188         BOOL NoPal = FALSE;
01189         if(BMInfo->bmiHeader.biBitCount >= 24)
01190             NoPal = TRUE;
01191 
01192         // 32 bit pixel flag -- needs to be squished into 24 bitness
01193         // and our bitmap size value
01194         BOOL eBitmapSize = BitmapSize;
01195         BOOL Is32Bit = FALSE;
01196         if(BMInfo->bmiHeader.biBitCount == 32)
01197         {
01198             Is32Bit = TRUE;
01199 
01200             // calculate a new eBitmapSize
01201             eBitmapSize = GetWidth() * 3;
01202             if((eBitmapSize & 0x3) != 0)
01203                 eBitmapSize = (eBitmapSize + 4) & ~0x3; // word align to 4 byte boundary
01204             eBitmapSize *= GetHeight();
01205         }
01206 
01207         // write header
01208         cmxImageInfo ii;
01209         cmxImageHeader ih;
01210         cmxRIMAGEHeader rh;
01211         cmxRIMAGEPaletteHeader ph;
01212 
01213         DWORD BitmapHeaderSize = sizeof(rh) + (NoPal?0:(sizeof(ph) + sizeof(cmxRIMAGEPaletteEntry) * BMInfo->bmiHeader.biClrUsed));
01214 
01215         ii.Type = cmxIMAGETYPE_RIMAGE;
01216         ii.Compression = 1;         // dunno what that'll do. Probably'll work.
01217         ii.Size = sizeof(ih) + BitmapHeaderSize + eBitmapSize;
01218         ii.CompressedSize = sizeof(ih) + BitmapHeaderSize + eBitmapSize;
01219 
01220         pDC->WriteData(&ii, sizeof(ii));
01221 
01222         // end tag
01223         if(!pDC->EndTag() || !pDC->WriteMinEndTag())
01224             return FALSE;
01225 
01226         // end the bitmap info section
01227         if(!pDC->EndSection())
01228             return FALSE;
01229 
01230         // start the bitmap data section
01231         if(!pDC->StartSection(CMXExportDC::CMXSECTION_IMAGDATA))
01232             return FALSE;
01233 
01234         // write the header -- we have to do the tag ourselves as it's got a 
01235         // 32 bit length value
01236         CMXFutureLength TagLen;
01237         if(pDC->IsThirtyTwoBit())
01238         {
01239             pDC->WriteByte(cmxTAG_DescrSection_Image_ImageData);
01240             DWORD len = 0;
01241             pDC->WriteData(&len, sizeof(len));
01242             TagLen.Init(pDC, - (INT32)sizeof(len), sizeof(len));
01243             TagLen.SetLengthStartPos(pDC, - (INT32)(sizeof(len) + sizeof(BYTE)));
01244         }   
01245 
01246         // do the image header
01247         ih.ImageType[0] = 'R';
01248         ih.ImageType[1] = 'I';
01249         ih.Size = eBitmapSize + sizeof(ih) + BitmapHeaderSize;
01250         ih.Reserved[0] = 0;
01251         ih.Reserved[1] = 0;
01252         ih.OffsetToPixels = sizeof(ih) + BitmapHeaderSize;
01253         
01254         if(!pDC->WriteData(&ih, sizeof(ih)))
01255             return FALSE;
01256 
01257         // make the bitmap header
01258         rh.Type = NoPal?cmxR_IMG_RGB:cmxR_IMG_PAL;
01259         rh.ComprType = 1;               // this probably means it's got no compression, but you never know
01260         rh.Width = GetWidth();
01261         rh.Height = GetHeight();
01262         rh.Planes = 1;                              // probably right
01263         rh.BitsPerPlane = NoPal?24:BMInfo->bmiHeader.biBitCount;
01264         rh.BytesPerLine = (rh.Width * rh.BitsPerPlane) / 8;
01265         if((rh.BytesPerLine & 0x3) != 0)
01266             rh.BytesPerLine = (rh.BytesPerLine + 4) & ~0x3; // word align to 4 byte boundary
01267         rh.BufSize = eBitmapSize;
01268         rh.ComprBufSize = 0;                        // probably as we're not compressing
01269         rh.XPelsPerKM = rh.YPelsPerKM = 0x3d400;    // random value nicked from a corel CMX file
01270         rh.PaletteOffset = NoPal?0:sizeof(rh);      // starts immediatly after this
01271         rh.DataOffset = BitmapHeaderSize;           //after the palette
01272         rh.StartBufOffset = 0;                      // no idea what this does
01273         rh.AlphaOffset = 0;                         // nope, haven't got one of those mate
01274         rh.MaskOffset = 0;                          // nor one of those
01275 
01276         if(rh.BitsPerPlane == 4 && !pDC->IsThirtyTwoBit())
01277         {
01278             rh.Type = cmxR_IMG_PAL4;
01279         }
01280 
01281         // write the bitmap header
01282         if(!pDC->WriteData(&rh, sizeof(rh)))
01283             return FALSE;
01284 
01285         if(!NoPal)
01286         {
01287             // is this contoned?
01288             CMXRenderRegion *pR = (CMXRenderRegion *)pRegion;
01289             RGBQUAD *pPal = pR->GetAreExportingContoneBitmap()
01290                 ?m_pContonePalette:BMInfo->bmiColors;
01291 
01292             // write the palette
01293             ph.Type = cmxR_PALETTE_RGB;
01294             ph.NumEntries = (WORD)BMInfo->bmiHeader.biClrUsed;
01295             if(!pDC->WriteData(&ph, sizeof(ph)))
01296                 return FALSE;
01297             // palette entries
01298             for(DWORD l = 0; l < BMInfo->bmiHeader.biClrUsed; l++)
01299             {
01300                 ERROR3IF(sizeof(cmxRIMAGEPaletteEntry) != 3, "wrong size of entry");
01301                 cmxRIMAGEPaletteEntry pi;
01302                 pi.b = pPal[l].rgbBlue;
01303                 pi.g = pPal[l].rgbGreen;
01304                 pi.r = pPal[l].rgbRed;
01305                 if(!pDC->WriteData(&pi, sizeof(pi)))
01306                     return FALSE;
01307             }
01308         }
01309 
01310         // should do it, I suppose.
01311 
01312         // write the bitmap data
01313         if(!Is32Bit)
01314         {
01315             // this isn't 32 bit pixels, so just slap everything to the file
01316             if(!pDC->WriteData(BMBytes, BitmapSize))
01317                 return FALSE;
01318         }
01319         else
01320         {
01321             // corel doesn't support 32 bit pixels, so we have to go through
01322             // the image data reducing it to 24 bit. Oh well.
01323             BYTE Buffer[CMXREDUCEBPPBUFFERSIZE * 3];
01324             INT32 BufLoc = 0;
01325             INT32 PixelsToGo = GetWidth() * GetHeight();
01326             INT32 PixelsToGoInLine = GetWidth();
01327             BYTE *Pixels = (BYTE *)BMBytes;
01328             INT32 Bytes = 0;
01329 
01330             while(PixelsToGo > 0)
01331             {
01332                 // bung a pixel in the buffer
01333                 Buffer[BufLoc++] = *(Pixels++);
01334                 Buffer[BufLoc++] = *(Pixels++);
01335                 Buffer[BufLoc++] = *(Pixels++);
01336                 Pixels++;
01337                 Bytes += 3;
01338 
01339                 // decrement counts
01340                 PixelsToGo--;
01341                 PixelsToGoInLine--;
01342 
01343                 // check to see if we're at the end of the line
01344                 if(PixelsToGoInLine <= 0)
01345                 {
01346                     // check to see if we need to word align here...
01347                     if((Bytes & 0x3) != 0)
01348                     {
01349                         INT32 Need = ((Bytes + 4) & ~0x3) - Bytes;
01350                         for(INT32 l = 0; l < Need; l++)
01351                         {
01352                             Buffer[BufLoc++] = 0;
01353                             Bytes++;
01354                         }
01355                     }
01356 
01357                     PixelsToGoInLine = GetWidth();  // reset counter
01358                 }
01359 
01360                 // test to see if we've done enough
01361                 if(BufLoc >= ((CMXREDUCEBPPBUFFERSIZE * 3) - 8))        // enough for another pixel or so
01362                 {
01363                     // write it to the file
01364                     pDC->WriteData(Buffer, BufLoc);
01365 
01366                     // reset counter
01367                     BufLoc = 0;
01368                 }
01369             }
01370 
01371             // write anything left to the file
01372             pDC->WriteData(Buffer, BufLoc);
01373         }
01374 
01375         // write the length
01376         if(pDC->IsThirtyTwoBit())
01377             TagLen.Write(pDC);
01378 
01379         // end tag...
01380         if(!pDC->WriteMinEndTag())
01381             return FALSE;
01382 
01383         // end the bitmap data section
01384         if(!pDC->EndSection())
01385             return FALSE;
01386 
01387         // end the bitmap list thingy
01388         if(!pDC->EndRIFFList())
01389             return FALSE;
01390 
01391         return TRUE;
01392     }
01393 #endif
01394 #endif
01395     // If we got here, no errors occured.
01396     return TRUE;
01397 }

BOOL CWxBitmap::ExportBitmapData RenderRegion pRegion  )  [virtual]
 

Exports this bitmap's image data to the given RenderRegion.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
?
Parameters:
pRegion - The Postscript RenderRegion to export to. In fact, if this is [INPUTS] not IsKindOf(CamelotEPSRenderRegion), this function will do nothing and return TRUE.
Returns:
TRUE for success
Notes: The RenderRegion is responsible for outputting all header/trailer info about the bitmap, and for calling ExportBitmapPalette or ExportContonePalette as appropriate, if necessary. Be very careful when fiddling with this code, because it affects postscript printing as well as all EPS export formats, including Xara v1.1 "native" EPS.

When exporting to postscript, this function can only handle 1,2,4,8,24,32 bpp images.

If you want to COLOUR SEPARATE the output, you should call ExportSeparatedData instead.

(BTW, This code is quite hideous, but I have not changed it, because it is too easy to break Postscript, AI EPS, Artworks EPS, and/or Camelot EPS by doing so)

See also:
CWxBitmap::ExportSeparatedData; CamelotEPSRenderRegion::DrawParallelogramBitmap

Implements OILBitmap.

Definition at line 1741 of file oilbitmap.cpp.

01742 {
01743 #if !defined(EXCLUDE_FROM_RALPH)
01744 RebuildXPEBitmap();
01745     // Check the render region type
01746     if (pRegion->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSRenderRegion)))
01747     {
01748         // It's Camelot EPS - export the bitmap.
01749         KernelDC *pDC = (KernelDC *) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC());
01750         Filter *pFilter = pDC->GetParentFilter();
01751 
01752         // Find out if it needs to be renderable
01753         BOOL Renderable = (IS_A(pRegion, CamelotEPSRenderRegion) || pRegion->IsPrinting());
01754 
01755         // If it is renderable, find out if we can use Level 2 features.
01756         BOOL UseLevel2 = FALSE;
01757 
01758         if (Renderable)
01759         {
01760 // WEBSTER-ranbirr-12/11/96
01761 #ifndef WEBSTER
01762             if (pRegion->IsPrinting())
01763             {
01764 
01765 #ifndef STANDALONE
01766                 // Get the print info for this job.
01767                 CCPrintInfo *pInfo = CCPrintInfo::GetCurrent();
01768                 if (pInfo != NULL)
01769                 {
01770                     PrintControl *pPrCtrl = pInfo->GetPrintControl();
01771                     if (pPrCtrl->GetPSLevel() == PSLEVEL_2)
01772                         // Printing to a level 2 device - party on!
01773                         UseLevel2 = TRUE;
01774                 }
01775 #else
01776     ERROR2(FALSE,"CWxBitmap::ExportBitmapData trying to print on Viewer version!");
01777 #endif
01778             }
01779             else
01780 #endif //webster
01781             {
01782                 // Use the EPS preference.
01783                 if (EPSFilter::XSEPSExportPSType == 2)
01784                     UseLevel2 = TRUE;
01785             }
01786         }
01787 
01788         // Export the bitmap pixel data itself.
01789         if (!Renderable)
01790             pDC->OutputToken(_T("%Camelot: Bitmap data"));
01791         pDC->OutputNewLine();
01792         
01793         // Do each scanline...
01794         //
01795         // NB. We add 7 to make sure we round up to the next byte for fractional bytes,
01796         //     otherwise we lose pixels at the end of scanlines for bitmaps with less
01797         //     than 8bpp depth.
01798         INT32 Width  = ((BMInfo->bmiHeader.biWidth * BMInfo->bmiHeader.biBitCount) + 7) / 8;
01799         INT32 Height = BMInfo->bmiHeader.biHeight;
01800 
01801         INT32 Ofs = 0;
01802 
01803         // If renderable, then don't pad the data (except to the next byte boundary).
01804         INT32 Padding = Renderable ? 1 : 4;
01805 
01806         // If we're printiand trying to output 32bpp, we'll output it as 24bpp
01807         BOOL Do32bpp = pRegion->IsPrinting() && (BMInfo->bmiHeader.biBitCount == 32);
01808         if (Do32bpp)
01809             Width = BMInfo->bmiHeader.biWidth * 3;  // 32bpp is converted down to 24bpp
01810 
01811         // Swap RGB data as PostScript expects it in BGR format.
01812         BOOL SwapRGB = Renderable && (BMInfo->bmiHeader.biBitCount == 24);
01813 
01814         // Expand 4bpp images to 8bpp images as the Adobe SDK imaging library does
01815         // not seem to work on some printers with 4bpp images (e.g. Canon LBP4-PS).
01816         BOOL Expand4bpp = Renderable && (BMInfo->bmiHeader.biBitCount == 4);
01817 
01818         INT32 DataSize = Width;
01819         LPBYTE pAllocatedMem = NULL;        // Memory we must remember to free on exit
01820         if (SwapRGB || Do32bpp)
01821         {
01822             // We need to swap the R and B components around as PostScript expects to get
01823             // data like this:  BGRBGRBGR...
01824             // So we need a buffer in which to do this
01825             pAllocatedMem = (LPBYTE) CCMalloc(Width);
01826             if (pAllocatedMem == NULL)
01827                 // No more memory!
01828                 return FALSE;
01829         }
01830         else if (Expand4bpp)
01831         {
01832             // We need to expand the 4bpp data to 8bpp data.
01833             // So we need a buffer in which to do this
01834             DataSize = ((BMInfo->bmiHeader.biWidth * 8) + 7) / 8;
01835             pAllocatedMem = (LPBYTE) CCMalloc(DataSize);
01836             if (pAllocatedMem == NULL)
01837                 // No more memory!
01838                 return FALSE;
01839 
01840             // Double buffer size
01841         }
01842 
01843         LPBYTE pBuf = pAllocatedMem;        // Scanline buffer pointer - may point into the source bitmap
01844 
01845         UINT32 ScanlineSize = DIBUtil::ScanlineSize(BMInfo->bmiHeader.biWidth, 
01846                                                    BMInfo->bmiHeader.biBitCount);
01847 
01848         // If we are going to do ASCII85, get ready for it.
01849         if (UseLevel2)
01850         {
01851             if (!pDC->StartASCII85Output(TRUE))  // TRUE => RLE please
01852                 // Error
01853                 return FALSE;
01854         }
01855 
01856 
01857         for (INT32 i = 0; i < Height; i++)
01858         {
01859             if (Do32bpp)
01860             {
01861                 // Take a copy of this scanline, skipping the Alpha channels, and reverse the
01862                 // RGB ordering so that PostScript can use the data directly.
01863                 INT32 k = Ofs;
01864                 for (INT32 j = 0; j < Width; j += 3)
01865                 {
01866                     pBuf[j]     = BMBytes[k + 2];
01867                     pBuf[j + 1] = BMBytes[k + 1];
01868                     pBuf[j + 2] = BMBytes[k];
01869 
01870                     k += 4;
01871                 }
01872             }
01873             else if (SwapRGB)
01874             {
01875                 // Take a copy of this scanline and reverse the RGB ordering so that
01876                 // PostScript can use the data directly.
01877                 for (INT32 j = 0; j < Width; j += 3)
01878                 {
01879                     pBuf[j]     = BMBytes[Ofs + j + 2];
01880                     pBuf[j + 1] = BMBytes[Ofs + j + 1];
01881                     pBuf[j + 2] = BMBytes[Ofs + j];
01882                 }
01883             }
01884             else if (Expand4bpp)
01885             {
01886                 // Take a copy of this 4bpp scanline and expand it to 8bpp.
01887                 INT32 k = 0;
01888                 for (INT32 j = 0; j < Width; j++)
01889                 {
01890                     pBuf[k++] = (BMBytes[Ofs + j] & 0xF0) >> 4;
01891                     pBuf[k++] = BMBytes[Ofs + j] & 0xF;
01892                 }
01893             }
01894             else
01895                 // Just point to raw data
01896                 pBuf = BMBytes + Ofs;
01897 
01898             // Write the data out, possibly encoded in ASCII85
01899             INT32 nBytes;
01900 
01901             if (UseLevel2)
01902                 // No padding needed for renderable PostScript/EPS.
01903                 nBytes = pDC->OutputASCII85(pBuf, DataSize);
01904             else
01905                 // Normal ASCII Hex output (or binary in Native files).
01906                 nBytes = pDC->OutputRawBinary(pBuf, DataSize, Padding);
01907 
01908             if (nBytes == -1)
01909             {
01910                 // Error - prob out of disc space
01911                 if (pAllocatedMem != NULL)
01912                     CCFree(pAllocatedMem);
01913 
01914                 return FALSE;
01915             }
01916 
01917             // Update progress display
01918             if (pFilter != NULL)
01919                 pFilter->UpdateExportedNodeCount(1);
01920 
01921             // Do next line
01922             Ofs += ScanlineSize;
01923         }
01924 
01925         if (UseLevel2)
01926         {
01927             if (!pDC->EndASCII85Output())
01928                 // Error
01929                 return FALSE;
01930         }
01931 
01932         // Free the temp buffer if necessary.
01933         if (pAllocatedMem != NULL)
01934             CCFree(pAllocatedMem);
01935     }
01936 #endif
01937     // If we got here, no errors occured.
01938     return TRUE;
01939 }

BOOL CWxBitmap::ExportBitmapPalette RenderRegion pRegion  )  [virtual]
 

Exports this bitmap's palette to the given RenderRegion.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
?
Returns:
TRUE for success
Notes: This function outputs the data in 2 different ways, depending on whether it thinks the RenderRegion is for Renderable postscript or not.

This function now handles colour separation and correction on export, by using the RenderRegion's RenderView to find an appropriate RGB output colour context to do the colour output for it.

See also:
CWxBitmap::ExportBitmapPaletteInternal

Implements OILBitmap.

Definition at line 1550 of file oilbitmap.cpp.

01551 {
01552 #if !defined(EXCLUDE_FROM_RALPH)
01553 RebuildXPEBitmap();
01554     // Check the render region type
01555     if (!pRegion->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSRenderRegion)))
01556     {
01557         ERROR3("ExportBitmapPalette called by non-CamelotEPSRenderRegion class");
01558         return(TRUE);
01559     }
01560 
01561     // Sanity check. Note that we allow deep bitmaps here, as this function exports nothing
01562     // when the bitmap has no palette, including deep images.
01563     ERROR3IF((BMInfo->bmiHeader.biBitCount != 1) &&
01564             (BMInfo->bmiHeader.biBitCount != 4) &&
01565             (BMInfo->bmiHeader.biBitCount != 8) &&
01566             (BMInfo->bmiHeader.biBitCount != 24) &&
01567             (BMInfo->bmiHeader.biBitCount != 32), "Bad bitmap depth in ExportBitmap!");
01568 
01569     // If it's a depp bitmap or it has no palette, then we return TRUE immediately
01570     if (BMInfo->bmiHeader.biBitCount > 8 || BMInfo->bmiHeader.biClrUsed < 1)
01571         return(TRUE);
01572 
01573     // Find out if it needs to be renderable (proper Adobe EPS)
01574     BOOL Renderable = (IS_A(pRegion, CamelotEPSRenderRegion) || pRegion->IsPrinting());
01575 
01576     if (Renderable)     // Renderable postscript, so output in proper Adobe format
01577         return(ExportBitmapPaletteInternal(pRegion, BMInfo->bmiHeader.biClrUsed, BMInfo->bmiColors));
01578 
01579 
01580     // Not renderable (it's CamelotEPS), so we can output the bitmap as raw binary
01581     KernelDC *pDC = (KernelDC *) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC());
01582 
01583     pDC->OutputToken(_T("%Camelot: Bitmap palette"));
01584     pDC->OutputRawBinary((BYTE *) BMInfo->bmiColors, 
01585                          BMInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD));
01586     pDC->OutputNewLine();
01587 #endif
01588     // If we got here, no errors occured.
01589     return TRUE;
01590 }

BOOL CWxBitmap::ExportBitmapPaletteInternal RenderRegion pRegion,
INT32  NumColours,
RGBQUAD pSrcCLUT
[protected]
 

Exports the given palette data to the given RenderRegion Used as an internal shared function for ExportBitmapPalette and ExportContonePalette.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (Moved Tim code into this shared subroutine)
Date:
1/7/96 (Original code date unknown)
Returns:
TRUE for success
The palette is exported twice - first as a greyscale CLUT, then as a colour CLUT.

Notes: This function now handles colour separation and correction on export, by using the RenderRegion's RenderView to find an appropriate RGB output colour context to do the colour output for it.

IF (pSrcCLUT == ContonePalette), then a GLOBAL DEFAULT colour context is used, so that the contone palette is NOT colour separated. It is expected that you will build and discard the contone palette very close to the ExportContonePalette call, so that it will be pre- separated for the current output context.

Definition at line 1429 of file oilbitmap.cpp.

01430 {
01431 #if !defined(EXCLUDE_FROM_RALPH)
01432 RebuildXPEBitmap();
01433     // Sanity check
01434     ERROR3IF((BMInfo->bmiHeader.biBitCount != 1) &&
01435             (BMInfo->bmiHeader.biBitCount != 4) &&
01436             (BMInfo->bmiHeader.biBitCount != 8) &&
01437             (BMInfo->bmiHeader.biBitCount != 24) &&
01438             (BMInfo->bmiHeader.biBitCount != 32), "Bad bitmap depth in ExportBitmap!");
01439 
01440     ERROR3IF(pRegion == NULL || pSrcCLUT == NULL, "Illegal NULL params");
01441 
01442     const INT32 ClutSize = 256;
01443 
01444     // Allocate an array in which we can construct the clut.
01445     LPBYTE pCLUT = (LPBYTE) CCMalloc(ClutSize * 3);
01446     if (pCLUT == NULL)
01447     {
01448         // Out of memory
01449         ERROR3("No memory");
01450         return FALSE;
01451     }
01452 
01453     // Find the output DC
01454     KernelDC *pDC = (KernelDC *) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC());
01455 
01456     // First, clear all entries to black
01457     memset(pCLUT, 0, ClutSize);
01458 
01459     // Find an RGB colour context to colour-separate the colours for us (if it's necessary)
01460     // (Note: If we're exporting the ContonePalette, then we assume that it is pre-separated,
01461     // and just get a simple (non-separating) RGB context instead, to avoid double-separating
01462     ColourContextRGBT *ccRGB = NULL;
01463     if (pSrcCLUT == m_pContonePalette)
01464         ccRGB = (ColourContextRGBT *) ColourManager::GetColourContext(COLOURMODEL_RGBT);
01465     else
01466         ccRGB = (ColourContextRGBT *) pRegion->GetRenderView()->GetColourContext(COLOURMODEL_RGBT);
01467     ERROR2IF(ccRGB == NULL, FALSE, "Can't get a ColourContextRGBT for EPS bitmap export");
01468 
01469     DocColour TempCol;
01470     // BLOCK
01471     {
01472         ColourRGBT RGB;
01473          
01474         // Build the greyscale CLUT first.
01475         for (INT32 i = 0; i < NumColours; i++)
01476         {
01477             TempCol.SetRGBValue(pSrcCLUT[i].rgbRed, pSrcCLUT[i].rgbGreen, pSrcCLUT[i].rgbBlue);
01478             ccRGB->ConvertColour(&TempCol, (ColourGeneric *) &RGB);
01479 
01480             double Grey =   (RGB.Red.MakeDouble()   * 0.305) +
01481                             (RGB.Green.MakeDouble() * 0.586) +
01482                             (RGB.Blue.MakeDouble()  * 0.109);
01483 
01484             pCLUT[i] = (BYTE) (Grey * 255.0);
01485         }
01486     }
01487 
01488     // Greyscale palette complete - output it as a hex string
01489     pDC->OutputNewLine();
01490     pDC->OutputToken(_T("<"));
01491     pDC->OutputRawBinary(pCLUT, ClutSize);
01492     pDC->OutputToken(_T(">"));
01493     pDC->OutputNewLine();
01494 
01495     // Ok, now do the colour palette.
01496     // First, clear all entries to black
01497     memset(pCLUT, 0, ClutSize * 3);
01498 
01499     // BLOCK
01500     {
01501         PColourRGBT RGB;
01502 
01503         for (INT32 i = 0; i < NumColours; i++)
01504         {
01505             TempCol.SetRGBValue(pSrcCLUT[i].rgbRed, pSrcCLUT[i].rgbGreen, pSrcCLUT[i].rgbBlue);
01506             ccRGB->ConvertColour(&TempCol, (ColourPacked *) &RGB);
01507             
01508             pCLUT[i * 3 + 0] = RGB.Red;
01509             pCLUT[i * 3 + 1] = RGB.Green;
01510             pCLUT[i * 3 + 2] = RGB.Blue;
01511         }
01512     }
01513 
01514     // RGB palette complete - output it as a hex string
01515     pDC->OutputNewLine();
01516     pDC->OutputToken(_T("<"));
01517     pDC->OutputRawBinary(pCLUT, ClutSize * 3);
01518     pDC->OutputToken(_T(">"));
01519     pDC->OutputNewLine();
01520 
01521     // Clean up
01522     CCFree(pCLUT);
01523 #endif
01524     // If we got here, no errors occured.
01525     return TRUE;
01526 }

BOOL CWxBitmap::ExportContonePalette RenderRegion pRegion  )  [virtual]
 

Exports this bitmap's contone palette to the given RenderRegion.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
?
Returns:
TRUE for success
You must have called BuildContonePalette before calling this function!

Notes: This funmction does NOT colour separate the contone palette. However, the colour is correctly separated when you call BuildContonePalette, so it is imperative that you build the contone palette immediately prior to export, and discard it immediately afterward (i.e. don't rely on a cached version of the contone palette).

See also:
OILBitmap::BuildContonePalette; CWxBitmap::ExportBitmapPaletteInternal

Implements OILBitmap.

Definition at line 1690 of file oilbitmap.cpp.

01691 {
01692 #if !defined(EXCLUDE_FROM_RALPH)
01693 RebuildXPEBitmap();
01694     ERROR2IF(m_pContonePalette == NULL, FALSE, "No contone palette to export!");
01695 
01696     // If it's Camelot EPS, then export the bitmap
01697     if (pRegion->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSRenderRegion)))
01698         return(ExportBitmapPaletteInternal(pRegion, BMInfo->bmiHeader.biClrUsed, m_pContonePalette));
01699 #endif
01700     // All ok
01701     return TRUE;
01702 }

BOOL CWxBitmap::ExportSeparatedData RenderRegion pRegion,
BYTE *  SepTables
[virtual]
 

Exports this bitmap's image data to the given RenderRegion, colour separating to an 8bpp image as it does so.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/7/96
Parameters:
pRegion - The Postscript RenderRegion to export to. In fact, if this is [INPUTS] not IsKindOf(CamelotEPSRenderRegion), this function will do nothing and return TRUE.
SepTables - See ExportBitmapData. This function should ONLY be called with a valid SepTabls pointer, from ExportBitmapData.

Returns:
TRUE for success
This function is the colour-separating analogue of ExportBitmapData.

It is only (currently) used when printing to postscript.

Notes: Separated bitmap data is ALWAYS in the form of a greyscale 8 bits per pixel

This function can handle any input bitmap depth (1/4/8/24/32) which CWxBitmap::ReadPixel supports.

This function may only be called when: SepTables != NULL pRegion->GetRenderView()->GetColourPlate()->GetType() is a separation plate (C/M/Y/K or Spot).

Implementation: We use ReadScanline32bpp to get the bitmap data in a generic 32bpp format, then pass a generic colour separation engine over it to generate a generic 8bpp greyscale separated bitmap. We could be more efficient for low bpp bitmaps, but this would just introduce more special-cases, and more chance of it not working in some circumstances.

See also:
CWxBitmap::ExportBitmapData

Implements OILBitmap.

Definition at line 1986 of file oilbitmap.cpp.

01987 {
01988 #ifndef STANDALONE
01989     ERROR3IF(pRegion == NULL || SepTables == NULL, "Illegal NULL params");
01990 
01991     if (!pRegion->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSRenderRegion)))
01992     {
01993         ERROR3("Not a CamelotEPSRenderRegion derived RenderRegion - bitmap not exported");
01994         return(TRUE);       // Return success - don't shaft the whole print just for one bitmap
01995     }
01996 
01997 RebuildXPEBitmap();
01998     KernelDC *pDC = (KernelDC *) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC());
01999     Filter *pFilter = pDC->GetParentFilter();
02000 
02001     // If it is renderable, find out if we can use Level 2 features.
02002     BOOL UseLevel2 = FALSE;
02003     BOOL Renderable = (IS_A(pRegion, CamelotEPSRenderRegion) || pRegion->IsPrinting());
02004 
02005     if (Renderable)
02006     {
02007 //  WEBSTER-ranbirr-12/11/96
02008 #ifndef WEBSTER
02009         if (pRegion->IsPrinting())
02010         {
02011             // Get the print info for this job.
02012             CCPrintInfo *pInfo = CCPrintInfo::GetCurrent();
02013             if (pInfo != NULL)
02014             {
02015                 PrintControl *pPrCtrl = pInfo->GetPrintControl();
02016                 UseLevel2 = (pPrCtrl->GetPSLevel() == PSLEVEL_2);
02017             }
02018         }
02019         else
02020 #endif //webster
02021 
02022             UseLevel2 = (EPSFilter::XSEPSExportPSType == 2);            // Use the EPS preference.
02023     }
02024 
02025     // Export the bitmap pixel data itself.
02026     if (!Renderable)
02027         pDC->OutputToken(_T("%Camelot: Bitmap data"));
02028     pDC->OutputNewLine();
02029     
02030     // Get some useful constants...
02031 //  const INT32 BitsPerPixel    = BMInfo->bmiHeader.biBitCount;
02032     const INT32 PixelWidth  = BMInfo->bmiHeader.biWidth;
02033     const INT32 PixelHeight = BMInfo->bmiHeader.biHeight;
02034     const INT32 ByteWidth   = PixelWidth;
02035 
02036     // If we have to change the scanlines in any way, we'll use a temporary scanline buffer
02037     // which can hold a full scanline of 8bpp pixels
02038     BYTE *pOutputBuffer = (BYTE *) CCMalloc(ByteWidth);
02039     if (pOutputBuffer == NULL)
02040     {
02041         ERROR3("Scanline buffer allocation failed");
02042         return(FALSE);
02043     }
02044 
02045     Pixel32bpp *pInputBuffer = (Pixel32bpp *) CCMalloc(PixelWidth * sizeof(Pixel32bpp));
02046     if (pInputBuffer == NULL)
02047     {
02048         ERROR3("No memory for 32bpp separation scanline");
02049         return(FALSE);
02050     }
02051 
02052     // If we are going to do ASCII85, get ready for it.
02053     if (UseLevel2 && !pDC->StartASCII85Output(TRUE))  // TRUE => RLE please
02054     {
02055         ERROR3("StartASCII85Output failed");
02056         return(FALSE);
02057     }
02058 
02059     // If separating, find a colour context for the separation to use
02060     ColourContext *OutputContext = NULL;
02061     if (SepTables != NULL)
02062     {
02063         ERROR3IF(pRegion->GetRenderView() == NULL, "Darn");
02064         OutputContext = pRegion->GetRenderView()->GetColourContext(COLOURMODEL_RGBT);
02065 
02066         ERROR3IF(OutputContext == NULL, "Double Darn");
02067     }
02068 
02069     INT32 nBytes;
02070     for (INT32 y = 0; y < PixelHeight; y++)
02071     {
02072         GetScanline32bpp(y, TRUE, pInputBuffer);
02073         ColourSeparateScanline32to8(OutputContext, SepTables, pOutputBuffer, pInputBuffer, PixelWidth);
02074 
02075         // Write the data out, possibly encoded in ASCII85
02076         if (UseLevel2)
02077             nBytes = pDC->OutputASCII85(pOutputBuffer, ByteWidth);
02078         else
02079             nBytes = pDC->OutputRawBinary(pOutputBuffer, ByteWidth, (Renderable) ? 1 : 4);
02080 
02081         if (nBytes == -1)
02082         {
02083             ERROR3("EPS output failed - Out of disc space?");
02084             CCFree(pOutputBuffer);
02085             return(FALSE);
02086         }
02087 
02088         // Update progress display
02089         if (pFilter != NULL)
02090             pFilter->UpdateExportedNodeCount(1);
02091     }
02092 
02093     CCFree(pInputBuffer);
02094     CCFree(pOutputBuffer);
02095 
02096     if (UseLevel2 && !pDC->EndASCII85Output())
02097     {
02098         ERROR3("EndASCII85Output failed");
02099         return(FALSE);
02100     }
02101     return(TRUE);
02102 #else
02103     ERROR2(FALSE,"CWxBitmap::SeparateBitmapData being called in Viewer version!");
02104 #endif
02105 }

BOOL CWxBitmap::ExportSeparatedPalette RenderRegion pRegion  )  [virtual]
 

Exports a greyscale 8bpp palette suitable for use by the bitmaps output by ExportSeparatedData.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/7/96
Parameters:
pRegion - The render region to export to [INPUTS]
Returns:
TRUE for success
Notes: This function is very specialised, for handling the output of a palette for an 8bpp greyscale seaparation plate of a bitmap to be output with OutputSeparatedData.

See CamelotEPSRenderRegion::DrawParallelogramBitmap for the only code which should be calling this function.

Returns:
Errors: Many ERROR3's - this bitmap must be deep, we must be printing, there must be a valid ColourPlate for separating the output.
See also:
CWxBitmap::ExportBitmapPalette; CWxBitmap::ExportSeparatedData

Implements OILBitmap.

Definition at line 1621 of file oilbitmap.cpp.

01622 {
01623 #if !defined(EXCLUDE_FROM_RALPH)
01624     ERROR3IF(pRegion == NULL, "Illegal NULL params");
01625     if (!pRegion->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSRenderRegion)))
01626     {
01627         ERROR3("ExportBitmapPalette called by non-CamelotEPSRenderRegion class");
01628         return(TRUE);
01629     }
01630 
01631     // Sanity checks
01632     ERROR3IF(!pRegion->IsPrinting(), "ExportSeparatedBitmapPalette called when not printing?");
01633 
01634     ERROR3IF(pRegion->GetRenderView() == NULL, "No render view");
01635     ERROR3IF(pRegion->GetRenderView()->GetColourPlate() == NULL,
01636             "Not colour separating in ExportSeparatedBitmapPalette");
01637 
01638 RebuildXPEBitmap();
01639     KernelDC *pDC = (KernelDC *) CCDC::ConvertFromNativeDC(pRegion->GetRenderDC());
01640     BYTE pCLUT[256 * 3];
01641 
01642     INT32 i;
01643     // Do a greyscale intensity CLUT
01644     for (i = 0; i < 256; i++)
01645         pCLUT[i] = i;
01646 
01647     pDC->OutputNewLine();
01648     pDC->OutputToken(_T("<"));
01649     pDC->OutputRawBinary(pCLUT, 256);
01650     pDC->OutputToken(_T(">"));
01651     pDC->OutputNewLine();
01652 
01653     // And do a 24bit RGB CLUT
01654     for (i = 0; i < 256*3; i+=3)
01655         pCLUT[i] = pCLUT[i+1] = pCLUT[i+2] = i/3;
01656 
01657     pDC->OutputNewLine();
01658     pDC->OutputToken(_T("<"));
01659     pDC->OutputRawBinary(pCLUT, 256 * 3);
01660     pDC->OutputToken(_T(">"));
01661     pDC->OutputNewLine();
01662 
01663 #endif
01664     return(TRUE);
01665 }

void CWxBitmap::ExtractBitsAndInfo LPBYTE ppBytes,
LPBITMAPINFO ppInfo
 

To extract the bitmap data for use elsewhere, sets them to null so that the CWxBitmap object can be deleted.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/8/2000
Parameters:
the bytes and bitmapinfo of this bitmap [OUTPUTS]
Returns:
-

Definition at line 4221 of file oilbitmap.cpp.

04222 {
04223 RebuildXPEBitmap();
04224     *ppBytes = BMBytes;
04225     *ppInfo = BMInfo;
04226 
04227     BMBytes = NULL;
04228     BMInfo = NULL;
04229 }

void CWxBitmap::GenerateGreyscaleTable  )  [virtual]
 

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/8/96

Implements OILBitmap.

Definition at line 3983 of file oilbitmap.cpp.

03984 {
03985 RebuildXPEBitmap();
03986 //  if (GetBPP() != 8)
03987     if (GetBPP()>8)
03988         return;
03989     UINT32 bpp = GetBPP() ;
03990 
03991     if (m_pGreyscaleTable != NULL)
03992         return;
03993 
03994     m_pGreyscaleTable = new BYTE[1<<bpp];
03995     if (m_pGreyscaleTable == NULL)
03996         return;
03997 
03998     for (INT32 i=0; i<1<<bpp; i++)
03999     {
04000         double R = BMInfo->bmiColors[i].rgbRed;
04001         double G = BMInfo->bmiColors[i].rgbGreen;
04002         double B = BMInfo->bmiColors[i].rgbBlue;
04003 
04004         m_pGreyscaleTable[i] = BYTE((R * 0.305) + (G * 0.586) + (B * 0.109));
04005 //      TRACEUSER( "Will", _T("Intensity[%d] = %d\n"), i, m_pGreyscaleTable[i]);
04006     }
04007 }

virtual ADDR CWxBitmap::GetBitmapBits  )  [inline, virtual]
 

Implements OILBitmap.

Definition at line 149 of file oilbitmap.h.

00149 {   return (ADDR)BMBytes;   }

LPBITMAPINFO CWxBitmap::GetBitmapInfo  )  [virtual]
 

To get at the BITMAPINFO palette that this bitmap may have.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
03/07/97
Returns:
The BITMAPINFO for this bitmap or null.
BITMAPINFO consists of:- BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1];

Implements OILBitmap.

Definition at line 4083 of file oilbitmap.cpp.

04084 {
04085 RebuildXPEBitmap();
04086     return BMInfo;
04087 }

LPBITMAPINFOHEADER CWxBitmap::GetBitmapInfoHeader  )  [virtual]
 

To get at the BITMAPINFOHEADER that this bitmap should have.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
03/07/97
Returns:
The bitmap header for this bitmap or null.
BITMAPINFO consists of:- BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1];

Implements OILBitmap.

Definition at line 4133 of file oilbitmap.cpp.

04134 {
04135 RebuildXPEBitmap();
04136     if (BMInfo == NULL)
04137         return NULL;
04138 
04139     // Return the BITMAPINFOHEADER for this bitmap
04140     return &BMInfo->bmiHeader;
04141 }

UINT32 CWxBitmap::GetBPP RenderRegion pRegion = NULL  )  [virtual]
 

Finds the colour resolution of this bitmap (or, if PRegion is specified, the colour resolution at which this bitmap should be output).

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/1/95
Parameters:
pRegion - NULL to get the real BPP of this bitmap [INPUTS] else points to the render region which will be rendering the bitmap - if the region is colour-separating, then the returned BPP will be set to the actual export BPP that will/should be used (i.e. deep colour bitmaps are generally colour separated to an 8bpp greyscale bitmap)
Returns:
The number of Bits per pixel of this bitmap

Errors: -

See also:
-

Implements OILBitmap.

Definition at line 637 of file oilbitmap.cpp.

00638 {
00639 RebuildXPEBitmap();
00640     // Currently, we colour-separate to the same number of BPP as the source bitmap,
00641     // so we always return the same value.
00642 
00643     if (BMInfo == NULL)
00644         return 0;
00645 
00646     return BMInfo->bmiHeader.biBitCount;
00647 }

UINT32 CWxBitmap::GetHeight void   )  [virtual]
 

Retrieve information on this bitmap.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/7/96
Returns:
The Pixel Height of this bitmap
See also:
CWxBitmap::GetInfo

Implements OILBitmap.

Definition at line 552 of file oilbitmap.cpp.

00553 {
00554 RebuildXPEBitmap();
00555     if (BMInfo == NULL)
00556         return(0);
00557 
00558     return(BMInfo->bmiHeader.biHeight);
00559 }

UINT32 CWxBitmap::GetHorizontalDPI  )  [virtual]
 

Retrieve information on this bitmap.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/6/97
Returns:
The Horizontal DPI of this bitmap
See also:
CWxBitmap::GetInfo

Implements OILBitmap.

Definition at line 573 of file oilbitmap.cpp.

00574 {
00575 RebuildXPEBitmap();
00576     if (BMInfo == NULL)
00577         return 96;
00578 
00579     INT32 PelW = BMInfo->bmiHeader.biXPelsPerMeter;
00580     if (PelW <= 0)
00581         PelW = DEFAULT_PIXEL_SIZE;
00582 
00583     UINT32 dpi = (UINT32)((((double)PelW * 254.0)/10000.0) + 0.5); // round up the result
00584     return dpi;
00585 }

BOOL CWxBitmap::GetInfo BitmapInfo Info,
RenderRegion pRegion = NULL
[virtual]
 

Kernel code can call this to obtain information about the bitmap in a platform- independent way. This function is implemented differently on different OIL layers.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
?/9/94
Parameters:
pRegion - NULL to get the real BPP of this bitmap [INPUTS] else points to the render region which will be rendering the bitmap - if the region is colour-separating, then the returned BPP will be set to the actual export BPP that will/should be used (i.e. deep colour bitmaps are generally colour separated to an 8bpp greyscale bitmap)
Output: *Info gets updated.

Returns:
TRUE if worked, FALSE if failed (e.g. no attached bitmap).
If you only need width/height/bpp/paletteentries, then see SeeAlso

Returns:
Errors: SetError NOT called. Scope: Public
See also:
CWxBitmap::GetWidth; CWxBitmap::GetHeight; CWxBitmap::GetBPP; CWxBitmap::GetNumPaletteEntries

Implements OILBitmap.

Definition at line 452 of file oilbitmap.cpp.

00453 {
00454     ERROR3IF(Info == NULL, "Illegal NULL param");
00455 RebuildXPEBitmap();
00456 
00457     if (BMInfo && BMBytes && !m_bNeedsXPERebuild)
00458     {
00459         Info->PixelWidth        = GetWidth();
00460         Info->PixelHeight       = GetHeight();
00461         Info->PixelDepth        = GetBPP(pRegion);
00462         Info->NumPaletteEntries = GetNumPaletteEntries();
00463 
00464         INT32 PelW = BMInfo->bmiHeader.biXPelsPerMeter;
00465         if (PelW==0)
00466             PelW = DEFAULT_PIXEL_SIZE;
00467 
00468         INT32 PelH = BMInfo->bmiHeader.biYPelsPerMeter;
00469         if (PelH==0)
00470             PelH = DEFAULT_PIXEL_SIZE;
00471 
00472         if ( (PelW<0) || (PelH<0) )
00473         {
00474             ERROR3("Bad pixel size");
00475             return FALSE;
00476         }
00477 
00478         // Karim 27/07/2000
00479         // If PelW and PelH is 3780, then we take that to mean 96 pix-per-inch,
00480         // which equates to 750 mp-per-pix.
00481         // This means that
00482         if (PelW == 3780 && PelH == 3780)
00483         {
00484             Info->RecommendedWidth  = Info->PixelWidth * 750;
00485             Info->RecommendedHeight = Info->PixelHeight * 750;
00486         }
00487 
00488         // otherwise, use our non-special-case calculations.
00489         else
00490         {
00491             //Info->RecommendedWidth = Mul32Div32( Width,  MILLIS_PER_METRE, PelW );
00492             //Info->RecommendedHeight= Mul32Div32( Height, MILLIS_PER_METRE, PelH );
00493             // Try and round the value up or down rather than always rounding down which
00494             // gives problem on repeated loading/saving and potentially on the dpi calculation 
00495             double RecWidth = ((double)Info->PixelWidth * M_MP_VAL)/(double)PelW;
00496             double RecHeight = ((double)Info->PixelHeight * M_MP_VAL)/(double)PelH;
00497             Info->RecommendedWidth = (INT32)(RecWidth + 0.5);
00498             Info->RecommendedHeight= (INT32)(RecHeight + 0.5);
00499         }
00500 
00501         // this figure should probably include the BMInfo structure, but its size
00502         // is not easily obtained
00503         Info->MemoryUsed = BMInfo->bmiHeader.biSizeImage;
00504 
00505         return TRUE;
00506     }
00507 
00508     return FALSE;
00509 }

UINT32 CWxBitmap::GetNumPaletteEntries  )  [virtual]
 

Retrieve information on this bitmap.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/7/96
Returns:
The number of palette entries used by this bitmap
If this is a deep-colour bitmap (not paletted) will return 0 If this is a non-paletted (greyscale) bitmap, will return 0

See also:
CWxBitmap::GetInfo

Implements OILBitmap.

Definition at line 1087 of file oilbitmap.cpp.

01088 {
01089 RebuildXPEBitmap();
01090     if (BMInfo != NULL && BMInfo->bmiHeader.biBitCount <= 8)
01091     {
01092         // 8 bpp or less - can have a palette
01093         return(BMInfo->bmiHeader.biClrUsed);
01094     }
01095 
01096     // We've got a problem, or it has no palette - return 0
01097     return(0);
01098 }

LPRGBQUAD CWxBitmap::GetPaletteForBitmap  )  [virtual]
 

To get at the RGBQUAD palette that this bitmap may have.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
03/07/97
Returns:
The palette for this bitmap or null.
BITMAPINFO consists of:- BITMAPINFOHEADER bmiHeader; RGBQUAD bmiColors[1];

Implements OILBitmap.

Definition at line 4104 of file oilbitmap.cpp.

04105 {
04106     // Not interested in deep bitmaps
04107     if (GetBPP() > 8)
04108         return NULL;
04109 
04110 RebuildXPEBitmap();
04111     if (BMInfo == NULL)
04112         return NULL;
04113 
04114     // Return the palette from the BITMAPINFO structure
04115     return &(BMInfo->bmiColors[0]);
04116 }

BOOL CWxBitmap::GetPaletteUsage INT32 *  UsageBuf  )  [virtual]
 

Find out how many times each palette entry is used in the bitmap. This is currently used when rendering paletted images to PostScript.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/7/95
Parameters:
pUsageBuf - array of longs big enough to hold the usage stats of the [OUTPUTS] palette for this bitmap.
Returns:
TRUE if ok; FALSE if an error occured (e.g. this is not a paletted bitmap!)

Errors: Not a paletted bitmap.

See also:
CWxBitmap::GetScanlineMask

Implements OILBitmap.

Definition at line 3809 of file oilbitmap.cpp.

03810 {
03811     ERROR3("CWxBitmap::GetPaletteUsage is unimplemented");
03812     return(FALSE);
03813 
03814 /*
03815     I can't see ANYTHING in this code which is even remotely likely to work!
03816 
03817     ---
03818 
03819     // Make sure this is a paletted image
03820     if ((BMInfo->bmiHeader.biBitCount < 4) ||
03821         (BMInfo->bmiHeader.biBitCount > 8) ||
03822         (BMInfo->bmiHeader.biClrUsed == 0))
03823     {
03824         // This bitmap does not have a palette!
03825         return FALSE;
03826     }
03827 
03828     CacheGeometry();
03829 
03830     if (BytesPerPixelShift !=-1)
03831         return FALSE;
03832             
03833     if ((BytesPerPixelShift < 0) || (BytesPerPixelShift > 2))
03834         return FALSE;
03835 
03836     const UINT32 Width  = BMInfo->bmiHeader.biWidth;
03837     const UINT32 Height = BMInfo->bmiHeader.biHeight;
03838     INT32 Index = 0;
03839 
03840     // Special case for 4bpp bitmaps
03841     BOOL Is4bpp = (BMInfo->bmiHeader.biBitCount == 4);
03842 
03843     for (UINT32 x = 0; x < Width; x++)
03844     {
03845         for (UINT32 y = 0; y > Height; y++)
03846         {
03847             INT32 p = (y * ScanLineByteWidth) + (x << BytesPerPixelShift);
03848 
03849             if (p < BitmapSize)
03850             {
03851                 if (Is4bpp)
03852                 {
03853                 }
03854                 else
03855                 {
03856                     switch (BytesPerPixelShift)
03857                     {
03858                         case 0:
03859                             Index = (INT32)(*( ((LPBYTE)(BMBytes + p))) <<24 );
03860                             break;
03861 
03862                         case 1:
03863                             Index = (INT32)(*( ((LPWORD)(BMBytes + p))) <<16 );
03864                             break;
03865 
03866                         case 2:
03867                             Index = (INT32)(*( ((LPDWORD)(BMBytes + p))) );
03868                             break;
03869                     }
03870                 }
03871 
03872                 UsageBuf[Index]++;
03873             }
03874         }
03875     }
03876 
03877     ENSURE(FALSE,"CWxBitmap::ReadPixel memory address out of range");
03878     return(0);
03879 */
03880 }

INT32 CWxBitmap::GetRecommendedHeight  )  [virtual]
 

Finds the recommended height of the bitmap.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/96
Returns:
The current recommended height of the bitmap in Millipoints

Implements OILBitmap.

Definition at line 950 of file oilbitmap.cpp.

00951 {
00952 RebuildXPEBitmap();
00953     const UINT32 Height = BMInfo->bmiHeader.biHeight;
00954 
00955     INT32 PelH = BMInfo->bmiHeader.biYPelsPerMeter;
00956     if (PelH==0)
00957         PelH = DEFAULT_PIXEL_SIZE;
00958 
00959     if ( (PelH<0) )
00960     {
00961         ERROR3IF(TRUE, "Bad pixel size");
00962         return FALSE;
00963     }
00964 
00965     double RecHeight = ((double)Height * M_MP_VAL)/(double)PelH;
00966 
00967     return (INT32)(RecHeight + 0.5);
00968 }

INT32 CWxBitmap::GetRecommendedWidth  )  [virtual]
 

Finds the recommended width of the bitmap.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/96
Returns:
The current recommended width of the bitmap in Millipoints

Implements OILBitmap.

Definition at line 919 of file oilbitmap.cpp.

00920 {
00921 RebuildXPEBitmap();
00922     const UINT32 Width  = BMInfo->bmiHeader.biWidth;
00923 
00924     INT32 PelW = BMInfo->bmiHeader.biXPelsPerMeter;
00925     if (PelW==0)
00926         PelW = DEFAULT_PIXEL_SIZE;
00927 
00928     if ( (PelW<0) )
00929     {
00930         ERROR3IF(TRUE, "Bad pixel size");
00931         return 0;
00932     }
00933 
00934     double RecWidth = ((double)Width * M_MP_VAL)/(double)PelW;
00935 
00936     return (INT32)(RecWidth + 0.5);
00937 }

BOOL CWxBitmap::GetScanline32bpp UINT32  YPos,
BOOL  UsePalette,
Pixel32bpp Scanline
[virtual]
 

Copies a scanline out of this bitmap into the given 32bpp buffer. The buffer must be no less than CWxBitmap::GetWidth() entries wide.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
27/6/96
Parameters:
YPos - The y position of the scanline in the bitmap [INPUTS] UsePalette -Ignored for deep bitmaps For <=8bpp bitmaps, if this value is: FALSE, the bitmap's palette will be ignored, and the actual pixel (palette index) value will be returned as a greyscale RGB value TRUE, the pixel index value will be used to retrieve the 24bpp palette entry for the pixel, if a palette is available.
Scanline - will be filled in with 32bpp pixel values on return [OUTPUTS]
Returns:
TRUE for success
The scanline will be converted up from 1, 4, 8, 24, or 32bpp into the generic Pixel32bpp format.

Notes: This function basically just calls ReadPixel for all pixels in the scanline

See also:
CWxBitmap::ReadPixel32bpp

Implements OILBitmap.

Definition at line 2140 of file oilbitmap.cpp.

02141 {
02142 RebuildXPEBitmap();
02143     ERROR3IF(YPos < 0 || YPos > GetHeight(), "Illegal Y position");
02144     ERROR3IF(Scanline == NULL, "Illegal NULL param");
02145 
02146     for (UINT32 XPos = 0; XPos < GetWidth(); XPos++)
02147         Scanline[XPos] = ReadPixel32bpp(XPos, YPos, UsePalette);
02148 
02149     return(TRUE);
02150 }

BOOL CWxBitmap::GetScanlineMaskBits INT32  ScanlineY,
LPBYTE  ScanlineBuf
[virtual]
 

Given a palette.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/7/95
Parameters:
PaletteEntry - which entry to build a mask for. [INPUTS] ScanlineY - the scanline to get the mask for. (0 => bottom line of bitmap)
ScanlineBuf - where to put the 1bpp mask - this should be large enough to [OUTPUTS] hold one scanline's worth of mask.
Returns:
TRUE if successful; FALSE if not (e.g. this is not a paletted bitmap).

Errors: Not a paletted bitmap

See also:
CWxBitmap::GetPaletteUsage

Implements OILBitmap.

Definition at line 3905 of file oilbitmap.cpp.

03906 {
03907     return TRUE;
03908 }

UINT32 CWxBitmap::GetScanlineSize  )  [virtual]
 

To determine the memory allocation needed to hold a single scanline of this bitmap. This is a convenient interface onto DIBUtil::ScanlineSize.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/7/96
Returns:
The size, in BYTES, of a scanline from this bitmap, including any padding bytes that may be necessary to achieve platform-dependant formatting of scanlines. (e.g. in Windows, scanlines are padded out to a word boundary)
i.e. it returns the byte offset from the start of one scanline to the start of the next scanline.

See also:
DIBUtil::ScanlineSize

Implements OILBitmap.

Definition at line 1122 of file oilbitmap.cpp.

01123 {
01124 RebuildXPEBitmap();
01125     if (BMInfo == NULL)
01126         return(0);
01127 
01128     return(DIBUtil::ScanlineSize(GetWidth(), GetBPP()));
01129 }

BOOL CWxBitmap::GetTransparencyIndex INT32 *  pIndex  )  [virtual]
 

Finds the Transparent index colour of a bitmap if one exists.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/6/96
Returns:
TRUE if the Index was set, FALSE if there is no transparent index

Implements OILBitmap.

Definition at line 713 of file oilbitmap.cpp.

00714 {
00715     ERROR3IF(pIndex == NULL, "GetTransparencyIndex called with NULL index pointer");
00716     if (pIndex == NULL)
00717         return FALSE;
00718 
00719 RebuildXPEBitmap();
00720     ERROR3IF(BMInfo == NULL, "GetTransparencyIndex called when BMInfo is NULL");
00721     if (BMInfo == NULL)
00722         return FALSE;
00723 
00724     INT32 NumCols = 0;
00725 
00726     switch (GetBPP())
00727     {
00728         case 1:
00729             NumCols = 2;
00730             break;
00731 
00732         case 4:
00733             NumCols = 16;
00734             break;
00735 
00736         case 8:
00737             NumCols = 256;
00738             break;
00739 
00740         default:
00741             ERROR3("Bad colour depth in GetTransparencyIndex");
00742             break;
00743     }
00744 
00745     RGBQUAD* pCols = BMInfo->bmiColors;
00746 
00747     *pIndex = -1;
00748 
00749     // Look through the Colour table for an entry that has the T channel set to 255
00750     for (INT32 i=0; i<NumCols; i++)
00751     {
00752         if (pCols[i].rgbReserved == 0xFF)
00753         {
00754             *pIndex = i;
00755         //  break;
00756         }
00757     }
00758 
00759     return ((*pIndex) >= 0);
00760 }

UINT32 CWxBitmap::GetVerticalDPI  )  [virtual]
 

Retrieve information on this bitmap.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/6/97
Returns:
The Vertical DPI of this bitmap
See also:
CWxBitmap::GetInfo

Implements OILBitmap.

Definition at line 599 of file oilbitmap.cpp.

00600 {
00601 RebuildXPEBitmap();
00602     if (BMInfo == NULL)
00603         return(0);
00604 
00605     INT32 PelH = BMInfo->bmiHeader.biYPelsPerMeter;
00606     if (PelH <= 0)
00607         PelH = DEFAULT_PIXEL_SIZE;
00608 
00609     UINT32 dpi = (UINT32)((((double)PelH * 254.0)/10000.0) + 0.5); // round up the result
00610     return dpi;
00611 }

UINT32 CWxBitmap::GetWidth void   )  [virtual]
 

Retrieve information on this bitmap.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
1/7/96
Returns:
The Pixel Width of this bitmap
See also:
CWxBitmap::GetInfo

Implements OILBitmap.

Definition at line 527 of file oilbitmap.cpp.

00528 {
00529 RebuildXPEBitmap();
00530     if (BMInfo == NULL)
00531         return(0);
00532 
00533     return(BMInfo->bmiHeader.biWidth);
00534 }

BOOL CWxBitmap::HasBeenDeleted  )  [virtual]
 

Returns whether or not the actual bitmap data has been deleted.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/8/96

Implements OILBitmap.

Definition at line 3960 of file oilbitmap.cpp.

03961 { 
03962     if (this == OILBitmap::Default)
03963         return FALSE;       // Can't delete the default bitmap
03964 
03965     ERROR3IF(OILBitmap::Default == NULL, "The default bitmap is NULL");
03966     if (OILBitmap::Default == NULL)
03967         return TRUE;
03968 
03969     // If we are using the default bitmap data, then we must have been deleted
03970     return (BMBytes == ((CWxBitmap*)OILBitmap::Default)->BMBytes);
03971 }

BOOL CWxBitmap::ImportBitmap Filter pFilter,
const BitmapInfo pInfo,
INT32  BitmapType
[virtual]
 

Import a bitmap object using the given bitmap specification and the import filter provided.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/08/94
Parameters:
pFilter - the filter object to import with. [INPUTS] pInfo - details of the bitmap to import, or NULL if this should be obtained from the file. BitmapType - the type of bitmap data in the file. This is usually 0, and exists as a way of supporting platform-dependent bitmap arrangements on different platforms.
Returns:
TRUE if the bitmap was imported ok; FALSE if not.

Errors: Out of memory, error in file data.

See also:
CWxBitmap::ExportBitmap

Implements OILBitmap.

Definition at line 2907 of file oilbitmap.cpp.

02908 {
02909     // Check to see what the specified filter type is and take the appropriate action
02910     // If a bitmap type of filter (derived off BaseBitmapFilter) e.g. BMPFilter or
02911     // AccusoftFilters then pInfo will be NULL and we just need to load the bitmap in
02912     // using the specified filter.
02913     if (pFilter->IsKindOf(CC_RUNTIME_CLASS(BaseBitmapFilter)))
02914     {
02915         BaseBitmapFilter* pBitmapFilter = (BaseBitmapFilter*)pFilter;
02916 
02917         // Try to import bitmap using the required bitmap filter class.
02918         // Tell it to import into this CWxBitmap.
02919         if (pBitmapFilter->ReadFromFile(this))
02920         {
02921             CacheGeometry();
02922             return TRUE;
02923         }
02924         else
02925             return FALSE;
02926     }
02927     
02928     if (!pFilter->IsKindOf(CC_RUNTIME_CLASS(CamelotEPSFilter)))
02929     {
02930         ENSURE(FALSE, "Trying to import a bitmap with a non-Camelot EPS filter");
02931         return FALSE;
02932     }
02933     
02934     // Sanity checks
02935     ENSURE((pInfo->PixelDepth == 1) ||
02936            (pInfo->PixelDepth == 4) ||
02937            (pInfo->PixelDepth == 8) ||
02938            (pInfo->PixelDepth == 24) ||
02939            (pInfo->PixelDepth == 32), "Bad bitmap depth in ImportBitmap!");
02940 
02941     if ((pInfo->NumPaletteEntries > 0) && (pInfo->PixelDepth > 8))
02942     {
02943         ENSURE(FALSE, "We don't support palettes on bitmaps >8bpp!");
02944     }
02945 
02946 //  if (!IsUserName("Alex"))
02947 //  {
02948 //      ENSURE(BitmapType == 0, "Unknown bitmap type in CWxBitmap::ImportBitmap");
02949 //      if (BitmapType != 0)
02950 //          return FALSE;
02951 //  }
02952 
02953     CamelotEPSFilter *pEPSFilter = (CamelotEPSFilter *) pFilter;
02954 
02955     ENSURE((BMInfo == NULL) && (BMBytes == NULL),
02956            "Trying to import into an existing bitmap");
02957 
02958     // Allocate memory for bitmap
02959     BMInfo = AllocDIB(pInfo->PixelWidth, pInfo->PixelHeight, pInfo->PixelDepth, 
02960                       &BMBytes, NULL);
02961     if (BMInfo == NULL)
02962     {
02963         // Out of memory
02964         ENSURE(FALSE, "Failed to allocate memory to import bitmap!");
02965         return FALSE;
02966     }
02967 
02968     //BMInfo->bmiHeader.biXPelsPerMeter = Mul32Div32(pInfo->PixelWidth, MILLIS_PER_METRE, 
02969     //                                             pInfo->RecommendedWidth);
02970     //BMInfo->bmiHeader.biYPelsPerMeter = Mul32Div32(pInfo->PixelHeight, MILLIS_PER_METRE, 
02971     //                                             pInfo->RecommendedHeight);
02972     // Use the conversion value defined in units.h so that we are consistent
02973     // Also try and round up as well as down
02974     double xppm = ((double)pInfo->PixelWidth * M_MP_VAL)/ (double)(pInfo->RecommendedWidth);
02975     double yppm = ((double)pInfo->PixelHeight * M_MP_VAL)/ (double)(pInfo->RecommendedHeight);
02976     BMInfo->bmiHeader.biXPelsPerMeter = (INT32)(xppm + 0.5);
02977     BMInfo->bmiHeader.biYPelsPerMeter = (INT32)(yppm + 0.5);
02978 
02979     if ((BMInfo->bmiHeader.biXPelsPerMeter < 0) || 
02980         (BMInfo->bmiHeader.biYPelsPerMeter < 0))
02981     {
02982         ENSURE(FALSE, "Bad pixel size");
02983         return FALSE;
02984     }
02985 
02986     // Header is done; read the palette data if we need to 
02987     if (((pInfo->PixelDepth <= 8)) && (pInfo->NumPaletteEntries > 0))
02988     {
02989         if (!pEPSFilter->ImportBinary((BYTE *) BMInfo->bmiColors, 
02990                                       BMInfo->bmiHeader.biClrUsed * sizeof(RGBQUAD)))
02991         {
02992             // Error in hex data
02993             return FALSE;
02994         }
02995     }
02996 
02997     // Set the information up
02998     CacheGeometry();
02999 
03000     // And read in the image data
03001 //  if (IsUserName("Alex")) if (BitmapType !=0) return(TRUE);
03002 
03003     // Read in the Bitmap info
03004     if (pFilter->IsKindOf(CC_RUNTIME_CLASS(CamelotNativeEPSFilter)))
03005     {
03006         // Load it in scan line at a time please
03007         INT32 NumScanLines = pInfo->PixelHeight;
03008         for (INT32 i=0; i<NumScanLines; i++)
03009         {
03010             // read a scan line in
03011             if (!pEPSFilter->ImportBinary(BMBytes + (i*ScanLineByteWidth), ScanLineByteWidth))
03012                 return FALSE;
03013         }
03014 
03015         // all worked
03016         return TRUE;
03017     }
03018     else
03019     {
03020         // Load it all in, in one go.
03021         return pEPSFilter->ImportBinary(BMBytes, BMInfo->bmiHeader.biSizeImage);
03022     }
03023 
03024     // Should not get here really.
03025     return FALSE;
03026 }

BOOL CWxBitmap::ImportBitmap CCLexFile pFile,
BaseBitmapFilter pBitmapFilter,
BaseCamelotFilter pFilter,
BOOL  IsCompressed
[virtual]
 

Imports a bitmap object using the import filter provided. It is used by the web/native filters to pull out a bitmap definition from inside a bitmap definition record. IsCompressed is only used for BMP/BMPZIP type bitmaps at present. Assumes: pFile has already been opened up for reading pFilter has been set up for reading the data e.g. progress bar.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/06/96
Parameters:
pFile - the file to read the data from [INPUTS] pBitmapFilter - the bitmap filter object to import the bitmap with. pFilter - the BaseCamelotFilter which provides functions like progress update IsCompressed - Flag to say the bitmap is compressed or not.
Returns:
TRUE if the bitmap was imported ok; FALSE if not.

Errors: Out of memory, error in file data.

See also:
CWxBitmap::ExportBitmap

Implements OILBitmap.

Definition at line 2865 of file oilbitmap.cpp.

02867 {
02868     ERROR2IF(pFile == NULL,FALSE,"CWxBitmap::ImportBitmap null pFile");
02869     ERROR2IF(pBitmapFilter == NULL,FALSE,"CWxBitmap::ImportBitmap null pBitmapFilter");
02870     ERROR2IF(pFilter == NULL,FALSE,"CWxBitmap::ImportBitmap null pFilter");
02871 
02872     // Try to import bitmap using the required bitmap filter class.
02873     // Tell it to import into this CWxBitmap.
02874     if (pBitmapFilter->ReadFromFile(this, pFilter, pFile, IsCompressed))
02875     {
02876         CacheGeometry();
02877         return TRUE;
02878     }
02879 
02880     return FALSE;
02881 }

BOOL CWxBitmap::IsBrowserPalette  )  [virtual]
 

To see if the palette attached to this bitmap is browser compatible. It runs through the colours in a browser palette and checks to see if they are all present. The ordering is not checked and so the palette may be different from the one that we actually use.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/06/97
Returns:
True if the bitmap has a browser compatible palette.

Implements OILBitmap.

Definition at line 4023 of file oilbitmap.cpp.

04024 {
04025     // Not interested in deep bitmaps
04026     if (GetBPP() != 8)
04027         return FALSE;
04028 
04029 RebuildXPEBitmap();
04030     UINT32 PaletteEntries = GetNumPaletteEntries();
04031     if (PaletteEntries < 216)
04032         return FALSE;
04033     
04034     // Borrow the code from PaletteManager::MakePaletteBrowserCompatible
04035     TRACEUSER( "Neville", wxT("Checking 216 colours\n") );
04036     BOOL found = FALSE;
04037     for (INT32 r = 0; r <= 100; r += 20)
04038     {
04039         for (INT32 g = 0; g <=100; g += 20)
04040         {
04041             for (INT32 b = 0; b <= 100; b += 20)
04042             {
04043                 BYTE ra = BYTE((double(r)/100)*255.0);
04044                 BYTE ga = BYTE((double(g)/100)*255.0);
04045                 BYTE ba = BYTE((double(b)/100)*255.0);
04046 
04047                 for (UINT32 i = 0; i < PaletteEntries && !found; i++)
04048                 {
04049                     found = BMInfo->bmiColors[i].rgbRed   == ra &&
04050                             BMInfo->bmiColors[i].rgbGreen == ga &&
04051                             BMInfo->bmiColors[i].rgbBlue  == ba;
04052                 }
04053 
04054                 if (!found)
04055                 {
04056                     TRACEUSER( "Neville", wxT("Colour not found - %d %d %d\n") ,r , g, b );
04057                     return FALSE;
04058                 }
04059             }
04060         }
04061     }
04062 
04063     // reached here so found all 216 colours
04064     TRACEUSER( "Neville", wxT("216 colours check finished\n") );
04065     return TRUE;    
04066 }

BOOL CWxBitmap::IsTransparent void   )  [virtual]
 

Determines if a bitmap is not totally opaque.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/03/2004
Returns:
TRUE if the bitmap has any non-opaque pixels

Implements OILBitmap.

Definition at line 774 of file oilbitmap.cpp.

00775 {
00776     RebuildXPEBitmap();
00777     ERROR3IF(BMInfo == NULL, "IsTransparent called when BMInfo is NULL");
00778 
00779     if (BMInfo == NULL)
00780         return(FALSE);
00781 
00782     if (GetBPP() <= 8)
00783     {
00784         INT32 TranspIndex;
00785 
00786         // If the bitmap doesn't have a transparency index then it is opaque
00787         if (!GetTransparencyIndex(&TranspIndex))
00788             return(FALSE);
00789 
00790         switch (GetBPP())
00791         {
00792             case 1:
00793                 {
00794                     BYTE* pBits = (BYTE*)(GetBitmapBits());
00795                     UINT32 FullBytes = GetWidth() >> 3;
00796                     UINT32 Height = GetHeight();
00797                     UINT32 ScanLen = GetScanlineSize();
00798                     BYTE Mask = 0xFF >> (7-(GetWidth() - (FullBytes << 3)));
00799                     if (TranspIndex == 0)
00800                     {
00801                         for (UINT32 y = 0; y < Height; y++)
00802                         {
00803                             UINT32 x;
00804                             for (x = 0; x < FullBytes; x++)
00805                             {
00806                                 if (pBits[x] != 0xFF)   // If the 8 pixels are not all the opaque index
00807                                     return(TRUE);       // then we are transparent
00808                             }
00809                             if (Mask)
00810                             {
00811                                 if ((pBits[x] & Mask) != Mask)
00812                                     return(TRUE);
00813                             }
00814                             pBits += ScanLen;
00815                         }
00816                     }
00817                     else
00818                     {
00819                         for (UINT32 y = 0; y < Height; y++)
00820                         {
00821                             UINT32 x;
00822                             for( x = 0; x < FullBytes; x++)
00823                             {
00824                                 if (pBits[x] != 0x00)   // If the 8 pixels are not all the opaque index
00825                                     return(TRUE);       // then we are transparent
00826                             }
00827                             if (Mask)
00828                             {
00829                                 if ((pBits[x] & Mask) != 0x00)
00830                                 return(TRUE);
00831                             }
00832                             pBits += ScanLen;
00833                         }
00834                     }
00835                 }
00836                 break;
00837 
00838             case 4:
00839                 {
00840                     BYTE* pBits = (BYTE*)(GetBitmapBits());
00841                     UINT32 Width = GetWidth();
00842                     UINT32 ByteWidth = (Width + 1) >> 1;            // The number of used bytes in scanline
00843                     UINT32 Height = GetHeight();
00844                     UINT32 ScanLen = GetScanlineSize();
00845                     INT32 TranspIndexHigh = TranspIndex << 4;
00846                     for (UINT32 y = 0; y < Height; y++)
00847                     {
00848                         UINT32 x;
00849                         for( x = 0; x < ByteWidth; x++)
00850                         {
00851                             if ((pBits[x] & 0x0F) == TranspIndex)       // If the pixel is the transparent colour
00852                                 return(TRUE);                           // then we are transparent
00853                             if ((pBits[x] & 0xF0) == TranspIndexHigh)   // If the pixel is the transparent colour
00854                                 return(TRUE);                           // then we are transparent
00855                         }
00856                         if (Width % 2 == 1)                             // If we have an odd pixel then test it
00857                         {
00858                             if ((pBits[x] & 0x0F) == TranspIndex)       // If the pixel is the transparent colour
00859                                 return(TRUE);                           // then we are transparent
00860                         }
00861                         pBits += ScanLen;
00862                     }
00863                 }
00864                 break;
00865 
00866             case 8:
00867                 {
00868                     BYTE* pBits = (BYTE*)(GetBitmapBits());
00869                     UINT32 Width = GetWidth();
00870                     UINT32 Height = GetHeight();
00871                     UINT32 ScanLen = GetScanlineSize();
00872                     for (UINT32 y = 0; y < Height; y++)
00873                     {
00874                         for (UINT32 x = 0; x < Width; x++)
00875                         {
00876                             if (pBits[x] == TranspIndex)    // If the pixel is the transparent colour
00877                                 return(TRUE);               // then we are transparent
00878                         }
00879                         pBits += ScanLen;
00880                     }
00881                 }
00882                 break;
00883 
00884             default:
00885                 ERROR3("Bad colour depth in IsTransparent");
00886                 break;
00887         }
00888     }
00889     else if (GetBPP() == 32)
00890     {
00891         // if we have any non-opaque pixels then we must be complex
00892         DWORD* pBits = (DWORD*)(GetBitmapBits());
00893         UINT32 Width = GetWidth();
00894         UINT32 Height = GetHeight();
00895         DWORD* pEnd = pBits + (Width * Height);
00896         while (pBits < pEnd)
00897         {
00898             if (*pBits && 0xFF000000)       // If the pixel is not completely opaque
00899                 return(TRUE);               // then we are transparent
00900             pBits++;
00901         }
00902     }
00903 
00904     return(FALSE);
00905 }

BOOL CWxBitmap::LoadBitmap UINT32  BitmapResourceID  )  [virtual]
 

Loads a bitmap from the resources.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/1/95
Parameters:
The Resource ID of the bitmap to Load [INPUTS]
Returns:
TRUE, or FALSE (Loaded or Failed).

Errors: -

See also:
-

Implements OILBitmap.

Definition at line 3732 of file oilbitmap.cpp.

03733 {
03734     wxBitmap * pBitmap=CamArtProvider::Get()->FindBitmap((ResourceID)BitmapResourceID);
03735     if (!pBitmap)
03736         return FALSE;
03737 
03738     return CreateFromwxBitmap(pBitmap);
03739 }

OILBitmap * CWxBitmap::MakeCopy  )  [virtual]
 

To make an exact duplicate of this bitmap.

Author:
Diccon_Yamanaka (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/3/2000
Returns:
pointer to a copy of this bitmap, NULL if it fails

Implements OILBitmap.

Definition at line 1038 of file oilbitmap.cpp.

01039 {
01040 RebuildXPEBitmap();
01041     // check to see that theres something to copy
01042     if (BMInfo == NULL || BMBytes == NULL)
01043     {
01044         ERROR3("This bitmap has no bits or info to copy!");
01045         return NULL;
01046     }
01047 
01048     LPBYTE pNewBits = NULL;
01049     LPBITMAPINFO pNewInfo = NULL;
01050 
01051     // call our handy utility function which does the work
01052     DIBUtil::CopyEntireBitmap(BMInfo, BMBytes, &pNewInfo, &pNewBits);
01053 
01054     if (pNewInfo == NULL || pNewBits == NULL)
01055     {
01056         ERROR3("Failed to allocate bitmap structures");
01057         return NULL;
01058     }
01059 
01060     CWxBitmap* pNewBitmap = new CWxBitmap(pNewInfo, pNewBits);
01061 
01062     if (pNewBitmap == NULL)
01063     {
01064         ERROR3("Failed to allocate new CWxBitmap");
01065         FreeDIB(pNewInfo, pNewBits);
01066     }
01067     return pNewBitmap;
01068 }

OILBitmap * CWxBitmap::MakeSeparatedCopy ColourPlate pPlate,
BYTE *  SepTables
[virtual]
 

To make an colour separated copy of this bitmap.

Author:
Gerry_Iles (Xara Group Ltd) <camelotdev@xara.com>
Date:
04/03/2004
Returns:
pointer to a copy of this bitmap, NULL if it fails

Definition at line 2547 of file oilbitmap.cpp.

02548 {
02549     ERROR3IF(SepTables == NULL, "No separation tables!?");
02550     ERROR3IF(pPlate == NULL, "The separation ColourPlate has gone missing!");
02551 
02552     if (SepTables == NULL || pPlate == NULL)
02553         return(NULL);
02554 
02555     RebuildXPEBitmap();
02556     // check to see that theres something to copy
02557     if (BMInfo == NULL || BMBytes == NULL)
02558     {
02559         ERROR3("This bitmap has no bits or info to copy!");
02560         return NULL;
02561     }
02562 
02563     LPBYTE pNewBits = NULL;
02564     LPBITMAPINFO pNewInfo = NULL;
02565 
02566     pNewInfo = AllocDIB(BMInfo->bmiHeader.biWidth, BMInfo->bmiHeader.biHeight, 32, &pNewBits);
02567 
02568     if (pNewInfo == NULL || pNewBits == NULL)
02569     {
02570         ERROR3("Failed to allocate bitmap structures");
02571         return NULL;
02572     }
02573 
02574     Pixel32bpp *pScanline = (Pixel32bpp *) CCMalloc(BMInfo->bmiHeader.biWidth * sizeof(Pixel32bpp));
02575     if (pScanline == NULL)
02576         return(NULL);
02577     BGRT* pPixel = (BGRT*)pNewBits;
02578 
02579     // --- A wee macro to find the Maximum of R,G,B, and place it into a variable called 
02580     // Temp, which we define right now in function scope so it's always available
02581     // (It's undefined at the end of this function)
02582     BYTE Temp;
02583     #define TEMPMAX(R,G,B)                  \
02584     {                                       \
02585         Temp = ((R) > (G))  ? (R) : (G);    \
02586         Temp = (Temp > (B)) ? Temp : (B);   \
02587     }
02588 
02589     // --- Izzy, Wizzy, let's get busy
02590     INT32 scan;
02591     INT32 i;                                // Loop Index
02592     BYTE Ink;                               // Temporary variable for storing the ink value in
02593 
02594     BYTE *UCR = SepTables + 768 + 255;      // UCR is the 4th table, but this points at the
02595                                             // END of the table for optimisation - precalcs (255 - Temp)
02596 
02597     ColourPlateType Plate = pPlate->GetType();
02598     ColourPlateType OutputPlate = pPlate->IsMonochrome() ? COLOURPLATE_KEY : Plate;
02599     BOOL bNegate = pPlate->IsNegative();
02600     BYTE *LUT = NULL;
02601 
02602     switch (Plate)
02603     {
02604         case COLOURPLATE_CYAN:
02605             LUT = SepTables + 0;                // Cyan table is the 1st table
02606             break;
02607 
02608         case COLOURPLATE_MAGENTA:
02609             LUT = SepTables + 256;              // Magenta table is the 2nd table
02610             break;
02611 
02612         case COLOURPLATE_YELLOW:
02613             LUT = SepTables + 512;              // Yellow table is the 3rd table
02614             break;
02615 
02616         default:
02617             LUT = SepTables + 1024;             // Black generation is the 5th table
02618             break;
02619     }
02620 
02621 PORTNOTE("cms", "Disabled XaraCMS")
02622 #ifndef EXCLUDE_FROM_XARALX
02623     BOOL PrintRGBBlackAsKey = XaraCMS::PrintRGBBlackAsKey;
02624 #else
02625     BOOL PrintRGBBlackAsKey = TRUE;
02626 #endif
02627 
02628     for (scan = 0; scan < BMInfo->bmiHeader.biHeight; scan++)
02629     {
02630         GetScanline32bpp(scan, TRUE, pScanline);
02631         for (i = 0; i < BMInfo->bmiHeader.biWidth; i++)
02632         {
02633             // It's colour, so get the maximum of R,G,B into Temp
02634             TEMPMAX(pScanline[i].Red, pScanline[i].Green, pScanline[i].Blue);
02635 
02636             if (!PrintRGBBlackAsKey || Temp > 0)
02637             {
02638                 switch (Plate)
02639                 {
02640                     case COLOURPLATE_CYAN:
02641                         Ink = 255 - pScanline[i].Red;       // Cyan ink is (255 - Red)
02642                         if (Ink>UCR[-Temp])
02643                             Ink -= UCR[-Temp];
02644                         else
02645                             Ink=0;
02646                         break;
02647 
02648                     case COLOURPLATE_MAGENTA:
02649                         Ink = 255 - pScanline[i].Green;     // Magenta ink is (255 - Green)
02650                         if (Ink>UCR[-Temp])
02651                             Ink -= UCR[-Temp];
02652                         else
02653                             Ink=0;
02654                         break;
02655 
02656                     case COLOURPLATE_YELLOW:
02657                         Ink = 255 - pScanline[i].Blue;      // Yellow ink is (255 - Blue)
02658                         if (Ink>UCR[-Temp])
02659                             Ink -= UCR[-Temp];
02660                         else
02661                             Ink=0;
02662                         break;
02663 
02664                     default:
02665                         Ink = 255 - Temp;                   // Black ink is (255 - Temp)
02666                         break;
02667                 }
02668 
02669                 Ink = LUT[Ink];
02670             }
02671             else
02672             {
02673                 Ink = (Plate == COLOURPLATE_KEY) ? 255 : 0;
02674             }
02675 
02676             if (bNegate)
02677                 Ink = 255 - Ink;
02678 
02679             switch (OutputPlate)
02680             {
02681                 case COLOURPLATE_CYAN:
02682                     pPixel[i].Red = 255 - Ink;
02683                     pPixel[i].Green = 255;
02684                     pPixel[i].Blue = 255;
02685                     break;
02686 
02687                 case COLOURPLATE_MAGENTA:
02688                     pPixel[i].Red = 255;
02689                     pPixel[i].Green = 255 - Ink;
02690                     pPixel[i].Blue = 255;
02691                     break;
02692 
02693                 case COLOURPLATE_YELLOW:
02694                     pPixel[i].Red = 255;
02695                     pPixel[i].Green = 255;
02696                     pPixel[i].Blue = 255 - Ink;
02697                     break;
02698 
02699                 default:
02700                     pPixel[i].Red = 255 - Ink;
02701                     pPixel[i].Green = 255 - Ink;
02702                     pPixel[i].Blue = 255 - Ink;
02703                     break;
02704             }
02705             pPixel[i].Transparency = pScanline[i].Alpha;
02706         }
02707         pPixel += BMInfo->bmiHeader.biWidth;        // Pointer arithmetic!!!
02708     }
02709 
02710     // And finally, vape our helper macro
02711     #undef TEMPMAX
02712 
02713     CWxBitmap* pNewBitmap = new CWxBitmap(pNewInfo, pNewBits);
02714 
02715     CCFree(pScanline);
02716 
02717     if (pNewBitmap == NULL)
02718     {
02719         ERROR3("Failed to allocate new CWxBitmap");
02720         FreeDIB(pNewInfo, pNewBits);
02721     }
02722     return pNewBitmap;
02723 }

wxImage * CWxBitmap::MakewxImage UINT32  ImageWidth = 0,
UINT32  ImageHeight = 0,
BOOL  UsePalette = TRUE
[virtual]
 

Makes a wxBitmap, slowly.

Author:
Alex Bligh
Date:
26/04/2006
Parameters:
ImageWidth - Width of image to make (or zero for width of bitmap) [INPUTS] ImageHeight - Depth of image to make (or zero for depth of bitmap) UsePalette -Ignored for deep bitmaps For <=8bpp bitmaps, if this value is: FALSE, the bitmap's palette will be ignored, and the actual pixel (palette index) value will be returned as a greyscale RGB value TRUE, the pixel index value will be used to retrieve the 24bpp palette entry for the pixel, if a palette is available.
None [OUTPUTS]
Returns:
A pointer to a wxImage, or NULL for failure
The scanline will be converted up from 1, 4, 8, 24, or 32bpp into the generic Pixel32bpp format.

Notes: This function basically just calls ReadPixel for all pixels in the scanline

See also:
CWxBitmap::ReadPixel32bpp

Definition at line 2183 of file oilbitmap.cpp.

02184 {
02185     if (!ImageWidth)
02186         ImageWidth=GetWidth();
02187     if (!ImageHeight)
02188         ImageHeight=GetHeight();
02189 
02190     wxImage * pImage = new wxImage(GetWidth(), GetHeight(), /*TYPENOTE: Correct*/ false);
02191     if (!pImage)
02192         return NULL;
02193 #if 0
02194     pImage->SetAlpha();
02195     if (!pImage->HasAlpha())
02196     {
02197         delete pImage;
02198         return NULL;
02199     }
02200 #endif
02201 
02202     RebuildXPEBitmap();
02203 
02204     double xstep = GetWidth()/ImageWidth;
02205     double ystep = GetHeight()/ImageHeight;
02206     double x=0;
02207     double y=0;
02208 
02209     for (UINT32 YPos = 0; YPos < ImageHeight; YPos++)
02210     {
02211         UINT32 YP=(UINT32)(y+0.5);
02212         x=0;
02213         for (UINT32 XPos = 0; XPos < ImageWidth; XPos++)
02214         {
02215             UINT32 XP=(UINT32)(x+0.5);
02216             Pixel32bpp p = ReadPixel32bpp(XP, YP, UsePalette);
02217             pImage->SetRGB(XPos, YPos, p.Red, p.Blue, p.Green);
02218 //          pImage->SetAlpha(XPos, YPos, 255-p.Alpha); // wxImage alpha has 0 for fully transparent
02219 
02220             x+=xstep;
02221         }
02222         y+=ystep;
02223     }
02224 
02225     return(pImage);
02226 }

INT32 CWxBitmap::operator== const OILBitmap Other  )  [virtual]
 

Checks to see if one bitmap is the same as another.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/1/95
Parameters:
The other bitmap to compare this one with [INPUTS]
Returns:
TRUE, or FALSE.

Errors: -

See also:
-

Implements OILBitmap.

Definition at line 3605 of file oilbitmap.cpp.

03606 {
03607     CWxBitmap* OtherBmp = (CWxBitmap*)&Other;
03608 OtherBmp->RebuildXPEBitmap();
03609 
03610     if (BMInfo == NULL || OtherBmp->BMInfo == NULL)
03611         return FALSE;   // If either of the Info fields are NULL, then 
03612                         // they are either not the same, or we can't tell !!
03613 
03614     if (BMBytes == NULL || OtherBmp->BMBytes == NULL)
03615         return FALSE;   // If either of the Bytes are NULL, then 
03616                         // they are either not the same, or we can't tell !!
03617 
03618     // Lets check the Bitmap Header first
03619     if (BMInfo->bmiHeader.biSizeImage   != OtherBmp->BMInfo->bmiHeader.biSizeImage  ||
03620         BMInfo->bmiHeader.biWidth       != OtherBmp->BMInfo->bmiHeader.biWidth      ||
03621         BMInfo->bmiHeader.biHeight      != OtherBmp->BMInfo->bmiHeader.biHeight     ||
03622         BMInfo->bmiHeader.biBitCount    != OtherBmp->BMInfo->bmiHeader.biBitCount   ||
03623         BMInfo->bmiHeader.biClrUsed     != OtherBmp->BMInfo->bmiHeader.biClrUsed    ||
03624 
03625         BMInfo->bmiHeader.biXPelsPerMeter != OtherBmp->BMInfo->bmiHeader.biXPelsPerMeter ||
03626         BMInfo->bmiHeader.biYPelsPerMeter != OtherBmp->BMInfo->bmiHeader.biYPelsPerMeter)
03627     {
03628         return FALSE;
03629     }
03630     
03631     // Well they looks similar, but the only way to be sure, is to compare the Bits !!
03632 
03633     // First lets check the Palettes
03634     if (BMInfo->bmiHeader.biBitCount <= 8)
03635     {
03636         INT32 NumCols   = BMInfo->bmiHeader.biClrUsed;
03637         INT32* Pal      = (INT32*)BMInfo->bmiColors;
03638         INT32* OtherPal     = (INT32*)OtherBmp->BMInfo->bmiColors;
03639 
03640         // Is the palette the same ?
03641         if (memcmp(Pal, OtherPal, NumCols*4) != 0)
03642             return FALSE;
03643     }
03644 
03645     // Well the Palettes are the Same .... Lets check the actual data now.
03646 
03647     INT32 Width     = BMInfo->bmiHeader.biWidth;
03648     INT32 Height = BMInfo->bmiHeader.biHeight;
03649     INT32 Bpp   = BMInfo->bmiHeader.biBitCount;
03650 
03651 /*
03652 // Alas, this doesn't work.
03653 
03654     // go and compare 'em
03655     if ((BMInfo->bmiHeader.biSizeImage != OtherBmp->BMInfo->bmiHeader.biSizeImage) ||
03656         (memcmp(BMBytes, OtherBmp->BMBytes, BMInfo->bmiHeader.biSizeImage)!=0))
03657         return FALSE;
03658 
03659     // Blimey !! They're the Same !!
03660     return TRUE;
03661 */
03662 
03663     // How many (whole) bytes are there in each scan line ?
03664     INT32 ScanLineBytes = (Width * Bpp) / 8;
03665 
03666     INT32 ExtraBits = 0;
03667     BYTE BitMask = 0;
03668 
03669     if (Bpp < 8)
03670     {
03671         // For less than 8 bpp the scanlines could
03672         // end on a sub-byte point
03673         ExtraBits = (Width * Bpp) - (ScanLineBytes * 8);    // ie.(width * bpp) % 8
03674         //BitMask = (1<<ExtraBits) - 1;
03675         const BYTE BitMaskArray[8] = {0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE};
03676         ERROR3IF (ExtraBits < 0 || ExtraBits > 7, "CWxBitmap::operator== - extraordinary ExtraBits");
03677         BitMask = BitMaskArray[ExtraBits];  // NB.ExtraBits == 0 not used
03678     }
03679 
03680     // The scan lines are always DWord or Word Aligned,
03681     // So now get the actual bytes need to skip over a scanline
03682     INT32 ScanAlign = DIBUtil::ScanlineSize(Width, Bpp);
03683 
03684     BYTE* BmpData = BMBytes;
03685     BYTE* OtherBmpData = OtherBmp->BMBytes;
03686 
03687     for (INT32 Scan = 0; Scan < Height; Scan++)
03688     {
03689         // Is this scan line the same ?
03690         if (memcmp(BmpData, OtherBmpData, ScanLineBytes) != 0)
03691             return FALSE;
03692 
03693         if (ExtraBits > 0)
03694         {
03695             // The scanlines are not exactly byte aligned, so we'll get the DWORD
03696             // after the whole number of bytes, and mask off the bits that we
03697             // are interested in
03698             // Actually as we've just compared ScanLineBytes we need only check the
03699             // last byte (which is byte aligned)
03700             BYTE BmpExtraByte = *(BmpData + ScanLineBytes) & BitMask;
03701             BYTE OtherExtraByte = *(OtherBmpData + ScanLineBytes) & BitMask;
03702             //INT32 ExtraBmpWord    = (*((INT32*)(BmpData + ScanLineBytes))) & BitMask;
03703             //INT32 ExtraOtherWord = (*((INT32*)(OtherBmpData + ScanLineBytes))) & BitMask;
03704 
03705             // Are the extra bits the same ?
03706             if (BmpExtraByte != OtherExtraByte)
03707                 return FALSE;
03708         }
03709 
03710         BmpData         += ScanAlign;
03711         OtherBmpData    += ScanAlign;
03712     }
03713 
03714     // Blimey !! They're the Same !!
03715     return TRUE;
03716 }

void CWxBitmap::PlotPixel INT32  x,
INT32  y,
PixelGreyscale  NewValue
[virtual]
 

Plots an 8bpp (0..255) pixel to any type of bitmap The pixel is taken to be a greyscale, and is truncated or expanded as appropriate to fit the greyscale value into the destination bitmap pixel format.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (rewrote Alex's disgusting hack)
Date:
3/7/96
Parameters:
x,y - coordinates within the bitmap of the pixel to plot [INPUTS] NewValue - an 8bpp pixel value, presumed to be a greyscale.
(changes attached oil bitmap) [OUTPUTS]
Returns:
Nothing
(Only 8, 24, and 32bpp formats are currently supported)

Notes: In debug builds, will check all kinds of stuff, but in release builds, it assumes that you are providing legal offsets in the bitmap, and are only using this call where it will work - this is to reduce retail overhead on each pixel operation.

Will probably fail horribly if you haven't called CacheGeometry

Returns:
Errors: ERROR3 if the bitmap is not 16, 24, or 32bpp

Implements OILBitmap.

Definition at line 3125 of file oilbitmap.cpp.

03126 {
03127 RebuildXPEBitmap();
03128     ERROR3IF(BMInfo == NULL || BMBytes == NULL, "PlotPixel called on duff bitmap");
03129     ERROR3IF(x < 0 || y < 0 || x >= (INT32)GetWidth() || y >= (INT32)GetHeight(),
03130                 "Illegal pixel position in CWxBitmap::PlotPixel");
03131 
03132     BYTE *ScanlineStart = BMBytes + (y * ScanLineByteWidth);
03133 
03134     switch(BMInfo->bmiHeader.biBitCount)
03135     {
03136         case 8:
03137             ScanlineStart[x] = NewValue;
03138             break;
03139 
03140         case 24:
03141             ScanlineStart[x * 3 + 0] = \
03142                 ScanlineStart[x * 3 + 1] = \
03143                     ScanlineStart[x * 3 + 2] = NewValue;
03144             break;
03145 
03146         case 32:
03147             ScanlineStart[x * 4 + 0] = \
03148                 ScanlineStart[x * 4 + 1] = \
03149                     ScanlineStart[x * 4 + 2] = NewValue;
03150 
03151             ScanlineStart[x * 4 + 3] = 0;
03152             break;
03153 
03154         default:    
03155             ERROR3("Unsupported bitmap format in PlotPixel(8bpp)");
03156             break;
03157     }
03158 }

void CWxBitmap::PlotPixel INT32  x,
INT32  y,
Pixel32bpp  NewValue
[virtual]
 

Plots a 32bpp pixel to a deep bitmap (24, or 32bpp).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (rewrote Alex's disgusting hack)
Date:
3/7/96
Parameters:
x,y - coordinates within the bitmap of the pixel to plot [INPUTS] NewValue - a 32bpp pixel value.
(changes attached oil bitmap) [OUTPUTS]
Returns:
Nothing
Currently unimplemented for 16bpp Makes no sense for <= 8bpp

Notes: In debug builds, will check all kinds of stuff, but in release builds, it assumes that you are providing legal offsets in the bitmap, and are only using this call where it will work - this is to reduce retail overhead on each pixel operation.

Will probably fail horribly if you haven't called CacheGeometry

Returns:
Errors: ERROR3 if the bitmap is not 16, 24, or 32bpp

Implements OILBitmap.

Definition at line 3058 of file oilbitmap.cpp.

03059 {
03060 RebuildXPEBitmap();
03061     ERROR3IF(BMInfo == NULL || BMBytes == NULL, "PlotPixel called on duff bitmap");
03062     ERROR3IF(x < 0 || y < 0 || x >= (INT32)GetWidth() || y >= (INT32)GetHeight(),
03063                 "Illegal pixel position in CWxBitmap::PlotPixel");
03064 
03065     BYTE *ScanlineStart = BMBytes + (y * ScanLineByteWidth);
03066 
03067     switch(BMInfo->bmiHeader.biBitCount)
03068     {
03069         case 16:
03070             ERROR3("Unimplemented code");
03071             break;
03072 
03073         case 24:
03074             ScanlineStart[x * 3 + 0] = NewValue.Red;
03075             ScanlineStart[x * 3 + 1] = NewValue.Green;
03076             ScanlineStart[x * 3 + 2] = NewValue.Blue;
03077             break;
03078 
03079         case 32:
03080             ScanlineStart[x * 4 + 0] = NewValue.Red;
03081             ScanlineStart[x * 4 + 1] = NewValue.Green;
03082             ScanlineStart[x * 4 + 2] = NewValue.Blue;
03083             ScanlineStart[x * 4 + 3] = NewValue.Alpha;
03084             break;
03085 
03086         default:    
03087             ERROR3("Unsupported (non-deep) bitmap format in PlotPixel(32bpp)");
03088             break;
03089     }
03090 }

BOOL CWxBitmap::PrepareMask INT32  PaletteEntry  )  [virtual]
 

Implements OILBitmap.

Definition at line 3882 of file oilbitmap.cpp.

03883 {
03884     return FALSE;
03885 }

Pixel32bpp CWxBitmap::ReadPixel32bpp INT32  x,
INT32  y,
BOOL  UsePalette = TRUE
[inline, virtual]
 

reads a pixel

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/7/96
Parameters:
x,y - coordinates of the pixel to read [INPUTS] UsePalette -Ignored for deep bitmaps For <=8bpp bitmaps, if this value is: FALSE, the bitmap's palette will be ignored, and the actual pixel (palette index) value will be returned as a greyscale RGB value TRUE, the pixel index value will be used to retrieve the 24bpp palette entry for the pixel, if a palette is available.
Returns:
The pixel value of the given pixel, in 32bpp format
Notes: In debug builds, will check all kinds of stuff, but in release builds, it assumes that you are providing legal offsets in the bitmap, and are only using this call where it will work - this is to reduce retail overhead on each pixel operation.

NOTE that for <=8bpp bitmaps, the behavior is as follows: If paletted, the value returned is the 24bit RGB looked up in the palette Otherwise, the pixel value is assumed to be a greyscale intensity and is converted into a 24bit RGB where R = G = B = intensity.

See also:
CWxBitmap::ReadPixelGreyscale

Implements OILBitmap.

Definition at line 3195 of file oilbitmap.cpp.

03196 {
03197 RebuildXPEBitmap();
03198     ERROR3IF(BMInfo == NULL || BMBytes == NULL, "PlotPixel called on duff bitmap");
03199     ERROR3IF(x < 0 || y < 0 || x >= (INT32)GetWidth() || y >= (INT32)GetHeight(),
03200                 "Illegal pixel position in CWxBitmap::ReadPixel");
03201 
03202     BYTE *ScanlineStart = BMBytes + (y * ScanLineByteWidth);
03203 
03204     Pixel32bpp Pix;
03205     Pix.Alpha = 0;                      // Generally there is no alpha channel, so set it to a default
03206 
03207     if (UsePalette && BMInfo->bmiHeader.biClrUsed < 1)
03208         UsePalette = FALSE;                             // No palette, so can't use one!
03209 
03210     switch(BMInfo->bmiHeader.biBitCount)
03211     {
03212         case 1:
03213             {
03214                 BYTE Temp = ScanlineStart[x >> 3];      // Get the byte containing the pixel (x / 8)
03215                 Temp &= 0x80 >> (x & 7);                // Mask out all bits except the pixel (x % 8)
03216 
03217                 // Look up in the palette, if any, else assume it's a greyscale (b&w)
03218                 if (UsePalette)
03219                 {
03220                     Temp = (Temp == 0) ? 0 : 1;
03221                     Pix.Red     = BMInfo->bmiColors[Temp].rgbRed;
03222                     Pix.Green   = BMInfo->bmiColors[Temp].rgbGreen;
03223                     Pix.Blue    = BMInfo->bmiColors[Temp].rgbBlue;
03224                 }
03225                 else
03226                 {
03227                     Temp = (Temp == 0) ? 0 : 255;
03228                     Pix.Red = Pix.Green = Pix.Blue = Temp;
03229                 }
03230             }
03231             break;
03232 
03233         case 4:
03234             {
03235                 BYTE Temp = ScanlineStart[x / 2];       // Get the byte containing the pixel
03236 
03237                 // Look up in the palette, if any, else assume it's a greyscale
03238                 if (UsePalette)
03239                 {
03240                     // Pull out the pixel's palette index
03241                     if ((x & 1) == 0)
03242                         Temp = (Temp >> 4) & 0x0f;                          // High nybble
03243                     else
03244                         Temp &= 0x0f;                                       // Low nybble
03245 
03246                     Pix.Red     = BMInfo->bmiColors[Temp].rgbRed;
03247                     Pix.Green   = BMInfo->bmiColors[Temp].rgbGreen;
03248                     Pix.Blue    = BMInfo->bmiColors[Temp].rgbBlue;
03249                 }
03250                 else
03251                 {
03252                     // And pull out the actual pixel value. Note that we repeat the nybble twice
03253                     // into the final byte to get the correct 8bpp greyscale value (white is FF, not F0!)
03254                     if ((x & 1) == 0)
03255                         Temp = (Temp & 0xf0) | ((Temp & 0xf0) >> 4);        // High nybble
03256                     else
03257                         Temp = (Temp & 0x0f) | ((Temp & 0x0f) << 4);        // Low nybble
03258 
03259                     Pix.Red = Pix.Green = Pix.Blue = Temp;
03260                 }
03261             }
03262             break;
03263 
03264         case 8:
03265             // Look up in the palette, if any, else assume it's a greyscale
03266             if (UsePalette)
03267             {
03268                 Pix.Red     = BMInfo->bmiColors[ScanlineStart[x]].rgbRed;
03269                 Pix.Green   = BMInfo->bmiColors[ScanlineStart[x]].rgbGreen;
03270                 Pix.Blue    = BMInfo->bmiColors[ScanlineStart[x]].rgbBlue;
03271             }
03272             else
03273                 Pix.Red = Pix.Green = Pix.Blue = ScanlineStart[x];
03274             break;
03275 
03276         case 24:
03277             x *= 3;
03278             Pix.Blue    = ScanlineStart[x++];
03279             Pix.Green   = ScanlineStart[x++];
03280             Pix.Red     = ScanlineStart[x++];
03281             break;
03282 
03283         case 32:
03284             x *= 4;
03285             Pix.Blue    = ScanlineStart[x++];
03286             Pix.Green   = ScanlineStart[x++];
03287             Pix.Red     = ScanlineStart[x++];
03288             Pix.Alpha   = ScanlineStart[x++];
03289             break;
03290 
03291         default:    
03292             Pix.Red = Pix.Green = Pix.Blue = 0;
03293             ERROR3("Unsupported bitmap format in ReadPixel(32bpp)");
03294             break;
03295     }
03296 
03297     return(Pix);
03298 }

PixelGreyscale CWxBitmap::ReadPixelGreyscale INT32  x,
INT32  y
[virtual]
 

reads a pixel

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/7/96
Parameters:
x,y - coordinates of the pixel to read [INPUTS]
Returns:
The pixel value of the given pixel, as an 8bpp greyscale
Notes: In debug builds, will check all kinds of stuff, but in release builds, it assumes that you are providing legal offsets in the bitmap, and are only using this call where it will work - this is to reduce retail overhead on each pixel operation.

Coloured pixels from deep bitmaps will be converted to greyscales Pixels from <=8bpp bitmaps will be read directly, and ASSUMED to be in a greyscale format (e.g. it does NOT read the palette entry for the pixel value and convert that to a greyscale)

See also:
CWxBitmap::ReadPixel32bpp

Implements OILBitmap.

Definition at line 3397 of file oilbitmap.cpp.

03398 {
03399 RebuildXPEBitmap();
03400     ERROR3IF(BMInfo == NULL || BMBytes == NULL, "PlotPixel called on duff bitmap");
03401     ERROR3IF(x < 0 || y < 0 || x >= (INT32)GetWidth() || y >= (INT32)GetHeight(),
03402                 "Illegal pixel position in CWxBitmap::ReadPixel");
03403 
03404     BYTE *ScanlineStart = BMBytes + (y * ScanLineByteWidth);
03405     PixelGreyscale Pix;
03406 
03407     switch(BMInfo->bmiHeader.biBitCount)
03408     {
03409         case 1:
03410             {
03411                 BYTE Temp = ScanlineStart[x >> 3];      // Get the byte containing the pixel (x / 8)
03412                 Temp &= 0x80 >> (x & 7);                // Mask out all bits except the pixel (x % 8)
03413 
03414                 Pix = (Temp == 0) ? 0 : 255;
03415             }
03416             break;
03417 
03418         case 4:
03419             {
03420                 BYTE Temp = ScanlineStart[x / 2];       // Get the byte containing the pixel
03421 
03422                 // And pull out the actual pixel value. Note that we repeat the nybble twice
03423                 // into the final byte to get the correct 8bpp greyscale value (white is FF, not F0!)
03424                 if ((x & 1) == 0)
03425                     Temp = (Temp & 0xf0) | ((Temp & 0xf0) >> 4);        // High nybble
03426                 else
03427                     Temp = (Temp & 0x0f) | ((Temp & 0x0f) << 4);        // Low nybble
03428 
03429                 Pix = Temp;
03430             }
03431             break;
03432 
03433         case 8:
03434             Pix = ScanlineStart[x];
03435             break;
03436 
03437         case 24:
03438             {
03439                 double Temp;
03440 
03441                 x *= 3;
03442                 Temp  = 0.109 * (double) ScanlineStart[x++];        // B
03443                 Temp += 0.586 * (double) ScanlineStart[x++];        // G
03444                 Temp += 0.305 * (double) ScanlineStart[x];          // R
03445 
03446                 Pix = (BYTE) Temp;
03447             }
03448             break;
03449  
03450         case 32:
03451             {
03452                 double Temp;
03453 
03454                 x *= 4;
03455                 Temp  = 0.109 * (double) ScanlineStart[x++];        // B
03456                 Temp += 0.586 * (double) ScanlineStart[x++];        // G
03457                 Temp += 0.305 * (double) ScanlineStart[x];          // R
03458                                                                     // Alpha
03459                 Pix = (BYTE) Temp;
03460             }
03461             break;
03462 
03463         default:    
03464             Pix = 0;
03465             ERROR3("Unsupported bitmap format in ReadPixel(32bpp)");
03466             break;
03467     }
03468 
03469     return(Pix);
03470 }

void CWxBitmap::ReplaceBitmap LPBYTE  pBytes,
LPBITMAPINFO  pInfo
[virtual]
 

To reset the bitmap stored in this CWxBitmap object.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
04/02/2004
Parameters:
the bytes and bitmapinfo of the new bitmap [INPUTS]
Returns:
-

Implements OILBitmap.

Definition at line 4246 of file oilbitmap.cpp.

04247 {
04248     if (IsDefaultBitmap())
04249     {
04250         ERROR2RAW("ReplaceBitmap asked to replace the default bitmap!");
04251         return;
04252     }
04253     // Do we have valid inputs?
04254     if (pBytes==NULL && pInfo==NULL)
04255     {
04256         ERROR2RAW("Call to ReplaceBitmap with bad parameters");
04257         return;
04258     }
04259 
04260     // Remove the old data from memory
04261     FreeDIB( BMInfo, BMBytes );
04262     DestroyGreyscaleVersion();
04263     DestroyContonePalette();
04264 
04265     // Set the new data pointers
04266     BMInfo = pInfo;
04267     BMBytes = pBytes;
04268 
04269     // Set the information up
04270     CacheGeometry();
04271 }

INT32 CWxBitmap::ReturnPaletteIndexUsed INT32  x,
INT32  y
[virtual]
 

When the user clicks in, or moves the mouse over a pixel in one of the preview images, this function is called to work out the actual palette index of the colour used.

Author:
Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/09/99
Parameters:
x,y - The x and y co-ordinates of the pixel under consideration [INPUTS]
Returns:
-1 if something went wrong, otherwise the relevant palette index.
Notes: This function is based on the function ReadPixel32bpp()

Implements OILBitmap.

Definition at line 3321 of file oilbitmap.cpp.

03322 {
03323 RebuildXPEBitmap();
03324     ERROR3IF(BMInfo == NULL || BMBytes == NULL, "PlotPixel called on duff bitmap");
03325     ERROR3IF(x < 0 || y < 0 || x >= (INT32)GetWidth() || y >= (INT32)GetHeight(),
03326                 "Illegal pixel position in CWxBitmap::ReadPixel");
03327 
03328     BYTE *ScanlineStart = BMBytes + (y * ScanLineByteWidth);
03329 
03330     INT32 PaletteIndex;
03331 
03332     switch(BMInfo->bmiHeader.biBitCount)
03333     {
03334         case 1:
03335             {
03336                 BYTE Temp = ScanlineStart[x >> 3];      // Get the byte containing the pixel (x / 8)
03337                 Temp &= 0x80 >> (x & 7);                // Mask out all bits except the pixel (x % 8)
03338                 Temp = (Temp == 0) ? 0 : 1;
03339                 PaletteIndex = Temp;
03340             }
03341             break;
03342 
03343         case 4:
03344             {
03345                 BYTE Temp = ScanlineStart[x / 2];       // Get the byte containing the pixel
03346 
03347                 // Pull out the pixel's palette index
03348                 if ((x & 1) == 0)
03349                     Temp = (Temp >> 4) & 0x0f;
03350                 else
03351                     Temp &= 0x0f;
03352 
03353                 PaletteIndex = Temp;
03354             }
03355             break;
03356 
03357         case 8:
03358             PaletteIndex = ScanlineStart[x];
03359             break;
03360 
03361         default:    
03362             PaletteIndex = -1;
03363             ERROR3( "Couldn't find the palette index" );
03364             break;
03365     }
03366 
03367     return PaletteIndex;
03368 }

void CWxBitmap::SetRecommendedHeight INT32  NewHeight  )  [virtual]
 

Sets the recommended height of the bitmap.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/96
Parameters:
NewHeight,the new height of the bitmap in Millipoints [INPUTS]

Implements OILBitmap.

Definition at line 1009 of file oilbitmap.cpp.

01010 {
01011 RebuildXPEBitmap();
01012     if (BMInfo)
01013     {   
01014         double PelH = DEFAULT_PIXEL_SIZE;
01015 
01016         if (NewHeight > 0)
01017         {
01018             const UINT32 Height = BMInfo->bmiHeader.biHeight;
01019             PelH = ((double)Height * M_MP_VAL)/(double)NewHeight;
01020         }
01021 
01022         BMInfo->bmiHeader.biYPelsPerMeter = (INT32)(PelH + 0.5);
01023     }
01024 }

void CWxBitmap::SetRecommendedWidth INT32  NewWidth  )  [virtual]
 

Sets the recommended width of the bitmap.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/6/96
Parameters:
NewWidth,the new width of the bitmap in Millipoints [INPUTS]

Implements OILBitmap.

Definition at line 981 of file oilbitmap.cpp.

00982 {
00983 RebuildXPEBitmap();
00984     if (BMInfo)
00985     {   
00986         double PelW = DEFAULT_PIXEL_SIZE;
00987 
00988         if (NewWidth > 0)
00989         {
00990             const UINT32 Width = BMInfo->bmiHeader.biWidth;
00991             PelW = ((double)Width * M_MP_VAL)/(double)NewWidth;
00992         }
00993 
00994         BMInfo->bmiHeader.biXPelsPerMeter = (INT32)(PelW + 0.5);
00995     }
00996 }

BOOL CWxBitmap::SetTransparencyIndex INT32  Index  )  [virtual]
 

Finds the Transparent index colour of a bitmap if one exists.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
5/6/96
Returns:
TRUE if the Index was set, FALSE if there is no transparent index

Implements OILBitmap.

Definition at line 660 of file oilbitmap.cpp.

00661 {
00662 RebuildXPEBitmap();
00663     ERROR3IF(BMInfo == NULL, "SetTransparencyIndex called when BMInfo is NULL");
00664     if (BMInfo == NULL)
00665         return FALSE;
00666 
00667     INT32 NumCols = 0;
00668 
00669     switch (GetBPP())
00670     {
00671         case 1:
00672             NumCols = 2;
00673             break;
00674 
00675         case 4:
00676             NumCols = 16;
00677             break;
00678 
00679         case 8:
00680             NumCols = 256;
00681             break;
00682 
00683         default:
00684             ERROR3("Bad colour depth in SetTransparencyIndex");
00685             break;
00686     }
00687 
00688     RGBQUAD* pCols = BMInfo->bmiColors;
00689 
00690     // Set the specified Index to be transparent
00691     for (INT32 i=0; i<NumCols; i++)
00692     {
00693         if (i == Index)
00694             pCols[i].rgbReserved = 0xFF;
00695         else
00696             pCols[i].rgbReserved = 0;
00697     }
00698 
00699     return TRUE;
00700 }

BOOL CWxBitmap::WritePalette BaseCamelotFilter pFilter  )  [virtual]
 

Function used when exporting an 8bpp JPEG into the web file and we need to squirt the palette information into the record ready for reuse when the file is loaded back in.

Author:
Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/06/96
Parameters:
pFilter - the filter to use to write the data. [INPUTS]
- [OUTPUTS]
Returns:
True if data saved ok, False otherwise

Implements OILBitmap.

Definition at line 2742 of file oilbitmap.cpp.

02743 {
02744     ERROR2IF(pFilter == NULL,FALSE,"CWxBitmap::WritePalette null pFilter");
02745 RebuildXPEBitmap();
02746 
02747     BOOL ok = TRUE;
02748 
02749     UINT32 NumberOfPaletteEntries = GetNumPaletteEntries();
02750     ERROR2IF(NumberOfPaletteEntries == 0 || NumberOfPaletteEntries > 256, FALSE,"Palette entries 0 or > 256!");
02751     // We will save the number of palette entries as a byte, 0 - 255
02752     BYTE Entries = NumberOfPaletteEntries - 1;
02753     if (ok) ok = pFilter->Write(Entries);
02754     for (UINT32 i = 0; i < NumberOfPaletteEntries; i++)
02755     {
02756 #if !defined(__WXMSW__)
02757 //TRACEUSER("Phil", _T("WritePalette r=%x g=%x b=%x\n"), BMInfo->bmiColors[i].rgbBlue, BMInfo->bmiColors[i].rgbGreen, BMInfo->bmiColors[i].rgbRed);
02758         if (ok) ok = pFilter->Write(BMInfo->bmiColors[i].rgbBlue);
02759         if (ok) ok = pFilter->Write(BMInfo->bmiColors[i].rgbGreen);
02760         if (ok) ok = pFilter->Write(BMInfo->bmiColors[i].rgbRed);
02761 #else
02762 //TRACEUSER("Phil", _T("WritePalette r=%x g=%x b=%x\n"), BMInfo->bmiColors[i].rgbRed, BMInfo->bmiColors[i].rgbGreen, BMInfo->bmiColors[i].rgbBlue);
02763         if (ok) ok = pFilter->Write(BMInfo->bmiColors[i].rgbRed);
02764         if (ok) ok = pFilter->Write(BMInfo->bmiColors[i].rgbGreen);
02765         if (ok) ok = pFilter->Write(BMInfo->bmiColors[i].rgbBlue);
02766 #endif
02767     }
02768 
02769     // During the preparation process we told the system we would update by the
02770     // the number of entries in the palette, so do so
02771     pFilter->IncProgressBarCount(NumberOfPaletteEntries);
02772 
02773     return ok;
02774 }


Friends And Related Function Documentation

OILBitmap* OILBitmap::Create UINT32  ,
UINT32  ,
UINT32  ,
UINT32 
[friend]
 

OILBitmap* OILBitmap::Create  )  [friend]
 

void OILBitmap::Deinit  )  [friend]
 

BOOL OILBitmap::Init  )  [friend]
 


Member Data Documentation

INT32 CWxBitmap::BitmapSize
 

Definition at line 230 of file oilbitmap.h.

LPBYTE CWxBitmap::BMBytes
 

Definition at line 243 of file oilbitmap.h.

LPBITMAPINFO CWxBitmap::BMInfo
 

Definition at line 242 of file oilbitmap.h.

INT32 CWxBitmap::ScanLineByteWidth
 

Definition at line 229 of file oilbitmap.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:21 2007 for Camelot by  doxygen 1.4.4