app.pixelColor

This app property contains a set of function to handle the color for Image pixels at the lowest level: an unsigned integer.

On Aseprite there are two kind of ways to handle colors:

  1. The Color object type (a high-level/abstract/user-friendly way to handle color)
  2. Or an unsigned integer (low-level/performance-wise) value which can represent several kind of colors:
    • For RGB images: a 32-bit unsigned integer value (8-bit for each of the four RGBA component)
    • Gray images: a 16-bit unsigned integer with Alpha and Grayscale value (8-bit for Alpha, 8-bit for Gray)
    • Indexed images: 8-bit unsigned integer which represents a value from 0 to 255 to reference a palette entry

For performance reasons, pixel values on images are handled with the second kind of colors: an unsigned integer value. This color format is used when you handle pixels directly with functions like Image:getPixel(), Image:putPixel(), or Image:pixels().

app.pixelColor.rgba()

local rgbaPixelValue = app.pixelColor.rgba(red, green, blue, [, alpha])

Constructs a 32-bit unsigned integer for RGBA images. Alpha will be 255 (i.e. 100% opaque) if it's not specified.

Example:

local pc = app.pixelColor
local redPixel = pc.rgba(255, 0, 0)
local semiTransparentWhite = pc.rgba(255, 255, 255, 128)

app.pixelColor.rgbaR()

local redComponent = app.pixelColor.rgbaR(rgbaPixelValue)

Returns the red component of the given 32-bit integer (rgbaPixelValue). This integer is a value created with app.pixelColor.rgba() or Image:getPixel() from a RGBA image.

Note: RGB components are not premultiplied by alpha.

Example:

local pc = app.pixelColor
local rgbaPixelValue = pc.rgba(255, 128, 0)
local redComponent = pc.rgbaR(rgbaPixelValue)
local greenComponent = pc.rgbaG(rgbaPixelValue)
-- redComponent is 255
-- greenComponent is 128

app.pixelColor.rgbaG()

Same as rgbaR() but with the Green component.

app.pixelColor.rgbaB()

Same as rgbaR() but with the Blue component.

app.pixelColor.rgbaA()

Same as rgbaR() but with the Alpha component.

app.pixelColor.graya()

local grayPixelValue = app.pixelColor.graya(gray [, alpha])

Constructs a 16-bit unsigned integer for grayscale images. Alpha will be 255 (i.e. 100% opaque) if it's not specified.

Example:

local pc = app.pixelColor
local black = pc.graya(0)
local white = pc.graya(255)
local semiTransparentWhite = pc.graya(255, 128)

app.pixelColor.grayaV()

local grayValue = app.pixelColor.grayaV(grayPixelValue)

Returns the gray component of the given 16-bit integer (grayPixelValue). This integer is a value created with app.pixelColor.graya() or Image:getPixel() from a grayscale image.

Example:

local pc = app.pixelColor
local grayPixelValue = pc.graya(128, 32)
local grayComponent = pc.grayaV(grayPixelValue)
local alphaComponent = pc.grayaA(grayPixelValue)
-- grayComponent is 128
-- alphaComponent is 32

app.pixelColor.grayaA()

Same as grayaV() but with the Alpha component.