picturefilter_zx81.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. -- picture converter - zx81 - from Paulo Silva, july 2012 - gpl licence
  2. w,h=getpicturesize()
  3. function grayscaleindexed(c)
  4. r,g,b=getcolor(c);return math.floor((b*11+r*30+g*59)/100);end
  5. wo=w;ho=h
  6. hn=ho+64+8;wn=wo+8
  7. if wn<256 then wn=256;end
  8. setpicturesize(wn,hn)
  9. ok,pixp,blol=inputbox("zx81","pixel-perfect",0,0,1,0,"blocks only",0,0,1,0);
  10. for y=0,h-1,1 do
  11. for x=0,w-1,1 do
  12. u=getpicturepixel(x,y)
  13. k=grayscaleindexed(u)
  14. putpicturepixel(x,y,k)
  15. end;end
  16. for c=0,255,1 do setcolor(c,c,c,c);end
  17. picdump1_st={
  18. "44444444000044444444000000000000444444440000444444440000000000000404040444444444040404044444444444444444444444444444444444444444",
  19. "44444444000044444444000000000000444444440000444444440000000000004040404044444444404040404404404444400044444404444444444444000044",
  20. "44444444000044444444000000000000444444440000444444440000000000000404040444444444040404044404404444044404440000044444444440444404",
  21. "44444444000044444444000000000000444444440000444444440000000000004040404044444444404040404444444440000444440404444440444444444044",
  22. "44444444444444444444444444444444000044440000444400004444000044440404040404040404444444444444444444044444440000044444444444440444",
  23. "44444444444444444444444444444444000044440000444400004444000044444040404040404040444444444444444444044444444404044444444444444444",
  24. "44444444444444444444444444444444000044440000444400004444000044440404040404040404444444444444444440000004440000044440444444440444",
  25. "44444444444444444444444444444444000044440000444400004444000044444040404040404040444444444444444444444444444404444444444444444444",
  26. "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444",
  27. "44444044440444444444444444444444444444444444444444444444444444444444444444444444444444444444444444000044444004444400004444000044",
  28. "44440444444044444440444444444044444444444444044444444444444040444444440444404444444444444444444440444004440404444044440440444404",
  29. "44440444444044444444044444440444440000044444044444444444444404444444404444444444444444444444444440440404444404444444440444440044",
  30. "44440444444044444444404444404444444444444400000444000004440000044444044444444444444444444444444440404404444404444400004444444404",
  31. "44440444444044444444044444440444440000044444044444444444444404444440444444404444444404444440044440044404444404444044444440444404",
  32. "44444044440444444440444444444044444444444444044444444444444040444404444444404444444404444440044444000044440000044000000444000044",
  33. "44444444444444444444444444444444444444444444444444444444444444444444444444044444444044444444444444444444444444444444444444444444",
  34. "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444",
  35. "44440444400000044400004440000004440000444400004444000044400000444400004440000444400000044000000444000044404444044400000444444404",
  36. "44400444404444444044444444444404404444044044440440444404404444044044440440444044404444444044444440444404404444044444044444444404",
  37. "44040444400000444000004444444044440000444044440440444404400000444044444440444404400000444000004440444444400000044444044444444404",
  38. "40440444444444044044440444440444404444044400000440000004404444044044444440444404404444444044444440440004404444044444044440444404",
  39. "40000004404444044044440444404444404444044444440440444404404444044044440440444044404444444044444440444404404444044444044440444404",
  40. "44440444440000444400004444404444440000444400004440444404400000444400004440000444400000044044444444000044404444044400000444000044",
  41. "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444",
  42. "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444",
  43. "40444044404444444044440440444404440000444000004444000044400000444400004400000004404444044044440440444404404444040444440440000004",
  44. "40440444404444444004400440044404404444044044440440444404404444044044444444404444404444044044440440444404440440444044404444444044",
  45. "40004444404444444040040440404404404444044044440440444404404444044400004444404444404444044044440440444404444004444404044444440444",
  46. "40440444404444444044440440440404404444044000004440404404400000444444440444404444404444044044440440444404444004444440444444404444",
  47. "40444044404444444044440440444004404444044044444440440404404440444044440444404444404444044404404440400404440440444440444444044444",
  48. "40444404400000044044440440444404440000444044444444000044404444044400004444404444440000444440044444044044404444044440444440000004",
  49. "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"}
  50. for y=0,table.getn(picdump1_st)-1,1 do
  51. tm_st=picdump1_st[y+1]
  52. for x=0,string.len(tm_st)-1,1 do
  53. a=tonumber( string.sub(tm_st,x+1,x+1),16)
  54. c=math.floor(a*255/4)
  55. putpicturepixel(x,ho+y+8,c)
  56. putpicturepixel(x,ho+y+32+8,255-c)
  57. putpicturepixel(x+128,ho+y+8,c)
  58. putpicturepixel(x+128,ho+y+32+8,255-c)
  59. end;end
  60. if pixp~=1 then
  61. statusmessage("pixp~=1 ...")
  62. waitbreak(0)
  63. for y1=0,h-1,2 do for x1=0,w-1,2 do
  64. statusmessage("blur:".. (math.floor(y1*100/h)) .."% " )
  65. waitbreak(0)
  66. kacm=0
  67. for y2=0,1,1 do for x2=0,1,1 do
  68. x=x1+x2;y=y1+y2;kacm=kacm+getpicturepixel(x,y)
  69. end;end
  70. for y2=0,1,1 do for x2=0,1,1 do
  71. x=x1+x2;y=y1+y2;putpicturepixel(x,y,math.floor(kacm/4))
  72. end;end
  73. end;end
  74. for y1=ho+8,ho+64+8-1,2 do for x1=128,256-1,2 do
  75. kacm=0
  76. for y2=0,1,1 do for x2=0,1,1 do
  77. x=x1+x2;y=y1+y2;kacm=kacm+getpicturepixel(x,y)
  78. end;end
  79. for y2=0,1,1 do for x2=0,1,1 do
  80. x=x1+x2;y=y1+y2;putpicturepixel(x,y,math.floor(kacm/4))
  81. end;end
  82. end;end
  83. end
  84. yqst=1;xqlm=15;stxy1=1
  85. if blol==1 then yqst=4;xqlm=10;end
  86. if pixp~=1 then stxy1=2;end
  87. for y1=0,ho-1,8 do for x1=0,wo-1,8 do dfi=65536;fgx=0;fgy=0
  88. statusmessage("converting:".. (math.floor(y1*100/ho)) .."% " )
  89. waitbreak(0)
  90. for yq=0,7,yqst do for xq=0,xqlm,1 do cnt=0
  91. for y2=0,7,stxy1 do for x2=0,7,stxy1 do
  92. q1=getpicturepixel(x1+x2,y1+y2)
  93. q2=getpicturepixel(128+(xq*8)+x2,ho+8+(yq*8)+y2)
  94. dq=math.abs(q2-q1);cnt=cnt+dq
  95. end;end
  96. if cnt<dfi then dfi=cnt;fgx=xq;fgy=yq;end
  97. end;end
  98. for y2=0,7,1 do for x2=0,7,1 do
  99. c=getpicturepixel((fgx*8)+x2,ho+8+(fgy*8)+y2)
  100. putpicturepixel(x1+x2,y1+y2,c)
  101. end;end
  102. end;end
  103. finalizepicture()
  104. setpicturesize(w,h)