Unit BGRAGifFormat

📄 Source code

Description

Structure and algorithms to read/write GIF files

Uses

Overview

Structures

Name Description
Class EColorQuantizerMissing Exception raised when no color quantizer is available
Record TGIFData Data describing a GIF file
Packed Record TGIFExtensionBlock GIF extension block
Packed Record TGIFGraphicControlExtension GIF graphic control extension
Packed Record TGIFImageDescriptor Image descriptor of GIF frame
Packed Record TGIFScreenDescriptor Screen descriptor for GIF rendering
Record TGifSubImage One image in the GIF animation
Packed Record TPackedRGBTriple 8-bit RGB values

Functions and Procedures

function BGRAToPackedRgbTriple(color: TBGRAPixel): TPackedRGBTriple;
function CeilLn2(AValue: Integer): integer;
procedure GIFDecodeLZW(AStream: TStream; AImage: TBGRACustomBitmap; const APalette: ArrayOfTBGRAPixel; transcolorIndex: integer; interlaced: boolean);
procedure GIFEncodeLZW(AStream: TStream; AImageData: PByte; AImageWidth, AImageHeight: integer; ABitDepth: byte);
function GIFLoadFromStream(stream: TStream; MaxImageCount: integer = maxLongint): TGIFData;
procedure GIFSaveToStream(AData: TGifData; Stream: TStream; AQuantizerFactory: TBGRAColorQuantizerAny; ADitheringAlgorithm: TDitheringAlgorithm);
function PackedRgbTribleToBGRA(rgb: TPackedRGBTriple): TBGRAPixel;

Types

TDisposeMode = (...);
TGIFSignature = packed array[1..6] of char;
TGifSubImageArray = array of TGifSubImage;

Constants

GIFBlockTerminator = $00;
GIFCodeTableSize = 4096;
GIFExtensionIntroducer = $21;
GIFFileTerminator = $3B;
GIFGraphicControlExtension_DisposeModeShift = 2;
GIFGraphicControlExtension_FunctionCode = $f9;
GIFGraphicControlExtension_TransparentFlag = $01;
GIFGraphicControlExtension_UserInputFlag = $02;
GIFImageDescriptor_InterlacedFlag = $40;
GIFImageDescriptor_LocalColorSortFlag = $20;
GIFImageDescriptor_LocalColorTableFlag = $80;
GIFImageIntroducer = $2c;
GIFInterlacedStart: array[1..4] of longint = (0, 4, 2, 1);
GIFInterlacedStep: array[1..4] of longint = (8, 8, 4, 2);
GIFScreenDescriptor_GlobalColorSortFlag = $08;
GIFScreenDescriptor_GlobalColorTableFlag = $80;
NetscapeApplicationIdentifier = 'NETSCAPE2.0';
NetscapeSubBlockIdBuffering = 2;
NetscapeSubBlockIdLoopCount = 1;

Description

Functions and Procedures

function BGRAToPackedRgbTriple(color: TBGRAPixel): TPackedRGBTriple;

This item has no description.

function CeilLn2(AValue: Integer): integer;

This item has no description.

procedure GIFDecodeLZW(AStream: TStream; AImage: TBGRACustomBitmap; const APalette: ArrayOfTBGRAPixel; transcolorIndex: integer; interlaced: boolean);

This item has no description.

procedure GIFEncodeLZW(AStream: TStream; AImageData: PByte; AImageWidth, AImageHeight: integer; ABitDepth: byte);

Encode an image supplied as an sequence of bytes, from left to right and top to bottom. Adapted from the work of Udo Schmal, http://www.gocher.me/FPWriteGIF

function GIFLoadFromStream(stream: TStream; MaxImageCount: integer = maxLongint): TGIFData;

This item has no description.

procedure GIFSaveToStream(AData: TGifData; Stream: TStream; AQuantizerFactory: TBGRAColorQuantizerAny; ADitheringAlgorithm: TDitheringAlgorithm);

This item has no description.

function PackedRgbTribleToBGRA(rgb: TPackedRGBTriple): TBGRAPixel;

This item has no description.

Types

TDisposeMode = (...);

What to do when finishing a frame and starting the next one

Values
  • dmNone
  • dmKeep: undefined value
  • dmErase: keep the changes done by the frame
  • dmRestore: clear everything after the frame (used by GIF but not available in PNG)
  • dmEraseArea: restore to how it was before the frame
TGIFSignature = packed array[1..6] of char;

Signature for a GIF file

TGifSubImageArray = array of TGifSubImage;

This item has no description.

Constants

GIFBlockTerminator = $00;

This item has no description.

GIFCodeTableSize = 4096;

This item has no description.

GIFExtensionIntroducer = $21;

This item has no description.

GIFFileTerminator = $3B;

This item has no description.

GIFGraphicControlExtension_DisposeModeShift = 2;

This item has no description.

GIFGraphicControlExtension_FunctionCode = $f9;

wait for user input at this frame (ignored)

GIFGraphicControlExtension_TransparentFlag = $01;

This item has no description.

GIFGraphicControlExtension_UserInputFlag = $02;

transparent color index is provided

GIFImageDescriptor_InterlacedFlag = $40;

local palette is present

GIFImageDescriptor_LocalColorSortFlag = $20;

image data is interlaced

GIFImageDescriptor_LocalColorTableFlag = $80;

This item has no description.

GIFImageIntroducer = $2c;

global palette colors are sorted by importance

GIFInterlacedStart: array[1..4] of longint = (0, 4, 2, 1);

local palette colors are sorted by importance

GIFInterlacedStep: array[1..4] of longint = (8, 8, 4, 2);

This item has no description.

GIFScreenDescriptor_GlobalColorSortFlag = $08;

global palette is present

GIFScreenDescriptor_GlobalColorTableFlag = $80;

This item has no description.

NetscapeApplicationIdentifier = 'NETSCAPE2.0';

This item has no description.

NetscapeSubBlockIdBuffering = 2;

This item has no description.

NetscapeSubBlockIdLoopCount = 1;

This item has no description.