hedgewars/uTextures.pas
changeset 10021 7f36194af01c
parent 10018 bdf75f0350bd
child 10040 4ac87acbaed9
equal deleted inserted replaced
10020:67e127027af6 10021:7f36194af01c
   124 end;
   124 end;
   125 
   125 
   126 { this will make invisible pixels that have a visible neighbor have the
   126 { this will make invisible pixels that have a visible neighbor have the
   127   same color as their visible neighbor, so that bilinear filtering won't
   127   same color as their visible neighbor, so that bilinear filtering won't
   128   display a "wrongly" colored border when zoomed in }
   128   display a "wrongly" colored border when zoomed in }
   129 procedure PrettifyAlpha(row1, row2: PLongwordArray; firsti, lasti: LongWord);
   129 procedure PrettifyAlpha(row1, row2: PLongwordArray; firsti, lasti, ioffset: LongWord);
   130 var
   130 var
   131     i: Longword;
   131     i: Longword;
   132     lpi, cpi, bpi: boolean; // was last/current/bottom neighbor pixel invisible?
   132     lpi, cpi, bpi: boolean; // was last/current/bottom neighbor pixel invisible?
   133 begin
   133 begin
       
   134     // suppress incorrect warning
       
   135     lpi:= true;
   134     for i:=firsti to lasti do
   136     for i:=firsti to lasti do
   135         begin
   137         begin
   136         // use first pixel in row1 as starting point
   138         // use first pixel in row1 as starting point
   137         if i = firsti then
   139         if i = firsti then
   138             lpi:= ((row1^[i] and AMask) = 0)
   140             cpi:= ((row1^[i] and AMask) = 0)
   139         else
   141         else
   140             begin
   142             begin
   141             cpi:= ((row1^[i] and AMask) = 0);
   143             cpi:= ((row1^[i] and AMask) = 0);
   142             if cpi <> lpi then
   144             if cpi <> lpi then
   143                 begin
   145                 begin
   144                 // invisible pixels get colors from visible neighbors
   146                 // invisible pixels get colors from visible neighbors
   145                 if (row1^[i] and AMask) = 0 then
   147                 if cpi then
   146                     begin
   148                     begin
   147                     row1^[i]:= row1^[i-1] and not AMask;
   149                     row1^[i]:= row1^[i-1] and not AMask;
   148                     // as this pixel is invisible and already colored correctly now, no point in further comparing it
   150                     // as this pixel is invisible and already colored correctly now, no point in further comparing it
   149                     lpi:= cpi;
   151                     lpi:= cpi;
   150                     continue;
   152                     continue;
   151                     end
   153                     end
   152                 else
   154                 else
   153                     row1^[i-1]:= row1^[i] and not AMask;
   155                     row1^[i-1]:= row1^[i] and not AMask;
   154                 lpi:= cpi;
       
   155                 end;
   156                 end;
   156             end;
   157             end;
   157         // also check bottom neighbor, lpi is now current pixel info
   158         lpi:= cpi;
       
   159         // also check bottom neighbor
   158         if row2 <> nil then
   160         if row2 <> nil then
   159             begin
   161             begin
   160             bpi:= ((row2^[i] and AMask) = 0);
   162             bpi:= ((row2^[i+ioffset] and AMask) = 0);
   161             if cpi <> bpi then
   163             if cpi <> bpi then
   162                 begin
   164                 begin
   163                 if cpi then
   165                 if cpi then
   164                     row1^[i]:= row2^[i] and not AMask
   166                     row1^[i]:= row2^[i+ioffset] and not AMask
   165                 else
   167                 else
   166                     row2^[i]:= row1^[i] and not AMask;
   168                     row2^[i+ioffset]:= row1^[i] and not AMask;
   167                 end;
   169                 end;
   168             end;
   170             end;
   169         end;
   171         end;
   170 end;
   172 end;
   171 
   173 
   178     slr:= surf^.h - 2;
   180     slr:= surf^.h - 2;
   179     si:= 0;
   181     si:= 0;
   180     li:= w - 1;
   182     li:= w - 1;
   181     for r:= 0 to slr do
   183     for r:= 0 to slr do
   182         begin
   184         begin
   183         PrettifyAlpha(pixels, pixels, si, li);
   185         PrettifyAlpha(pixels, pixels, si, li, w);
   184         // move indices to next row
   186         // move indices to next row
   185         si:= si + w;
   187         si:= si + w;
   186         li:= li + w;
   188         li:= li + w;
   187         end;
   189         end;
   188     // don't forget last row
   190     // don't forget last row
   189     PrettifyAlpha(pixels, nil, si, li);
   191     PrettifyAlpha(pixels, nil, si, li, w);
   190 end;
   192 end;
   191 
   193 
   192 procedure PrettifyAlpha2D(pixels: TLandArray; height, width: LongWord);
   194 procedure PrettifyAlpha2D(pixels: TLandArray; height, width: LongWord);
   193 var
   195 var
   194     // current y; last x, second last y of array;
   196     // current y; last x, second last y of array;
   196 begin
   198 begin
   197     sly:= height - 2;
   199     sly:= height - 2;
   198     lx:= width - 1;
   200     lx:= width - 1;
   199     for y:= 0 to sly do
   201     for y:= 0 to sly do
   200         begin
   202         begin
   201         PrettifyAlpha(PLongWordArray(pixels[y]), PLongWordArray(pixels[y+1]), 0, lx);
   203         PrettifyAlpha(PLongWordArray(pixels[y]), PLongWordArray(pixels[y+1]), 0, lx, 0);
   202         end;
   204         end;
   203     // don't forget last row
   205     // don't forget last row
   204     PrettifyAlpha(PLongWordArray(pixels[sly+1]), nil, 0, lx);
   206     PrettifyAlpha(PLongWordArray(pixels[sly+1]), nil, 0, lx, 0);
   205 end;
   207 end;
   206 
   208 
   207 function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
   209 function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
   208 var tw, th, x, y: Longword;
   210 var tw, th, x, y: Longword;
   209     tmpp: pointer;
   211     tmpp: pointer;