Ignore:
Timestamp:
May 21, 2020, 7:58:42 PM (4 years ago)
Author:
chronos
Message:
  • Added: Inactive scaling functions for future HighDPI support.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Term.pas

    r227 r245  
    554554  Sharpen = 80;
    555555type
    556   TBuffer = array [0 .. 99999, 0 .. 2] of integer;
     556  TBuffer = array [0 .. 99999, 0 .. 2] of Integer;
    557557var
    558   sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch, xdivider,
    559     ydivider: integer;
    560   resampled: ^TBuffer;
     558  Sum, Cnt, dx, dy, nx, ny, ix, iy, ir, x, y, c, ch: Integer;
     559  xdivider, ydivider: Integer;
     560  Resampled: ^TBuffer;
    561561  PixelPtr: TPixelPointer;
    562562begin
    563   nx := BigImp.width div xSizeBig * xSizeSmall;
    564   ny := BigImp.height div ySizeBig * ySizeSmall;
     563  nx := BigImp.Width div xSizeBig * xSizeSmall;
     564  ny := BigImp.Height div ySizeBig * ySizeSmall;
    565565
    566566  // resample icons
    567   GetMem(resampled, nx * ny * 12);
    568   FillChar(resampled^, nx * ny * 12, 0);
     567  GetMem(Resampled, nx * ny * 12);
     568  FillChar(Resampled^, nx * ny * 12, 0);
    569569  BigImp.BeginUpdate;
    570   for ix := 0 to BigImp.width div xSizeBig - 1 do
    571     for iy := 0 to BigImp.height div ySizeBig - 1 do
    572       for y := 0 to ySizeBig - 2 * cut - 1 do
    573       begin
    574         ydivider := (y * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
    575           (ySizeBig - 2 * cut) - y * ySizeSmall;
     570  for ix := 0 to BigImp.Width div xSizeBig - 1 do
     571    for iy := 0 to BigImp.Height div ySizeBig - 1 do begin
     572      PixelPtr := PixelPointer(BigImp, ScaleToNative(ix * xSizeBig),
     573        ScaleToNative(cut + iy * ySizeBig));
     574      for y := 0 to ScaleToNative(ySizeBig - 2 * cut) - 1 do begin
     575        ydivider := (ScaleFromNative(y) * ySizeSmall div (ySizeBig - 2 * cut) + 1) *
     576          (ySizeBig - 2 * cut) - ScaleFromNative(y) * ySizeSmall;
    576577        if ydivider > ySizeSmall then
    577578          ydivider := ySizeSmall;
    578         PixelPtr := PixelPointer(BigImp, 0, cut + iy * ySizeBig + y);
    579         for x := 0 to xSizeBig - 1 do
    580         begin
    581           ir := ix * xSizeSmall + iy * nx * ySizeSmall + x *
    582             xSizeSmall div xSizeBig + y *
     579        for x := 0 to ScaleToNative(xSizeBig) - 1 do begin
     580          ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(x) *
     581            xSizeSmall div xSizeBig + ScaleFromNative(y) *
    583582            ySizeSmall div (ySizeBig - 2 * cut) * nx;
    584           xdivider := (x * xSizeSmall div xSizeBig + 1) * xSizeBig - x *
    585             xSizeSmall;
     583          xdivider := (ScaleFromNative(x) * xSizeSmall div xSizeBig + 1) *
     584            xSizeBig - ScaleFromNative(x) * xSizeSmall;
    586585          if xdivider > xSizeSmall then
    587586            xdivider := xSizeSmall;
    588           for ch := 0 to 2 do
    589           begin
    590             PixelPtr.SetX(ix * xSizeBig + x);
     587          for ch := 0 to 2 do begin
    591588            c := PixelPtr.Pixel^.Planes[ch];
    592             inc(resampled[ir, ch], c * xdivider * ydivider);
     589            Inc(Resampled[ir, ch], c * xdivider * ydivider);
    593590            if xdivider < xSizeSmall then
    594               inc(resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
     591              Inc(Resampled[ir + 1, ch], c * (xSizeSmall - xdivider) *
    595592                ydivider);
    596593            if ydivider < ySizeSmall then
    597               inc(resampled[ir + nx, ch],
     594              Inc(Resampled[ir + nx, ch],
    598595                c * xdivider * (ySizeSmall - ydivider));
    599596            if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then
    600               inc(resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
     597              Inc(Resampled[ir + nx + 1, ch], c * (xSizeSmall - xdivider) *
    601598                (ySizeSmall - ydivider));
    602599          end;
     600          PixelPtr.NextPixel;
    603601        end;
     602        PixelPtr.NextLine;
    604603      end;
     604    end;
    605605  BigImp.EndUpdate;
    606606
    607   // sharpen resampled icons
     607  // Sharpen Resampled icons
    608608  SmallImp.SetSize(nx, ny);
    609609  SmallImp.BeginUpdate;
    610   for y := 0 to ny - 1 do begin
    611     PixelPtr := PixelPointer(SmallImp, 0, y);
    612     for x := 0 to nx - 1 do
     610  PixelPtr := PixelPointer(SmallImp);
     611  for y := 0 to ScaleToNative(ny) - 1 do begin
     612    for x := 0 to ScaleToNative(nx) - 1 do begin
    613613      for ch := 0 to 2 do begin
    614         sum := 0;
     614        Sum := 0;
    615615        Cnt := 0;
    616616        for dy := -1 to 1 do
    617           if ((dy >= 0) or (y mod ySizeSmall > 0)) and
    618             ((dy <= 0) or (y mod ySizeSmall < ySizeSmall - 1)) then
     617          if ((dy >= 0) or (ScaleFromNative(y) mod ySizeSmall > 0)) and
     618            ((dy <= 0) or (ScaleFromNative(y) mod ySizeSmall < ySizeSmall - 1)) then
    619619            for dx := -1 to 1 do
    620               if ((dx >= 0) or (x mod xSizeSmall > 0)) and
    621                 ((dx <= 0) or (x mod xSizeSmall < xSizeSmall - 1)) then
     620              if ((dx >= 0) or (ScaleFromNative(x) mod xSizeSmall > 0)) and
     621                ((dx <= 0) or (ScaleFromNative(x) mod xSizeSmall < xSizeSmall - 1)) then
    622622              begin
    623                 inc(sum, resampled[x + dx + nx * (y + dy), ch]);
    624                 inc(Cnt);
     623                Inc(Sum, Resampled[ScaleFromNative(x) + dx + nx * (ScaleFromNative(y) + dy), ch]);
     624                Inc(Cnt);
    625625              end;
    626         sum := ((Cnt * Sharpen + 800) * resampled[x + nx * y, ch] - sum *
     626        Sum := ((Cnt * Sharpen + 800) * Resampled[ScaleFromNative(x) + nx * ScaleFromNative(y), ch] - Sum *
    627627          Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * cut));
    628         if sum < 0 then sum := 0;
    629         if sum > 255 then sum := 255;
    630         PixelPtr.SetX(x);
    631         PixelPtr.Pixel^.Planes[ch] := sum;
     628        if Sum < 0 then Sum := 0;
     629        if Sum > 255 then Sum := 255;
     630        PixelPtr.Pixel^.Planes[ch] := Sum;
    632631      end;
     632      PixelPtr.NextPixel;
     633    end;
     634    PixelPtr.NextLine;
    633635  end;
    634636  SmallImp.EndUpdate;
    635   FreeMem(resampled);
     637  FreeMem(Resampled);
    636638end;
    637639
     
    40664068  MiniPixel := PixelPointer(Mini);
    40674069  PrevMiniPixel := PixelPointer(Mini);
    4068   for y := 0 to G.ly - 1 do
    4069   begin
    4070     for x := 0 to G.lx - 1 do
    4071       if MyMap[x + G.lx * y] and fTerrain <> fUNKNOWN then
    4072       begin
    4073         Loc := x + G.lx * y;
     4070  for y := 0 to ScaleToNative(G.ly) - 1 do
     4071  begin
     4072    for x := 0 to ScaleToNative(G.lx) - 1 do
     4073      if MyMap[ScaleFromNative(x) + G.lx * ScaleFromNative(y)] and fTerrain <> fUNKNOWN then
     4074      begin
     4075        Loc := ScaleFromNative(x) + G.lx * ScaleFromNative(y);
    40744076        for i := 0 to 1 do
    40754077        begin
    4076           xm := ((x - xwMini) * 2 + i + y and 1 - hw + G.lx * 5) mod (G.lx * 2);
     4078          xm := ((x - ScaleToNative(xwMini)) * 2 + i + y and 1 - ScaleToNative(hw) +
     4079            ScaleToNative(G.lx) * 5) mod (ScaleToNative(G.lx) * 2);
    40774080          MiniPixel.SetXY(xm, y);
    40784081          cm := MiniColors[MyMap[Loc] and fTerrain, i];
Note: See TracChangeset for help on using the changeset viewer.