aseprite/api

How to cache current PixelFormat values?

Dylmm opened this issue · 1 comments

Dylmm commented

Is there currently a way to save the PixelFormat values?
I'm using some extension scripts that only work in certain color modes.
A quick patch I use is to ChangePixelFormat in the scripts to change to the right color mode.
I'm looking for a way to re-correct it back to the previous color mode after it's finished.

Hi @Dylmm,

I use a helper function like this to make conversions easier:

local function changePixelFormat(format)
    if format == ColorMode.INDEXED then
        app.command.ChangePixelFormat { format = "indexed" }
    elseif format == ColorMode.GRAY then
        app.command.ChangePixelFormat { format = "gray" }
    elseif format == ColorMode.RGB then
        app.command.ChangePixelFormat { format = "rgb" }
    end
end

local oldMode = app.activeSprite.colorMode
changePixelFormat(ColorMode.RGB)
-- Do RGB mode work here.
changePixelFormat(oldMode)

A sprite has a colorMode property. The constants are documented here.

(Since you're using the app.command, I'm assuming you're interested in Sprites. It's a bit different for Images.)