Speed up the RGBA->BGRA conversion (FS#1112)
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
2b0398c59b
commit
ed763b9ad3
|
@ -23,6 +23,11 @@ local wibox = require("wibox")
|
||||||
local surface = require("gears.surface")
|
local surface = require("gears.surface")
|
||||||
local cairo = require("lgi").cairo
|
local cairo = require("lgi").cairo
|
||||||
|
|
||||||
|
local schar = string.char
|
||||||
|
local sbyte = string.byte
|
||||||
|
local tcat = table.concat
|
||||||
|
local tins = table.insert
|
||||||
|
|
||||||
--- Notification library
|
--- Notification library
|
||||||
local naughty = {}
|
local naughty = {}
|
||||||
|
|
||||||
|
@ -535,40 +540,44 @@ if capi.dbus then
|
||||||
args.icon = icon
|
args.icon = icon
|
||||||
elseif hints.icon_data or hints.image_data then
|
elseif hints.icon_data or hints.image_data then
|
||||||
if hints.icon_data == nil then hints.icon_data = hints.image_data end
|
if hints.icon_data == nil then hints.icon_data = hints.image_data end
|
||||||
-- icon_data is an array:
|
|
||||||
-- 1 -> width, 2 -> height, 3 -> rowstride, 4 -> has alpha
|
|
||||||
-- 5 -> bits per sample, 6 -> channels, 7 -> data
|
|
||||||
local width, height, rowstride = hints.icon_data[1], hints.icon_data[2], hints.icon_data[3]
|
|
||||||
|
|
||||||
local imgdata = ""
|
-- icon_data is an array:
|
||||||
local format, bpp
|
-- 1 -> width
|
||||||
-- If has alpha (ARGB32)
|
-- 2 -> height
|
||||||
if hints.icon_data[6] == 4 then
|
-- 3 -> rowstride
|
||||||
format, bpp = cairo.Format.ARGB32, 4
|
-- 4 -> has alpha
|
||||||
-- If has not alpha (RGB24)
|
-- 5 -> bits per sample
|
||||||
elseif hints.icon_data[6] == 3 then
|
-- 6 -> channels
|
||||||
format, bpp = cairo.Format.RGB24, 3
|
-- 7 -> data
|
||||||
end
|
local w, h, rowstride, _, _, channels, data = unpack(hints.icon_data)
|
||||||
|
|
||||||
|
local format = cairo.Format[channels == 4 and 'ARGB32' or 'RGB24']
|
||||||
|
|
||||||
-- Figure out some stride magic (cairo dictates rowstride)
|
-- Figure out some stride magic (cairo dictates rowstride)
|
||||||
local stride = cairo.Format.stride_for_width(format, width)
|
local stride = cairo.Format.stride_for_width(format, w)
|
||||||
local append = string.format("%c", 0):rep(stride - 4 * width)
|
local append = schar(0):rep(stride - 4 * w)
|
||||||
local offset = 0
|
local offset = 0
|
||||||
|
|
||||||
-- Now convert each row on its own
|
-- Now convert each row on its own
|
||||||
for y = 1, height do
|
local rows = {}
|
||||||
for i = 1 + offset, width * bpp + offset, bpp do
|
|
||||||
imgdata = imgdata .. hints.icon_data[7]:sub(i, i + 2):reverse()
|
for y = 1, h do
|
||||||
if bpp == 4 then
|
local this_row = {}
|
||||||
imgdata = imgdata .. hints.icon_data[7]:sub(i + 3, i + 3)
|
|
||||||
else
|
for i = 1 + offset, w * channels + offset, channels do
|
||||||
imgdata = imgdata .. string.format("%c", 255)
|
local R, G, B, A = sbyte(data, i, i + channels - 1)
|
||||||
end
|
tins(this_row, schar(B, G, R, A or 255))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle rowstride, offset is stride for the input, append for output
|
-- Handle rowstride, offset is stride for the input, append for output
|
||||||
|
tins(this_row, append)
|
||||||
|
tins(rows, tcat(this_row))
|
||||||
|
|
||||||
offset = offset + rowstride
|
offset = offset + rowstride
|
||||||
imgdata = imgdata .. append
|
|
||||||
end
|
end
|
||||||
args.icon = cairo.ImageSurface.create_for_data(imgdata, format,
|
|
||||||
width, height, stride)
|
args.icon = cairo.ImageSurface.create_for_data(tcat(rows), format,
|
||||||
|
w, h, stride)
|
||||||
end
|
end
|
||||||
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
if replaces_id and replaces_id ~= "" and replaces_id ~= 0 then
|
||||||
args.replaces_id = replaces_id
|
args.replaces_id = replaces_id
|
||||||
|
|
Loading…
Reference in New Issue