wowlib 0.0.0
Read & write World of Warcraft client files — a C++26 core
Loading...
Searching...
No Matches
wowlib::formats::blp::detail::DxtCodec Class Reference

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).

Detailed Description

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.

Definition at line 40 of file codec.hpp.

Constructor & Destructor Documentation

◆ DxtCodec()

wowlib::formats::blp::detail::DxtCodec::DxtCodec ( PixelFormat format)
inlineexplicitnoexcept
Parameters
formatthe resolved block format (Dxt1, Dxt3, Dxt5 or Bc5).

Definition at line 43 of file codec.hpp.

Member Function Documentation

◆ _decodeColorBlock()

void wowlib::formats::blp::detail::DxtCodec::_decodeColorBlock ( const std::uint8_t * block,
BlockPixels & out,
bool punchThrough )
staticprotectednoexcept

Decode one BC1 color block (8 bytes) into 16 RGBA pixels.

Parameters
blockthe 8 color-block bytes.
outthe 16 decoded pixels.
punchThroughwhether 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().

◆ _decodeExplicitAlpha()

void wowlib::formats::blp::detail::DxtCodec::_decodeExplicitAlpha ( const std::uint8_t * block,
BlockPixels & out )
staticprotectednoexcept

Decode one BC2 explicit-alpha block (8 bytes, 4 bits per texel) onto the alpha channel of out.

Parameters
blockthe 8 alpha bytes.
outthe 16 pixels to stamp alpha into.

Definition at line 96 of file blp.cpp.

Referenced by decode().

◆ _decodeInterpolatedAlpha()

void wowlib::formats::blp::detail::DxtCodec::_decodeInterpolatedAlpha ( const std::uint8_t * block,
std::span< std::uint8_t, 16 > out )
staticprotectednoexcept

Decode one BC3/BC4 interpolated-alpha block (8 bytes) into 16 values.

Parameters
blockthe 8 alpha-block bytes.
outthe 16 decoded 8-bit values, row-major.

Definition at line 103 of file blp.cpp.

Referenced by decode().

◆ _encodePunchThroughBlock()

void wowlib::formats::blp::detail::DxtCodec::_encodePunchThroughBlock ( const BlockPixels & pixels,
std::uint8_t * dest )
staticprotectednoexcept

Encode one BC1 punch-through block (color0 <= color1 3-color mode, alpha < 128 texels as index 3) — the mode stb_dxt does not emit.

Parameters
pixelsthe 16 RGBA texels.
destthe 8 output bytes.

Definition at line 139 of file blp.cpp.

Referenced by encode().

◆ _extractBlock()

BlockPixels wowlib::formats::blp::detail::DxtCodec::_extractBlock ( std::span< const std::uint8_t > rgba,
std::uint32_t width,
std::uint32_t height,
std::uint32_t bx,
std::uint32_t by )
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).

Parameters
rgbathe level's RGBA bytes.
widththe level width in pixels.
heightthe level height in pixels.
bxthe block column.
bythe block row.
Returns
the 16 RGBA texels.

Definition at line 122 of file blp.cpp.

Referenced by encode().

◆ blockBytes()

std::size_t wowlib::formats::blp::detail::DxtCodec::blockBytes ( ) const
inlinenodiscardnoexcept

The byte size of one compressed block (8 for BC1, 16 otherwise).

Returns
the block byte size.

Definition at line 48 of file codec.hpp.

References wowlib::formats::blp::Dxt1.

Referenced by decode(), encode(), and encodedSize().

◆ decode()

Result< std::vector< std::uint8_t > > wowlib::formats::blp::detail::DxtCodec::decode ( std::span< const std::byte > src,
std::uint32_t width,
std::uint32_t height ) const
nodiscard

Decode one level's block stream to RGBA8 pixels.

Parameters
srcthe on-disk block bytes; may be shorter than encodedSize() (a known client quirk) — missing blocks decode transparent black.
widththe level width in pixels.
heightthe level height in pixels.
Returns
width * height * 4 RGBA bytes.

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().

◆ encode()

Result< FileBuffer > wowlib::formats::blp::detail::DxtCodec::encode ( std::span< const std::uint8_t > rgba,
std::uint32_t width,
std::uint32_t height ) const
nodiscard

Encode RGBA8 pixels to one level's block stream, exactly encodedSize() bytes.

Parameters
rgbawidth * height * 4 RGBA bytes.
widththe level width in pixels.
heightthe level height in pixels.
Returns
the compressed block bytes.

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().

◆ encodedSize()

std::size_t wowlib::formats::blp::detail::DxtCodec::encodedSize ( std::uint32_t width,
std::uint32_t height ) const
inlinenodiscardnoexcept

The exact payload size of a level per the block formula ceil(w/4) * ceil(h/4) * blockBytes().

Parameters
widththe level width in pixels.
heightthe level height in pixels.
Returns
the encoded byte count.

Definition at line 58 of file codec.hpp.

References blockBytes().

Referenced by wowlib::formats::blp::BLP::validate().


The documentation for this class was generated from the following files: