Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6581 leency 1
--SCENE: Remap pic 2 RGB, 1lineED-dith. (Same line simple error-diffusion dither)
2
--by Richard Fhager
3
--http://hem.fyristorg.com/dawnbringer/
4
 
5
-- Copyright 2010 Richard Fhager
6
--
7
-- This program is free software; you can redistribute it and/or
8
-- modify it under the terms of the GNU General Public License
9
-- as published by the Free Software Foundation; version 2
10
-- of the License. See 
11
 
12
 
13
power = 0.615
14
 
15
c1 = 0.8 -- Error weight (white is green)
16
c2 = 0.2 -- RGB weight (white is r+g+b)
17
 
18
-- Set Palette (to a predefined one)
19
 
20
colors = {{  0,  0,  0},
21
          {255,  0,  0},
22
          {  0,255,  0},
23
          {  0,  0,255}
24
         }
25
 
26
 
27
chm = {1,0,0}
28
 
29
for c = 1, #colors, 1 do
30
  setcolor(c-1,colors[c][1],colors[c][2],colors[c][3])
31
end
32
 
33
for c = #colors, 255, 1 do
34
  setcolor(c,0,0,0)
35
end
36
 
37
 
38
 
39
w, h = getpicturesize()
40
 
41
for y = 0, h - 1, 1 do
42
 
43
  re = 0
44
  ge = 0
45
  be = 0
46
 
47
  for x = (y%2), w - 1, 1 do
48
 
49
    r,g,b = getbackupcolor(getbackuppixel(x,y));
50
 
51
      rn = re * c1 + r * chm[1+(y+0+x)%3] * c2
52
      gn = ge * c1 + g * chm[1+(y+1+x)%3] * c2
53
      bn = be * c1 + b * chm[1+(y+2+x)%3] * c2
54
 
55
      n = matchcolor(rn,gn,bn);
56
 
57
    putpicturepixel(x, y, n);
58
 
59
 
60
    rn,gn,bn =  getcolor(getpicturepixel(x,y));
61
 
62
    re = (re + (r - rn)) * power
63
    ge = (ge + (g - gn)) * power
64
    be = (be + (b - bn)) * power
65
 
66
 
67
 
68
  end
69
end