Image Processing¶
This page describes the image processing features supported by Kirikiri Z.
Overview¶
Image processing in Kirikiri Z uses a CPU-side 32bpp BGRA bitmap (tTVPBaseBitmap) as the compositing surface. Pixel operations such as blending (compositing operations) and resampling (scaling and rotation) are accelerated with SIMD implementations (SSE2 / AVX2 / NEON), and a C reference implementation (tvpgl.c) is provided for environments where SIMD is not available.
There is also a GPU drawing path based on the OpenGL ES Canvas / Texture classes, which performs texture compositing and shader-based drawing on the GPU.
Contents¶
Readable and writable image formats
Specifications¶
| Compositing operations |
Opaque | Multiplicative | Photoshop-compatible Linear Dodge (additive) |
Photoshop-compatible Hard Light |
Photoshop-compatible Lighten |
| Compositing operations |
Alpha | Dodge | Photoshop-compatible Linear Burn (subtractive) |
Photoshop-compatible Soft Light |
Photoshop-compatible Darken |
| Compositing operations |
Additive alpha | Lighten | Photoshop-compatible Multiply |
Photoshop-compatible Color Dodge |
Photoshop-compatible Difference |
| Compositing operations |
Additive | Darken | Photoshop-compatible Screen |
Photoshop 5.x and earlier compatible Color Dodge |
Photoshop 5.x and earlier compatible Difference |
| Compositing operations |
Subtractive | Screen | Photoshop-compatible Overlay |
Photoshop-compatible Color Burn |
Photoshop-compatible Exclusion |
Readable and writable image formats¶
The following image formats can be both read and written out of the box.
| Format | Extension | Notes |
|---|---|---|
| BMP | .bmp | The standard Windows bitmap format. A 32bpp BMP is treated as having an alpha channel. |
| JPEG | .jpg / .jpeg | Decoded and encoded with libjpeg-turbo. |
| PNG | .png | Decoded and encoded with libpng. Supports alpha channels. |
| TLG5 / TLG6 | .tlg | Kirikiri's own lossless compression format. TLG5 is designed for fast decoding, TLG6 for a high compression ratio. |
The main/mask split format is also supported, in which the color image (main) and the alpha channel (mask) are stored separately. The mask image's file name is the main image's file name with _m appended (for example, abc_m.jpg for abc.jpg). The main and mask images may use different formats.
Plugins can add support for more image formats.
Compositing operations¶
The table below lists the layer compositing operations (layer types). In the formulas, result is the result, dest is the luminance of the destination, src is the luminance of the image being composited, and α is the per-pixel alpha value; all values range from 0.0 to 1.0. blend(a, b, r) means a × (1.0 - r) + b × r.
| No. | Type | Formula | Description |
|---|---|---|---|
| 1 | Opaque | result = src | Composites without referring to the alpha channel. |
| 2 | Alpha | result = blend(dest, src, α) | Performs alpha compositing. This is the most basic type for transparency. |
| 3 | Additive alpha | result = min(1.0, dest × ( 1.0 - α ) + src) | Performs additive alpha compositing. |
| 4 | Additive | result = min(1.0, dest + src) | Performs additive compositing. Well suited to glow effects. Equivalent to Photoshop's "Linear Dodge" (see 11), except that alpha is ignored in this operation. The neutral color (the color that causes no change when composited) is black. |
| 5 | Subtractive | result = max(0.0, dest + src - 1.0) * The only difference from result = dest - src is whether src is inverted. |
Performs subtractive compositing. α is ignored. The neutral color is white. |
| 6 | Multiplicative | result = dest × src | Performs multiplicative compositing. α is ignored. The neutral color is white. |
| 7 | Dodge | result = min(1.0, dest ÷ ( 1.0 - src ) ) | Performs dodge compositing. Well suited to depicting objects lit by light. α is ignored. The neutral color is black. |
| 8 | Lighten | result = max(dest, src) | Performs "Lighten" compositing. α is ignored. The neutral color is black. |
| 9 | Darken | result = min(dest, src) | Performs "Darken" compositing. α is ignored. The neutral color is white. |
| 10 | Screen | result = 1.0 - ( 1.0 - dest ) × ( 1.0 - src ) | Performs "Screen" compositing. α is ignored. The neutral color is black. |
| 11 | Photoshop-compatible Linear Dodge (additive) |
result = blend(dest, min(1.0, dest + src), α) | Performs Photoshop-compatible "Linear Dodge" (additive) compositing. Unlike 4 (Additive), α is not ignored. The neutral color is black. |
| 12 | Photoshop-compatible Linear Burn (subtractive) |
result = blend(dest, max(0.0, dest + src - 1.0), α) | Performs Photoshop-compatible "Linear Burn" (subtractive) compositing. Unlike 5 (Subtractive), α is not ignored. The neutral color is white. |
| 13 | Photoshop-compatible Multiply |
result = blend(dest, dest × src, α) | Performs Photoshop-compatible "Multiply" compositing. Unlike 6 (Multiplicative), α is not ignored. The neutral color is white. |
| 14 | Photoshop-compatible Screen |
result = blend(dest, 1.0 - (1.0 - dest) × (1.0 - src), α) | Performs Photoshop-compatible "Screen" compositing. Unlike 10 (Screen), α is not ignored. The neutral color is black. |
| 15 | Photoshop-compatible Overlay |
result = blend(dest, overlay(dest, src), α) where overlay(a, b) = a × b × 2.0 (if a < 0.5) 1.0 - (1.0 - a) × (1.0 - b) × 2.0 (otherwise) |
Performs Photoshop-compatible "Overlay" compositing. The neutral color is 50% gray. |
| 16 | Photoshop-compatible Hard Light |
result = blend(dest, hardlight(dest, src), α) where hardlight(a, b) = a × b × 2.0 (if b < 0.5) 1.0 - (1.0 - a) × (1.0 - b) × 2.0 (otherwise) |
Performs Photoshop-compatible "Hard Light" compositing. The neutral color is 50% gray. |
| 17 | Photoshop-compatible Soft Light |
result = blend(dest, softlight(dest, src), α) where softlight(a, b) = a0.5 ÷ b (when b ≥ 0.5) a2.0 × (1.0 - b) (otherwise) |
Performs Photoshop-compatible "Soft Light" compositing. The neutral color is 50% gray. |
| 18 | Photoshop-compatible Color Dodge |
result = blend(dest, min(1.0, dest ÷ ( 1.0 - src ) ), α) | Performs Photoshop-compatible "Color Dodge" compositing. Unlike ltDodge, α is not ignored. The neutral color is black. |
| 19 | Photoshop 5.x and earlier compatible Color Dodge |
result = min(1.0, dest ÷ ( 1.0 - src × α) ) | Performs "Color Dodge" compositing compatible with Photoshop 5.x and earlier. The formula differs slightly from 18 (Photoshop-compatible Color Dodge). The neutral color is black. |
| 20 | Photoshop-compatible Color Burn |
result = blend(dest, max(0.0, 1.0 - (1.0 - dest) ÷ src), α) | Performs Photoshop-compatible "Color Burn" compositing. The neutral color is white. |
| 21 | Photoshop-compatible Lighten |
result = blend(dest, max(dest, src), α) | Performs Photoshop-compatible "Lighten" compositing. Unlike 8 (Lighten), α is not ignored. The neutral color is black. |
| 22 | Photoshop-compatible Darken |
result = blend(dest, min(dest, src), α) | Performs Photoshop-compatible "Darken" compositing. Unlike 9 (Darken), α is not ignored. The neutral color is white. |
| 23 | Photoshop-compatible Difference |
result = blend(dest, abs(dest - src), α) | Performs Photoshop-compatible "Difference" compositing. The neutral color is black. |
| 24 | Photoshop 5.x and earlier compatible Difference |
result = abs(dest - src × α) | Performs "Difference" compositing compatible with Photoshop 5.x and earlier. The formula differs slightly from 23 (Photoshop-compatible Difference). The neutral color is black. |
| 25 | Photoshop-compatible Exclusion |
result = blend(dest, dest + src - 2.0 × src × dest, α) | Performs Photoshop-compatible "Exclusion" compositing. The neutral color is black. |