|
wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
|
The DXT/BC block codec. More...
#include <wowlib/formats/blp/codec.hpp>
Public Member Functions | |
| DxtCodec (PixelFormat format) noexcept | |
| std::size_t | blockBytes () const noexcept |
| The byte size of one compressed block (8 for BC1, 16 otherwise). | |
| std::size_t | encodedSize (std::uint32_t width, std::uint32_t height) const noexcept |
| The exact payload size of a level per the block formula ceil(w/4) * ceil(h/4) * blockBytes(). | |
| Result< std::vector< std::uint8_t > > | decode (std::span< const std::byte > src, std::uint32_t width, std::uint32_t height) const |
| Decode one level's block stream to RGBA8 pixels. | |
| Result< FileBuffer > | encode (std::span< const std::uint8_t > rgba, std::uint32_t width, std::uint32_t height) const |
| Encode RGBA8 pixels to one level's block stream, exactly encodedSize() bytes. | |
Static Protected Member Functions | |
| static void | _decodeColorBlock (const std::uint8_t *block, BlockPixels &out, bool punchThrough) noexcept |
| Decode one BC1 color block (8 bytes) into 16 RGBA pixels. | |
| static void | _decodeExplicitAlpha (const std::uint8_t *block, BlockPixels &out) noexcept |
| Decode one BC2 explicit-alpha block (8 bytes, 4 bits per texel) onto the alpha channel of out. | |
| static void | _decodeInterpolatedAlpha (const std::uint8_t *block, std::span< std::uint8_t, 16 > out) noexcept |
| Decode one BC3/BC4 interpolated-alpha block (8 bytes) into 16 values. | |
| static void | _encodePunchThroughBlock (const BlockPixels &pixels, std::uint8_t *dest) noexcept |
| Encode one BC1 punch-through block (color0 <= color1 3-color mode, alpha < 128 texels as index 3) — the mode stb_dxt does not emit. | |
| static BlockPixels | _extractBlock (std::span< const std::uint8_t > rgba, std::uint32_t width, std::uint32_t height, std::uint32_t bx, std::uint32_t by) noexcept |
| Extract one 4x4 block from a level, clamping reads at the right/bottom edges (partial blocks repeat their last row/column, matching what the compressors expect). | |
The DXT/BC block codec.
Constructed with the resolved block format (its state — Dxt1, Dxt3, Dxt5 or Bc5); decode()/encode() move a whole level between its block stream and RGBA8 pixels. Tolerates the known client quirk of understated mip sizes by decoding short streams into transparent-black padding.
|
inlineexplicitnoexcept |
|
staticprotectednoexcept |
Decode one BC1 color block (8 bytes) into 16 RGBA pixels.
| block | the 8 color-block bytes. |
| out | the 16 decoded pixels. |
| punchThrough | whether the color0 <= color1 3-color mode maps index 3 to transparent black (BC1 semantics; BC2/ BC3 color blocks always decode 4-color). |
Definition at line 60 of file blp.cpp.
Referenced by decode().
|
staticprotectednoexcept |
|
staticprotectednoexcept |
|
staticprotectednoexcept |
|
staticprotectednoexcept |
Extract one 4x4 block from a level, clamping reads at the right/bottom edges (partial blocks repeat their last row/column, matching what the compressors expect).
| rgba | the level's RGBA bytes. |
| width | the level width in pixels. |
| height | the level height in pixels. |
| bx | the block column. |
| by | the block row. |
Definition at line 122 of file blp.cpp.
Referenced by encode().
|
inlinenodiscardnoexcept |
The byte size of one compressed block (8 for BC1, 16 otherwise).
Definition at line 48 of file codec.hpp.
References wowlib::formats::blp::Dxt1.
Referenced by decode(), encode(), and encodedSize().
|
nodiscard |
Decode one level's block stream to RGBA8 pixels.
| src | the on-disk block bytes; may be shorter than encodedSize() (a known client quirk) — missing blocks decode transparent black. |
| width | the level width in pixels. |
| height | the level height in pixels. |
Definition at line 207 of file blp.cpp.
References _decodeColorBlock(), _decodeExplicitAlpha(), _decodeInterpolatedAlpha(), wowlib::formats::blp::Bc5, blockBytes(), wowlib::formats::blp::Dxt1, wowlib::formats::blp::Dxt3, wowlib::formats::blp::Dxt5, wowlib::makeError(), and wowlib::NotSupported.
Referenced by wowlib::formats::blp::BLP::decode().
|
nodiscard |
Encode RGBA8 pixels to one level's block stream, exactly encodedSize() bytes.
| rgba | width * height * 4 RGBA bytes. |
| width | the level width in pixels. |
| height | the level height in pixels. |
Definition at line 264 of file blp.cpp.
References _encodePunchThroughBlock(), _extractBlock(), wowlib::formats::blp::Bc5, blockBytes(), wowlib::formats::blp::Dxt1, wowlib::formats::blp::Dxt3, wowlib::formats::blp::Dxt5, wowlib::makeError(), and wowlib::NotSupported.
Referenced by wowlib::formats::blp::BLP::encode().
|
inlinenodiscardnoexcept |
The exact payload size of a level per the block formula ceil(w/4) * ceil(h/4) * blockBytes().
| width | the level width in pixels. |
| height | the level height in pixels. |
Definition at line 58 of file codec.hpp.
References blockBytes().
Referenced by wowlib::formats::blp::BLP::validate().