|
wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
|
The palettized codec. More...
#include <wowlib/formats/blp/codec.hpp>
Public Member Functions | |
| PaletteCodec (std::uint8_t alphaDepth) noexcept | |
| std::size_t | encodedSize (std::uint32_t width, std::uint32_t height) const noexcept |
| The exact payload size of a level: one index byte per pixel plus the packed alpha plane. | |
| Result< std::vector< std::uint8_t > > | decode (std::span< const std::byte > src, std::span< const CImVector, BlpPaletteSize > palette, std::uint32_t width, std::uint32_t height) const |
| Decode one level's index + alpha-plane payload to RGBA8 pixels. | |
| Result< FileBuffer > | encode (std::span< const std::uint8_t > rgba, std::span< const CImVector, BlpPaletteSize > palette, std::uint32_t width, std::uint32_t height) const |
| Encode RGBA8 pixels against an existing palette: nearest-entry indices plus the packed alpha plane, exactly encodedSize() bytes. | |
| std::array< CImVector, BlpPaletteSize > | buildPalette (std::span< const std::uint8_t > rgba) const |
| Build a 256-entry palette for an image (median-cut over the opaque RGB values; an image with <= 256 distinct colors gets them verbatim). | |
Protected Member Functions | |
| std::uint8_t | _unpackAlpha (std::span< const std::byte > plane, std::size_t index) const noexcept |
| The alpha value of texel index unpacked from the plane at this codec's bit depth (255 when the depth is 0). | |
| void | _packAlpha (std::uint8_t alpha, std::span< std::byte > plane, std::size_t index) const noexcept |
| Pack one texel's alpha into the plane at this codec's bit depth. | |
Static Protected Member Functions | |
| static std::uint8_t | _nearestIndex (std::span< const CImVector, BlpPaletteSize > palette, std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept |
| The palette entry nearest to (r, g, b) by squared RGB distance. | |
The palettized codec.
Constructed with the alpha-plane bit depth (its state — 0, 1, 4 or 8 bits per pixel); decode() looks indices up in the 256-entry BGRX palette and unpacks the trailing alpha plane, encode() maps pixels to nearest palette entries and packs the plane. Palette construction (median-cut quantization) is its own verb so one palette serves every mip level.
|
inlineexplicitnoexcept |
|
staticprotectednoexcept |
The palette entry nearest to (r, g, b) by squared RGB distance.
| palette | the color table. |
| r | the red value. |
| g | the green value. |
| b | the blue value. |
Definition at line 358 of file blp.cpp.
References wowlib::formats::blp::BlpPaletteSize.
Referenced by encode().
|
protectednoexcept |
|
protectednoexcept |
|
nodiscard |
Build a 256-entry palette for an image (median-cut over the opaque RGB values; an image with <= 256 distinct colors gets them verbatim).
| rgba | the level-0 RGBA bytes. |
Definition at line 419 of file blp.cpp.
References wowlib::formats::blp::BlpPaletteSize.
Referenced by wowlib::formats::blp::BLP::encode().
|
nodiscard |
Decode one level's index + alpha-plane payload to RGBA8 pixels.
| src | the on-disk payload bytes; short payloads decode their missing texels transparent black. |
| palette | the file's 256-entry color table. |
| width | the level width in pixels. |
| height | the level height in pixels. |
Definition at line 377 of file blp.cpp.
References _unpackAlpha(), wowlib::formats::common::CImVector::b, wowlib::formats::common::CImVector::g, and wowlib::formats::common::CImVector::r.
Referenced by wowlib::formats::blp::BLP::decode().
|
nodiscard |
Encode RGBA8 pixels against an existing palette: nearest-entry indices plus the packed alpha plane, exactly encodedSize() bytes.
| rgba | width * height * 4 RGBA bytes. |
| palette | the color table to index into. |
| width | the level width in pixels. |
| height | the level height in pixels. |
Definition at line 395 of file blp.cpp.
References _nearestIndex(), _packAlpha(), and encodedSize().
Referenced by wowlib::formats::blp::BLP::encode().
|
inlinenodiscardnoexcept |