Changeset 72


Ignore:
Timestamp:
Jan 15, 2017, 11:47:01 AM (7 years ago)
Author:
chronos
Message:
  • Modified: Unified direct pixel access using TPixelPointer.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Integrated.lpi

    r69 r72  
    450450        <StackChecks Value="True"/>
    451451      </Checks>
    452       <VerifyObjMethodCallValidity Value="True"/>
    453452    </CodeGeneration>
    454453    <Linking>
  • trunk/LocalPlayer/CityScreen.pas

    r71 r72  
    438438    XX, YY: Integer;
    439439    Gray: Integer;
    440     PixelPtr: PPixel32;
    441     LinePtr: PPixel32;
     440    PixelPtr: TPixelPointer;
    442441  begin
    443442    Offscreen.BeginUpdate;
    444     LinePtr := GetBitmapPixelPtr(Offscreen, X, Y);
     443    PixelPtr.Init(Offscreen, X, Y);
    445444    for YY := 0 to h - 1 do begin
    446       PixelPtr := LinePtr;
    447445      for XX := 0 to w - 1 do begin
    448         Gray := (Integer(PixelPtr^.B) + Integer(PixelPtr^.G) + Integer(PixelPtr^.R)
    449           ) * 85 shr 8;
    450         PixelPtr^.B := 0;
    451         PixelPtr^.G := 0;
    452         PixelPtr^.R := Gray; // 255-(255-gray) div 2;
    453         PixelPtr := Pointer(PixelPtr) + (Offscreen.RawImage.Description.BitsPerPixel shr 3);
     446        Gray := (Integer(PixelPtr.Pixel^.B) + Integer(PixelPtr.Pixel^.G) +
     447        Integer(PixelPtr.Pixel^.R)) * 85 shr 8;
     448        PixelPtr.Pixel^.B := 0;
     449        PixelPtr.Pixel^.G := 0;
     450        PixelPtr.Pixel^.R := Gray; // 255-(255-gray) div 2;
     451        PixelPtr.NextPixel;
    454452      end;
    455       LinePtr := Pointer(LinePtr) + Offscreen.RawImage.Description.BytesPerLine;
     453      PixelPtr.NextLine;
    456454    end;
    457455    Offscreen.EndUpdate;
  • trunk/LocalPlayer/TechTree.pas

    r57 r72  
    123123  X, Y, ad, TexWidth, TexHeight: Integer;
    124124  s: string;
    125   SrcPixel, DstPixel: PPixel32;
     125  SrcPixel, DstPixel: TPixelPointer;
    126126begin
    127127  if Image = nil then
     
    165165    // texturize background
    166166    Image.BeginUpdate;
    167     TexWidth := Paper.width;
    168     TexHeight := Paper.height;
    169     for Y := 0 to Image.height - 1 do
    170     begin
    171       for X := 0 to Image.width - 1 do
    172       begin
    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;
     167    TexWidth := Paper.Width;
     168    TexHeight := Paper.Height;
     169    DstPixel.Init(Image);
     170    SrcPixel.Init(Paper);
     171    for Y := 0 to Image.Height - 1 do begin
     172      for X := 0 to Image.Width - 1 do begin
     173        if (DstPixel.Pixel^.ARGB and $FFFFFF) = $7F007F then begin // transparent
     174          SrcPixel.SetXY(X mod TexWidth, Y mod TexHeight);
     175          DstPixel.Pixel^.B := SrcPixel.Pixel^.B;
     176          DstPixel.Pixel^.G := SrcPixel.Pixel^.G;
     177          DstPixel.Pixel^.R := SrcPixel.Pixel^.R;
    180178        end;
     179        DstPixel.NextPixel;
    181180      end;
     181      DstPixel.NextLine;
    182182    end;
    183183    Image.EndUpdate;
  • trunk/LocalPlayer/Term.pas

    r69 r72  
    40544054var
    40554055  uix, cix, x, y, Loc, i, hw, xm, cm, cmPolOcean, cmPolNone: integer;
    4056   PrevMiniPixel, MiniPixel: PPixel32;
     4056  PrevMiniPixel, MiniPixel: TPixelPointer;
    40574057begin
    40584058  cmPolOcean := GrExt[HGrSystem].Data.Canvas.Pixels[101, 67];
     
    40654065  end;
    40664066  Mini.BeginUpdate;
     4067  MiniPixel.Init(Mini);
     4068  PrevMiniPixel.Init(Mini);
    40674069  for y := 0 to G.ly - 1 do
    40684070  begin
     
    40744076        begin
    40754077          xm := ((x - xwMini) * 2 + i + y and 1 - hw + G.lx * 5) mod (G.lx * 2);
    4076           MiniPixel := GetBitmapPixelPtr(Mini, xm, y);
     4078          MiniPixel.SetXY(xm, y);
    40774079          cm := MiniColors[MyMap[Loc] and fTerrain, i];
    40784080          if ClientMode = cEditMap then
     
    40994101            if y > 0 then begin
    41004102              // 2x2 city dot covers two lines
    4101               PrevMiniPixel := GetBitmapPixelPtr(Mini, xm, y - 1);
    4102               PrevMiniPixel^.B := cm shr 16;
    4103               PrevMiniPixel^.G := cm shr 8 and $FF;
    4104               PrevMiniPixel^.R := cm and $FF;
     4103              PrevMiniPixel.SetXY(xm, y - 1);
     4104              PrevMiniPixel.Pixel^.B := cm shr 16;
     4105              PrevMiniPixel.Pixel^.G := cm shr 8 and $FF;
     4106              PrevMiniPixel.Pixel^.R := cm and $FF;
    41054107            end
    41064108          end
     
    41314133              cm := Tribe[MyRO.Territory[Loc]].Color;
    41324134          end;
    4133           MiniPixel^.B := cm shr 16;
    4134           MiniPixel^.G := cm shr 8 and $FF;
    4135           MiniPixel^.R := cm and $FF;
     4135          MiniPixel.Pixel^.B := cm shr 16;
     4136          MiniPixel.Pixel^.G := cm shr 8 and $FF;
     4137          MiniPixel.Pixel^.R := cm and $FF;
    41364138        end;
    41374139      end;
  • trunk/LocalPlayer/Wonders.pas

    r52 r72  
    8282  var
    8383    X, Y, ch, x0Dst, y0Dst, x0Src, y0Src, darken, c: Integer;
    84     Src, Dst: PPixel32;
     84    Src, Dst: TPixelPointer;
    8585  begin
    8686    x0Dst := ClientWidth div 2 - xSizeBig div 2 + RingPosition[i, 0];
     
    8888    x0Src := (i mod 7) * xSizeBig;
    8989    y0Src := (i div 7 + SystemIconLines) * ySizeBig;
     90    Src.Init(BigImp, x0Src, y0Src);
     91    Dst.Init(Offscreen, x0Dst, y0Dst);
    9092    for Y := 0 to ySizeBig - 1 do begin
    9193      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;
     94        Darken := ((255 - Src.Pixel^.B) * 3 + (255 - Src.Pixel^.G) *
     95          15 + (255 - Src.Pixel^.R) * 9) div 128;
    9696        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;
    100         end
    101       end
     97          c := Dst.Pixel^.Planes[ch] - Darken;
     98          if c < 0 then Dst.Pixel^.Planes[ch] := 0
     99            else Dst.Pixel^.Planes[ch] := c;
     100        end;
     101        Src.NextPixel;
     102        Dst.NextPixel;
     103      end;
     104      Src.NextLine;
     105      Dst.NextLine;
    102106    end;
    103107  end;
     
    122126  i, X, Y, r, ax, ch, c: Integer;
    123127  HaveWonder: boolean;
    124   Line: array [0 .. 1] of PPixel32;
     128  Line: array [0..1] of TPixelPointer;
    125129  s: string;
    126130begin
     
    153157  xm := ClientWidth div 2;
    154158  ym := ClientHeight div 2;
     159  Line[0].Init(Offscreen);
     160  Line[1].Init(Offscreen);
    155161  for Y := 0 to 127 do begin
    156162    for X := 0 to 179 do begin
     
    163169        for i := 0 to 1 do
    164170          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;
    168             if c < 0 then
    169               Line[i]^.Planes[ch] := 0
    170             else
    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;
    175             if c < 0 then
    176               Line[i]^.Planes[ch] := 0
    177             else
    178               Line[i]^.Planes[ch] := c;
     171            Line[0].SetXY(xm + X, ym + Y);
     172            Line[1].SetXY(xm + X, ym - 1 - Y);
     173            c := Line[i].Pixel^.Planes[ch] - darken;
     174            if c < 0 then Line[i].Pixel^.Planes[ch] := 0
     175              else Line[i].Pixel^.Planes[ch] := c;
     176            Line[0].SetXY(xm - 1 - X, ym + Y);
     177            Line[1].SetXY(xm - 1 - X, ym - 1 - Y);
     178            c := Line[i].Pixel^.Planes[ch] - darken;
     179            if c < 0 then Line[i].Pixel^.Planes[ch] := 0
     180              else Line[i].Pixel^.Planes[ch] := c;
    179181          end;
    180182    end;
  • trunk/ScreenTools.pas

    r68 r72  
    3535    Pixel: PPixel32;
    3636    Line: PPixel32;
     37    RelLine: PPixel32;
    3738    BytesPerPixel: Integer;
    3839    BytesPerLine: Integer;
    39     procedure NextLine; inline;
    40     procedure NextPixel; inline;
    41     procedure SetXY(X, Y: Integer); inline;
    42     procedure SetX(X: Integer); inline;
    43     procedure Init(Bitmap: TBitmap; X: Integer = 0; Y: Integer = 0); inline;
     40    procedure NextLine; inline; // Move pointer to start of new base line
     41    procedure NextPixel; inline; // Move pointer to next pixel
     42    procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base
     43    procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base
     44    procedure Init(Bitmap: TBitmap; BaseX: Integer = 0; BaseY: Integer = 0); inline;
    4445  end;
    4546  PPixelPointer = ^TPixelPointer;
     
    4849function ChangeResolution(x, y, bpp, freq: integer): boolean;
    4950{$ENDIF}
    50 function GetBitmapPixelPtr(Bitmap: TBitmap; X, Y: Integer): PPixel32;
    5151procedure RestoreResolution;
    5252function Play(Item: string; Index: integer = -1): boolean;
     
    298298end;
    299299
    300 function GetBitmapPixelPtr(Bitmap: TBitmap; X, Y: Integer): PPixel32;
    301 begin
    302   Result := Pointer(Bitmap.RawImage.Data) + X * (Bitmap.RawImage.Description.BitsPerPixel shr 3) + Y * Bitmap.RawImage.Description.BytesPerLine;
    303 end;
    304 
    305300procedure EmptyMenu(MenuItems: TMenuItem; Keep: integer = 0);
    306301var
     
    464459  begin
    465460    Bmp.BeginUpdate;
    466     PixelPtr.Init(bmp, 0, 0);
     461    PixelPtr.Init(bmp);
    467462    for Y := 0 to Bmp.Height - 1 do begin
    468463      for X := 0 to Bmp.Width - 1 do begin
     
    483478  FileName: string;
    484479  Source: TBitmap;
    485   DataPixel, MaskPixel: PPixel32;
     480  DataPixel, MaskPixel: TPixelPointer;
    486481begin
    487482  i := 0;
     
    517512    GrExt[nGrExt].Data.BeginUpdate;
    518513    GrExt[nGrExt].Mask.BeginUpdate;
    519     for y := 0 to Source.Height - 1 do
    520     begin
    521       for x := 0 to xmax - 1 do
    522       begin
    523         DataPixel := GetBitmapPixelPtr(GrExt[nGrExt].Data, x, y);
    524         MaskPixel := GetBitmapPixelPtr(GrExt[nGrExt].Mask, x, Y);
    525 
    526         OriginalColor := DataPixel^.ARGB and $FFFFFF;
    527         if (OriginalColor = $FF00FF) or (OriginalColor = $7F007F) then
    528         begin // transparent
    529           MaskPixel^.ARGB := $FFFFFF;
    530           DataPixel^.ARGB := DataPixel^.ARGB and $FF000000
    531         end
    532         else
    533         begin
    534           MaskPixel^.ARGB := $000000; // non-transparent
    535           if Gamma <> 100 then
    536           begin
    537             DataPixel^.B := GammaLUT[DataPixel^.B];
    538             DataPixel^.G := GammaLUT[DataPixel^.G];
    539             DataPixel^.R := GammaLUT[DataPixel^.R];
    540           end
    541         end
    542       end
     514    DataPixel.Init(GrExt[nGrExt].Data);
     515    MaskPixel.Init(GrExt[nGrExt].Mask);
     516    for y := 0 to Source.Height - 1 do begin
     517      for x := 0 to xmax - 1 do begin
     518        OriginalColor := DataPixel.Pixel^.ARGB and $FFFFFF;
     519        if (OriginalColor = $FF00FF) or (OriginalColor = $7F007F) then begin // transparent
     520          MaskPixel.Pixel^.ARGB := $FFFFFF;
     521          DataPixel.Pixel^.ARGB := DataPixel.Pixel^.ARGB and $FF000000
     522        end else begin
     523          MaskPixel.Pixel^.ARGB := $000000; // non-transparent
     524          if Gamma <> 100 then begin
     525            DataPixel.Pixel^.B := GammaLUT[DataPixel.Pixel^.B];
     526            DataPixel.Pixel^.G := GammaLUT[DataPixel.Pixel^.G];
     527            DataPixel.Pixel^.R := GammaLUT[DataPixel.Pixel^.R];
     528          end;
     529        end;
     530        DataPixel.NextPixel;
     531        MaskPixel.NextPixel;
     532      end;
     533      DataPixel.NextLine;
     534      MaskPixel.NextLine;
    543535    end;
    544536    GrExt[nGrExt].Data.EndUpdate;
     
    562554begin
    563555  Dst.BeginUpdate;
    564   PixelPtr.Init(Dst, 0, 0);
     556  PixelPtr.Init(Dst);
    565557  for yy := 0 to h - 1 do begin
    566558    for xx := 0 to w - 1 do begin
     
    580572var
    581573  X, Y: Integer;
    582   Brightness, test: integer;
    583   PixelSrc: ^Byte;
    584   PixelDst: PPixel32;
    585 begin
    586   //TODO Assert(Src.PixelFormat = pf8bit);
     574  Brightness, Test: Integer;
     575  PixelSrc: TPixelPointer;
     576  PixelDst: TPixelPointer;
     577  pf: TPixelFormat;
     578begin
     579  pf := src.PixelFormat;
     580  //Assert(Src.PixelFormat = pf8bit);
    587581  Assert(dst.PixelFormat = pf24bit);
    588582  if xDst < 0 then
     
    607601  dst.BeginUpdate;
    608602  Src.BeginUpdate;
     603  PixelDst.Init(Dst, xDst, yDst);
     604  PixelSrc.Init(Src, xSrc, ySrc);
    609605  for Y := 0 to h - 1 do begin
    610     PixelDst := GetBitmapPixelPtr(dst, xDst, yDst + Y);
    611     PixelSrc := Pointer(GetBitmapPixelPtr(Src, xSrc, ySrc + Y));
    612606    for X := 0 to w - 1 do begin
    613       Brightness := PixelSrc^;
    614       test := (PixelDst^.R * Brightness) shr 7;
    615       if test >= 256 then PixelDst^.R := 255
    616         else PixelDst^.R := test; // Red
    617       test := (PixelDst^.G * Brightness) shr 7;
    618       if test >= 256 then PixelDst^.G := 255
    619         else PixelDst^.G := test; // Green
    620       test := (PixelDst^.B * Brightness) shr 7;
    621       if test >= 256 then
    622         PixelDst^.R := 255
    623       else
    624         PixelDst^.B := test; // Blue
    625       PixelDst := Pointer(PixelDst) + (Dst.RawImage.Description.BitsPerPixel shr 3);
    626       PixelSrc := Pointer(PixelSrc) + (Src.RawImage.Description.BitsPerPixel shr 3);
    627     end;
     607      Brightness := PixelSrc.Pixel^.B; // One byte for 8-bit color
     608      test := (PixelDst.Pixel^.R * Brightness) shr 7;
     609      if test >= 256 then PixelDst.Pixel^.R := 255
     610        else PixelDst.Pixel^.R := test; // Red
     611      test := (PixelDst.Pixel^.G * Brightness) shr 7;
     612      if test >= 256 then PixelDst.Pixel^.G := 255
     613        else PixelDst.Pixel^.G := test; // Green
     614      test := (PixelDst.Pixel^.B * Brightness) shr 7;
     615      if test >= 256 then PixelDst.Pixel^.R := 255
     616        else PixelDst.Pixel^.B := Test; // Blue
     617      PixelDst.NextPixel;
     618      PixelSrc.NextPixel;
     619    end;
     620    PixelDst.NextLine;
     621    PixelSrc.NextLine;
    628622  end;
    629623  src.EndUpdate;
     
    639633var
    640634  ix, iy, amp1, amp2, trans, Value: integer;
    641   SrcPixel, DstPixel: PPixel32;
     635  SrcPixel, DstPixel: TPixelPointer;
    642636begin
    643637  if xDst < 0 then begin
     
    660654  Src.BeginUpdate;
    661655  dst.BeginUpdate;
    662   for iy := 0 to h - 1 do
    663   begin
    664     for ix := 0 to w - 1 do
    665     begin
    666       SrcPixel := GetBitmapPixelPtr(Src, xSrc + ix, ySrc + iy);
    667       DstPixel := GetBitmapPixelPtr(Dst, xDst + ix, yDst + iy);
    668       trans := SrcPixel^.B * 2; // green channel = transparency
    669       amp1 := SrcPixel^.G * 2;
    670       amp2 := SrcPixel^.R * 2;
    671       if trans <> $FF then
    672       begin
    673         Value := (DstPixel^.B * trans + ((Color2 shr 16) and $FF) * amp2
     656  SrcPixel.Init(Src, xSrc, ySrc);
     657  DstPixel.Init(Dst, xDst, yDst);
     658  for iy := 0 to h - 1 do begin
     659    for ix := 0 to w - 1 do begin
     660      trans := SrcPixel.Pixel^.B * 2; // green channel = transparency
     661      amp1 := SrcPixel.Pixel^.G * 2;
     662      amp2 := SrcPixel.Pixel^.R * 2;
     663      if trans <> $FF then begin
     664        Value := (DstPixel.Pixel^.B * trans + ((Color2 shr 16) and $FF) * amp2
    674665          + ((Color1 shr 16) and $FF) * amp1) div $FF;
    675         if Value < 256 then DstPixel^.B := Value
    676         else DstPixel^.B := 255;
    677         Value := (DstPixel^.G * trans + ((Color2 shr 8) and $FF) * amp2
     666        if Value < 256 then DstPixel.Pixel^.B := Value
     667          else DstPixel.Pixel^.B := 255;
     668        Value := (DstPixel.Pixel^.G * trans + ((Color2 shr 8) and $FF) * amp2
    678669          + ((Color1 shr 8) and $FF) * amp1) div $FF;
    679         if Value < 256 then DstPixel^.G := Value
    680           else DstPixel^.G := 255;
    681         Value := (DstPixel^.R * trans + (Color2 and $FF) * amp2 +
     670        if Value < 256 then DstPixel.Pixel^.G := Value
     671          else DstPixel.Pixel^.G := 255;
     672        Value := (DstPixel.Pixel^.R * trans + (Color2 and $FF) * amp2 +
    682673          (Color1 and $FF) * amp1) div $FF;
    683         if Value < 256 then DstPixel^.R := Value
    684           else DstPixel^.R := 255;
     674        if Value < 256 then DstPixel.Pixel^.R := Value
     675          else DstPixel.Pixel^.R := 255;
    685676      end;
    686     end;
     677      SrcPixel.NextPixel;
     678      DstPixel.NextPixel;
     679    end;
     680    SrcPixel.NextLine;
     681    DstPixel.NextLine;
    687682  end;
    688683  Src.EndUpdate;
     
    698693var
    699694  i, Red, Green: integer;
    700   Pixel: PPixel32;
     695  PixelPtr: TPixelPointer;
    701696begin
    702697  bmp.BeginUpdate;
    703698  assert(bmp.PixelFormat = pf24bit);
    704699  h := y + h;
    705   while y < h do
    706   begin
    707     Pixel := GetBitmapPixelPtr(Bmp, x, y);
    708     for i := 0 to w - 1 do
    709     begin
    710       Red := ((Pixel^.B * (Color0 and $0000FF) + Pixel^.G * (Color1 and $0000FF)
    711         + Pixel^.R * (Color2 and $0000FF)) shr 8) and $ff;
    712       Green := ((Pixel^.B * ((Color0 shr 8) and $0000FF) + Pixel^.G *
    713         ((Color1 shr 8) and $0000FF) + Pixel^.R * ((Color2 shr 8) and
     700  PixelPtr.Init(Bmp, x, y);
     701  while y < h do begin
     702    for i := 0 to w - 1 do  begin
     703      Red := ((PixelPtr.Pixel^.B * (Color0 and $0000FF) + PixelPtr.Pixel^.G * (Color1 and $0000FF)
     704        + PixelPtr.Pixel^.R * (Color2 and $0000FF)) shr 8) and $ff;
     705      Green := ((PixelPtr.Pixel^.B * ((Color0 shr 8) and $0000FF) + PixelPtr.Pixel^.G *
     706        ((Color1 shr 8) and $0000FF) + PixelPtr.Pixel^.R * ((Color2 shr 8) and
    714707        $0000FF)) shr 8) and $ff;
    715       Pixel^.B := ((Pixel^.B * ((Color0 shr 16) and $0000FF) + Pixel^.G *
    716         ((Color1 shr 16) and $0000FF) + Pixel^.R * ((Color2 shr 16) and $0000FF))
     708      PixelPtr.Pixel^.B := ((PixelPtr.Pixel^.B * ((Color0 shr 16) and $0000FF) + PixelPtr.Pixel^.G *
     709        ((Color1 shr 16) and $0000FF) + PixelPtr.Pixel^.R * ((Color2 shr 16) and $0000FF))
    717710        shr 8) and $ff; // Blue
    718       Pixel^.G := Green;
    719       Pixel^.R := Red;
    720       Pixel := pointer(Pixel) + (Bmp.RawImage.Description.BitsPerPixel shr 3);
     711      PixelPtr.Pixel^.G := Green;
     712      PixelPtr.Pixel^.R := Red;
     713      PixelPtr.NextPixel;
    721714    end;
    722715    inc(y);
     716    PixelPtr.NextLine;
    723717  end;
    724718  bmp.EndUpdate;
     
    749743  DestCanvas.CopyRect(Rect(X, Y, X + Width, Y + Height), SrcCanvas,
    750744    Rect(XSrc, YSrc, XSrc + Width, YSrc + Height));
     745  Result := True;
    751746end;
    752747
     
    14471442end;
    14481443
    1449 procedure TPixelPointer.Init(Bitmap: TBitmap; X: Integer = 0; Y: Integer = 0); inline;
    1450 begin
    1451   Base := PPixel32(Bitmap.RawImage.Data);
     1444procedure TPixelPointer.Init(Bitmap: TBitmap; BaseX: Integer = 0; BaseY: Integer = 0); inline;
     1445begin
    14521446  BytesPerLine := Bitmap.RawImage.Description.BytesPerLine;
    14531447  BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3;
    1454   SetXY(X, Y);
     1448  Base := PPixel32(Bitmap.RawImage.Data + BaseX * BytesPerPixel + BaseY * BytesPerLine);
     1449  SetXY(0, 0);
    14551450end;
    14561451
  • trunk/Start.pas

    r64 r72  
    822822var
    823823  x, y: integer;
    824   PicturePixel: PPixel32;
     824  PicturePixel: TPixelPointer;
    825825begin
    826826  SetMainTextureByAge(-1);
     
    830830  Fill(EmptyPicture.Canvas, 0, 0, 64, 64, (wMaintexture - 64) div 2,
    831831    (hMaintexture - 64) div 2);
    832   for y := 0 to 63 do
    833   begin // darken texture for empty slot
    834     for x := 0 to 64 - 1 do
    835     begin
    836       PicturePixel := GetBitmapPixelPtr(EmptyPicture, x, y);
    837       PicturePixel^.B := Max(PicturePixel^.B - 28, 0);
    838       PicturePixel^.G := Max(PicturePixel^.G - 28, 0);
    839       PicturePixel^.R := Max(PicturePixel^.R - 28, 0);
    840     end
     832  // darken texture for empty slot
     833  PicturePixel.Init(EmptyPicture);
     834  for y := 0 to 63 do begin
     835    for x := 0 to 64 - 1 do begin
     836      PicturePixel.Pixel^.B := Max(PicturePixel.Pixel^.B - 28, 0);
     837      PicturePixel.Pixel^.G := Max(PicturePixel.Pixel^.G - 28, 0);
     838      PicturePixel.Pixel^.R := Max(PicturePixel.Pixel^.R - 28, 0);
     839      PicturePixel.NextPixel;
     840    end;
     841    PicturePixel.NextLine;
    841842  end;
    842843  EmptyPicture.EndUpdate;
     
    10011002  var
    10021003    i, x, y, xm, cm: integer;
    1003     MiniPixel: PPixel32;
     1004    MiniPixel: TPixelPointer;
    10041005    Map: ^TTileList;
    10051006  begin
     
    10111012    Mini.SetSize(MiniWidth * 2, MiniHeight);
    10121013    Mini.BeginUpdate;
     1014    MiniPixel.Init(Mini);
    10131015    for y := 0 to MiniHeight - 1 do begin
    10141016      for x := 0 to MiniWidth - 1 do begin
    10151017        for i := 0 to 1 do begin
    10161018          xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
    1017           MiniPixel := GetBitmapPixelPtr(Mini, xm, y);
     1019          MiniPixel.SetX(xm);
    10181020          cm := MiniColors
    10191021            [Map[x * lxmax div MiniWidth + lxmax *
    10201022            ((y * (lymax - 1) + MiniHeight div 2) div (MiniHeight - 1))] and
    10211023            fTerrain, i];
    1022           MiniPixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
    1023           MiniPixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
    1024           MiniPixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
     1024          MiniPixel.Pixel^.B := ((cm shr 16) and $FF) * Brightness div 3;
     1025          MiniPixel.Pixel^.G := ((cm shr 8) and $FF) * Brightness div 3;
     1026          MiniPixel.Pixel^.R := ((cm shr 0) and $FF) * Brightness div 3;
    10251027        end;
    10261028      end;
     1029      MiniPixel.NextLine;
    10271030    end;
    10281031    Mini.EndUpdate;
     
    10351038  var
    10361039    i, x, y, xm, cm, Tile, OwnColor, EnemyColor: integer;
    1037     MiniPixel, PrevMiniPixel: PPixel32;
     1040    MiniPixel, PrevMiniPixel: TPixelPointer;
    10381041  begin
    10391042    OwnColor := GrExt[HGrSystem].Data.Canvas.Pixels[95, 67];
     
    10451048    begin
    10461049      Mini.BeginUpdate;
     1050      MiniPixel.Init(Mini);
     1051      PrevMiniPixel.Init(Mini, 0, -1);
    10471052      for y := 0 to MiniHeight - 1 do begin
    10481053        for x := 0 to MiniWidth - 1 do begin
    10491054          for i := 0 to 1 do begin
    10501055            xm := (x * 2 + i + y and 1) mod (MiniWidth * 2);
    1051             MiniPixel := GetBitmapPixelPtr(Mini, xm, y);
     1056            MiniPixel.SetX(xm);
    10521057            Tile := SaveMap[x + MiniWidth * y];
    10531058            if Tile and fTerrain = fUNKNOWN then
     
    10611066              if y > 0 then begin
    10621067                // 2x2 city dot covers two lines
    1063                 PrevMiniPixel := GetBitmapPixelPtr(Mini, xm, y - 1);
    1064                 PrevMiniPixel^.B := cm shr 16;
    1065                 PrevMiniPixel^.G:= cm shr 8 and $FF;
    1066                 PrevMiniPixel^.R := cm and $FF;
     1068                PrevMiniPixel.SetX(xm);
     1069                PrevMiniPixel.Pixel^.B := cm shr 16;
     1070                PrevMiniPixel.Pixel^.G:= cm shr 8 and $FF;
     1071                PrevMiniPixel.Pixel^.R := cm and $FF;
    10671072              end
    10681073            end
     
    10741079            else
    10751080              cm := MiniColors[Tile and fTerrain, i];
    1076             MiniPixel^.B := cm shr 16;
    1077             MiniPixel^.G:= cm shr 8 and $FF;
    1078             MiniPixel^.R := cm and $FF;
     1081            MiniPixel.Pixel^.B := cm shr 16;
     1082            MiniPixel.Pixel^.G:= cm shr 8 and $FF;
     1083            MiniPixel.Pixel^.R := cm and $FF;
    10791084          end;
    10801085        end;
Note: See TracChangeset for help on using the changeset viewer.