-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathostro_to9.lua
More file actions
executable file
·48 lines (43 loc) · 1.23 KB
/
ostro_to9.lua
File metadata and controls
executable file
·48 lines (43 loc) · 1.23 KB
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
-- ostro_mo5.lua : converts a color image into a
-- TO9 image (320x200x16 with color clashes)
-- using Ostromoukhov's error diffusion algorithm.
--
-- Version: 02-jan-2017
--
-- Copyright 2016-2017 by Samuel Devulder
--
-- This program is free software; you can redistribute
-- it and/or modify it under the terms of the GNU
-- General Public License as published by the Free
-- Software Foundation; version 2 of the License.
-- See <http://www.gnu.org/licenses/>
pcall(function() require('lib/cmdline') end)
run('lib/ostromoukhov.lua')
run('lib/color_reduction.lua')
OstroDither:new():dither40cols(function(w,h,getLinearPixel)
local c16 = h==200 and w==320
for y=0,h-1 do
for x=0,w-1 do
if getbackuppixel(x,y)>15 then c16 = false end
end
end
local pal
if c16 then
pal = {}
for i=0,15 do
local r,g,b=getbackupcolor(i)
r = thomson.levels.pc2to[r]
g = thomson.levels.pc2to[g]
b = thomson.levels.pc2to[b]
pal[i+1] = r+g*16+b*256-273
end
else
pal=ColorReducer:new():analyzeWithDither(w,h,
getLinearPixel,
function(y)
thomson.info("Building palette...",math.floor(y*100),"%")
end):boostBorderColors():buildPalette(16)
end
thomson.palette(0, pal)
return pal
end)