Class TBGRACustomColorQuantizer

Unit

Declaration

type TBGRACustomColorQuantizer = class(TObject)

Description

Abstract class for color quantization.

Quantization is the process by which each color is reduced to an index into a palette. Surrounding pixels can affect the approximate color, an effect called dithering.

Hierarchy

Overview

Methods

Public constructor Create(ABitmap: TBGRACustomBitmap; AAlpha: TAlphaChannelPaletteOption); overload; virtual; abstract;
Public constructor Create(AColors: array of TBGRAPixel; ASeparateAlphaChannel: boolean); overload;
Public constructor Create(APalette: TBGRACustomPalette; ASeparateAlphaChannel: boolean); overload; virtual; abstract;
Public constructor Create(ABitmap: TBGRACustomBitmap; AAlpha: TAlphaChannelPaletteOption; AReductionColorCount: integer); overload; virtual; abstract;
Public constructor Create(AColors: array of TBGRAPixel; ASeparateAlphaChannel: boolean; AReductionColorCount: integer); overload;
Public constructor Create(APalette: TBGRACustomPalette; ASeparateAlphaChannel: boolean; AReductionColorCount: integer); overload; virtual; abstract;
Public function GetDitheredBitmap(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; ABounds: TRect): TBGRACustomBitmap; overload; virtual; abstract;
Public function GetDitheredBitmap(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap): TBGRACustomBitmap; overload;
Public function GetDitheredBitmapIndexedData(ABitDepth: integer; AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap): Pointer; overload;
Public function GetDitheredBitmapIndexedData(ABitDepth: integer; AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; out AScanlineSize: PtrInt): Pointer; overload;
Public function GetDitheredBitmapIndexedData(ABitDepth: integer; AByteOrder: TRawImageByteOrder; AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; out AScanlineSize: PtrInt): Pointer; overload; virtual; abstract;
Protected function GetDominantColor: TBGRAPixel; virtual;
Protected function GetPalette: TBGRACustomApproxPalette; virtual; abstract;
Protected function GetReductionColorCount: integer; virtual; abstract;
Protected function GetSourceColor(AIndex: integer): TBGRAPixel; virtual; abstract;
Protected function GetSourceColorCount: Integer; virtual; abstract;
Public procedure ApplyDitheringInplace(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; ABounds: TRect); overload; virtual; abstract;
Public procedure ApplyDitheringInplace(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap); overload;
Public procedure SaveBitmapToFile(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; AFilenameUTF8: string); overload;
Public procedure SaveBitmapToFile(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; AFilenameUTF8: string; AFormat: TBGRAImageFormat); overload;
Public procedure SaveBitmapToStream(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; AStream: TStream; AFormat: TBGRAImageFormat); virtual; abstract;
Protected procedure SetReductionColorCount(AValue: Integer); virtual; abstract;

Properties

Public property DominantColor: TBGRAPixel read GetDominantColor;
Public property ReducedPalette: TBGRACustomApproxPalette read GetPalette;
Public property ReductionColorCount: Integer read GetReductionColorCount write SetReductionColorCount;
Public property SourceColor[AIndex: integer]: TBGRAPixel read GetSourceColor;
Public property SourceColorCount: Integer read GetSourceColorCount;

Description

Methods

Public constructor Create(ABitmap: TBGRACustomBitmap; AAlpha: TAlphaChannelPaletteOption); overload; virtual; abstract;

This item has no description.

Public constructor Create(AColors: array of TBGRAPixel; ASeparateAlphaChannel: boolean); overload;

This item has no description.

Public constructor Create(APalette: TBGRACustomPalette; ASeparateAlphaChannel: boolean); overload; virtual; abstract;

This item has no description.

Public constructor Create(ABitmap: TBGRACustomBitmap; AAlpha: TAlphaChannelPaletteOption; AReductionColorCount: integer); overload; virtual; abstract;

This item has no description.

Public constructor Create(AColors: array of TBGRAPixel; ASeparateAlphaChannel: boolean; AReductionColorCount: integer); overload;

This item has no description.

Public constructor Create(APalette: TBGRACustomPalette; ASeparateAlphaChannel: boolean; AReductionColorCount: integer); overload; virtual; abstract;

This item has no description.

Public function GetDitheredBitmap(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; ABounds: TRect): TBGRACustomBitmap; overload; virtual; abstract;

This item has no description.

Public function GetDitheredBitmap(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap): TBGRACustomBitmap; overload;

This item has no description.

Public function GetDitheredBitmapIndexedData(ABitDepth: integer; AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap): Pointer; overload;

This item has no description.

Public function GetDitheredBitmapIndexedData(ABitDepth: integer; AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; out AScanlineSize: PtrInt): Pointer; overload;

This item has no description.

Public function GetDitheredBitmapIndexedData(ABitDepth: integer; AByteOrder: TRawImageByteOrder; AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; out AScanlineSize: PtrInt): Pointer; overload; virtual; abstract;

This item has no description.

Protected function GetDominantColor: TBGRAPixel; virtual;

This item has no description.

Protected function GetPalette: TBGRACustomApproxPalette; virtual; abstract;

This item has no description.

Protected function GetReductionColorCount: integer; virtual; abstract;

This item has no description.

Protected function GetSourceColor(AIndex: integer): TBGRAPixel; virtual; abstract;

This item has no description.

Protected function GetSourceColorCount: Integer; virtual; abstract;

This item has no description.

Public procedure ApplyDitheringInplace(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; ABounds: TRect); overload; virtual; abstract;

This item has no description.

Public procedure ApplyDitheringInplace(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap); overload;

This item has no description.

Public procedure SaveBitmapToFile(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; AFilenameUTF8: string); overload;

This item has no description.

Public procedure SaveBitmapToFile(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; AFilenameUTF8: string; AFormat: TBGRAImageFormat); overload;

This item has no description.

Public procedure SaveBitmapToStream(AAlgorithm: TDitheringAlgorithm; ABitmap: TBGRACustomBitmap; AStream: TStream; AFormat: TBGRAImageFormat); virtual; abstract;

This item has no description.

Protected procedure SetReductionColorCount(AValue: Integer); virtual; abstract;

This item has no description.

Properties

Public property DominantColor: TBGRAPixel read GetDominantColor;

Colors that is the most represented in the source

Public property ReducedPalette: TBGRACustomApproxPalette read GetPalette;

Palette with reduced number of colors after applying quantization

Public property ReductionColorCount: Integer read GetReductionColorCount write SetReductionColorCount;

Number of different colors in the reduced palette.

By default, there are 256 colors.

Example to reduce an image to 16 colors:

uses BGRAColorQuantization, BGRABitmapTypes, BGRABitmap;
var
  quant : TBGRAColorQuantizer;
  sourceBmp: TBGRABitmap;
begin
  sourceBmp := TBGRABitmap.Create('picture.jpg');
  quant := TBGRAColorQuantizer.Create(sourceBmp, acIgnore);
  quant.ReductionColorCount := 16;
  quant.SaveBitmapToFile(daFloydSteinberg, sourceBmp, 'picture_in_4_bits.bmp');
  quant.Free;
  sourceBmp.Free;
end;

Public property SourceColor[AIndex: integer]: TBGRAPixel read GetSourceColor;

Value of a color in the source

Public property SourceColorCount: Integer read GetSourceColorCount;

Number colors provided in the source