Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cache current PixelFormat values? #85

Open
Dylmm opened this issue Aug 14, 2022 · 1 comment
Open

How to cache current PixelFormat values? #85

Dylmm opened this issue Aug 14, 2022 · 1 comment
Labels

Comments

@Dylmm
Copy link

Dylmm commented Aug 14, 2022

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.

@behreajj
Copy link
Contributor

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants