cellcolourreducer.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. xcell=8;ycell=8 --bug: innacurate greenish result when ycell=1 or =2
  2. for y1=0,height-1,ycell do
  3. for x1=0,width-1,xcell do
  4. wcnt=0
  5. for y2=0,ycell-1,1 do
  6. for x2=0,xcell-1,1 do
  7. x=x1+x2;y=y1+y2
  8. r,g,b=get_rgb(x,y)
  9. w=((b*11)+(r*30)+(g*59))/100
  10. wcnt=wcnt+w
  11. end;end
  12. wcnt=wcnt/(xcell*ycell)
  13. r0cnt=0;g0cnt=0;b0cnt=0;t0cnt=0;r1cnt=0;g1cnt=1;b1cnt=0;t1cnt=0
  14. for y2=0,ycell-1,1 do
  15. for x2=0,xcell-1,1 do
  16. x=x1+x2;y=y1+y2
  17. r,g,b=get_rgb(x,y)
  18. w=((b*11)+(r*30)+(g*59))/100
  19. if w<wcnt then
  20. r0cnt=r0cnt+r;g0cnt=g0cnt+g;b0cnt=b0cnt+b;t0cnt=t0cnt+1
  21. else
  22. r1cnt=r1cnt+r;g1cnt=g1cnt+g;b1cnt=b1cnt+b;t1cnt=t1cnt+1
  23. end
  24. end;end
  25. r0cnt=r0cnt/t0cnt;g0cnt=g0cnt/t0cnt;b0cnt=b0cnt/t0cnt
  26. r1cnt=r1cnt/t1cnt;g1cnt=g1cnt/t1cnt;b1cnt=b1cnt/t1cnt
  27. for y2=0,ycell-1,1 do
  28. for x2=0,xcell-1,1 do
  29. x=x1+x2;y=y1+y2
  30. r,g,b=get_rgb(x,y)
  31. w=((b*11)+(r*30)+(g*59))/100
  32. if w<wcnt then
  33. set_rgb(x,y,r0cnt,g0cnt,b0cnt)
  34. else
  35. set_rgb(x,y,r1cnt,g1cnt,b1cnt)
  36. end
  37. end;end
  38. end
  39. progress(y1/height)
  40. end