compress_rgba8

Function compress_rgba8 

Source
pub fn compress_rgba8(
    variation: CompressionVariant,
    rgba_data: &[u8],
    blocks_buffer: &mut [u8],
    width: u32,
    height: u32,
    stride: u32,
)
Expand description

Compresses raw RGBA8 data into using a texture block compression format.

It supports BC1 through BC7 compression formats and provides CPU-based texture compression for RGBA8 data.

§Data Layout Requirements

The input data must be in RGBA8 format (8 bits per channel, 32 bits per pixel). The data is expected to be in row-major order, with optional stride for padding between rows.

§Buffer Requirements

The destination buffer must have sufficient capacity to store the compressed blocks. The required size can be calculated using CompressionVariant::blocks_byte_size().

For example:

let required_size = variant.blocks_byte_size(width, height);
assert!(blocks_buffer.len() >= required_size);

§Arguments

  • variation - The block compression format to use
  • rgba_data - Source RGBA8 pixel data
  • blocks_buffer - Destination buffer for the compressed blocks
  • width - Width of the image in pixels
  • height - Height of the image in pixels
  • stride - Number of bytes per row in the source data (for padding). Must be width * 4 for tightly packed RGBA data.

§Panics

  • If width or height is not a multiple of 4
  • If the destination blocks_buffer is too small to hold the compressed data

§Example

use block_compression::{encode::compress_rgba8, CompressionVariant};

let rgba_data = vec![0u8; 256 * 256 * 4]; // Your RGBA data
let width = 256;
let height = 256;
let stride = width * 4; // Tightly packed rows
let variant = CompressionVariant::BC1;

let mut blocks_buffer = vec![0u8; variant.blocks_byte_size(width, height)];

compress_rgba8(
    variant,
    &rgba_data,
    &mut blocks_buffer,
    width,
    height,
    stride,
);