Changeset 52 for trunk/LocalPlayer


Ignore:
Timestamp:
Jan 11, 2017, 10:14:11 PM (8 years ago)
Author:
chronos
Message:
  • Fixed: More Bitmap.ScanLine replaced by direct access to RAWImage data.
Location:
trunk/LocalPlayer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LocalPlayer/CityScreen.pas

    r38 r52  
    431431  end;
    432432
    433   procedure MakeRed(x, y, w, h: integer);
    434   type
    435     TLine = array [0 .. 99999, 0 .. 2] of byte;
    436     PLine = ^TLine;
    437 
    438     procedure RedLine(line: PLine; length: integer);
    439     var
    440       i, gray: integer;
    441     begin
    442       for i := 0 to length - 1 do
    443       begin
    444         gray := (integer(line[i, 0]) + integer(line[i, 1]) + integer(line[i, 2])
     433  procedure MakeRed(X, Y, W, H: Integer);
     434  var
     435    XX, YY: Integer;
     436    Gray: Integer;
     437    PixelPtr: PPixel32;
     438    LinePtr: PPixel32;
     439  begin
     440    Offscreen.BeginUpdate;
     441    LinePtr := GetBitmapPixelPtr(Offscreen, X, Y);
     442    for YY := 0 to h - 1 do begin
     443      PixelPtr := LinePtr;
     444      for XX := 0 to w - 1 do begin
     445        Gray := (Integer(PixelPtr^.B) + Integer(PixelPtr^.G) + Integer(PixelPtr^.R)
    445446          ) * 85 shr 8;
    446         line[i, 0] := 0;
    447         line[i, 1] := 0;
    448         line[i, 2] := gray; // 255-(255-gray) div 2;
     447        PixelPtr^.B := 0;
     448        PixelPtr^.G := 0;
     449        PixelPtr^.R := Gray; // 255-(255-gray) div 2;
     450        PixelPtr := Pointer(PixelPtr) + (Offscreen.RawImage.Description.BitsPerPixel shr 3);
    449451      end;
    450     end;
    451 
    452   var
    453     i: integer;
    454   begin
    455     Offscreen.BeginUpdate;
    456     for i := 0 to h - 1 do
    457       RedLine(@(PLine(offscreen.ScanLine[y + i])[x]), w);
     452      LinePtr := Pointer(LinePtr) + Offscreen.RawImage.Description.BytesPerLine;
     453    end;
    458454    Offscreen.EndUpdate;
    459455  end;
  • trunk/LocalPlayer/Help.pas

    r51 r52  
    365365  nHeaven = 28;
    366366  maxsum = 9 * 9 * 255 * 75 div 100;
    367 type
    368   TLine = array [0 .. 649, 0 .. 2] of Byte;
    369367var
    370368  x, y, dx, dy, xSrc, ySrc, sum, xx: integer;
    371369  Heaven: array [0 .. nHeaven] of integer;
    372   PaintLine, CoalLine: ^TLine;
    373   ImpLine: array [-1 .. 1] of ^TLine;
     370  PaintPtr, CoalPtr: TPixelPointer;
     371  ImpPtr: array [-1 .. 1] of TPixelPointer;
    374372begin
    375373  // assume eiffel tower has free common heaven
     
    385383    if (y0 + y >= 0) and (y0 + y < InnerHeight) then
    386384    begin
    387       PaintLine := OffScreen.ScanLine[y0 + y];
    388       CoalLine := Templates.ScanLine[yCoal + y];
     385      PaintPtr.Init(OffScreen, 0, y0 + y);
     386      CoalPtr.Init(Templates, 0, yCoal + y);
    389387      for dy := -1 to 1 do
    390388        if ((y + dy) shr 1 >= 0) and ((y + dy) shr 1 < ySizeBig) then
    391           ImpLine[dy] := BigImp.ScanLine[ySrc + (y + dy) shr 1];
     389          ImpPtr[dy].Init(BigImp, 0, ySrc + (y + dy) shr 1);
    392390      for x := 0 to xSizeBig * 2 - 1 do
    393391      begin
     
    396394        begin
    397395          xx := xSrc + (x + dx) shr 1;
     396          ImpPtr[dy].SetX(xx);
    398397          for dy := -1 to 1 do
    399398            if ((y + dy) shr 1 < 0) or ((y + dy) shr 1 >= ySizeBig) or
    400399              ((x + dx) shr 1 < 0) or ((x + dx) shr 1 >= xSizeBig) or
    401400              ((y + dy) shr 1 < nHeaven) and
    402               (ImpLine[dy, xx, 0] shl 16 + ImpLine[dy, xx, 1] shl 8 +
    403               ImpLine[dy, xx, 2] = Heaven[(y + dy) shr 1]) then
     401              (ImpPtr[dy].Pixel^.B shl 16 + ImpPtr[dy].Pixel^.G shl 8 +
     402              ImpPtr[dy].Pixel^.R = Heaven[(y + dy) shr 1]) then
    404403              sum := sum + 9 * 255
    405404            else
    406               sum := sum + ImpLine[dy, xx, 0] + 5 * ImpLine[dy, xx, 1] + 3 *
    407                 ImpLine[dy, xx, 2];
     405              sum := sum + ImpPtr[dy].Pixel^.B + 5 * ImpPtr[dy].Pixel^.G + 3 *
     406                ImpPtr[dy].Pixel^.R;
    408407        end;
    409408        if sum < maxsum then
    410409        begin // no saturation
    411           sum := 1 shl 22 - (maxsum - sum) * (256 - CoalLine[xCoal + x, 0] * 2);
    412           PaintLine[x0 + x, 0] := PaintLine[x0 + x, 0] * sum shr 22;
    413           PaintLine[x0 + x, 1] := PaintLine[x0 + x, 1] * sum shr 22;
    414           PaintLine[x0 + x, 2] := PaintLine[x0 + x, 2] * sum shr 22;
     410          CoalPtr.SetX(xCoal + x);
     411          sum := 1 shl 22 - (maxsum - sum) * (256 - CoalPtr.Pixel^.B * 2);
     412          PaintPtr.SetX(x0 + x);
     413          PaintPtr.Pixel^.B := PaintPtr.Pixel^.B * sum shr 22;
     414          PaintPtr.Pixel^.G := PaintPtr.Pixel^.G * sum shr 22;
     415          PaintPtr.Pixel^.R := PaintPtr.Pixel^.R * sum shr 22;
    415416        end;
    416417      end;
  • trunk/LocalPlayer/TechTree.pas

    r38 r52  
    120120
    121121procedure TTechTreeDlg.FormShow(Sender: TObject);
    122 type
    123   TLine = array [0 .. 9999, 0 .. 2] of Byte;
    124122var
    125123  X, Y, ad, TexWidth, TexHeight: Integer;
    126124  s: string;
    127   SrcLine, DstLine: ^TLine;
     125  SrcPixel, DstPixel: PPixel32;
    128126begin
    129127  if Image = nil then
     
    171169    for Y := 0 to Image.height - 1 do
    172170    begin
    173       SrcLine := Paper.ScanLine[Y mod TexHeight];
    174       DstLine := Image.ScanLine[Y];
    175171      for X := 0 to Image.width - 1 do
    176172      begin
    177         if Cardinal((@DstLine[X])^) and $FFFFFF = $7F007F then // transparent
    178           DstLine[X] := SrcLine[X mod TexWidth];
     173        DstPixel := GetBitmapPixelPtr(Image, X, Y);
     174        if (DstPixel^.ARGB and $FFFFFF) = $7F007F then // transparent
     175        begin
     176          SrcPixel := GetBitmapPixelPtr(Paper, X mod TexWidth, Y mod TexHeight);
     177          DstPixel^.B := SrcPixel^.B;
     178          DstPixel^.G := SrcPixel^.G;
     179          DstPixel^.R := SrcPixel^.R;
     180        end;
    179181      end;
    180182    end;
  • trunk/LocalPlayer/Term.pas

    r50 r52  
    506506  Sharpen = 80;
    507507type
    508   TLine = array [0 .. 99999, 0 .. 2] of Byte;
    509508  TBuffer = array [0 .. 99999, 0 .. 2] of integer;
    510509var
     
    512511    ydivider: integer;
    513512  resampled: ^TBuffer;
    514   line: ^TLine;
     513  PixelPtr: TPixelPointer;
    515514begin
    516515  nx := BigImp.width div xSizeBig * xSizeSmall;
     
    529528        if ydivider > ySizeSmall then
    530529          ydivider := ySizeSmall;
    531         line := BigImp.ScanLine[cut + iy * ySizeBig + y];
     530        PixelPtr.Init(BigImp, 0, cut + iy * ySizeBig + y);
    532531        for x := 0 to xSizeBig - 1 do
    533532        begin
     
    541540          for ch := 0 to 2 do
    542541          begin
    543             c := line[ix * xSizeBig + x, ch];
     542            PixelPtr.SetX(ix * xSizeBig + x);
     543            c := PixelPtr.Pixel^.Planes[ch];
    544544            inc(resampled[ir, ch], c * xdivider * ydivider);
    545545            if xdivider < xSizeSmall then
     
    558558
    559559  // sharpen resampled icons
    560   SmallImp.width := nx;
    561   SmallImp.height := ny;
     560  SmallImp.SetSize(nx, ny);
    562561  SmallImp.BeginUpdate;
    563   for y := 0 to ny - 1 do
    564   begin
    565     line := SmallImp.ScanLine[y];
     562  for y := 0 to ny - 1 do begin
     563    PixelPtr.Init(SmallImp, 0, y);
    566564    for x := 0 to nx - 1 do
    567       for ch := 0 to 2 do
    568       begin
     565      for ch := 0 to 2 do begin
    569566        sum := 0;
    570567        Cnt := 0;
     
    581578        sum := ((Cnt * Sharpen + 800) * resampled[x + nx * y, ch] - sum *
    582579          Sharpen) div (800 * xSizeBig * (ySizeBig - 2 * cut));
    583         if sum < 0 then
    584           sum := 0;
    585         if sum > 255 then
    586           sum := 255;
    587         line[x][ch] := sum;
     580        if sum < 0 then sum := 0;
     581        if sum > 255 then sum := 255;
     582        PixelPtr.SetX(x);
     583        PixelPtr.Pixel^.Planes[ch] := sum;
    588584      end;
    589585  end;
     
    40664062
    40674063procedure TMainScreen.MiniPaint;
    4068 type
    4069   TLine = array [0 .. 99999999, 0 .. 2] of Byte;
    40704064var
    40714065  uix, cix, x, y, Loc, i, hw, xm, cm, cmPolOcean, cmPolNone: integer;
    4072   PrevMiniLine, MiniLine: ^TLine;
     4066  PrevMiniPixel, MiniPixel: PPixel32;
    40734067begin
    40744068  cmPolOcean := GrExt[HGrSystem].Data.Canvas.Pixels[101, 67];
     
    40804074    FillRect(Rect(0, 0, Mini.width, Mini.height));
    40814075  end;
    4082   MiniLine := nil;
    40834076  Mini.BeginUpdate;
    40844077  for y := 0 to G.ly - 1 do
    40854078  begin
    4086     PrevMiniLine := MiniLine;
    4087     MiniLine := Mini.ScanLine[y];
    40884079    for x := 0 to G.lx - 1 do
    40894080      if MyMap[x + G.lx * y] and fTerrain <> fUNKNOWN then
     
    40934084        begin
    40944085          xm := ((x - xwMini) * 2 + i + y and 1 - hw + G.lx * 5) mod (G.lx * 2);
     4086          MiniPixel := GetBitmapPixelPtr(Mini, xm, y);
    40954087          cm := MiniColors[MyMap[Loc] and fTerrain, i];
    40964088          if ClientMode = cEditMap then
     
    41154107            end;
    41164108            cm := $808080 or cm shr 1; { increase brightness }
    4117             if PrevMiniLine <> nil then
    4118             begin // 2x2 city dot covers two scanlines
    4119               PrevMiniLine[xm, 0] := cm shr 16;
    4120               PrevMiniLine[xm, 1] := cm shr 8 and $FF;
    4121               PrevMiniLine[xm, 2] := cm and $FF;
     4109            if y > 0 then begin
     4110              // 2x2 city dot covers two scanlines
     4111              PrevMiniPixel := GetBitmapPixelPtr(Mini, xm, y - 1);
     4112              PrevMiniPixel^.B := cm shr 16;
     4113              PrevMiniPixel^.G := cm shr 8 and $FF;
     4114              PrevMiniPixel^.R := cm and $FF;
    41224115            end
    41234116          end
     
    41484141              cm := Tribe[MyRO.Territory[Loc]].Color;
    41494142          end;
    4150           MiniLine[xm, 0] := cm shr 16;
    4151           MiniLine[xm, 1] := cm shr 8 and $FF;
    4152           MiniLine[xm, 2] := cm and $FF;
     4143          MiniPixel^.B := cm shr 16;
     4144          MiniPixel^.G := cm shr 8 and $FF;
     4145          MiniPixel^.R := cm and $FF;
    41534146        end;
    41544147      end;
  • trunk/LocalPlayer/Wonders.pas

    r38 r52  
    7878
    7979procedure TWondersDlg.OffscreenPaint;
    80 type
    81   TLine = array [0 .. 649, 0 .. 2] of Byte;
    8280
    8381  procedure DarkIcon(i: Integer);
    8482  var
    8583    X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;
    86     Src, Dst: ^TLine;
     84    Src, Dst: PPixel32;
    8785  begin
    8886    x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i, 0];
     
    9088    x0Src := (i mod 7) * xSizeBig;
    9189    y0Src := (i div 7 + SystemIconLines) * ySizeBig;
    92     for Y := 0 to ySizeBig - 1 do
    93     begin
    94       Src := BigImp.ScanLine[y0Src + Y];
    95       Dst := Offscreen.ScanLine[y0Dst + Y];
    96       for X := 0 to xSizeBig - 1 do
    97       begin
    98         darken := ((255 - Src[x0Src + X][0]) * 3 + (255 - Src[x0Src + X][1]) *
    99           15 + (255 - Src[x0Src + X][2]) * 9) div 128;
    100         for ch := 0 to 2 do
    101         begin
    102           c := Dst[x0Dst + X][ch] - darken;
    103           if c < 0 then
    104             Dst[x0Dst + X][ch] := 0
    105           else
    106             Dst[x0Dst + X][ch] := c;
     90    for Y := 0 to ySizeBig - 1 do begin
     91      for X := 0 to xSizeBig - 1 do begin
     92        Src := GetBitmapPixelPtr(BigImp, x0Src + X, y0Src + Y);
     93        Dst := GetBitmapPixelPtr(Offscreen, x0Dst + X, y0Dst + Y);
     94        darken := ((255 - Src^.B) * 3 + (255 - Src^.G) *
     95          15 + (255 - Src^.R) * 9) div 128;
     96        for ch := 0 to 2 do begin
     97          c := Dst^.Planes[ch] - darken;
     98          if c < 0 then Dst^.Planes[ch] := 0
     99            else Dst^.Planes[ch] := c;
    107100        end
    108101      end
     
    129122  i, X, Y, r, ax, ch, c: Integer;
    130123  HaveWonder: boolean;
    131   Line: array [0 .. 1] of ^TLine;
     124  Line: array [0 .. 1] of PPixel32;
    132125  s: string;
    133126begin
     
    160153  xm := ClientWidth div 2;
    161154  ym := ClientHeight div 2;
    162   for Y := 0 to 127 do
    163   begin
    164     Line[0] := Offscreen.ScanLine[ym + Y];
    165     Line[1] := Offscreen.ScanLine[ym - 1 - Y];
    166     for X := 0 to 179 do
    167     begin
     155  for Y := 0 to 127 do begin
     156    for X := 0 to 179 do begin
    168157      r := X * X * (32 * 32) + Y * Y * (45 * 45);
    169158      ax := ((1 shl 16 div 32) * 45) * Y;
     
    173162        ((ax < amax1 * X) or (ax > amin3 * X))) then
    174163        for i := 0 to 1 do
    175           for ch := 0 to 2 do
    176           begin
    177             c := Line[i][xm + X][ch] - darken;
     164          for ch := 0 to 2 do begin
     165            Line[0] := GetBitmapPixelPtr(Offscreen, xm + X, ym + Y);
     166            Line[1] := GetBitmapPixelPtr(Offscreen, xm + X, ym - 1 - Y);
     167            c := Line[i]^.Planes[ch] - darken;
    178168            if c < 0 then
    179               Line[i][xm + X][ch] := 0
     169              Line[i]^.Planes[ch] := 0
    180170            else
    181               Line[i][xm + X][ch] := c;
    182             c := Line[i][xm - 1 - X][ch] - darken;
     171              Line[i]^.Planes[ch] := c;
     172            Line[0] := GetBitmapPixelPtr(Offscreen, xm - 1 - X, ym + Y);
     173            Line[1] := GetBitmapPixelPtr(Offscreen, xm - 1 - X, ym - 1 - Y);
     174            c := Line[i]^.Planes[ch] - darken;
    183175            if c < 0 then
    184               Line[i][xm - 1 - X][ch] := 0
     176              Line[i]^.Planes[ch] := 0
    185177            else
    186               Line[i][xm - 1 - X][ch] := c;
     178              Line[i]^.Planes[ch] := c;
    187179          end;
    188180    end;
Note: See TracChangeset for help on using the changeset viewer.