Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
Haio::Codecs Namespace Reference

Namespaces

namespace  Tga

Classes

struct  DefaultColor
struct  DefaultColor< Format::GIF >
struct  DefaultColor< Format::JPEG >
struct  DefaultColor< Format::PNG >
struct  DefaultColor< Format::PPM >
struct  DefaultColor< Format::ROM >
struct  DefaultColor< Format::TGA >
struct  DefaultColor< Format::ZCIS >

Concepts

concept  HasDefaultColor
concept  Detectable
concept  Decodable
concept  Encodable
concept  Movable
concept  Convertible

Functions

template<Format F, Color P = DefaultColor<F>::value>
bool Detect (Bytes)=delete
template<Format F, Color P = DefaultColor<F>::value>
Result< Image< P > > Decode (const Blob &)=delete
template<Format F, Color P>
Result< Blob > Encode (Image< P >)=delete
template<Color From, Color To>
Result< void > Move (Bytes src, std::span< uint8_t > dst, Size size)=delete
template<Color From, Color To>
requires Movable<From, To>
Result< Image< To > > convertVia (Image< From > src)
template<>
Result< void > Move< Color::BGR888, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::BGR888, Color::RGBA8888 > (Image< Color::BGR888 > src)
template<>
Result< void > Move< Color::BGRA8888, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::BGRA8888, Color::RGBA8888 > (Image< Color::BGRA8888 > src)
template<>
Result< void > Move< Color::CHR_NES, Color::PALETTE > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::PALETTE > > Convert< Color::CHR_NES, Color::PALETTE > (Image< Color::CHR_NES > src)
template<>
Result< void > Move< Color::ETC1, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::ETC1, Color::RGBA8888 > (Image< Color::ETC1 > src)
template<>
Result< void > Move< Color::GRAY8, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::GRAY8, Color::RGBA8888 > (Image< Color::GRAY8 > src)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::PALETTE, Color::RGBA8888 > (Image< Color::PALETTE > src)
template<>
Result< void > Move< Color::RGB555, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::RGB555, Color::RGBA8888 > (Image< Color::RGB555 > src)
template<>
Result< void > Move< Color::RGB565, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::RGB565, Color::RGBA8888 > (Image< Color::RGB565 > src)
template<>
Result< void > Move< Color::RGB888, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::RGB888, Color::RGBA8888 > (Image< Color::RGB888 > src)
template<>
Result< void > Move< Color::RGBA5551, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::RGBA5551, Color::RGBA8888 > (Image< Color::RGBA5551 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::BGR888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::BGR888 > > Convert< Color::RGBA8888, Color::BGR888 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::BGRA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::BGRA8888 > > Convert< Color::RGBA8888, Color::BGRA8888 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::ETC1 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::ETC1 > > Convert< Color::RGBA8888, Color::ETC1 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::RGB555 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGB555 > > Convert< Color::RGBA8888, Color::RGB555 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::RGB565 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGB565 > > Convert< Color::RGBA8888, Color::RGB565 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::RGB888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGB888 > > Convert< Color::RGBA8888, Color::RGB888 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::RGBA5551 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA5551 > > Convert< Color::RGBA8888, Color::RGBA5551 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::RGBA8888, Color::YUV420 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::YUV420 > > Convert< Color::RGBA8888, Color::YUV420 > (Image< Color::RGBA8888 > src)
template<>
Result< void > Move< Color::YUV420, Color::RGBA8888 > (Bytes src, std::span< uint8_t > dst, Size size)
template<>
Result< Image< Color::RGBA8888 > > Convert< Color::YUV420, Color::RGBA8888 > (Image< Color::YUV420 > src)
template<>
Result< Blob > Encode< Format::ANSI, Color::RGB888 > (Image< Color::RGB888 > img)
template<>
Result< Image< Color::RGB565 > > Decode< Format::DDS, Color::RGB565 > (const Blob &blob)
template<>
Result< Image< Color::RGBA8888 > > Decode< Format::DDS, Color::RGBA8888 > (const Blob &blob)
template<>
bool Detect< Format::DDS, Color::RGB565 > (Bytes data)
template<>
bool Detect< Format::DDS, Color::RGBA8888 > (Bytes data)
template<>
Result< Blob > Encode< Format::DDS, Color::RGB565 > (Image< Color::RGB565 > img)
template<>
Result< Blob > Encode< Format::DDS, Color::RGBA8888 > (Image< Color::RGBA8888 > img)
template<>
Result< Image< Color::RGBA8888 > > Decode< Format::GIF, Color::RGBA8888 > (const Blob &blob)
template<>
Result< Image< Color::RGB888 > > Decode< Format::GIF, Color::RGB888 > (const Blob &blob)
template<>
bool Detect< Format::GIF, Color::RGBA8888 > (Bytes data)
template<>
bool Detect< Format::GIF, Color::RGB888 > (Bytes data)
template<>
Result< Image< Color::YUV420 > > Decode< Format::JPEG, Color::YUV420 > (const Blob &blob)
template<>
bool Detect< Format::JPEG, Color::YUV420 > (Bytes data)
template<>
Result< Blob > Encode< Format::JPEG, Color::YUV420 > (Image< Color::YUV420 > img)
template<>
Result< Image< Color::ETC1 > > Decode< Format::KTX, Color::ETC1 > (const Blob &blob)
template<>
Result< Image< Color::RGB565 > > Decode< Format::KTX, Color::RGB565 > (const Blob &blob)
template<>
Result< Image< Color::RGBA8888 > > Decode< Format::KTX, Color::RGBA8888 > (const Blob &blob)
template<>
bool Detect< Format::KTX, Color::ETC1 > (Bytes data)
template<>
bool Detect< Format::KTX, Color::RGB565 > (Bytes data)
template<>
bool Detect< Format::KTX, Color::RGBA8888 > (Bytes data)
template<>
Result< Blob > Encode< Format::KTX, Color::ETC1 > (Image< Color::ETC1 > img)
template<>
Result< Blob > Encode< Format::KTX, Color::RGB565 > (Image< Color::RGB565 > img)
template<>
Result< Blob > Encode< Format::KTX, Color::RGBA8888 > (Image< Color::RGBA8888 > img)
template<>
Result< Image< Color::ETC1 > > Decode< Format::KTX2, Color::ETC1 > (const Blob &blob)
template<>
Result< Image< Color::RGB565 > > Decode< Format::KTX2, Color::RGB565 > (const Blob &blob)
template<>
Result< Image< Color::RGBA8888 > > Decode< Format::KTX2, Color::RGBA8888 > (const Blob &blob)
template<>
bool Detect< Format::KTX2, Color::ETC1 > (Bytes data)
template<>
bool Detect< Format::KTX2, Color::RGB565 > (Bytes data)
template<>
bool Detect< Format::KTX2, Color::RGBA8888 > (Bytes data)
template<>
Result< Blob > Encode< Format::KTX2, Color::ETC1 > (Image< Color::ETC1 > img)
template<>
Result< Blob > Encode< Format::KTX2, Color::RGB565 > (Image< Color::RGB565 > img)
template<>
Result< Blob > Encode< Format::KTX2, Color::RGBA8888 > (Image< Color::RGBA8888 > img)
template<>
Result< Image< Color::RGBA8888 > > Decode< Format::PNG, Color::RGBA8888 > (const Blob &blob)
template<>
Result< Image< Color::RGB888 > > Decode< Format::PNG, Color::RGB888 > (const Blob &blob)
template<>
bool Detect< Format::PNG, Color::RGBA8888 > (Bytes data)
template<>
bool Detect< Format::PNG, Color::RGB888 > (Bytes data)
template<>
bool Detect< Format::PNG, Color::GRAY8 > (Bytes data)
template<>
Result< Image< Color::RGB888 > > Decode< Format::PPM, Color::RGB888 > (const Blob &blob)
template<>
Result< Image< Color::GRAY8 > > Decode< Format::PPM, Color::GRAY8 > (const Blob &blob)
template<>
bool Detect< Format::PPM, Color::RGB888 > (Bytes data)
template<>
bool Detect< Format::PPM, Color::GRAY8 > (Bytes data)
template<>
Result< Blob > Encode< Format::PPM, Color::RGBA8888 > (Image< Color::RGBA8888 > img)
template<>
Result< Image< Color::ETC1 > > Decode< Format::PVR, Color::ETC1 > (const Blob &blob)
template<>
Result< Image< Color::RGB565 > > Decode< Format::PVR, Color::RGB565 > (const Blob &blob)
template<>
Result< Image< Color::RGBA8888 > > Decode< Format::PVR, Color::RGBA8888 > (const Blob &blob)
template<>
bool Detect< Format::PVR, Color::ETC1 > (Bytes data)
template<>
bool Detect< Format::PVR, Color::RGB565 > (Bytes data)
template<>
bool Detect< Format::PVR, Color::RGBA8888 > (Bytes data)
template<>
Result< Blob > Encode< Format::PVR, Color::ETC1 > (Image< Color::ETC1 > img)
template<>
Result< Blob > Encode< Format::PVR, Color::RGB565 > (Image< Color::RGB565 > img)
template<>
Result< Blob > Encode< Format::PVR, Color::RGBA8888 > (Image< Color::RGBA8888 > img)
template<>
Result< Image< Color::CHR_NES > > Decode< Format::ROM, Color::CHR_NES > (const Blob &blob)
template<>
bool Detect< Format::ROM, Color::CHR_NES > (Bytes data)
template<>
Result< Image< Color::BGRA8888 > > Decode< Format::TGA, Color::BGRA8888 > (const Blob &blob)
template<>
Result< Image< Color::BGR888 > > Decode< Format::TGA, Color::BGR888 > (const Blob &blob)
template<>
Result< Image< Color::RGBA5551 > > Decode< Format::TGA, Color::RGBA5551 > (const Blob &blob)
template<>
Result< Image< Color::RGB555 > > Decode< Format::TGA, Color::RGB555 > (const Blob &blob)
template<>
Result< Image< Color::PALETTE > > Decode< Format::TGA, Color::PALETTE > (const Blob &blob)
template<>
Result< Image< Color::GRAY8 > > Decode< Format::TGA, Color::GRAY8 > (const Blob &blob)
template<>
bool Detect< Format::TGA, Color::BGRA8888 > (Bytes data)
template<>
bool Detect< Format::TGA, Color::BGR888 > (Bytes data)
template<>
bool Detect< Format::TGA, Color::RGBA5551 > (Bytes data)
template<>
bool Detect< Format::TGA, Color::RGB555 > (Bytes data)
template<>
bool Detect< Format::TGA, Color::PALETTE > (Bytes data)
template<>
bool Detect< Format::TGA, Color::GRAY8 > (Bytes data)
template<>
Result< Blob > Encode< Format::TGA, Color::BGRA8888 > (Image< Color::BGRA8888 > img)
template<>
Result< Blob > Encode< Format::TGA, Color::BGR888 > (Image< Color::BGR888 > img)
template<>
Result< Blob > Encode< Format::TGA, Color::RGBA5551 > (Image< Color::RGBA5551 > img)
template<>
Result< Blob > Encode< Format::TGA, Color::RGB555 > (Image< Color::RGB555 > img)
template<>
Result< Blob > Encode< Format::TGA, Color::PALETTE > (Image< Color::PALETTE > img)
template<>
Result< Blob > Encode< Format::TGA, Color::GRAY8 > (Image< Color::GRAY8 > img)
template<>
Result< Blob > Encode< Format::UTF8, Color::RGB888 > (Image< Color::RGB888 > img)
template<>
bool Detect< Format::ZCIS, Color::RGBA8888 > (Bytes data)
template<>
Result< Blob > Encode< Format::ZCIS, Color::RGBA8888 > (Image< Color::RGBA8888 > img)
Convert
template<Color From, Color To>
Result< Image< To > > Convert (Image< From >)=delete
template<>
Result< Blob > Encode< Format::PNG, Color::RGBA8888 > (Image< Color::RGBA8888 > img)

Detailed Description

the verbs. they live apart from the vocabulary above because the runtime facade in haio_registry.hpp offers Decode(const Blob&) and Detect(Bytes) with the very same parameter lists: without a namespace between them, Decode(blob) and Decode<Format::PNG>(blob) read alike and do different things.


Class Documentation

◆ Haio::Codecs::DefaultColor

struct Haio::Codecs::DefaultColor
template<Format F>
struct Haio::Codecs::DefaultColor< F >

the colour a format carries when nobody says otherwise. only formats with a real answer declare it: a ktx2 holds any of three, so Decode<Format::KTX2> alone is a compile error telling the caller to be specific.

Definition at line 143 of file haio_codec.hpp.

Function Documentation

◆ Convert()

template<Color From, Color To>
Result< Image< To > > Haio::Codecs::Convert ( Image< From > )
delete

colour to colour, no file involved. the heavy ones live behind Move

Here is the call graph for this function:

◆ Convert< Color::CHR_NES, Color::PALETTE >()

the indices arrive without colours. what to hang on them is a separate question, answered by whoever asked for the conversion, because a chr file does not carry a palette and never did: the console held it somewhere else entirely.

Definition at line 1 of file palette.cpp.

Here is the call graph for this function:

◆ Convert< Color::PALETTE, Color::RGBA8888 >()

indices become the colours they point at.

this one direction is always possible and never loses anything, which is why it needs no filter while the way back does.

Definition at line 1 of file rgba8888.cpp.

Here is the call graph for this function:

◆ Convert< Color::RGBA8888, Color::YUV420 >()

Definition at line 1 of file yuv420.cpp.

Here is the call graph for this function:

◆ Convert< Color::YUV420, Color::RGBA8888 >()

Definition at line 1 of file rgba8888.cpp.

Here is the call graph for this function:

◆ convertVia()

template<Color From, Color To>
requires Movable<From, To>
Result< Image< To > > Haio::Codecs::convertVia ( Image< From > src)

the shape every Convert specialisation has: check, allocate, hand the work to Move. it lives here so a new colour pair is one Move and one line instead of ten.

Definition at line 21 of file haio_convert.hpp.

Here is the call graph for this function:

◆ Decode()

template<Format F, Color P = DefaultColor<F>::value>
Result< Image< P > > Haio::Codecs::Decode ( const Blob & )
delete
Here is the call graph for this function:

◆ Decode< Format::JPEG, Color::YUV420 >()

straight to yuv planes, which is what the file already holds.

a jpeg is yuv all the way down, so a decoder that hands back rgb has both thrown away the chroma layout and spent the work doing it. asking for the planes means the picture arrives as it was stored, and whoever wants rgb converts once, visibly.

only 4:2:0 is read. it is what cameras and ad creatives produce, and reading 4:4:4 or 4:2:2 into a buffer sized for 4:2:0 would quietly truncate the chroma rather than fail, so those are refused instead.

Definition at line 14 of file decode.cpp.

◆ Decode< Format::ROM, Color::CHR_NES >()

every pattern table in the cartridge, stacked one below another.

the header says where they start: sixteen bytes of it, then a trainer if there is one, then the program itself, and only then the pattern data. picking which bank to look at is left to the caller, because by then it is a crop.

Todo
a cartridge with no chr rom keeps its patterns in ram and builds them as it runs, so there is nothing in the file to show. those are refused rather than drawn as an empty square.

Definition at line 14 of file decode.cpp.

◆ Detect()

template<Format F, Color P = DefaultColor<F>::value>
bool Haio::Codecs::Detect ( Bytes )
delete

deleted on purpose. a codec declares only the pairs it can do, and naming one it left out is ill-formed, which is what lets the concepts below answer for themselves instead of failing at link time. drop a codec from the build and its format stays in the enum, naming itself, with every capability gone.

Here is the call graph for this function:

◆ Encode()

template<Format F, Color P>
Result< Blob > Haio::Codecs::Encode ( Image< P > )
delete
Here is the call graph for this function:

◆ Encode< Format::ANSI, Color::RGB888 >()

one terminal cell per pixel, coloured by its background.

the picture ends up half the height of the utf8 one for the same number of rows, and it works on anything that can colour a background, including terminals with no font to draw a half block with.

Todo
a terminal that cannot do 24 bit colour renders this as noise. detecting that means reading COLORTERM, and falling back means quantising to the 256 colour cube.

Definition at line 12 of file encode.cpp.

◆ Encode< Format::JPEG, Color::YUV420 >()

from yuv planes, which is what a jpeg wants.

anything else converts first, and does so where the caller can see it: an encoder that quietly accepted rgb would hide a colour conversion inside what looks like a container change.

Definition at line 17 of file encode.cpp.

◆ Encode< Format::UTF8, Color::RGB888 >()

two pixel rows per terminal row, using the upper half block.

the foreground paints the top pixel and the background the bottom one, which buys twice the vertical resolution of the ansi rendering for the same number of lines and makes the aspect ratio come out roughly square.

an odd number of rows leaves the last cell with nothing below it, and its background is left black rather than repeating the row above: a doubled last line reads as part of the picture, a dark one reads as the edge.

a terminal keeps the colour it was last told, so saying it again is bytes nobody reads. a picture in few colours repeats itself constantly, and this is exactly the picture somebody renders in a terminal.

the pair is tracked rather than each half, because a cell sets both at once.

Definition at line 12 of file encode.cpp.

◆ Move()

template<Color From, Color To>
Result< void > Haio::Codecs::Move ( Bytes src,
std::span< uint8_t > dst,
Size size )
delete

the hot loop under Convert, and what a codec calls when it wants to write pixels straight into a buffer it already owns. dst is sized by the caller so the simd paths can rely on it, and size is here because block formats like etc1 cannot be transformed pixel by pixel.

it reports rather than assumes: the loop runs once per image, so one Result on the way out costs nothing next to the work inside it.

Here is the call graph for this function:

◆ Move< Color::CHR_NES, Color::PALETTE >()

template<>
Result< void > Haio::Codecs::Move< Color::CHR_NES, Color::PALETTE > ( Bytes src,
std::span< uint8_t > dst,
Size size )

unpacks nes pattern data into one index per byte.

a tile is sixteen bytes: eight rows of the low bit, then eight rows of the high bit. so a pixel's two bits sit eight bytes apart, and the leftmost pixel is the most significant bit rather than the least.

nothing here needs a palette, which is why it fits Move at all: the indices are 0 to 3 whatever colours are eventually hung on them.

Definition at line 1 of file palette.cpp.

◆ Move< Color::RGBA8888, Color::YUV420 >()

template<>
Result< void > Haio::Codecs::Move< Color::RGBA8888, Color::YUV420 > ( Bytes src,
std::span< uint8_t > dst,
Size size )

the way back: full range bt.601 again, and the chroma of a two by two block is the average of its four pixels rather than the top left one.

taking one pixel and calling it the block would be cheaper and is what a naive encoder does; it shows up as ragged colour on edges, because the sample that happened to be first decides for three others.

Definition at line 1 of file yuv420.cpp.

◆ Move< Color::YUV420, Color::RGBA8888 >()

template<>
Result< void > Haio::Codecs::Move< Color::YUV420, Color::RGBA8888 > ( Bytes src,
std::span< uint8_t > dst,
Size size )

jfif colour, which is full range bt.601 and not the studio range video uses. a decoder written against the video coefficients produces a picture that is visibly washed out rather than obviously wrong, which is the sort of mistake that ships.

the two chroma planes are half size in both directions, so each of their samples covers a two by two block of luma.

Definition at line 1 of file rgba8888.cpp.