class

CrImage::WEBP::TransformEncoder

Inherits Reference / Object

TransformEncoder handles WebP lossless transform operations.

Implements the four VP8L transforms that improve compression:

  • Predictor: Predicts pixels from neighbors, encodes differences
  • Color: Correlates color channels
  • Subtract Green: Removes green from red and blue channels
  • Color Indexing (Palette): Reduces to indexed colors

Class methods

apply_color(pixels : Array(CrImage::Color::NRGBA), width : Int32, height : Int32) : Tuple(Int32, Int32, Int32, Array(CrImage::Color::NRGBA))

Applies color transform to pixels.

Decorrelates color channels by subtracting scaled green from red and blue. Improves compression for natural images.

Returns: Tuple of {tile_bits, block_width, block_height, transform_blocks}

Source
apply_palette(pixels : Array(CrImage::Color::NRGBA), width : Int32, height : Int32) : Tuple(Array(CrImage::Color::NRGBA), Int32)

Applies palette transform.

Extracts unique colors as palette, packs pixel indices efficiently (1, 2, 4, or 8 pixels per byte depending on palette size), and applies delta encoding to palette.

Returns: Tuple of {palette, packed_width}

Raises: FormatError if more than 256 unique colors

Source
apply_predictor(pixels : Array(CrImage::Color::NRGBA), width : Int32, height : Int32) : Tuple(Int32, Int32, Int32, Array(CrImage::Color::NRGBA))

Applies predictor transform to pixels.

Divides image into tiles, selects best predictor mode for each tile based on entropy, and encodes pixel differences from predictions.

Returns: Tuple of {tile_bits, block_width, block_height, predictor_blocks}

Source
apply_subtract_green(pixels : Array(CrImage::Color::NRGBA)) : Nil

Applies subtract green transform.

Subtracts green channel from red and blue channels. This simple transform exploits correlation between color channels.

Source

Nested types