2010-08-20 22:27:07 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local string = string
|
|
|
|
local table = table
|
2012-06-15 10:49:33 +02:00
|
|
|
local unpack = unpack or table.unpack -- v5.1: unpack, v5.2: table.unpack
|
2010-08-20 22:27:07 +02:00
|
|
|
local tonumber = tonumber
|
2012-02-17 17:48:11 +01:00
|
|
|
local ipairs = ipairs
|
2010-09-29 18:54:20 +02:00
|
|
|
local pairs = pairs
|
|
|
|
local type = type
|
2012-05-27 19:20:34 +02:00
|
|
|
local cairo = require("lgi").cairo
|
|
|
|
local surface = require("gears.surface")
|
2010-08-20 22:27:07 +02:00
|
|
|
|
2012-06-12 10:13:46 +02:00
|
|
|
local color = { mt = {} }
|
gears.color: Add a pattern cache
This makes gears.color() cache patterns in a weak table and returns that cached
pattern when we get called with the same argument again.
To benchmark this change, the following code was used:
local time = require("socket").gettime
function benchmark(func)
local begin = time()
local iter = 0
while time() - begin < 1 do
func()
iter = iter + 1
end
return iter
end
for _, arg in pairs({
"#00aa00",
"solid:#00aa00",
"radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff",
"linear:1,2:3,4:0,#000000:1,#ffffff",
"png:/home/psychon/Wallpaper/Bars.png",
{ type = "solid", color = "#00aa00" },
{ type = "radial", from = { 50, 50, 10 }, to = { 55, 55, 30 }, stops = { { 0, "#ff0000" }, { 0.5, "#00ff00" }, { 1, "#0000ff" } } },
{ type = "linear", from = { 1, 2 }, to = { 3, 4 }, stops = { { 0, "#000000" }, { 1, "#ffffff" } } },
{ type = "png", file = "/home/psychon/Wallpaper/Bars.png" },
}) do
collectgarbage("collect")
print(benchmark(function() gears.color.create_pattern(arg) end), arg)
end
Before this change (larger numbers are better, this measures how many times we
can create the given pattern per second):
29525 #00aa00
29344 solid:#00aa00
3446 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
4845 linear:1,2:3,4:0,#000000:1,#ffffff
32855 png:/home/psychon/Wallpaper/Bars.png
29883 table: 0x1bb67e0
3868 table: 0x1bb6830
5339 table: 0x1bb6c60
32772 table: 0x1bb6fe0
After this change:
126188 #00aa00
125962 solid:#00aa00
125125 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
125213 linear:1,2:3,4:0,#000000:1,#ffffff
113659 png:/home/psychon/Wallpaper/Bars.png
125586 table: 0x1232680
125249 table: 0x12326d0
125468 table: 0x1232b00
113711 table: 0x1232e80
As you see, this makes some cases about 35 times faster (although I have to
admit that something like this can be expected from such a synthetic benchmark).
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-29 22:52:04 +01:00
|
|
|
local pattern_cache = setmetatable({}, { __mode = 'v' })
|
2010-08-20 22:27:07 +02:00
|
|
|
|
2010-09-29 18:54:20 +02:00
|
|
|
--- Parse a HTML-color.
|
|
|
|
-- This function can parse colors like #rrggbb and #rrggbbaa.
|
|
|
|
-- For example, parse_color("#00ff00ff") would return 0, 1, 0, 1.
|
2010-08-20 22:27:07 +02:00
|
|
|
-- Thanks to #lua for this. :)
|
2010-09-29 18:54:20 +02:00
|
|
|
-- @param col The color to parse
|
|
|
|
-- @return 4 values which each are in the range [0, 1].
|
2012-06-12 10:13:46 +02:00
|
|
|
function color.parse_color(col)
|
2010-08-20 22:27:07 +02:00
|
|
|
local rgb = {}
|
|
|
|
for pair in string.gmatch(col, "[^#].") do
|
2010-09-29 18:54:20 +02:00
|
|
|
local i = tonumber(pair, 16)
|
|
|
|
if i then
|
|
|
|
table.insert(rgb, i / 255)
|
|
|
|
end
|
2010-08-20 22:27:07 +02:00
|
|
|
end
|
|
|
|
while #rgb < 4 do
|
|
|
|
table.insert(rgb, 1)
|
|
|
|
end
|
|
|
|
return unpack(rgb)
|
|
|
|
end
|
|
|
|
|
2010-09-29 18:54:20 +02:00
|
|
|
--- Find all numbers in a string
|
|
|
|
-- @param s The string to parse
|
|
|
|
-- @return Each number found as a separate value
|
|
|
|
local function parse_numbers(s)
|
|
|
|
local res = {}
|
|
|
|
for k in string.gmatch(s, "-?[0-9]+[.]?[0-9]*") do
|
|
|
|
table.insert(res, tonumber(k))
|
|
|
|
end
|
|
|
|
return unpack(res)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a solid pattern
|
|
|
|
-- @param col The color for the pattern
|
|
|
|
-- @return A cairo pattern object
|
2012-06-12 10:13:46 +02:00
|
|
|
function color.create_solid_pattern(col)
|
2010-09-29 18:54:20 +02:00
|
|
|
local col = col
|
|
|
|
if col == nil then
|
|
|
|
col = "#000000"
|
2012-02-17 17:48:11 +01:00
|
|
|
elseif type(col) == "table" then
|
|
|
|
col = col.color
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
2012-06-12 10:13:46 +02:00
|
|
|
return cairo.Pattern.create_rgba(color.parse_color(col))
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create an image pattern from a png file
|
|
|
|
-- @param file The filename of the file
|
|
|
|
-- @return a cairo pattern object
|
2012-06-12 10:13:46 +02:00
|
|
|
function color.create_png_pattern(file)
|
2012-02-17 17:48:11 +01:00
|
|
|
local file = file
|
|
|
|
if type(file) == "table" then
|
|
|
|
file = file.file
|
|
|
|
end
|
2012-05-27 19:20:34 +02:00
|
|
|
local image = surface.load(file)
|
2014-03-15 23:53:01 +01:00
|
|
|
local pattern = cairo.Pattern.create_for_surface(image)
|
|
|
|
pattern:set_extend(cairo.Extend.REPEAT)
|
|
|
|
return pattern
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
|
|
|
|
2012-02-17 17:48:11 +01:00
|
|
|
-- Add stops to the given pattern.
|
2010-09-29 18:54:20 +02:00
|
|
|
-- @param p The cairo pattern to add stops to
|
|
|
|
-- @param iterator An iterator that returns strings. Each of those strings
|
|
|
|
-- should be in the form place,color where place is in [0, 1].
|
2012-02-17 17:48:11 +01:00
|
|
|
local function add_iterator_stops(p, iterator)
|
2010-09-29 18:54:20 +02:00
|
|
|
for k in iterator do
|
|
|
|
local sub = string.gmatch(k, "[^,]+")
|
2012-06-12 10:13:46 +02:00
|
|
|
local point, clr = sub(), sub()
|
|
|
|
p:add_color_stop_rgba(point, color.parse_color(clr))
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-17 17:48:11 +01:00
|
|
|
-- Add a list of stops to a given pattern
|
|
|
|
local function add_stops_table(pat, arg)
|
|
|
|
for _, stop in ipairs(arg) do
|
2012-06-12 10:13:46 +02:00
|
|
|
pat:add_color_stop_rgba(stop[1], color.parse_color(stop[2]))
|
2012-02-17 17:48:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create a pattern from a string
|
|
|
|
local function string_pattern(creator, arg)
|
|
|
|
local iterator = string.gmatch(arg, "[^:]+")
|
|
|
|
-- Create a table where each entry is a number from the original string
|
|
|
|
local args = { parse_numbers(iterator()) }
|
|
|
|
local to = { parse_numbers(iterator()) }
|
|
|
|
-- Now merge those two tables
|
|
|
|
for k, v in pairs(to) do
|
|
|
|
table.insert(args, v)
|
|
|
|
end
|
|
|
|
-- And call our creator function with the values
|
2012-02-26 05:09:09 +01:00
|
|
|
local p = creator(unpack(args))
|
2012-02-17 17:48:11 +01:00
|
|
|
|
|
|
|
add_iterator_stops(p, iterator)
|
|
|
|
return p
|
|
|
|
end
|
|
|
|
|
2010-09-29 18:54:20 +02:00
|
|
|
--- Create a linear pattern object.
|
|
|
|
-- The pattern is created from a string. This string should have the following
|
2012-01-11 11:14:26 +01:00
|
|
|
-- form: "x0,y0:x1,y1:<stops>"
|
2012-02-17 17:48:11 +01:00
|
|
|
-- Alternatively, the pattern can be specified as a table:
|
|
|
|
-- { type = "linear", from = { x0, y0 }, to = { x1, y1 },
|
|
|
|
-- stops = { <stops> } }
|
2010-09-29 18:54:20 +02:00
|
|
|
-- x0,y0 and x1,y1 are the start and stop point of the pattern.
|
2012-02-17 17:48:11 +01:00
|
|
|
-- For the explanation of "<stops>", see create_pattern().
|
2010-09-29 18:54:20 +02:00
|
|
|
-- @param arg The argument describing the pattern
|
|
|
|
-- @return a cairo pattern object
|
2012-06-12 10:13:46 +02:00
|
|
|
function color.create_linear_pattern(arg)
|
2012-02-17 17:48:11 +01:00
|
|
|
local pat
|
|
|
|
|
|
|
|
if type(arg) == "string" then
|
2012-05-27 19:20:34 +02:00
|
|
|
return string_pattern(cairo.Pattern.create_linear, arg)
|
2012-02-17 17:48:11 +01:00
|
|
|
elseif type(arg) ~= "table" then
|
|
|
|
error("Wrong argument type: " .. type(arg))
|
|
|
|
end
|
|
|
|
|
2012-05-27 19:20:34 +02:00
|
|
|
pat = cairo.Pattern.create_linear(arg.from[1], arg.from[2], arg.to[1], arg.to[2])
|
2012-02-17 17:48:11 +01:00
|
|
|
add_stops_table(pat, arg.stops)
|
|
|
|
return pat
|
|
|
|
end
|
2010-09-29 18:54:20 +02:00
|
|
|
|
|
|
|
--- Create a radial pattern object.
|
|
|
|
-- The pattern is created from a string. This string should have the following
|
2012-01-11 11:14:26 +01:00
|
|
|
-- form: "x0,y0,r0:x1,y1,r1:<stops>"
|
2012-02-17 17:48:11 +01:00
|
|
|
-- Alternatively, the pattern can be specified as a table:
|
|
|
|
-- { type = "radial", from = { x0, y0, r0 }, to = { x1, y1, r1 },
|
|
|
|
-- stops = { <stops> } }
|
2010-09-29 18:54:20 +02:00
|
|
|
-- x0,y0 and x1,y1 are the start and stop point of the pattern.
|
|
|
|
-- r0 and r1 are the radii of the start / stop circle.
|
2012-02-17 17:48:11 +01:00
|
|
|
-- For the explanation of "<stops>", see create_pattern().
|
2010-09-29 18:54:20 +02:00
|
|
|
-- @param arg The argument describing the pattern
|
|
|
|
-- @return a cairo pattern object
|
2012-06-12 10:13:46 +02:00
|
|
|
function color.create_radial_pattern(arg)
|
2012-02-17 17:48:11 +01:00
|
|
|
local pat
|
2010-09-29 18:54:20 +02:00
|
|
|
|
2012-02-17 17:48:11 +01:00
|
|
|
if type(arg) == "string" then
|
2012-05-27 19:20:34 +02:00
|
|
|
return string_pattern(cairo.Pattern.create_radial, arg)
|
2012-02-17 17:48:11 +01:00
|
|
|
elseif type(arg) ~= "table" then
|
|
|
|
error("Wrong argument type: " .. type(arg))
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
2012-02-17 17:48:11 +01:00
|
|
|
|
2012-05-27 19:20:34 +02:00
|
|
|
pat = cairo.Pattern.create_radial(arg.from[1], arg.from[2], arg.from[3],
|
2012-02-17 17:48:11 +01:00
|
|
|
arg.to[1], arg.to[2], arg.to[3])
|
|
|
|
add_stops_table(pat, arg.stops)
|
|
|
|
return pat
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
|
|
|
|
2012-02-17 17:48:11 +01:00
|
|
|
--- Mapping of all supported color types. New entries can be added.
|
2012-06-12 10:13:46 +02:00
|
|
|
color.types = {
|
2012-06-12 10:13:46 +02:00
|
|
|
solid = color.create_solid_pattern,
|
|
|
|
png = color.create_png_pattern,
|
|
|
|
linear = color.create_linear_pattern,
|
|
|
|
radial = color.create_radial_pattern
|
2010-09-29 18:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
--- Create a pattern from a given string.
|
2014-09-13 14:16:54 +02:00
|
|
|
-- For full documentation of this function, please refer to create_pattern().
|
|
|
|
-- This difference between create_pattern() and this function is that this
|
|
|
|
-- function does not insert the generated objects into the pattern cache. Thus,
|
|
|
|
-- you are allowed to modify the returned object.
|
|
|
|
-- @see create_pattern
|
2010-09-29 18:54:20 +02:00
|
|
|
-- @param col The string describing the pattern.
|
|
|
|
-- @return a cairo pattern object
|
2014-09-13 14:16:54 +02:00
|
|
|
function color.create_pattern_uncached(col)
|
2013-02-11 14:26:05 +01:00
|
|
|
-- If it already is a cairo pattern, just leave it as that
|
|
|
|
if cairo.Pattern:is_type_of(col) then
|
|
|
|
return col
|
|
|
|
end
|
2014-04-03 20:27:45 +02:00
|
|
|
local col = col or "#000000"
|
2010-09-29 18:54:20 +02:00
|
|
|
if type(col) == "string" then
|
|
|
|
local t = string.match(col, "[^:]+")
|
2012-06-12 10:13:46 +02:00
|
|
|
if color.types[t] then
|
2010-09-29 18:54:20 +02:00
|
|
|
local pos = string.len(t)
|
|
|
|
local arg = string.sub(col, pos + 2)
|
2014-09-13 14:16:54 +02:00
|
|
|
return color.types[t](arg)
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
2012-02-17 17:48:11 +01:00
|
|
|
elseif type(col) == "table" then
|
|
|
|
local t = col.type
|
2012-06-12 10:13:46 +02:00
|
|
|
if color.types[t] then
|
2014-09-13 14:16:54 +02:00
|
|
|
return color.types[t](col)
|
2012-02-17 17:48:11 +01:00
|
|
|
end
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
2014-09-13 14:16:54 +02:00
|
|
|
return color.create_solid_pattern(col)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a pattern from a given string.
|
|
|
|
-- This function can create solid, linear, radial and png patterns. In general,
|
|
|
|
-- patterns are specified as strings formatted as"type:arguments". "arguments"
|
|
|
|
-- is specific to the pattern used. For example, one can use
|
|
|
|
-- "radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff"
|
|
|
|
-- Alternatively, patterns can be specified via tables. In this case, the
|
|
|
|
-- table's 'type' member specifies the type. For example:
|
|
|
|
-- { type = "radial", from = { 50, 50, 10 }, to = { 55, 55, 30 },
|
|
|
|
-- stops = { { 0, "#ff0000" }, { 0.5, "#00ff00" }, { 1, "#0000ff" } } }
|
|
|
|
-- Any argument that cannot be understood is passed to create_solid_pattern().
|
|
|
|
--
|
|
|
|
-- Please note that you MUST NOT modify the returned pattern, for example by
|
|
|
|
-- calling :set_matrix() on it, because this function uses a cache and your
|
|
|
|
-- changes could thus have unintended side effects. Use create_pattern_uncached
|
|
|
|
-- if you need to modify the returned pattern.
|
|
|
|
-- @see create_pattern_uncached, create_solid_pattern, create_png_pattern,
|
|
|
|
-- create_linear_pattern, create_radial_pattern
|
|
|
|
-- @param col The string describing the pattern.
|
|
|
|
-- @return a cairo pattern object
|
|
|
|
function color.create_pattern(col)
|
|
|
|
-- If it already is a cairo pattern, just leave it as that
|
|
|
|
if cairo.Pattern:is_type_of(col) then
|
|
|
|
return col
|
|
|
|
end
|
|
|
|
local col = col or "#000000"
|
|
|
|
local result = pattern_cache[col]
|
gears.color: Add a pattern cache
This makes gears.color() cache patterns in a weak table and returns that cached
pattern when we get called with the same argument again.
To benchmark this change, the following code was used:
local time = require("socket").gettime
function benchmark(func)
local begin = time()
local iter = 0
while time() - begin < 1 do
func()
iter = iter + 1
end
return iter
end
for _, arg in pairs({
"#00aa00",
"solid:#00aa00",
"radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff",
"linear:1,2:3,4:0,#000000:1,#ffffff",
"png:/home/psychon/Wallpaper/Bars.png",
{ type = "solid", color = "#00aa00" },
{ type = "radial", from = { 50, 50, 10 }, to = { 55, 55, 30 }, stops = { { 0, "#ff0000" }, { 0.5, "#00ff00" }, { 1, "#0000ff" } } },
{ type = "linear", from = { 1, 2 }, to = { 3, 4 }, stops = { { 0, "#000000" }, { 1, "#ffffff" } } },
{ type = "png", file = "/home/psychon/Wallpaper/Bars.png" },
}) do
collectgarbage("collect")
print(benchmark(function() gears.color.create_pattern(arg) end), arg)
end
Before this change (larger numbers are better, this measures how many times we
can create the given pattern per second):
29525 #00aa00
29344 solid:#00aa00
3446 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
4845 linear:1,2:3,4:0,#000000:1,#ffffff
32855 png:/home/psychon/Wallpaper/Bars.png
29883 table: 0x1bb67e0
3868 table: 0x1bb6830
5339 table: 0x1bb6c60
32772 table: 0x1bb6fe0
After this change:
126188 #00aa00
125962 solid:#00aa00
125125 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
125213 linear:1,2:3,4:0,#000000:1,#ffffff
113659 png:/home/psychon/Wallpaper/Bars.png
125586 table: 0x1232680
125249 table: 0x12326d0
125468 table: 0x1232b00
113711 table: 0x1232e80
As you see, this makes some cases about 35 times faster (although I have to
admit that something like this can be expected from such a synthetic benchmark).
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-29 22:52:04 +01:00
|
|
|
if not result then
|
2014-09-13 14:16:54 +02:00
|
|
|
result = color.create_pattern_uncached(col)
|
|
|
|
pattern_cache[col] = result
|
gears.color: Add a pattern cache
This makes gears.color() cache patterns in a weak table and returns that cached
pattern when we get called with the same argument again.
To benchmark this change, the following code was used:
local time = require("socket").gettime
function benchmark(func)
local begin = time()
local iter = 0
while time() - begin < 1 do
func()
iter = iter + 1
end
return iter
end
for _, arg in pairs({
"#00aa00",
"solid:#00aa00",
"radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff",
"linear:1,2:3,4:0,#000000:1,#ffffff",
"png:/home/psychon/Wallpaper/Bars.png",
{ type = "solid", color = "#00aa00" },
{ type = "radial", from = { 50, 50, 10 }, to = { 55, 55, 30 }, stops = { { 0, "#ff0000" }, { 0.5, "#00ff00" }, { 1, "#0000ff" } } },
{ type = "linear", from = { 1, 2 }, to = { 3, 4 }, stops = { { 0, "#000000" }, { 1, "#ffffff" } } },
{ type = "png", file = "/home/psychon/Wallpaper/Bars.png" },
}) do
collectgarbage("collect")
print(benchmark(function() gears.color.create_pattern(arg) end), arg)
end
Before this change (larger numbers are better, this measures how many times we
can create the given pattern per second):
29525 #00aa00
29344 solid:#00aa00
3446 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
4845 linear:1,2:3,4:0,#000000:1,#ffffff
32855 png:/home/psychon/Wallpaper/Bars.png
29883 table: 0x1bb67e0
3868 table: 0x1bb6830
5339 table: 0x1bb6c60
32772 table: 0x1bb6fe0
After this change:
126188 #00aa00
125962 solid:#00aa00
125125 radial:50,50,10:55,55,30:0,#ff0000:0.5,#00ff00:1,#0000ff
125213 linear:1,2:3,4:0,#000000:1,#ffffff
113659 png:/home/psychon/Wallpaper/Bars.png
125586 table: 0x1232680
125249 table: 0x12326d0
125468 table: 0x1232b00
113711 table: 0x1232e80
As you see, this makes some cases about 35 times faster (although I have to
admit that something like this can be expected from such a synthetic benchmark).
Signed-off-by: Uli Schlachter <psychon@znc.in>
2014-03-29 22:52:04 +01:00
|
|
|
end
|
|
|
|
return result
|
2010-09-29 18:54:20 +02:00
|
|
|
end
|
|
|
|
|
2014-03-16 14:58:14 +01:00
|
|
|
--- Check if a pattern is opaque.
|
|
|
|
-- A pattern is transparent if the background on which it gets drawn (with
|
|
|
|
-- operator OVER) doesn't influence the visual result.
|
|
|
|
-- @param col An argument that create_pattern() accepts
|
|
|
|
-- @return The pattern if it is surely opaque, else nil
|
|
|
|
function color.create_opaque_pattern(col)
|
|
|
|
local pattern = color.create_pattern(col)
|
|
|
|
local type = pattern:get_type()
|
|
|
|
local extend = pattern:get_extend()
|
|
|
|
|
|
|
|
if type == "SOLID" then
|
|
|
|
local status, r, g, b, a = pattern:get_rgba()
|
|
|
|
if a ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
return pattern
|
|
|
|
elseif type == "SURFACE" then
|
2014-03-23 21:51:29 +01:00
|
|
|
local status, surface = pattern:get_surface()
|
|
|
|
if status ~= "SUCCESS" or surface.content ~= "COLOR" then
|
2014-03-16 14:58:14 +01:00
|
|
|
-- The surface has an alpha channel which *might* be non-opaque
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Only the "NONE" extend mode is forbidden, everything else doesn't
|
|
|
|
-- introduce transparent parts
|
|
|
|
if pattern:get_extend() == "NONE" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return pattern
|
|
|
|
elseif type == "LINEAR" then
|
|
|
|
local status, stops = pattern:get_color_stop_count()
|
|
|
|
|
|
|
|
-- No color stops or extend NONE -> pattern *might* contain transparency
|
|
|
|
if stops == 0 or pattern:get_extend() == "NONE" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Now check if any of the color stops contain transparency
|
|
|
|
for i = 0, stops - 1 do
|
|
|
|
local status, offset, r, g, b, a = pattern:get_color_stop_rgba(i)
|
|
|
|
if a ~= 1 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return pattern
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Unknown type, e.g. mesh or raster source or unsupported type (radial
|
|
|
|
-- gradients can do weird self-intersections)
|
|
|
|
end
|
|
|
|
|
2012-06-12 10:13:46 +02:00
|
|
|
function color.mt:__call(...)
|
|
|
|
return color.create_pattern(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(color, color.mt)
|
2010-08-20 22:27:07 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|