LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
Data Structures
AVIF

Read and write AV1 Image File Format images. More...

Collaboration diagram for AVIF:

Data Structures

struct  gdAvifWriteOptions
 AVIF encoder options used by gdImageAvifPtrWithOptions(). More...
 
struct  gdAvifInfo
 Information extracted from the AVIF image and container. More...
 

AVIF Write Options

enum  { GD_AVIF_CHROMA_SUBSAMPLING_AUTO = 0 , GD_AVIF_CHROMA_SUBSAMPLING_YUV420 = 1 , GD_AVIF_CHROMA_SUBSAMPLING_YUV444 = 2 }
 
enum  
 
void gdAvifInfoInit (gdAvifInfo *info)
 Initialize AVIF information and clear the metadata pointer.
 
int gdAvifGetInfo (FILE *inFile, gdAvifInfo *info)
 Read AVIF information from a stdio stream without closing it. *.
 
int gdAvifGetInfoCtx (gdIOCtxPtr in, gdAvifInfo *info)
 Read AVIF information from a gdIOCtx without closing it.
 
int gdAvifGetInfoPtr (int size, const void *data, gdAvifInfo *info)
 Read AVIF information from memory without taking ownership.
 
void gdAvifWriteOptionsInit (gdAvifWriteOptions *options)
 Initialize AVIF write options with gd defaults.
 

AVIF Reading

gdImagePtr gdImageCreateFromAvif (FILE *inFile)
 Create a truecolor image from AVIF data in a stdio stream.
 
gdImagePtr gdImageCreateFromAvifPtr (int size, void *data)
 Create a truecolor image from AVIF data in memory.
 
gdImagePtr gdImageCreateFromAvifCtx (gdIOCtxPtr infile)
 Create a truecolor image from AVIF data in an IO context.
 

AVIF Writing

void gdImageAvif (gdImagePtr im, FILE *outFile)
 Write a truecolor image as AVIF data to a stdio stream.
 
void gdImageAvifEx (gdImagePtr im, FILE *outFile, int quality, int speed)
 Write a truecolor image as AVIF data to a stdio stream.
 
void * gdImageAvifPtr (gdImagePtr im, int *size)
 Encode a truecolor image as AVIF data in memory.
 
void * gdImageAvifPtrEx (gdImagePtr im, int *size, int quality, int speed)
 Encode a truecolor image as AVIF data in memory.
 
void * gdImageAvifPtrWithOptions (gdImagePtr im, int *size, const gdAvifWriteOptions *options)
 Encode a truecolor image as AVIF data in memory using write options.
 
int gdImageAvifWithOptions (gdImagePtr im, FILE *outFile, const gdAvifWriteOptions *options)
 Write AVIF data to a stdio stream using write options.
 
int gdImageAvifCtxWithOptions (gdImagePtr im, gdIOCtxPtr outfile, const gdAvifWriteOptions *options)
 Write AVIF data to a gdIOCtx using write options.
 
void gdImageAvifCtx (gdImagePtr im, gdIOCtxPtr outfile, int quality, int speed)
 Write a truecolor image as AVIF data to an IO context.
 

Detailed Description

Read and write AV1 Image File Format images.

AVIF support reads AVIF data from stdio streams, memory buffers, or gd IO contexts and returns truecolor images. If the AVIF input contains an image sequence, gd reads the first image and ignores subsequent frames. AVIF writing accepts truecolor images and can write to stdio streams, memory buffers, or gd IO contexts with quality, speed, lossless, and chroma-subsampling options.

FILE *in;
gdImagePtr im;
void *data;
int size;
in = fopen("input.avif", "rb");
if (in == NULL) {
return 1;
}
fclose(in);
if (im == NULL) {
return 1;
}
options.quality = 90;
options.speed = 6;
data = gdImageAvifPtrWithOptions(im, &size, &options);
if (data != NULL) {
gdFree(data);
}
gdImageDestroy(im);
void gdAvifWriteOptionsInit(gdAvifWriteOptions *options)
Initialize AVIF write options with gd defaults.
Definition gd_avif.c:674
void * gdImageAvifPtrWithOptions(gdImagePtr im, int *size, const gdAvifWriteOptions *options)
Encode a truecolor image as AVIF data in memory using write options.
Definition gd_avif.c:750
gdImagePtr gdImageCreateFromAvif(FILE *inFile)
Create a truecolor image from AVIF data in a stdio stream.
Definition gd_avif.c:685
@ GD_AVIF_CHROMA_SUBSAMPLING_YUV444
Definition gd.h:3466
Write an image as JPEG data to a gdIOCtx.
AVIF encoder options used by gdImageAvifPtrWithOptions().
Definition gd.h:3479
int speed
Definition gd.h:3481
int chroma_subsampling
Definition gd.h:3483
int quality
Definition gd.h:3480

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

AVIF chroma subsampling modes for gdAvifWriteOptions::chroma_subsampling.

Enumerator
GD_AVIF_CHROMA_SUBSAMPLING_AUTO 

Choose subsampling automatically from the quality settings.

GD_AVIF_CHROMA_SUBSAMPLING_YUV420 

Use 4:2:0 chroma subsampling.

GD_AVIF_CHROMA_SUBSAMPLING_YUV444 

Use 4:4:4 chroma subsampling.

◆ anonymous enum

anonymous enum

AVIF YUV pixel formats reported by gdAvifInfo::yuv_format.

Function Documentation

◆ gdAvifGetInfo()

int gdAvifGetInfo ( FILE *  inFile,
gdAvifInfo info 
)

Read AVIF information from a stdio stream without closing it. *.

Parameters
inFilePointer to the input FILE stream.
infoPointer to the gdAvifInfo structure to populate.
Returns
Returns 1 on success, or 0 on failure.

◆ gdAvifGetInfoCtx()

int gdAvifGetInfoCtx ( gdIOCtxPtr  in,
gdAvifInfo info 
)

Read AVIF information from a gdIOCtx without closing it.

Parameters
inPointer to the gdIOCtx input context.
infoPointer to the gdAvifInfo structure to populate.
Returns
Returns 1 on success, or 0 on failure.

◆ gdAvifGetInfoPtr()

int gdAvifGetInfoPtr ( int  size,
const void *  data,
gdAvifInfo info 
)

Read AVIF information from memory without taking ownership.

Parameters
sizeSize of the AVIF memory buffer in bytes.
dataPointer to the AVIF memory buffer.
infoPointer to the gdAvifInfo structure to populate.
Returns
Returns 1 on success, or 0 on failure.

◆ gdAvifInfoInit()

void gdAvifInfoInit ( gdAvifInfo info)

Initialize AVIF information and clear the metadata pointer.

Parameters
infoPointer to the gdAvifInfo structure to initialize.

◆ gdAvifWriteOptionsInit()

void gdAvifWriteOptionsInit ( gdAvifWriteOptions options)

Initialize AVIF write options with gd defaults.

Call this before changing selected gdAvifWriteOptions fields and passing the structure to gdImageAvifPtrWithOptions().

Parameters
optionsPointer to the options structure to initialize.

◆ gdImageAvif()

void gdImageAvif ( gdImagePtr  im,
FILE *  outFile 
)

Write a truecolor image as AVIF data to a stdio stream.

gdImageAvif() uses gd's default AVIF quality and speed settings. The image is borrowed for the duration of the call, and outFile is not closed.

Parameters
imThe truecolor image to write.
outFilePointer to the output FILE stream.

◆ gdImageAvifCtx()

void gdImageAvifCtx ( gdImagePtr  im,
gdIOCtxPtr  outfile,
int  quality,
int  speed 
)

Write a truecolor image as AVIF data to an IO context.

gdImageAvifCtx() writes im with explicit quality and speed settings. Quality values range from 0 to 100, with higher values improving quality and 100 requesting lossless output; -1 selects the default. Speed is passed to the AVIF encoder and clamped to its supported range. The image is borrowed for the duration of the call, and outfile is not closed.

Parameters
imThe truecolor image to write.
outfileThe output IO context.
qualityCompression quality from 0 to 100, or -1 for the default.
speedEncoder speed; lower values are slower and may improve compression.

◆ gdImageAvifEx()

void gdImageAvifEx ( gdImagePtr  im,
FILE *  outFile,
int  quality,
int  speed 
)

Write a truecolor image as AVIF data to a stdio stream.

gdImageAvifEx() writes im with explicit quality and speed settings. Quality values range from 0 to 100, with higher values improving quality and 100 requesting lossless output; -1 selects the default. Speed is passed to the AVIF encoder and clamped to its supported range. The image is borrowed for the duration of the call, and outFile is not closed.

Parameters
imThe truecolor image to write.
outFilePointer to the output FILE stream.
qualityCompression quality from 0 to 100, or -1 for the default.
speedEncoder speed; lower values are slower and may improve compression.

◆ gdImageAvifPtr()

void * gdImageAvifPtr ( gdImagePtr  im,
int *  size 
)

Encode a truecolor image as AVIF data in memory.

gdImageAvifPtr() uses gd's default AVIF quality and speed settings. The image is borrowed for the duration of the call. On success, the returned buffer is owned by the caller and must be freed with gdFree().

Parameters
imThe truecolor image to encode.
sizePointer that receives the encoded buffer size in bytes.
Returns
A newly allocated AVIF data buffer, or NULL on error.

◆ gdImageAvifPtrEx()

void * gdImageAvifPtrEx ( gdImagePtr  im,
int *  size,
int  quality,
int  speed 
)

Encode a truecolor image as AVIF data in memory.

gdImageAvifPtrEx() writes im with explicit quality and speed settings. Quality values range from 0 to 100, with higher values improving quality and 100 requesting lossless output; -1 selects the default. Speed is passed to the AVIF encoder and clamped to its supported range. The image is borrowed for the duration of the call. On success, the returned buffer is owned by the caller and must be freed with gdFree().

Parameters
imThe truecolor image to encode.
sizePointer that receives the encoded buffer size in bytes.
qualityCompression quality from 0 to 100, or -1 for the default.
speedEncoder speed; lower values are slower and may improve compression.
Returns
A newly allocated AVIF data buffer, or NULL on error.

◆ gdImageAvifPtrWithOptions()

void * gdImageAvifPtrWithOptions ( gdImagePtr  im,
int *  size,
const gdAvifWriteOptions options 
)

Encode a truecolor image as AVIF data in memory using write options.

gdImageAvifPtrWithOptions() borrows im and options for the duration of the call. Pass NULL for options to use gd defaults. On success, the returned buffer is owned by the caller and must be freed with gdFree().

Parameters
imThe truecolor image to encode.
sizePointer that receives the encoded buffer size in bytes.
optionsAVIF encoder options, or NULL for defaults.
Returns
A newly allocated AVIF data buffer, or NULL on error.

◆ gdImageCreateFromAvif()

gdImagePtr gdImageCreateFromAvif ( FILE *  inFile)

Create a truecolor image from AVIF data in a stdio stream.

gdImageCreateFromAvif() does not close inFile. If the AVIF contains an image sequence, only the first image is decoded. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

Parameters
inFilePointer to the input FILE stream.
Returns
A newly allocated truecolor image, or NULL on error.

◆ gdImageCreateFromAvifCtx()

gdImagePtr gdImageCreateFromAvifCtx ( gdIOCtxPtr  infile)

Create a truecolor image from AVIF data in an IO context.

gdImageCreateFromAvifCtx() reads from infile without closing it. If the AVIF contains an image sequence, only the first image is decoded. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

Parameters
infileThe input IO context.
Returns
A newly allocated truecolor image, or NULL on error.

◆ gdImageCreateFromAvifPtr()

gdImagePtr gdImageCreateFromAvifPtr ( int  size,
void *  data 
)

Create a truecolor image from AVIF data in memory.

gdImageCreateFromAvifPtr() reads size bytes from data without taking ownership of the buffer. If the AVIF contains an image sequence, only the first image is decoded. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

Parameters
sizeSize of data in bytes.
dataPointer to the AVIF data.
Returns
A newly allocated truecolor image, or NULL on error.