-
Notifications
You must be signed in to change notification settings - Fork 22
/
bitmap_rgbaf.lua
65 lines (49 loc) · 1.7 KB
/
bitmap_rgbaf.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--floating point RGBA bitmap types for HDR storage and internal processing.
local bitmap = require'bitmap'
local glue = require'glue'
local ffi = require'ffi'
bitmap.colortypes.rgbaf = {channels = 'rgba', max = 1}
bitmap.formats.rgbaf = glue.merge({bpp = 32 * 4, ctype = ffi.typeof'float',
colortype = 'rgbaf', bitmap.formats.rgba8})
bitmap.formats.rgbad = glue.merge({bpp = 64 * 4, ctype = ffi.typeof'double',
colortype = 'rgbaf', bitmap.formats.rgba8})
bitmap.converters.rgbaf = {}
function bitmap.converters.rgbaf.rgba8(r, g, b, a)
return r * 255, g * 255, b * 255, a * 255
end
function bitmap.converters.rgba8.rgbaf(r, g, b, a)
return r * (1 / 255), g * (1 / 255), b * (1 / 255), a * (1 / 255)
end
function bitmap.converters.rgbaf.rgba16(r, g, b, a)
return r * 65535, g * 65535, b * 65535, a * 65535
end
function bitmap.converters.rgba16.rgbaf(r, g, b, a)
return r * (1 / 65535), g * (1 / 65535), b * (1 / 65535), a * (1 / 65535)
end
function bitmap.converters.rgbaf.ga8(r, g, b, a)
return bitmap.rgb2g(r, g, b) * 255, a
end
function bitmap.converters.ga8.rgbaf(g, a)
g = g / 255
a = a / 255
return g, g, g, a
end
function bitmap.converters.rgbaf.ga16(r, g, b, a)
return bitmap.rgb2g(r, g, b) * 65535, a
end
function bitmap.converters.ga16.rgbaf(g, a)
g = g / 65535
a = a / 65535
return g, g, g, a
end
function bitmap.converters.cmyk8.rgbaf(c, m, y, k)
return c * k / 65535, m * k / 65535, y * k / 65535, 1
end
function bitmap.converters.ycck8.rgbaf(y, cb, cr, k)
return
(y + 1.402 * (cr - 128)) / 255,
(y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128)) / 255,
(y + 1.772 * (cb - 128) ) / 255,
1
end
if not ... then require'bitmap_demo' end