Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Remove dither pattern with horizontal approach - 1 pixel up and own supportedd- will add this for two in future---
- -- Method 2 is different from method 1
- --
- -- This variant needs image to only use colors < 16
- -- Determines which color should store the average of colors i and j.
- -- Only works if i and j are different and both < 16.
- function transp(i, j)
- if i < j then
- return i*15+j+15
- else
- return j*15+i+15
- end
- end
- -- Prepares the palette.
- -- Thanks to DawnBringer for gamma expertise
- -- Gamma factor should be set close to 1.6 for converting images designed on
- -- very low resolutions, up to 2.2 on very high resolutions.
- --
- gamma = 1.8 -- gamma factor.
- for i = 0, 15 do
- for j = i+1, 15 do
- r1, g1, b1 = getcolor(i);
- r2, g2, b2 = getcolor(j);
- r3 = math.pow(((math.pow(r1/255,gamma) + math.pow(r2/255,gamma)) / 2),(1/gamma))*255
- g3 = math.pow(((math.pow(g1/255,gamma) + math.pow(g2/255,gamma)) / 2),(1/gamma))*255
- b3 = math.pow(((math.pow(b1/255,gamma) + math.pow(b2/255,gamma)) / 2),(1/gamma))*255
- setcolor(transp(i,j), r3, g3, b3)
- end
- end
- -- Remove dither pattern with horizontal approach - 1 pixel up and own supportedd- will add it for two in furue---
- w, h = getpicturesize()
- for y = 0, h - 1, 1 do
- for x = 0, w - 4, 1 do
- get = getbackuppixel
- put = putpicturepixel
- c1 = get(x,y);
- c2 = get(x+1,y);
- c3 = get(x+2,y);
- c4 = get(x+3,y);
- 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
- r1, g1, b1 = getcolor(c1);
- r2, g2, b2 = getcolor(c2);
- avgcol = transp(c1, c2)
- put(x, y, avgcol);
- put(x+1, y, avgcol);
- put(x+2, y, avgcol);
- put(x+3, y, avgcol);
- -- expand on all 4 directions up --
- 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
- put(x, y+1, avgcol);
- end
- 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
- put(x+1, y+1, avgcol);
- end
- 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
- put(x+2, y+1, avgcol);
- end
- 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
- put(x+3, y+1, avgcol);
- end
- -- expand on all 4 directions down --
- 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
- put(x, y-1, avgcol);
- end
- 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
- put(x+1, y-1, avgcol);
- end
- 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
- put(x+2, y-1, avgcol);
- end
- 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
- put(x+3, y-1, avgcol);
- end
- end
- end
- end
- -- Remove left dither pattern with 4x1 vertical. Contains some important if then else conditions.--
- w, h = getpicturesize()
- for y = 0, h - 4, 1 do
- for x = 0, w - 1, 1 do
- get = getbackuppixel
- put = putpicturepixel
- c1 = get(x,y);
- c2 = get(x,y+1);
- c3 = get(x,y+2);
- c4 = get(x,y+3);
- 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
- r1, g1, b1 = getcolor(c1);
- r2, g2, b2 = getcolor(c2);
- avgcol = transp(c1, c2)
- put(x, y, avgcol);
- put(x, y+1, avgcol);
- put(x, y+2, avgcol);
- put(x, y+3, avgcol);
- -- expand on all 4 directions up --
- if (get(x+1,y) == c2) and (((get(x+1,y+1) ~= c2) and (get(x+1,y-1) == c1)) or ((get(x+1,y+1) == c1) and (get(x+1,y-1) ~= c2))) then
- put(x+1, y, avgcol);
- end
- if (get(x+1,y+1) == c1) and (((get(x+1,y+2) ~= c1) and (get(x+1,y) == c2)) or ((get(x+1,y+2) == c2) and (get(x+1,y) ~= c1))) then
- put(x+1, y+1, avgcol);
- end
- if (get(x+1,y+2) == c2) and (((get(x+1,y+3) ~= c2) and (get(x+1,y+1) == c1)) or ((get(x+1,y+3) == c1) and (get(x+1,y+1) ~= c2))) then
- put(x+1, y+2, avgcol);
- end
- if (get(x+1,y+3) == c1) and (((get(x+1,y+4) ~= c1) and (get(x+1,y+2) == c2)) or ((get(x+1,y+4) == c2) and (get(x+1,y+2) ~= c1))) then
- put(x+1, y+3, avgcol);
- end
- -- expand on all 4 directions down --
- if (get(x-1,y) == c2) and (((get(x-1,y+1) ~= c2) and (get(x-1,y-1) == c1)) or ((get(x-1,y+1) == c1) and (get(x-1,y-1) ~= c2))) then
- put(x-1, y, avgcol);
- end
- if (get(x-1,y+1) == c1) and (((get(x-1,y+2) ~= c1) and (get(x-1,y) == c2)) or ((get(x-1,y+2) == c2) and (get(x-1,y) ~= c1))) then
- put(x-1, y+1, avgcol);
- end
- if (get(x-1,y+2) == c2) and (((get(x-1,y+3) ~= c2) and (get(x-1,y+1) == c1)) or ((get(x-1,y+3) == c1) and (get(x-1,y+1) ~= c2))) then
- put(x-1, y+2, avgcol);
- end
- if (get(x-1,y+3) == c1) and (((get(x-1,y+4) ~= c1) and (get(x-1,y+2) == c2)) or ((get(x-1,y+4) == c2) and (get(x-1,y+2) ~= c1))) then
- put(x-1, y+3, avgcol);
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement