Search guides and the APICtrl K
  1. API reference
  2. Files and codecs

gfx/image_format.h

ImageFileFormat: whatever image a plugin is handed, decoded by what it is rather than by what its name says.

#include <sonore/gfx/image_format.h>
  • 2types
  • 1other declaration
On this page

Design notes

Why sniff

A file's extension is a claim somebody typed. Cover art saved as "art.png" by a tool that wrote a JPEG, a ".jpg" that is a PNG because a web server converted it, a preset's picture with no name at all because it came out of a state blob -- each decodes fine by its first bytes and fails by its name. Every format here starts with a signature that says what it is: PNG's eight bytes, JPEG's FF D8 FF, GIF's "GIF87a" or "GIF89a". So the bytes decide.

The formats it recognises and does NOT decode -- WebP, BMP, TIFF, HEIC, AVIF, ICO -- are named in the error rather than called "not an image". A user told "WebP is not supported" converts the file; one told "unknown format" assumes it is broken.

Types 2

An image of any of the formats ImageFileFormat reads.

Decodes a PNG, JPEG or GIF from bytes or a file, choosing the decoder by the bytes' signature rather than the name -- see the file comment.

Plays the part of the reference's ImageFileFormat, as static functions over PngDecoder, JpegDecoder and GifDecoder: nothing to construct, no state, safe from any thread but not the audio thread (it allocates, and loadFile reads the disk). A failure comes back as a DecodedImage with error set.

Enums 1

↑↓ to move↵ to openEvery public name in the headers, and every guide