hedgewars/uLandGraphics.pas
changeset 10877 baad1cc9b749
parent 10864 9cf20f487ee9
child 10878 963bc20f511c
equal deleted inserted replaced
10876:d012728b89b9 10877:baad1cc9b749
   918         end;
   918         end;
   919     end;
   919     end;
   920     Despeckle:= false
   920     Despeckle:= false
   921 end;
   921 end;
   922 
   922 
       
   923 // a bit of AA for explosions
   923 procedure Smooth(X, Y: LongInt);
   924 procedure Smooth(X, Y: LongInt);
       
   925 var c, r, g, b, a, i: integer;
       
   926     nx, ny: LongInt;
       
   927     pixel: LongWord;
       
   928 begin
       
   929 
       
   930 // only AA inwards
       
   931 if (Land[Y, X] and lfDamaged) = 0 then
       
   932     exit;
       
   933 
       
   934 // check location
       
   935 if (Y <= LongInt(topY) + 1) or (Y >= LAND_HEIGHT-2)
       
   936 or (X <= LongInt(leftX) + 1) or (X >= LongInt(rightX) - 1) then
       
   937     exit;
       
   938 
       
   939 // counter for neighbor pixels that are not known to be undamaged
       
   940 c:= 8;
       
   941 
       
   942 // accumalating rgba value of relevant pixels here
       
   943 r:= 0;
       
   944 g:= 0;
       
   945 b:= 0;
       
   946 a:= 0;
       
   947 
       
   948 // iterate over all neighbor pixels (also itself, will be skipped anyway)
       
   949 for nx:= X-1 to X+1 do
       
   950     for ny:= Y-1 to Y+1 do
       
   951         // only consider undamaged neighbors (also leads to skipping itself)
       
   952         if (Land[ny, nx] and lfDamaged) = 0 then
       
   953             begin
       
   954             pixel:= LandPixels[ny, nx];
       
   955             inc(r, (pixel and RMask) shr RShift);
       
   956             inc(g, (pixel and GMask) shr GShift);
       
   957             inc(b, (pixel and BMask) shr BShift);
       
   958             inc(a, (pixel and AMask) shr AShift);
       
   959             dec(c);
       
   960             end;
       
   961 
       
   962 // nothing do to if all neighbors damaged
       
   963 if c < 1 then
       
   964     exit;
       
   965 
       
   966 // use explosion color for damaged pixels
       
   967 for i:= 1 to c do
       
   968     begin
       
   969     inc(r, ExplosionBorderColorR);
       
   970     inc(g, ExplosionBorderColorG);
       
   971     inc(b, ExplosionBorderColorB);
       
   972     inc(a, 255);
       
   973     end;
       
   974 
       
   975 // set resulting color value based on average of all neighbors
       
   976 r:= r div 8;
       
   977 g:= g div 8;
       
   978 b:= b div 8;
       
   979 a:= a div 8;
       
   980 LandPixels[y,x]:= (r shl RShift) or (g shl GShift) or (b shl BShift) or (a shl AShift);
       
   981 
       
   982 end;
       
   983 
       
   984 procedure Smooth_oldImpl(X, Y: LongInt);
   924 begin
   985 begin
   925 // a bit of AA for explosions
   986 // a bit of AA for explosions
   926 if (Land[Y, X] = 0) and (Y > LongInt(topY) + 1) and
   987 if (Land[Y, X] = 0) and (Y > LongInt(topY) + 1) and
   927     (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
   988     (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
   928     begin
   989     begin
  1062                 end;
  1123                 end;
  1063             end;
  1124             end;
  1064         end;
  1125         end;
  1065      end;
  1126      end;
  1066 
  1127 
  1067 for y:= 0 to LAND_HEIGHT div 32 - 1 do
  1128 // smooth explosion borders (except if land is blurry)
  1068     for x:= 0 to LAND_WIDTH div 32 - 1 do
  1129 if (cReducedQuality and rqBlurryLand) = 0 then
  1069         if LandDirty[y, x] <> 0 then
  1130     for y:= 0 to LAND_HEIGHT div 32 - 1 do
  1070             begin
  1131         for x:= 0 to LAND_WIDTH div 32 - 1 do
  1071             ty:= y * 32;
  1132             if LandDirty[y, x] <> 0 then
  1072             tx:= x * 32;
  1133                 begin
  1073             for yy:= ty to ty + 31 do
  1134                 ty:= y * 32;
  1074                 for xx:= tx to tx + 31 do
  1135                 tx:= x * 32;
  1075                     Smooth(xx,yy)
  1136                 for yy:= ty to ty + 31 do
  1076             end;
  1137                     for xx:= tx to tx + 31 do
       
  1138                         Smooth(xx,yy)
       
  1139                 end;
  1077 
  1140 
  1078 for y:= 0 to LAND_HEIGHT div 32 - 1 do
  1141 for y:= 0 to LAND_HEIGHT div 32 - 1 do
  1079     for x:= 0 to LAND_WIDTH div 32 - 1 do
  1142     for x:= 0 to LAND_WIDTH div 32 - 1 do
  1080         if LandDirty[y, x] <> 0 then
  1143         if LandDirty[y, x] <> 0 then
  1081             begin
  1144             begin