hedgewars/uLand.pas
changeset 10016 59a6d65fcb60
parent 9998 736015b847e3
child 10018 bdf75f0350bd
equal deleted inserted replaced
10014:56d2f2d5aad8 10016:59a6d65fcb60
    56     SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
    56     SetLength(LandDirty, (LAND_HEIGHT div 32), (LAND_WIDTH div 32));
    57     // 0.5 is already approaching on unplayable
    57     // 0.5 is already approaching on unplayable
    58     if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= 0.5;
    58     if (width div 4096 >= 2) or (height div 2048 >= 2) then cMaxZoomLevel:= 0.5;
    59     cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
    59     cMinMaxZoomLevelDelta:= cMaxZoomLevel - cMinZoomLevel
    60     end;
    60     end;
       
    61 end;
       
    62 
       
    63 { this will make invisible pixels that have a visible neighbor have the
       
    64   same color as their visible neighbor, so that bilinear filtering won't
       
    65   display a "wrongly" colored border when zoomed in }
       
    66 procedure PrettifyLandAlpha();
       
    67 var
       
    68     x, y, lastx, lasty: Longword;
       
    69     lpi, cpi, bpi: boolean; // was last/current/bottom neighbor pixel invisible?
       
    70 begin
       
    71     lasty:= LAND_HEIGHT - 1;
       
    72     lastx:= LAND_WIDTH - 1;
       
    73     if (cReducedQuality and rqBlurryLand) <> 0 then
       
    74         begin
       
    75         lasty:= lasty div 2;
       
    76         lastx:= lastx div 2;
       
    77         end;
       
    78     for y:= 0 to lasty do
       
    79         for x:= 0 to lastx do
       
    80             begin
       
    81             // use first pixel in row as starting point
       
    82             //LandPixels[y, x]:= (LandPixels[y, x] and (BMask or GMask or AMask));
       
    83             if x = 0 then
       
    84                 lpi:= ((LandPixels[y, x] and AMask) = 0)
       
    85             else
       
    86                 begin
       
    87                 cpi:= ((LandPixels[y, x] and AMask) = 0);
       
    88                 if lpi <> cpi then
       
    89                     begin
       
    90                     // invisible pixels get colors from visible neighbors
       
    91                     if cpi then
       
    92                         begin
       
    93                         LandPixels[y, x]:= LandPixels[y, x-1] and not AMask;
       
    94                         // as this pixel is invisible and already colored correctly now, no point in further comparing it
       
    95                         lpi:= cpi;
       
    96                         continue;
       
    97                         end
       
    98                     else
       
    99                         LandPixels[y, x-1]:= LandPixels[y, x] and not AMask;
       
   100                     lpi:= cpi;
       
   101                     end;
       
   102                 end;
       
   103             // also check bottom neighbor, lpi is now current pixel info
       
   104             if y < lasty - 1 then
       
   105                 begin
       
   106                 bpi:= ((LandPixels[y+1, x] and AMask) = 0);
       
   107                 if cpi <> bpi then
       
   108                     begin
       
   109                     if cpi then
       
   110                         LandPixels[y, x]:= LandPixels[y+1, x] and not AMask
       
   111                     else
       
   112                         LandPixels[y+1, x]:= LandPixels[y, x] and not AMask;
       
   113                     end;
       
   114                 end
       
   115             end;
    61 end;
   116 end;
    62 
   117 
    63 
   118 
    64 procedure DrawBorderFromImage(Surface: PSDL_Surface);
   119 procedure DrawBorderFromImage(Surface: PSDL_Surface);
    65 var tmpsurf: PSDL_Surface;
   120 var tmpsurf: PSDL_Surface;
   809                     w:= 255;
   864                     w:= 255;
   810                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
   865                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
   811                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
   866                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
   812                 end
   867                 end
   813     end;
   868     end;
       
   869 
       
   870 PrettifyLandAlpha();
   814 end;
   871 end;
   815 
   872 
   816 procedure GenPreview(out Preview: TPreview);
   873 procedure GenPreview(out Preview: TPreview);
   817 var rh, rw, ox, oy, x, y, xx, yy, t, bit, cbit, lh, lw: LongInt;
   874 var rh, rw, ox, oy, x, y, xx, yy, t, bit, cbit, lh, lw: LongInt;
   818 begin
   875 begin