Learn R Programming

wal (version 0.1.0)

img.to.wal: Convert image to WAL instance.

Description

Convert an input RGB image to a WAL instance, re-mapping its colors to the WAL palette in the process and generating the mipmaps.

Usage

img.to.wal(in_image, apply_palette = wal::pal_q2(), wal = wal.template())

Value

wal instance

Arguments

in_image

numeric matrix with 3 dimensions: widt, height, channels. Values must be in range 0..1. This is the image format returned by jpeg::readJPEG and png::readPNG. The image can have arbitrary colors, but the colors in the final WAL image will be limited to the palette. Both the width and height must be multiples of 8. Typical idtech1/2 textures use 32, 64, ..., 512. The reason is the mipmaps.

apply_palette

n x 3 integer matrix, the palette for the WAL image. This is not saved to the wal image, but still required because the colors from the in_image will be adapted to the palette colors (replaced with the most similar ones). If the palette does not cover the colors in the source image well, the resulting WAL image will look bad (dissimilar to the source image).

wal

a wal instance. Note that 1 will be substracted from the data when it is written, as indices are stored 0-based in the file.

Examples

Run this code
if (FALSE) {
   wal = img.to.wal(jpeg::readJPEG("~/mytex.jpg"));
}

Run the code above in your browser using DataLab