Unit avifbgra
Description
Easy to use classes and functions to read/write images in AVIF format.
It supports multi-image files.
Note that it requires libavif library.
Uses
- Classes
- SysUtils
- BGRABitmapTypes
- libavif
Overview
Structures
Name | Description |
---|---|
Class EAvifException |
Exception when using libavif library |
Class TAvifReader |
Reader for AVIF images or animations (not derived from TFPCustomImageReader) |
Class TAvifWriter |
Writer for AVIF images or animations (not derived from TFPCustomImageWriter) |
Functions and Procedures
procedure AvifLoadFromFile(const AFilename: string; aBitmap: TBGRACustomBitmap); |
procedure AvifLoadFromFileNative(const AFilename: string; aBitmap: TBGRACustomBitmap); |
procedure AvifLoadFromMemory(AData: Pointer; ASize: cardinal; aBitmap: TBGRACustomBitmap); |
procedure AvifLoadFromStream(AStream: TStream; aBitmap: TBGRACustomBitmap); |
function AvifSaveToFile(ABitmap: TBGRACustomBitmap; const AFilename: string; AIgnoreAlpha: boolean = False; AQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; AQualityAlpha0to100: integer = AVIF_BGRA_DEFAULT_QUALITY_ALPHA; APixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; ACodec: avifCodecChoice = AVIF_BGRA_CODEC_CHOICE_AUTO; ASpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT): nativeuint; overload; |
function AvifSaveToFile(aBitmap: TBGRACustomBitmap; const AFilename: string; aQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; aSpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT; aPixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; aIgnoreAlpha: boolean = false): NativeUInt; |
function AvifSaveToMemory(ABitmap: TBGRACustomBitmap; AData: Pointer; ASize: nativeuint; AIgnoreAlpha: boolean = False; AQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; AQualityAlpha0to100: integer = AVIF_BGRA_DEFAULT_QUALITY_ALPHA; APixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; ACodec: avifCodecChoice = AVIF_BGRA_CODEC_CHOICE_AUTO; ASpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT): nativeuint; overload; |
function AvifSaveToMemory(aBitmap: TBGRACustomBitmap; AData: Pointer; ASize: cardinal; aQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; aSpeed0to10:integer = AVIF_BGRA_SPEED_DEFAULT; aPixelFormat:avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; aIgnoreAlpha:boolean = false): NativeUInt; |
function AvifSaveToStream(aBitmap: TBGRACustomBitmap; AStream: TStream; aQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; aSpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT; aPixelFormat:avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; aIgnoreAlpha:boolean = false): NativeUInt; |
function AvifSaveToStream(ABitmap: TBGRACustomBitmap; AStream: TStream; AIgnoreAlpha: boolean = False; AQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; AQualityAlpha0to100: integer = AVIF_BGRA_DEFAULT_QUALITY_ALPHA; APixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; ACodec: avifCodecChoice = AVIF_BGRA_CODEC_CHOICE_AUTO; ASpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT): nativeuint; overload; |
function AvifValidateHeaderSignature( aBuffer: Pointer ): boolean; |
Types
avifCodecChoice = libavif.avifCodecChoice; |
avifPixelFormat = libavif.avifPixelFormat; |
Constants
Description
Functions and Procedures
procedure AvifLoadFromFile(const AFilename: string; aBitmap: TBGRACustomBitmap); |
Load an AVIF image from the given file |
procedure AvifLoadFromFileNative(const AFilename: string; aBitmap: TBGRACustomBitmap); |
Load an AVIF image from the given file without using the reader class |
procedure AvifLoadFromMemory(AData: Pointer; ASize: cardinal; aBitmap: TBGRACustomBitmap); |
Load an AVIF image from memory, without using the reader class |
procedure AvifLoadFromStream(AStream: TStream; aBitmap: TBGRACustomBitmap); |
Load an AVIF image from the given stream |
function AvifSaveToFile(ABitmap: TBGRACustomBitmap; const AFilename: string; AIgnoreAlpha: boolean = False; AQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; AQualityAlpha0to100: integer = AVIF_BGRA_DEFAULT_QUALITY_ALPHA; APixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; ACodec: avifCodecChoice = AVIF_BGRA_CODEC_CHOICE_AUTO; ASpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT): nativeuint; overload; |
Save an image into a file using AVIF format. Return the number of bytes needed. |
function AvifSaveToFile(aBitmap: TBGRACustomBitmap; const AFilename: string; aQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; aSpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT; aPixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; aIgnoreAlpha: boolean = false): NativeUInt; |
Save an image into a file using AVIF format. Return the number of bytes needed. |
function AvifSaveToMemory(ABitmap: TBGRACustomBitmap; AData: Pointer; ASize: nativeuint; AIgnoreAlpha: boolean = False; AQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; AQualityAlpha0to100: integer = AVIF_BGRA_DEFAULT_QUALITY_ALPHA; APixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; ACodec: avifCodecChoice = AVIF_BGRA_CODEC_CHOICE_AUTO; ASpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT): nativeuint; overload; |
Save an image to memory using AVIF format. Return the number of bytes needed. |
function AvifSaveToMemory(aBitmap: TBGRACustomBitmap; AData: Pointer; ASize: cardinal; aQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; aSpeed0to10:integer = AVIF_BGRA_SPEED_DEFAULT; aPixelFormat:avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; aIgnoreAlpha:boolean = false): NativeUInt; |
Save an image to memory using AVIF format. Return the number of bytes needed. |
function AvifSaveToStream(aBitmap: TBGRACustomBitmap; AStream: TStream; aQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; aSpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT; aPixelFormat:avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; aIgnoreAlpha:boolean = false): NativeUInt; |
Save an image into a stream using AVIF format. Return the number of bytes needed. |
function AvifSaveToStream(ABitmap: TBGRACustomBitmap; AStream: TStream; AIgnoreAlpha: boolean = False; AQuality0to100: integer = AVIF_BGRA_DEFAULT_QUALITY; AQualityAlpha0to100: integer = AVIF_BGRA_DEFAULT_QUALITY_ALPHA; APixelFormat: avifPixelFormat = AVIF_BGRA_PIXEL_FORMAT_DEFAULT; ACodec: avifCodecChoice = AVIF_BGRA_CODEC_CHOICE_AUTO; ASpeed0to10: integer = AVIF_BGRA_SPEED_DEFAULT): nativeuint; overload; |
Save an image into a stream using AVIF format. Return the number of bytes needed. |
function AvifValidateHeaderSignature( aBuffer: Pointer ): boolean; |
Checks that the signature of the memory block correspond to a valid AVIF header |
Types
avifCodecChoice = libavif.avifCodecChoice; |
Codec choices for encoding and/or decoding AVIF |
avifPixelFormat = libavif.avifPixelFormat; |
Pixel format to use when encoding the image |
Constants
AVIF_BGRA_CODEC_CHOICE_AUTO = AVIF_CODEC_CHOICE_AUTO; |
Let the encoder choose the adequate codec |
AVIF_BGRA_DEFAULT_MAX_THREADS = 2; |
Default number of allocated threads for processing |
AVIF_BGRA_DEFAULT_QUALITY = 30; |
Default quality of color compression |
AVIF_BGRA_DEFAULT_QUALITY_ALPHA = AVIF_BGRA_DEFAULT_QUALITY + AVIF_BGRA_DEFAULT_QUALITY_ALPHA_DELTA; |
Default quality of compression of the alpha channel |
AVIF_BGRA_DEFAULT_QUALITY_ALPHA_DELTA = 25; |
Default difference between color quality and alpha quality |
AVIF_BGRA_DEFAULT_TIMESCALE = 30; |
Default timescale of the media (in Hz), not relevant for images |
AVIF_BGRA_LOSSLESS_QUALITY = 100; |
Specify that no information will be lost in the compression process |
AVIF_BGRA_PIXEL_FORMAT_DEFAULT = AVIF_PIXEL_FORMAT_YUV420; |
Common format for image compression with half the resolution for chroma channels (ignored when used with AVIF_BGRA_LOSSLESS_QUALITY) |
AVIF_BGRA_SPEED_DEFAULT = AVIF_SPEED_DEFAULT; |
Let the encoder choose the adequate speed |
AVIF_CODEC_CHOICE_AOM = libavif.AVIF_CODEC_CHOICE_AOM; |
AOM stands for Alliance for Open Media, which is the consortium that developed the AV1 codec. This choice indicates the use of AOM's reference implementation for both encoding and decoding AVIF images. |
AVIF_CODEC_CHOICE_AVM = libavif.AVIF_CODEC_CHOICE_AVM; |
Ongoing development in the next-generation video compression technology beyond AV1. |
AVIF_CODEC_CHOICE_DAV1D = libavif.AVIF_CODEC_CHOICE_DAV1D; |
This decoding-only codec is focused on decoding AV1 content. Developed by the VideoLAN, VLC, and FFmpeg communities, dav1d is known for its speed and efficiency in decoding AV1 streams. |
AVIF_CODEC_CHOICE_LIBGAV1 = libavif.AVIF_CODEC_CHOICE_LIBGAV1; |
This decoding-only codec is developed by Google. It is designed for efficiency and is used in various Google products for decoding AV1 content. |
AVIF_CODEC_CHOICE_RAV1E = libavif.AVIF_CODEC_CHOICE_RAV1E; |
This encoding-only codec is designed to offer efficient encoding of video content. |
AVIF_CODEC_CHOICE_SVT = libavif.AVIF_CODEC_CHOICE_SVT; |
This encoding-only codec focuses on offering high performance and scalability. SVT stands for Scalable Video Technology. |
AVIF_PIXEL_FORMAT_YUV400 = libavif.AVIF_PIXEL_FORMAT_YUV400; |
This is a monochrome format where only the Y (luminance) component is used, and there are no U and V (chrominance) components. Essentially, it's a grayscale image, which can significantly reduce the file size while being appropriate for images that don't require color. |
AVIF_PIXEL_FORMAT_YUV420 = libavif.AVIF_PIXEL_FORMAT_YUV420; |
Utilizing the YUV color space with 4:2:0 chroma subsampling, this format reduces both the horizontal and vertical resolution of the chroma channels by half relative to the luminance channel. This is a commonly used format for digital video compression, offering significant file size reduction at the cost of some image quality, especially in areas with high color detail. |
AVIF_PIXEL_FORMAT_YUV422 = libavif.AVIF_PIXEL_FORMAT_YUV422; |
This format also uses the YUV color space but with 4:2:2 chroma subsampling. Here, the horizontal resolution of the chroma channels is halved compared to the luminance channel, reducing the image size while still maintaining good quality. It strikes a balance between compression and image quality. |
AVIF_PIXEL_FORMAT_YUV444 = libavif.AVIF_PIXEL_FORMAT_YUV444; |
This format uses YUV color space with a 4:4:4 chroma subsampling. In this format, each component (Y for luminance, U, and V for chrominance) has the same sample rate, meaning there's no chroma subsampling. This results in high-quality images because it retains all the color information. |