Last active
January 10, 2021 14:59
-
-
Save mes51/f90331af552231f39adb5ed3847ebe86 to your computer and use it in GitHub Desktop.
UnMult的なスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obj.pixeloption("type", "rgb") | |
local w, h = obj.getpixel() | |
local inf = 1 / 0 | |
for y = 0, h - 1 do | |
for x = 0, w - 1 do | |
local r, g, b, a = obj.getpixel(x, y) | |
if a < 255 then | |
r = (r * a) / 256 | |
g = (g * a) / 256 | |
b = (b * a) / 256 | |
end | |
local rate = 255 / math.max(math.max(r, g), b) | |
if rate ~= inf then | |
local tr = r * rate | |
local tg = g * rate | |
local tb = b * rate | |
if tb > 0 then | |
a = (b * 256) / tb | |
elseif tg > 0 then | |
a = (g * 256) / tg | |
elseif tr > 0 then | |
a = (r * 256) / tr | |
else | |
a = 0 | |
end | |
obj.putpixel(x, y, math.min(tr, 255), math.min(tg, 255), math.min(tb, 255), math.min(a, 255)) | |
else | |
obj.putpixel(x, y, 0, 0, 0, 0) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方