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

ase
min(a: Int, b: Int): Int

Returns the minimum of two integers.

Name Type Description
a Int First value
b Int Second value
Returns Description
Int The smaller value

ase
max(a: Int, b: Int): Int
Name Type
a Int
b Int
Returns
Int

ase
abs(v: Int): Int
Name Type
v Int
Returns
Int

ase
half(v: Int): Int
Name Type
v Int
Returns
Int

ase
div(a: Int, b: Int): Int
Name Type
a Int
b Int
Returns
Int

ase
blendMultiply(b: Int, s: Int, t: Int): Int

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)

ase
blendScreen(b: Int, s: Int, t: Int): Int

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)

ase
blendOverlay(b: Int, s: Int, t: Int): Int
Name Type
b Int
s Int
t Int
Returns
Int

ase
blendDarken(b: Int, s: Int): Int
Name Type
b Int
s Int
Returns
Int

ase
blendLighten(b: Int, s: Int): Int
Name Type
b Int
s Int
Returns
Int

ase
blendHardLight(b: Int, s: Int, t: Int): Int
Name Type
b Int
s Int
t Int
Returns
Int

ase
blendDifference(b: Int, s: Int): Int
Name Type
b Int
s Int
Returns
Int

ase
blendExclusion(b: Int, s: Int, t: Int): Int
Name Type
b Int
s Int
t Int
Returns
Int

ase
blendColorDodge(b: Int, s: Int): Int

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)

ase
blendColorBurn(b: Int, s: Int): Int
Name Type
b Int
s Int
Returns
Int

ase
blendSoftLight(_b: Int, _s: Int): Int

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)

ase
blendDivide(b: Int, s: Int): Int
Name Type
b Int
s Int
Returns
Int

ase
rgba(r: Int, g: Int, b: Int, a: Int): AlphaColor

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)
Returns Description
AlphaColor ARGB color value

ase
rgbaLuma(c: AlphaColor): Int

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)

ase
rgbLuma(r: Int, g: Int, b: Int): Int

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)

ase
rgbaBlenderSrc(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor

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

ase
rgbaBlenderMerge(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor

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)
Returns Description
AlphaColor The merged color

ase
rgbaBlenderNegBw(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderRedTint(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderBlueTint(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderNormal(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor

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

ase
rgbaBlenderNormalDstOver(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderMultiply(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor

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)
Returns Description
AlphaColor The blended color

ase
rgbaBlenderScreen(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderOverlay(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderDarken(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderLighten(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderColorDodge(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderColorBurn(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderHardLight(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderSoftLight(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderDifference(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderExclusion(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
lum(r: Float, g: Float, b: Float): Float

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)

ase
sat(r: Float, g: Float, b: Float): Float

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)

ase
clipColor(): Void

ase
setLum(l: Float): Void
Name Type
l Float

ase
rgbaBlenderHslHue(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor

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)
Returns Description
AlphaColor The blended color

ase
rgbaBlenderHslSaturation(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderHslColor(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderHslLuminosity(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderAddition(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor

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)
Returns Description
AlphaColor The blended color

ase
rgbaBlenderSubtract(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

ase
rgbaBlenderDivide(backdrop: AlphaColor, src: AlphaColor, opacity: Int): AlphaColor
Name Type
backdrop AlphaColor
src AlphaColor
opacity Int
Returns
AlphaColor

Private Members

ase
A_MASK: Int

Bit mask for extracting alpha channel from ARGB color.


ase
RGB_MASK: Int

Bit mask for extracting RGB channels from ARGB color.


ase
A_SHIFT: Int

Bit shift amount for alpha channel in ARGB format.


ase
mul_un8_0(a: Int, b: Int, t: Int): Int

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

ase
mul_un8_1(t: Int): Int

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)

ase
div_un8(a: Int, b: Int): Int
Name Type
a Int
b Int
Returns
Int

ase
setSat(s: Float): Void
Name Type
s Float