AsepriteBlendFuncs
ceramic.AsepriteBlendFuncs (Class)
Blending functions that operate at pixel/color level, ported from Aseprite source code.
This class provides a comprehensive set of blend modes compatible with Aseprite files,
implementing standard compositing operations like multiply, screen, overlay, and more
advanced modes like color dodge, soft light, and HSL-based blending.
All blending operations work with RGBA colors and support opacity/transparency.
The implementations are optimized for performance with inline functions and
platform-specific optimizations.
References:
- W3C Compositing and Blending Level 1: http://dev.w3.org/fxtf/compositing-1/
- Aseprite source: https://github.com/aseprite/aseprite
See: AsepriteData for usage in Aseprite file rendering
Static Members
Returns the minimum of two integers.
Name |
Type |
Description |
a |
Int |
First value |
b |
Int |
Second value |
Returns |
Description |
Int |
The smaller value |
Multiply blend mode: Darkens by multiplying colors.
Result = backdrop * source
Name |
Type |
Description |
b |
Int |
Backdrop (base) color component (0-255) |
s |
Int |
Source color component (0-255) |
t |
Int |
Temporary variable for optimization |
Returns |
Description |
Int |
Blended color component (0-255) |
Screen blend mode: Lightens by inverting, multiplying, and inverting again.
Result = 1 - (1-backdrop) * (1-source)
Name |
Type |
Description |
b |
Int |
Backdrop color component (0-255) |
s |
Int |
Source color component (0-255) |
t |
Int |
Temporary variable for optimization |
Returns |
Description |
Int |
Blended color component (0-255) |
Color dodge blend mode: Brightens the backdrop to reflect the source.
Result = backdrop / (1 - source)
Name |
Type |
Description |
b |
Int |
Backdrop color component (0-255) |
s |
Int |
Source color component (0-255) |
Returns |
Description |
Int |
Blended color component (0-255) |
Soft light blend mode: Similar to overlay but softer.
Uses a complex formula that creates a subtle lighting effect.
Name |
Type |
Description |
_b |
Int |
Backdrop color component (0-255) |
_s |
Int |
Source color component (0-255) |
Returns |
Description |
Int |
Blended color component (0-255) |
Creates an AlphaColor from RGBA components.
Name |
Type |
Description |
r |
Int |
Red component (0-255) |
g |
Int |
Green component (0-255) |
b |
Int |
Blue component (0-255) |
a |
Int |
Alpha component (0-255) |
Calculates the luminance of an ARGB color.
Uses standard luminance weights for RGB components.
Name |
Type |
Description |
c |
AlphaColor |
The color to analyze |
Returns |
Description |
Int |
Luminance value (0-255) |
Calculates luminance from RGB components.
Uses ITU-R BT.709 luma coefficients.
Name |
Type |
Description |
r |
Int |
Red component (0-255) |
g |
Int |
Green component (0-255) |
b |
Int |
Blue component (0-255) |
Returns |
Description |
Int |
Luminance value (0-255) |
Source blend mode: Replaces backdrop with source.
Name |
Type |
Description |
backdrop |
AlphaColor |
The base color |
src |
AlphaColor |
The source color |
opacity |
Int |
Blend opacity (0-255) |
Returns |
Description |
AlphaColor |
The source color unchanged |
Merge blend mode: Blends colors based on opacity.
Similar to normal blend but with different alpha handling.
Name |
Type |
Description |
backdrop |
AlphaColor |
The base color |
src |
AlphaColor |
The source color |
opacity |
Int |
Blend opacity (0-255) |
Normal blend mode: Standard alpha compositing.
This is the most common blend mode, implementing Porter-Duff "over" operator.
Name |
Type |
Description |
backdrop |
AlphaColor |
The base color |
src |
AlphaColor |
The source color |
opacity |
Int |
Blend opacity (0-255) |
Returns |
Description |
AlphaColor |
The composited color |
Multiply blend mode for RGBA colors.
Darkens the image by multiplying color values.
Name |
Type |
Description |
backdrop |
AlphaColor |
The base color |
src |
AlphaColor |
The source color |
opacity |
Int |
Blend opacity (0-255) |
Calculates luminance using different weights than rgbLuma.
Uses NTSC/PAL weights for backward compatibility.
Name |
Type |
Description |
r |
Float |
Red component (0-1) |
g |
Float |
Green component (0-1) |
b |
Float |
Blue component (0-1) |
Returns |
Description |
Float |
Luminance value (0-1) |
Calculates color saturation.
Name |
Type |
Description |
r |
Float |
Red component (0-1) |
g |
Float |
Green component (0-1) |
b |
Float |
Blue component (0-1) |
Returns |
Description |
Float |
Saturation value (0-1) |
HSL Hue blend mode: Uses hue from source, saturation and luminosity from backdrop.
Name |
Type |
Description |
backdrop |
AlphaColor |
The base color |
src |
AlphaColor |
The source color |
opacity |
Int |
Blend opacity (0-255) |
Addition blend mode: Adds color values together.
Results are clamped to prevent overflow.
Name |
Type |
Description |
backdrop |
AlphaColor |
The base color |
src |
AlphaColor |
The source color |
opacity |
Int |
Blend opacity (0-255) |
Private Members
Bit mask for extracting alpha channel from ARGB color.
Bit mask for extracting RGB channels from ARGB color.
Bit shift amount for alpha channel in ARGB format.
Optimized 8-bit multiplication (part 1).
Multiplies two 8-bit values with rounding.
Name |
Type |
Description |
a |
Int |
First value (0-255) |
b |
Int |
Second value (0-255) |
t |
Int |
Temporary storage |
Returns |
Description |
Int |
Intermediate result |
Optimized 8-bit multiplication (part 2).
Completes the multiplication with proper rounding.
Name |
Type |
Description |
t |
Int |
Intermediate result from mul_un8_0 |
Returns |
Description |
Int |
Final multiplied value (0-255) |