diff -r 59a6d65fcb60 -r bdf75f0350bd hedgewars/uTextures.pas --- a/hedgewars/uTextures.pas Sun Jan 19 13:41:11 2014 +0100 +++ b/hedgewars/uTextures.pas Sun Jan 19 14:58:54 2014 +0100 @@ -25,7 +25,8 @@ function NewTexture(width, height: Longword; buf: Pointer): PTexture; procedure Surface2GrayScale(surf: PSDL_Surface); function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; -procedure PrettifySurfaceAlpha(surf: PSDL_Surface; p: PLongwordArray); +procedure PrettifySurfaceAlpha(surf: PSDL_Surface; pixels: PLongwordArray); +procedure PrettifyAlpha2D(pixels: TLandArray; height, width: LongWord); procedure FreeTexture(tex: PTexture); procedure FreeAndNilTexture(var tex: PTexture); @@ -125,51 +126,84 @@ { this will make invisible pixels that have a visible neighbor have the same color as their visible neighbor, so that bilinear filtering won't display a "wrongly" colored border when zoomed in } -procedure PrettifySurfaceAlpha(surf: PSDL_Surface; p: PLongwordArray); +procedure PrettifyAlpha(row1, row2: PLongwordArray; firsti, lasti: LongWord); var - i, lasti: Longword; + i: Longword; lpi, cpi, bpi: boolean; // was last/current/bottom neighbor pixel invisible? begin - lasti:= surf^.w * surf^.h - 1; - for i:=0 to lasti do + for i:=firsti to lasti do begin - // use first pixel in row as starting point - //p^[i]:= p^[i] and (BMask or GMask); - if (i mod surf^.w) = 0 then - lpi:= ((p^[i] and AMask) = 0) + // use first pixel in row1 as starting point + if i = firsti then + lpi:= ((row1^[i] and AMask) = 0) else begin - cpi:= ((p^[i] and AMask) = 0); + cpi:= ((row1^[i] and AMask) = 0); if cpi <> lpi then begin // invisible pixels get colors from visible neighbors - if (p^[i] and AMask) = 0 then + if (row1^[i] and AMask) = 0 then begin - p^[i]:= p^[i-1] and not AMask; + row1^[i]:= row1^[i-1] and not AMask; // as this pixel is invisible and already colored correctly now, no point in further comparing it lpi:= cpi; continue; end else - p^[i-1]:= p^[i] and not AMask; + row1^[i-1]:= row1^[i] and not AMask; lpi:= cpi; end; end; // also check bottom neighbor, lpi is now current pixel info - if i < lasti - surf^.w then + if row2 <> nil then begin - bpi:= ((p^[i + surf^.w] and AMask) = 0); + bpi:= ((row2^[i] and AMask) = 0); if cpi <> bpi then begin if cpi then - p^[i]:= p^[i + surf^.w] and not AMask + row1^[i]:= row2^[i] and not AMask else - p^[i + surf^.w]:= p^[i] and not AMask; + row2^[i]:= row1^[i] and not AMask; end; end; end; end; +procedure PrettifySurfaceAlpha(surf: PSDL_Surface; pixels: PLongwordArray); +var + // current row index, second last row index of array, width and first/last i of row + r, slr, w, si, li: LongWord; +begin + w:= surf^.w; + slr:= surf^.h - 2; + si:= 0; + li:= w - 1; + for r:= 0 to slr do + begin + PrettifyAlpha(pixels, pixels, si, li); + // move indices to next row + si:= si + w; + li:= li + w; + end; + // don't forget last row + PrettifyAlpha(pixels, nil, si, li); +end; + +procedure PrettifyAlpha2D(pixels: TLandArray; height, width: LongWord); +var + // current y; last x, second last y of array; + y, lx, sly: LongWord; +begin + sly:= height - 2; + lx:= width - 1; + for y:= 0 to sly do + begin + PrettifyAlpha(PLongWordArray(pixels[y]), PLongWordArray(pixels[y+1]), 0, lx); + end; + // don't forget last row + PrettifyAlpha(PLongWordArray(pixels[sly+1]), nil, 0, lx); +end; + function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; var tw, th, x, y: Longword; tmpp: pointer;