Advertisement
Guest User

garfx method1 transp lua

a guest
Jan 17th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.41 KB | None | 0 0
  1. -- Remove dither pattern with horizontal approach - 1 pixel up and own supportedd- will add this for two in future---
  2. -- Method 1 not so image persistend like method 2
  3.  
  4. -- This variant needs image to only use colors < 16
  5.  
  6.  
  7. -- Determines which color should store the average of colors i and j.
  8. -- Only works if i and j are different and both < 16.
  9. function transp(i, j)
  10.   if i < j then
  11.     return i*15+j+15
  12.   else
  13.     return j*15+i+15
  14.   end
  15. end
  16.  
  17. -- Prepares the palette.
  18. -- Thanks to DawnBringer for gamma expertise
  19. -- Gamma factor should be set close to 1.6 for converting images designed on
  20. -- very low resolutions, up to 2.2 on very high resolutions.
  21. --
  22. gamma = 1.8 -- gamma factor.
  23. for i = 0, 15 do
  24.   for j = i+1, 15 do
  25.     r1, g1, b1 = getcolor(i);
  26.     r2, g2, b2 = getcolor(j);    
  27.     r3 = math.pow(((math.pow(r1/255,gamma) + math.pow(r2/255,gamma)) / 2),(1/gamma))*255
  28.     g3 = math.pow(((math.pow(g1/255,gamma) + math.pow(g2/255,gamma)) / 2),(1/gamma))*255
  29.     b3 = math.pow(((math.pow(b1/255,gamma) + math.pow(b2/255,gamma)) / 2),(1/gamma))*255            
  30.     setcolor(transp(i,j), r3, g3, b3)
  31.   end
  32. end
  33.  
  34. -- Remove dither pattern with horizontal approach - 1 pixel up and own supportedd- will add  it for two in furue---
  35.  
  36. w, h = getpicturesize()
  37.  
  38. for y = 0, h - 1, 1 do
  39.  
  40.   for x = 0, w - 4, 1 do
  41.  
  42. get = getbackuppixel
  43. put = putpicturepixel  
  44. c1 = get(x,y);
  45. c2 = get(x+1,y);
  46. c3 = get(x+2,y);
  47. c4 = get(x+3,y);
  48.    
  49. if (c1 == c3) and (c2 == c4) and (c1 ~= c2) and (c2 ~= c3) and (get(x,y+1) ~= c1) and (get(x+1,y+1) ~= c2) and (get(x+2,y+1) ~= c3) and (get(x+3,y+1) ~= c4) and (get(x,y-1) ~= c1) and (get(x+1,y-1) ~= c2) and (get(x+2,y-1) ~= c3) and (get(x+3,y-1) ~= c4) then
  50.   r1, g1, b1 = getcolor(c1);
  51.   r2, g2, b2 = getcolor(c2);
  52.  
  53.  
  54.   avgcol = transp(c1, c2)
  55.  
  56.   put(x, y, avgcol);
  57.   put(x+1, y, avgcol);
  58.   put(x+2, y, avgcol);
  59.   put(x+3, y, avgcol);
  60.  
  61. -- expand on all 4 directions up --
  62.     if (get(x,y+1) == c2) and (get(x+1,y+1) ~= c2) and (get(x-1,y+1) ~= c2) and ((get(x+1,y+1) == c1) or (get(x-1,y+1) == c1)) then
  63. put(x, y+1, avgcol);
  64.   end
  65.   if (get(x+1,y+1) == c1) and (get(x+2,y+1) ~= c1) and (get(x,y+1) ~= c1) and ((get(x+2,y+1) == c2) or (get(x,y+1) == c2)) then
  66. put(x+1, y+1, avgcol);
  67.   end
  68.   if (get(x+2,y+1) == c2) and (get(x+3,y+1) ~= c2) and (get(x+1,y+1) ~= c2) and ((get(x+3,y+1) == c1) or (get(x+1,y+1) == c1)) then
  69. put(x+2, y+1, avgcol);
  70.   end
  71.   if (get(x+3,y+1) == c1) and  (get(x+4,y+1) ~= c1) and (get(x+2,y+1) ~= c1) and ((get(x+4,y+1) == c2) or (get(x+2,y+1) == c2)) then
  72. put(x+3, y+1, avgcol);
  73.   end
  74. -- expand on all 4 directions down --
  75.     if (get(x,y-1) == c2) and (get(x+1,y-1) ~= c2) and (get(x-1,y-1) ~= c2) and ((get(x+1,y-1) == c1) or (get(x-1,y-1) == c1)) then
  76. put(x, y-1, avgcol);
  77.   end
  78.   if (get(x+1,y-1) == c1) and (get(x+2,y-1) ~= c1) and (get(x,y-1) ~= c1) and ((get(x+2,y-1) == c2) or (get(x,y-1) == c2)) then
  79. put(x+1, y-1, avgcol);
  80.   end
  81.   if (get(x+2,y-1) == c2) and (get(x+3,y-1) ~= c2) and (get(x+1,y-1) ~= c2) and ((get(x+3,y-1) == c1) or (get(x+1,y-1) == c1)) then
  82. put(x+2, y-1, avgcol);
  83.   end
  84.   if (get(x+3,y-1) == c1) and  (get(x+4,y-1) ~= c1) and (get(x+2,y-1) ~= c1) and ((get(x+4,y-1) == c2) or (get(x+2,y-1) == c2)) then
  85. put(x+3, y-1, avgcol);
  86.   end
  87. end
  88.   end
  89. end
  90.  
  91. -- Remove left dither pattern with 4x1 vertical. Contains some important if then else conditions.--
  92.  
  93. w, h = getpicturesize()
  94.  
  95. for y = 0, h - 4, 1 do
  96.  
  97.   for x = 0, w - 1, 1 do
  98.  
  99. get = getbackuppixel
  100. put = putpicturepixel  
  101. c1 = get(x,y);
  102. c2 = get(x,y+1);
  103. c3 = get(x,y+2);
  104. c4 = get(x,y+3);
  105.    
  106. if (c1 == c3) and (c2 == c4) and  (c1 ~= c2) and (c2 ~= c3) and (get(x+1,y) ~= c1) and (get(x+1,y+1) ~= c2) and (get(x+1,y+2) ~= c3) and (get(x+1,y+3) ~= c4) and (get(x-1,y) ~= c1) and (get(x-1,y+1) ~= c2) and (get(x-1,y+2) ~= c3) and (get(x-1,y+3) ~= c4) and (get(x,y+4) ~=c4) and (get(x,y-1) ~=c1) then
  107.   r1, g1, b1 = getcolor(c1);
  108.   r2, g2, b2 = getcolor(c2);
  109.  
  110.  
  111.   avgcol = transp(c1, c2)
  112.  
  113.   put(x, y, avgcol);
  114.   put(x, y+1, avgcol);
  115.   put(x, y+2, avgcol);
  116.   put(x, y+3, avgcol);
  117.  
  118. -- expand on all 4 directions up --
  119.   if (get(x+1,y) == c2) and ((get(x+1,y+1) ~= c2) or (get(x+1,y-1) == c1)) and ((get(x+1,y+1) == c1) or (get(x+1,y-1) ~= c2)) then
  120. put(x+1, y, avgcol);
  121.   end
  122.   if (get(x+1,y+1) == c1) and ((get(x+1,y+2) ~= c1) or (get(x+1,y) == c2)) and ((get(x+1,y+2) == c2) or (get(x+1,y) ~= c1)) then
  123. put(x+1, y+1, avgcol);
  124.   end
  125.   if (get(x+1,y+2) == c2) and ((get(x+1,y+3) ~= c2) or (get(x+1,y+1) == c1)) and ((get(x+1,y+3) == c1) or (get(x+1,y+1) ~= c2)) then
  126. put(x+1, y+2, avgcol);
  127.   end
  128.   if (get(x+1,y+3) == c1) and  ((get(x+1,y+4) ~= c1) or (get(x+1,y+2) == c2)) and ((get(x+1,y+4) == c2) or (get(x+1,y+2) ~= c1)) then
  129. put(x+1, y+3, avgcol);
  130.   end
  131. -- expand on all 4 directions down --
  132.   if (get(x-1,y) == c2) and ((get(x-1,y+1) ~= c2) or (get(x-1,y-1) == c1)) and ((get(x-1,y+1) == c1) or (get(x-1,y-1) ~= c2)) then
  133. put(x-1, y, avgcol);
  134.   end
  135.   if (get(x-1,y+1) == c1) and ((get(x-1,y+2) ~= c1) or (get(x-1,y) == c2)) and ((get(x-1,y+2) == c2) or (get(x-1,y) ~= c1)) then
  136. put(x-1, y+1, avgcol);
  137.   end
  138.   if (get(x-1,y+2) == c2) and ((get(x-1,y+3) ~= c2) or (get(x-1,y+1) == c1)) and ((get(x-1,y+3) == c1) or (get(x-1,y+1) ~= c2)) then
  139. put(x-1, y+2, avgcol);
  140.   end
  141.   if (get(x-1,y+3) == c1) and  ((get(x-1,y+4) ~= c1) or (get(x-1,y+2) == c2)) and ((get(x-1,y+4) == c2) or (get(x-1,y+2) ~= c1)) then
  142. put(x-1, y+3, avgcol);
  143.   end
  144. end
  145.   end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement