Skip to content
This repository has been archived by the owner on Jan 17, 2020. It is now read-only.

convert_color_alpha ARGB-Ass-value not found #4

Closed
Kagu-chan opened this issue Jun 9, 2015 · 1 comment
Closed

convert_color_alpha ARGB-Ass-value not found #4

Kagu-chan opened this issue Jun 9, 2015 · 1 comment

Comments

@Kagu-chan
Copy link

Hi,

in old Yutils core (used from FXSpindle) the function Yutils.ass.convert_coloralpha contains an incorrect regular expression:

elseif ass_r_a:find("^&H%x%x%x%x%x%x%x%x$") then    -- ASS color+alpha (style)

here an & at the end is missing

elseif ass_r_a:find("^&H%x%x%x%x%x%x%x%x&$") then   -- ASS color+alpha (style)

Also at result value this is missing. It may be missed in ealier versions, in current version (aegisub at Ubuntu) its required and used as it seems Or is this an error from aegisub byself?.

Ill tell you this to take care about while redeveloping the library (:
Good luck

My (not so clean) implementation (but for this i have all maybe required values from one function, optimizing and refactoring follows later as usual for me):

        coloralpha = function(ass_a_r, g, b, a)
            -- result: a, r, g, b, ass_complete, ass_color, ass_alpha
            local result = { a = nil, r = nil, g = nil, b = nil, ass = nil, ass_c = nil, ass_a = nil }

            g = g and g or false -- set g explicit to false if it not given
            if g then -- g is given, with this b should be given too
                a = a and a or false -- set a explicit to false if it not given
                if a then -- a r g b in numbers is given
                    r = ass_a_r
                else -- r g b in numbers is given
                    r = ass_a_r
                    a = 255
                end
            else -- just ass_a_r is given
                if type(ass_a_r) == "string" then -- ass value is given
                    if ass_a_r:find("^&H%x%x&$") then -- ass alpha is given
                        a = 255 - tonumber(ass_a_r:sub(3,4), 16)
                        r, g, b = 0, 0, 0
                    elseif ass_a_r:find("^&H%x%x%x%x%x%x&$") then -- ass r g b is given
                        a = 255
                        r = tonumber(ass_a_r:sub(7,8), 16)
                        g = tonumber(ass_a_r:sub(5,6), 16)
                        b = tonumber(ass_a_r:sub(3,4), 16)
                    elseif ass_a_r:find("^&H%x%x%x%x%x%x%x%x&$") then -- ass r g b a is given
                        a = 255 - tonumber(ass_a_r:sub(3,4), 16)
                        r = tonumber(ass_a_r:sub(9,10), 16) 
                        g = tonumber(ass_a_r:sub(7,8), 16) 
                        b = tonumber(ass_a_r:sub(5,6), 16)
                    else
                        error(string.format("invalid string %q", ass_a_r))
                    end
                else -- alpha in number is given
                    a = ass_a_r
                    r, g, b = 0, 0, 0
                end
            end

            result.a, result.r, result.g, result.b = a, r, g, b
            result.ass = string.format("&H%02X%02X%02X%02X&", 255 - a, b, g, r)
            result.ass_r = string.format("&H%02X%02X%02X&", b, g, r)
            result.ass_a = string.format("&H%02X&", 255 - a)

            return unpack(result)
        end,
@Kagu-chan Kagu-chan reopened this Jun 9, 2015
@Kagu-chan
Copy link
Author

OK, in ass it is as you written, in aegi it seems to be handlet in other manner, so it isnt an issue

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

No branches or pull requests

1 participant