Conv32to8 Class Reference

Inheritance diagram for Conv32to8:

DIBConvert List of all members.

Public Member Functions

 Conv32to8 (UINT32, LPLOGPALETTE, UINT32)
 Constructor.
 ~Conv32to8 ()
BOOL Convert (LPBYTE Input, LPBYTE Output, UINT32 Height, BOOL FirstStrip)

Private Attributes

BITMAPINFOHEADER SourceHeader
BITMAPINFOHEADER DestHeader
LPLOGPALETTE DestPalette
UINT32 Dither

Detailed Description

Definition at line 151 of file dibconv.cpp.


Constructor & Destructor Documentation

Conv32to8::Conv32to8 UINT32  Width,
LPLOGPALETTE  Palette,
UINT32  DitherType
 

Constructor.

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

Definition at line 485 of file dibconv.cpp.

00486 {
00487     ERROR3IF(Palette == NULL,"Conv32to8 null palette specified");
00488 
00489     SourceHeader.biPlanes = 1;
00490     SourceHeader.biBitCount = 32;
00491     SourceHeader.biWidth = Width;
00492     SourceHeader.biClrUsed = 0;
00493 
00494     DestHeader.biPlanes = 1;
00495     DestHeader.biBitCount = 8;
00496     DestHeader.biWidth = Width;
00497     DestHeader.biClrUsed = 256;
00498 
00499     DestPalette = Palette;
00500 
00501     // Remember which dithering to use
00502     Dither = DitherType;
00503 
00504     // lets use this palette for the conversion
00505     GDrawContext *GDC = GetConvertContext();
00506 
00507     GDC->SetupBitmap(Width, 16, 8, NULL);
00508 
00509     // This should return a palette plus tell it what dithering we require
00510     // 0 = ordered dither, not 0 for error diffusion or no dithering.
00511 
00512     pcLOGPALETTE lpPalette = GDC->SelectPalette((Dither == XARADITHER_SIMPLE ||
00513                                                  Dither == XARADITHER_ERROR_DIFFUSION ||
00514                                                  Dither == XARADITHER_NONE) ? 1 : 0 );
00515     if (lpPalette == NULL)
00516     {
00517         ENSURE(lpPalette, "Didnt get a palette for export");
00518     }
00519 
00520 
00521     // Graeme (25/9/00) - Removed to prevent a problem with creating a bitmap copy of an
00522     // existing bitmap.
00523 /*
00524     // Added by Craig Hamilton 15/9/00.
00525     // This section of code will replace any flag value with null if it is not a valid value.
00526     INT32 i;
00527 
00528     for(i=0;i<DestPalette->palNumEntries;i++)
00529     {
00530         if(DestPalette->palPalEntry[i].peFlags != NULL && DestPalette->palPalEntry[i].peFlags != PC_EXPLICIT &&
00531             DestPalette->palPalEntry[i].peFlags != PC_NOCOLLAPSE && DestPalette->palPalEntry[i].peFlags != PC_RESERVED)
00532         {
00533             DestPalette->palPalEntry[i].peFlags = NULL;
00534         }
00535     }
00536     // End added.
00537 */
00538 
00539     GDC->InitialiseWithPalette(DestPalette);
00540 }

Conv32to8::~Conv32to8  ) 
 

Definition at line 542 of file dibconv.cpp.

00543 {
00544 }


Member Function Documentation

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

Implements DIBConvert.

Definition at line 546 of file dibconv.cpp.

00547 {
00548     SourceHeader.biHeight = Height;
00549       DestHeader.biHeight = Height;
00550 
00551     //  If we are converting to 8 bit, and the bitmap has less than 256 colours, then
00552     //  it is better to avoid the GDraw conversion function, and do our own instead.
00553 PORTNOTE("other","Removed GRenderOptPalette usage")
00554 #ifndef EXCLUDE_FROM_XARALX
00555     if( GRenderOptPalette::DoGDrawConversion && !GRenderOptPalette::UseOldPalette )
00556     {
00557         // GAT
00558         RGBQUAD aFastPalette[0x100] ;
00559         BYTE aIndex[0x100] ;
00560         UINT32 nEntries = 0 ;
00561 
00562         //  Go through the supplied bitmap strip.
00563         RGBQUAD* InputBytes = (RGBQUAD*)Input ;
00564         BYTE*   OutputBytes = Output ;
00565         UINT32 Width = SourceHeader.biWidth ;
00566         //  Need an offset if the width of the bitmap is not a multiple of 4.
00567         INT32 OffsetValue = Width % 4 ;
00568         if( OffsetValue > 0 )
00569             OffsetValue = 4 - OffsetValue ;
00570 
00571         for( UINT32 j=0 ; j<Height ; j++ )
00572         {
00573             for( UINT32 i=0 ; i<Width ; i++ )
00574             {
00575                 // Get the RGB value for the current pixel.
00576                 // Mask out the alpha channel.
00577                 RGBQUAD rgb = *InputBytes++ ;
00578                 (DWORD&)rgb &= 0xFFFFFF ;
00579                 // Search through the palette to try and find this colour.
00580                 // This code assumes that it will definitely not be more
00581                 // than 256 colours in the palette.
00582                 for( UINT32 k=0 ; k<nEntries ; k++ )
00583                     if( (DWORD&)aFastPalette[k]==(DWORD&)rgb )
00584                     {
00585                         *OutputBytes++ = aIndex[k] ;
00586                         goto done ;     // Use goto for efficiency.
00587                     }
00588                 // Pixel not found so add to tables.
00589                 {
00590                     PALETTEENTRY pe = {rgb.rgbRed,rgb.rgbGreen,rgb.rgbBlue,0} ;
00591                     *OutputBytes++ = aIndex[nEntries] = PaletteManager::FindIndexOfNearestColour( pe, DestPalette ) ;
00592                     aFastPalette[nEntries++] = rgb ;
00593                     ASSERT(nEntries<=256) ;
00594                 }
00595         done:   ;
00596             }
00597             //  After the current row has been done, then apply any 'filler' bytes
00598             //  necessary.
00599             OutputBytes += OffsetValue ;
00600         }
00601         //  Finished now.
00602         return TRUE;
00603     }
00604     else
00605 #endif
00606     {
00607         //  Go here if we have an optimised palette
00608         DWORD DitherWord = Dither;
00609         TRACEUSER( "Andy?", _T("Convert32to8, Strip = %d, dither = %d\n"), FirstStrip, Dither);
00610 
00611         if (Dither == XARADITHER_SIMPLE || Dither == XARADITHER_ERROR_DIFFUSION)
00612         {
00613             // We are using some form of error diffusion ....
00614 
00615             // Set second byte to 255 if this is the First strip,
00616             // so that the error buffer is cleared
00617             DitherWord |= (( FirstStrip ? 0 : 255 ) << 8);
00618         }
00619 
00620         GDrawContext *GDC = GetConvertContext();
00621         const BOOL res = GDC->ConvertBitmap( &SourceHeader, Input, &DestHeader, Output, DitherWord);
00622 
00623         if (!res)
00624             TRACE( _T("GColour_ConvertBitmap did error %x\n"), GetLastError() );
00625 
00626         return TRUE;
00627     }
00628 }


Member Data Documentation

BITMAPINFOHEADER Conv32to8::DestHeader [private]
 

Definition at line 161 of file dibconv.cpp.

LPLOGPALETTE Conv32to8::DestPalette [private]
 

Definition at line 162 of file dibconv.cpp.

UINT32 Conv32to8::Dither [private]
 

Definition at line 163 of file dibconv.cpp.

BITMAPINFOHEADER Conv32to8::SourceHeader [private]
 

Definition at line 160 of file dibconv.cpp.


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