Conv24to8 Class Reference

Inheritance diagram for Conv24to8:

DIBConvert List of all members.

Public Member Functions

 Conv24to8 (UINT32, LPLOGPALETTE, UINT32)
 Constructor to Special convert 24 to 8 class.
 ~Conv24to8 ()
BOOL Convert (LPBYTE Input, LPBYTE Output, UINT32 Height, BOOL FirstStrip)

Protected Member Functions

void Convert24to32 (INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits)

Private Attributes

BITMAPINFOHEADER SourceHeader
BITMAPINFOHEADER DestHeader
LPLOGPALETTE DestPalette
UINT32 Dither
LPBYTE InputBuffer32bpp

Detailed Description

Definition at line 199 of file dibconv.cpp.


Constructor & Destructor Documentation

Conv24to8::Conv24to8 UINT32  Width,
LPLOGPALETTE  Palette,
UINT32  DitherType
 

Constructor to Special convert 24 to 8 class.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>?
Date:
29/06/96

Definition at line 777 of file dibconv.cpp.

00778 {
00779     ERROR3IF(Palette == NULL,"Conv32to8 null palette specified");
00780 
00781     SourceHeader.biPlanes = 1;
00782     SourceHeader.biBitCount = 32;
00783     SourceHeader.biWidth = Width;
00784     SourceHeader.biClrUsed = 0;
00785 
00786     DestHeader.biPlanes = 1;
00787     DestHeader.biBitCount = 8;
00788     DestHeader.biWidth = Width;
00789     DestHeader.biClrUsed = 256;
00790 
00791     DestPalette = Palette;
00792 
00793     // Remember which dithering to use
00794     Dither = DitherType;
00795 
00796     // lets use this palette for the conversion
00797     GDrawContext *GDC = GetConvertContext();
00798 
00799     GDC->SetupBitmap(Width, 16, 8, NULL);
00800 
00801     // This should return a palette plus tell it what dithering we require
00802     // 0 = ordered dither, not 0 for error diffusion or no dithering.
00803 
00804     pcLOGPALETTE lpPalette = GDC->SelectPalette((Dither == XARADITHER_SIMPLE ||
00805                                                             Dither == XARADITHER_ERROR_DIFFUSION ||
00806                                                             Dither == XARADITHER_NONE) ? 1 : 0 );
00807     if (lpPalette == NULL)
00808     {
00809         ENSURE(lpPalette, "Didnt get a palette for export");
00810     }
00811 
00812     GDC->InitialiseWithPalette(DestPalette);
00813 
00814     // GDraw can only cope with 32 bpp data and so we need to convert the data into 32bpp
00815     // before calling GDraw. This is the buffer we use for this
00816     InputBuffer32bpp = NULL;
00817 }

Conv24to8::~Conv24to8  ) 
 

Definition at line 819 of file dibconv.cpp.

00820 {
00821     GRenderRegion::EnsurePalette(-1);
00822     if (InputBuffer32bpp != NULL)
00823         CCFree(InputBuffer32bpp);
00824 }


Member Function Documentation

BOOL Conv24to8::Convert LPBYTE  Input,
LPBYTE  Output,
UINT32  Height,
BOOL  FirstStrip
[virtual]
 

Implements DIBConvert.

Definition at line 826 of file dibconv.cpp.

00827 {
00828     // Assumes first strip will be the largest and so allocates a conversion buffer of this size
00829     
00830     SourceHeader.biHeight = Height;
00831 
00832     DestHeader.biHeight = Height;
00833 
00834     INT32 Width24bpp = DIBUtil::ScanlineSize(SourceHeader.biWidth, 24);
00835     INT32 Width32bpp = DIBUtil::ScanlineSize(SourceHeader.biWidth, 32);
00836     if (InputBuffer32bpp == NULL)
00837     {
00838         // If we haven't done so already then allocate ourselves our conversion buffer
00839         InputBuffer32bpp = (LPBYTE)CCMalloc(Width32bpp * Height);
00840         if (InputBuffer32bpp == NULL)
00841             return FALSE;
00842     }
00843 
00844     // Copy the data across from the source 24bpp buffer into the 32bpp buffer
00845     INT32 PixelWidth = SourceHeader.biWidth;
00846     LPBYTE InputBits = Input;
00847     LPBYTE OutputBits = InputBuffer32bpp;
00848     // Convert it a pixel line at a time
00849     for (UINT32 i = 0; i < Height; i++)
00850     {
00851         Convert24to32(PixelWidth, InputBits, OutputBits);
00852         InputBits += Width24bpp;
00853         OutputBits += Width32bpp;
00854     }
00855 
00856     DWORD DitherWord = Dither;
00857     if (FirstStrip)
00858         TRACEUSER( "Neville", _T("Convert24to8, Strip = %d, dither = %d\n"), FirstStrip, Dither);
00859 
00860     if (Dither == XARADITHER_SIMPLE || Dither == XARADITHER_ERROR_DIFFUSION)
00861     {
00862         // We are using some form of error diffusion ....
00863 
00864         // Set second byte to 255 if this is the First strip,
00865         // so that the error buffer is cleared
00866         DitherWord |= (( FirstStrip ? 0 : 255 ) << 8);
00867     }
00868 
00869     GDrawContext *GDC = GetConvertContext();
00870     const BOOL res = GDC->ConvertBitmap( &SourceHeader, InputBuffer32bpp, &DestHeader, Output, DitherWord);
00871     if (!res)
00872         TRACE( _T("GColour_ConvertBitmap did error %x\n"), GetLastError() );
00873 
00874     return TRUE;
00875 }

void Conv24to8::Convert24to32 INT32  PixelWidth,
LPBYTE  InputBits,
LPBYTE  OutputBits
[protected]
 

Definition at line 877 of file dibconv.cpp.

00878 {
00879     // Convert a scanline from 24 to 32 bpp so that GDraw can work with it
00880     // source form is B,G,R
00881     // dest is B,G,R,spare
00882     // Note: if not little-endian, is this still true?
00883     while (PixelWidth--)
00884     {
00885         OutputBits[0] = InputBits[0];
00886         OutputBits[1] = InputBits[1];
00887         OutputBits[2] = InputBits[2];
00888         OutputBits[3] = 0xFF;
00889         OutputBits += 4;
00890         InputBits  += 3;
00891     }
00892 }


Member Data Documentation

BITMAPINFOHEADER Conv24to8::DestHeader [private]
 

Definition at line 212 of file dibconv.cpp.

LPLOGPALETTE Conv24to8::DestPalette [private]
 

Definition at line 213 of file dibconv.cpp.

UINT32 Conv24to8::Dither [private]
 

Definition at line 214 of file dibconv.cpp.

LPBYTE Conv24to8::InputBuffer32bpp [private]
 

Definition at line 216 of file dibconv.cpp.

BITMAPINFOHEADER Conv24to8::SourceHeader [private]
 

Definition at line 211 of file dibconv.cpp.


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