• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# cellcolourreducer.lua

a guest Jan 5th, 2011 172 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. -- cell colour reducer
2. -- jan'11, from Paulo Silva, with help from people from GrafX2 google group (DawnBringer, Adrien Destugues (PulkoMandy), and Yves Rizoud)
3. -- 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/>
4. w,h=getpicturesize()
5. xcell=8;ycell=1
6. function grayscaleindexed(c)
7.   r,g,b=getcolor(c)
8.   return math.floor((b*11+r*30+g*59)/100);end
9. celcnt={};for n=0,255,1 do celcnt[n+1]=0;end -- Arraycounter must have initial value
10. for y1=0,h-1,ycell do
11.   for x1=0,w-1,xcell do
12.     for i=0,255,1 do
13.       celcnt[i+1]=0;end
14.     for y2=0,ycell-1,1 do
15.       for x2=0,xcell-1,1 do
16.         x=x1+x2;y=y1+y2
17.         u=getpicturepixel(x,y)
18.         celcnt[u+1]=celcnt[u+1]+(1000*xcell*ycell)+math.random(0,950)
19.         end
20.       end
21.     ikattr=0;paattr=0;ikcnt=0;pacnt=0
22.     for i=0,255,1 do
23.       if ikcnt<celcnt[i+1] then ikcnt=celcnt[i+1];ikattr=i;end
24.       end
25.     celcnt[ikattr+1]=0
26.     for i=0,255,1 do
27.       if pacnt<celcnt[i+1] then pacnt=celcnt[i+1];paattr=i;end
28.       end
29.     if grayscaleindexed(ikattr)>grayscaleindexed(paattr) then tmpr=ikattr;ikattr=paattr;paattr=tmpr;end
30.     wmid=math.floor((grayscaleindexed(paattr)+grayscaleindexed(ikattr))/2)
31.     for y2=0,ycell-1,1 do
32.       for x2=0,xcell-1,1 do
33.         x=x1+x2;y=y1+y2
34.         u=getpicturepixel(x,y)
35.         if u==ikattr then
36.             idou=ikattr
37.           elseif u==paattr then
38.             idou=paattr
39.           else
40.             idou=ikattr
41.             if grayscaleindexed(u)>wmid then idou=paattr;end
42.           end
43.         putpicturepixel(x,y,idou)
44.         end
45.       end
46.     end
47.   end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?