Board index » delphi » TGifImage - color table overflow

TGifImage - color table overflow

I am using TGifImage on an ActiveForm.

I am passing a 24bit TBitmap typecast as a TGraphic to the following
routine.

I am constantly getting a Color Table Overflow.

Is there a step in preparation I have missed?

Do I free the TGIFGraphicControlExtension created?

<snip>

function TimageX.Images_SaveGraphicToGIF(  GFC: TGraphic; sFilename: string;
                                        sColorReduction, sDithering: string;
                                        bTransparent: boolean;
                                        sTransparentColor: string ):
boolean;
var
   GIF: TGIFImage;
   Ext: TGIFGraphicControlExtension;
   gColorReduction: TColorReduction;
   gDitherMode : TDitherMode;
begin
     result := False;
     sColorReduction := LowerCase( Trim( sColorReduction ) );
//     if sColorReduction = 'windows20' then
//        gColorReduction := rmWindows20
//     else
     if sColorReduction = 'windows256' then
        gColorReduction := rmWindows256
//     else if sColorReduction = 'windowsgray' then
//        gColorReduction := rmWindowsGray
     else if sColorReduction = 'monochrome' then
        gColorReduction := rmMonochrome
     else if sColorReduction = 'grayscale' then
        gColorReduction := rmGrayScale
//     else if sColorReduction = 'netscape' then
//        gColorReduction := rmNetscape
//     else if sColorReduction = 'quantize' then
//        gColorReduction := rmQuantize
     else if sColorReduction = 'quantizewindows' then
        gColorReduction := rmQuantizeWindows;
     sDithering := LowerCase( Trim( sDithering ) );
     if sDithering = 'nearest' then
        gDitherMode := dmNearest
     else if sDithering = 'floydsteinberg' then
        gDitherMode := dmFloydSteinberg
//     else if sDithering = 'stucki' then
//        gDitherMode := dmStucki
//     else if sDithering = 'sierra' then
//        gDitherMode := dmSierra
     else if sDithering = 'jajuni' then
        gDitherMode := dmJaJuNI;
//     else if sDithering = 'stevearche' then
//        gDitherMode := dmSteveArche
//     else if sDithering = 'burkes' then
//        gDitherMode := dmBurkes;
     GIF := TGIFImage.Create;
     try
        GIF.ColorReduction := gColorReduction;
        GIF.DitherMode := gDitherMode;
        GIF.Assign( GFC );
        Ext := TGIFGraphicControlExtension.Create( GIF.Images[0] );
        Ext.Transparent := bTransparent;
        if Lowercase( sTransparentColor ) = 'pixel' then
           Ext.TransparentColorIndex :=  GIF.Images[0].Pixels[0,
GIF.Height-1]
        else
            Ext.TransparentColor := WidestringToColor( sTransparentColor );
        GIF.Images[0].Extensions.Add(Ext);
        GIF.SaveToFile( sFilename );
        result := True;
     finally
            GIF.Free;
//            Ext.free;
     end;
end;

</snip>

function TGIFColorMap.Add(Color: TColor): integer;
begin
  if (FCount >= GIFMaxColors) then
    // Color map full
    Error(sTooManyColors); <<<<<<<<<<<<<<<<<<<

Nic Roche
Net Extra
www.extra.net.au

 

Re:TGifImage - color table overflow


Quote
"Nic Roche" <n...@extra.net.au> wrote:
> I am constantly getting a Color Table Overflow.

Color table overflow means that you have, maybe indirectly, tried to
insert more than 256 colors into a GIF color table. This usually
happens when you convert a true color bitmap to GIF. In your case, my
guess is that you fail to set TGIFImage.ColorReduction to a value
different from rmNone prior to the conversion. I suggest you either
set the GIFImageDefaultColorReduction global variable to an
appropriate default value, or use a default value in your routine in
case your string matching fails.

Quote
> Do I free the TGIFGraphicControlExtension created?

No. TGIFImage takes care of that for you.

Please note that if you assign a transparent bitmap
(TBitmap.Transparent = True) to a TGIFImage, TGIFImage will
automatically create a transparent GIF from it (i.e. it also creates
the TGIFGraphicControlExtension). I'm not sure that I have documented
this fact.

DIXI

+--------------------from usenet----------------------+
|  Anders Bo Melander    | mailto:and...@melander.dk  |
|  Denmark               | http://www.melander.dk     |
+------------------------+----------------------------+

Re:TGifImage - color table overflow


This ended up being a TransparentColor assignment that was not in the
palette.

tnx Anders.

--
Nic Roche
Net Extra
www.extra.net.au

Quote
Anders Melander <and...@melander.dk> wrote in message

news:3845b491.20217351@forums.borland.com...
Quote
> "Nic Roche" <n...@extra.net.au> wrote:

> > I am constantly getting a Color Table Overflow.

> Color table overflow means that you have, maybe indirectly, tried to
> insert more than 256 colors into a GIF color table. This usually
> happens when you convert a true color bitmap to GIF. In your case, my
> guess is that you fail to set TGIFImage.ColorReduction to a value
> different from rmNone prior to the conversion. I suggest you either
> set the GIFImageDefaultColorReduction global variable to an
> appropriate default value, or use a default value in your routine in
> case your string matching fails.

> > Do I free the TGIFGraphicControlExtension created?

> No. TGIFImage takes care of that for you.

> Please note that if you assign a transparent bitmap
> (TBitmap.Transparent = True) to a TGIFImage, TGIFImage will
> automatically create a transparent GIF from it (i.e. it also creates
> the TGIFGraphicControlExtension). I'm not sure that I have documented
> this fact.

> DIXI

> +--------------------from usenet----------------------+
> |  Anders Bo Melander    | mailto:and...@melander.dk  |
> |  Denmark               | http://www.melander.dk     |
> +------------------------+----------------------------+

Other Threads