Changeset 483 for trunk/LocalPlayer


Ignore:
Timestamp:
Dec 8, 2023, 11:23:59 AM (13 months ago)
Author:
chronos
Message:
  • Fixed: Small improvements graphics scaling for high DPI.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/Term.pas

    r480 r483  
    713713
    714714procedure InitSmallImp;
    715 const
    716   Cut = 4;
    717   Sharpen = 80;
    718 type
    719   TBuffer = array [0 .. 99999, 0 .. 2] of Integer;
    720 var
    721   Sum: Int64;
    722   Cnt, dx, dy, nx, ny, ix, iy, ir, X, Y, C, ch: Integer;
    723   xdivider, ydivider: Integer;
    724   Resampled: ^TBuffer;
    725   PixelPtr: TPixelPointer;
    726   V: Integer;
    727 begin
    728   nx := BigImp.Width div xSizeBig * xSizeSmall;
    729   ny := BigImp.Height div ySizeBig * ySizeSmall;
    730 
    731   // resample icons
    732   GetMem(Resampled, nx * ny * 12);
    733   FillChar(Resampled^, nx * ny * 12, 0);
    734   BigImp.BeginUpdate;
    735   for ix := 0 to BigImp.Width div xSizeBig - 1 do
    736     for iy := 0 to BigImp.Height div ySizeBig - 1 do begin
    737       PixelPtr := TPixelPointer.Create(BigImp, ScaleToNative(ix * xSizeBig),
    738         ScaleToNative(Cut + iy * ySizeBig));
    739       for Y := 0 to ScaleToNative(ySizeBig - 2 * Cut) - 1 do begin
    740         ydivider := (ScaleFromNative(Y) * ySizeSmall div (ySizeBig - 2 * Cut) + 1) *
    741           (ySizeBig - 2 * Cut) - ScaleFromNative(Y) * ySizeSmall;
    742         if ydivider > ySizeSmall then
    743           ydivider := ySizeSmall;
    744         for X := 0 to ScaleToNative(xSizeBig) - 1 do begin
    745           ir := ix * xSizeSmall + iy * nx * ySizeSmall + ScaleFromNative(X) *
    746             xSizeSmall div xSizeBig + ScaleFromNative(Y) *
    747             ySizeSmall div (ySizeBig - 2 * Cut) * nx;
    748           xdivider := (ScaleFromNative(X) * xSizeSmall div xSizeBig + 1) *
    749             xSizeBig - ScaleFromNative(X) * xSizeSmall;
    750           if xdivider > xSizeSmall then
    751             xdivider := xSizeSmall;
    752           for ch := 0 to 2 do begin
    753             C := PixelPtr.Pixel^.Planes[ch];
    754             Inc(Resampled[ir, ch], C * xdivider * ydivider);
    755             if xdivider < xSizeSmall then
    756               Inc(Resampled[ir + 1, ch], C * (xSizeSmall - xdivider) *
    757                 ydivider);
    758             if ydivider < ySizeSmall then
    759               Inc(Resampled[ir + nx, ch],
    760                 C * xdivider * (ySizeSmall - ydivider));
    761             if (xdivider < xSizeSmall) and (ydivider < ySizeSmall) then
    762               Inc(Resampled[ir + nx + 1, ch], C * (xSizeSmall - xdivider) *
    763                 (ySizeSmall - ydivider));
    764           end;
    765           PixelPtr.NextPixel;
    766         end;
    767         PixelPtr.NextLine;
    768       end;
    769     end;
    770   BigImp.EndUpdate;
    771 
    772   // Sharpen Resampled icons
    773   SmallImp.SetSize(nx, ny);
    774   SmallImp.BeginUpdate;
    775   PixelPtr := TPixelPointer.Create(SmallImp);
    776   for Y := 0 to ScaleToNative(ny) - 1 do begin
    777     for X := 0 to ScaleToNative(nx) - 1 do begin
    778       for ch := 0 to 2 do begin
    779         Sum := 0;
    780         Cnt := 0;
    781         for dy := -1 to 1 do
    782           if ((dy >= 0) or (ScaleFromNative(Y) mod ySizeSmall > 0)) and
    783             ((dy <= 0) or (ScaleFromNative(Y) mod ySizeSmall < ySizeSmall - 1)) then
    784             for dx := -1 to 1 do
    785               if ((dx >= 0) or (ScaleFromNative(X) mod xSizeSmall > 0)) and
    786                 ((dx <= 0) or (ScaleFromNative(X) mod xSizeSmall < xSizeSmall - 1)) then
    787               begin
    788                 V := Resampled[ScaleFromNative(X) + dx + nx * (ScaleFromNative(Y) + dy), ch];
    789                 Inc(Sum, V);
    790                 Inc(Cnt);
    791               end;
    792         V := Resampled[ScaleFromNative(X) + nx * ScaleFromNative(Y), ch];
    793         Sum := ((Cnt * Sharpen + 800) * V - Sum * Sharpen)
    794           div (800 * xSizeBig * (ySizeBig - 2 * Cut));
    795         Sum := Round(Sum / ScaleToNative(ScaleToNative(1)));
    796         if Sum < 0 then Sum := 0;
    797         if Sum > 255 then Sum := 255;
    798         PixelPtr.Pixel^.Planes[ch] := Sum;
    799       end;
    800       PixelPtr.NextPixel;
    801     end;
    802     PixelPtr.NextLine;
    803   end;
    804   SmallImp.EndUpdate;
    805   FreeMem(Resampled);
     715begin
     716  SmallImp.SetSize(BigImp.Width * xSizeSmall div xSizeBig,
     717    BigImp.Height * ySizeSmall div ySizeBig);
     718  UnshareBitmap(SmallImp);
     719  SmallImp.Canvas.StretchDraw(Rect(0, 0, SmallImp.Width, SmallImp.Height), BigImp);
    806720end;
    807721
Note: See TracChangeset for help on using the changeset viewer.