Ignore:
Timestamp:
Dec 25, 2023, 11:35:51 AM (5 months ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/DpiControls/Dpi.PixelPointer.pas

    r501 r506  
    99  TColor32 = type Cardinal;
    1010  TColor32Component = (ccBlue, ccGreen, ccRed, ccAlpha);
     11  TColor32Planes = array[0..3] of Byte;
    1112
    1213  { TPixel32 }
     
    1415  TPixel32 = packed record
    1516  private
    16     procedure SetRGB(AValue: Cardinal);
    17     function GetRGB: Cardinal;
     17    procedure SetRGB(AValue: Cardinal); inline;
     18    function GetRGB: Cardinal; inline;
    1819  public
    1920    property RGB: Cardinal read GetRGB write SetRGB;
     
    2122      0: (B, G, R, A: Byte);
    2223      1: (ARGB: TColor32);
    23       2: (Planes: array[0..3] of Byte);
     24      2: (Planes: TColor32Planes);
    2425      3: (Components: array[TColor32Component] of Byte);
    2526  end;
     
    2930
    3031  TPixelPointer = record
     32  private
     33    function GetPixelARGB: TColor32; inline;
     34    function GetPixelB: Byte; inline;
     35    function GetPixelG: Byte; inline;
     36    function GetPixelPlane(Index: Byte): Byte;
     37    function GetPixelR: Byte; inline;
     38    function GetPixelA: Byte; inline;
     39    function GetPixelPlanes: TColor32Planes;
     40    function GetPixelRGB: Cardinal;
     41    procedure SetPixelARGB(Value: TColor32); inline;
     42    procedure SetPixelB(Value: Byte); inline;
     43    procedure SetPixelG(Value: Byte); inline;
     44    procedure SetPixelPlane(Index: Byte; AValue: Byte);
     45    procedure SetPixelR(Value: Byte); inline;
     46    procedure SetPixelA(Value: Byte); inline;
     47    procedure SetPixelRGB(Value: Cardinal);
     48  public
    3149    Base: PPixel32;
    3250    Pixel: PPixel32;
     
    4664    procedure CheckRange; inline; // Check if current pixel position is not out of range
    4765    class function Create(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; static;
     66    property PixelARGB: TColor32 read GetPixelARGB write SetPixelARGB;
     67    property PixelRGB: Cardinal read GetPixelRGB write SetPixelRGB;
     68    property PixelB: Byte read GetPixelB write SetPixelB;
     69    property PixelG: Byte read GetPixelG write SetPixelG;
     70    property PixelR: Byte read GetPixelR write SetPixelR;
     71    property PixelA: Byte read GetPixelA write SetPixelA;
     72    property PixelPlane[Index: Byte]: Byte read GetPixelPlane write SetPixelPlane;
    4873  end;
    4974  PPixelPointer = ^TPixelPointer;
     
    91116  Line := Pointer(Line) + BytesPerLine;
    92117  Pixel := Line;
    93   CheckRange;
    94118end;
    95119
     
    98122  Line := Pointer(Line) - BytesPerLine;
    99123  Pixel := Line;
    100   CheckRange;
    101124end;
    102125
     
    104127begin
    105128  Pixel := Pointer(Pixel) + BytesPerPixel;
    106   CheckRange;
    107129end;
    108130
     
    110132begin
    111133  Pixel := Pointer(Pixel) - BytesPerPixel;
    112   CheckRange;
    113134end;
    114135
     
    122143begin
    123144  Pixel := Pointer(Line) + X * BytesPerPixel;
    124   CheckRange;
    125145end;
    126146
    127147procedure TPixelPointer.CheckRange;
     148{$IFOPT R+}
    128149var
    129150  X: Integer;
    130151  Y: Integer;
     152{$ENDIF}
    131153begin
    132154  {$IFOPT R+}
    133155  if (PByte(Pixel) < PByte(Data)) or
    134     (PByte(Pixel) >= PByte(Data) + Height * BytesPerLine + BytesPerLine) then begin
     156    (PByte(Pixel) >= PByte(Data) + Height * BytesPerLine) then begin
    135157    X := PByte(Pixel) - PByte(Data);
    136158    Y := Floor(X / BytesPerLine);
     
    140162  end;
    141163  {$ENDIF}
     164end;
     165
     166function TPixelPointer.GetPixelPlanes: TColor32Planes;
     167begin
     168  CheckRange;
     169  Result := Pixel^.Planes;
     170end;
     171
     172function TPixelPointer.GetPixelRGB: Cardinal;
     173begin
     174  CheckRange;
     175  Result := Pixel^.RGB;
     176end;
     177
     178procedure TPixelPointer.SetPixelARGB(Value: TColor32);
     179begin
     180  CheckRange;
     181  Pixel^.ARGB := Value;
     182end;
     183
     184procedure TPixelPointer.SetPixelB(Value: Byte);
     185begin
     186  CheckRange;
     187  Pixel^.B := Value;
     188end;
     189
     190procedure TPixelPointer.SetPixelG(Value: Byte);
     191begin
     192  CheckRange;
     193  Pixel^.G := Value;
     194end;
     195
     196procedure TPixelPointer.SetPixelPlane(Index: Byte; AValue: Byte);
     197begin
     198  CheckRange;
     199  Pixel^.Planes[Index] := AValue;
     200end;
     201
     202procedure TPixelPointer.SetPixelR(Value: Byte);
     203begin
     204  CheckRange;
     205  Pixel^.R := Value;
     206end;
     207
     208procedure TPixelPointer.SetPixelA(Value: Byte);
     209begin
     210  CheckRange;
     211  Pixel^.A := Value;
     212end;
     213
     214function TPixelPointer.GetPixelARGB: TColor32;
     215begin
     216  CheckRange;
     217  Result := Pixel^.ARGB;
     218end;
     219
     220function TPixelPointer.GetPixelB: Byte;
     221begin
     222  CheckRange;
     223  Result := Pixel^.B;
     224end;
     225
     226function TPixelPointer.GetPixelG: Byte;
     227begin
     228  CheckRange;
     229  Result := Pixel^.G;
     230end;
     231
     232function TPixelPointer.GetPixelPlane(Index: Byte): Byte;
     233begin
     234  CheckRange;
     235  Result := Pixel^.Planes[Index];
     236end;
     237
     238function TPixelPointer.GetPixelR: Byte;
     239begin
     240  CheckRange;
     241  Result := Pixel^.R;
     242end;
     243
     244function TPixelPointer.GetPixelA: Byte;
     245begin
     246  CheckRange;
     247  Result := Pixel^.A;
     248end;
     249
     250procedure TPixelPointer.SetPixelRGB(Value: Cardinal);
     251begin
     252  CheckRange;
     253  Pixel^.RGB := Value;
    142254end;
    143255
     
    154266  for Y := 0 to DstRect.Height - 1 do begin
    155267    for X := 0 to DstRect.Width - 1 do begin
    156       DstPtr.Pixel^.ARGB := SrcPtr.Pixel^.ARGB;
     268      DstPtr.PixelARGB := SrcPtr.PixelARGB;
    157269      SrcPtr.NextPixel;
    158270      DstPtr.NextPixel;
     
    190302      DstPtr.SetXY(X, Y);
    191303      SrcPtr.SetXY(R.Left, R.Top);
    192       C := SrcPtr.Pixel^.ARGB;
    193       DstPtr.Pixel^.ARGB := C;
     304      C := SrcPtr.PixelARGB;
     305      DstPtr.PixelARGB := C;
    194306      for YY := 0 to R.Height - 1 do begin
    195307        for XX := 0 to R.Width - 1 do begin
    196           DstPtr.Pixel^.ARGB := C;
     308          DstPtr.PixelARGB := C;
    197309          DstPtr.NextPixel;
    198310        end;
     
    214326  for Y := 0 to Bitmap.Height - 1 do begin
    215327    for X := 0 to Bitmap.Width - 1 do begin
    216       Ptr.Pixel^.ARGB := Color;
     328      Ptr.PixelARGB := Color;
    217329      Ptr.NextPixel;
    218330    end;
     
    231343  for Y := 0 to Rect.Height - 1 do begin
    232344    for X := 0 to Rect.Width - 1 do begin
    233       Ptr.Pixel^.ARGB := Color;
     345      Ptr.PixelARGB := Color;
    234346      Ptr.NextPixel;
    235347    end;
     
    248360  for Y := 0 to Bitmap.Height - 1 do begin
    249361    for X := 0 to Bitmap.Width - 1 do begin
    250       Ptr.Pixel^.ARGB := SwapRedBlue(Ptr.Pixel^.ARGB);
     362      Ptr.PixelARGB := SwapRedBlue(Ptr.PixelARGB);
    251363      Ptr.NextPixel;
    252364    end;
     
    265377  for Y := 0 to Bitmap.Height - 1 do begin
    266378    for X := 0 to Bitmap.Width - 1 do begin
    267       Ptr.Pixel^.ARGB := Ptr.Pixel^.ARGB xor $ffffff;
     379      Ptr.PixelARGB := Ptr.PixelARGB xor $ffffff;
    268380      Ptr.NextPixel;
    269381    end;
     
    285397  for Y := 0 to Bitmap.Height - 1 do begin
    286398    for X := 0 to Bitmap.Width - 1 do begin
    287       A := Ptr.Pixel^.A; //(Ptr.Pixel^.A + Pixel.A) shr 1;
    288       R := (Ptr.Pixel^.R + Pixel.R) shr 1;
    289       G := (Ptr.Pixel^.G + Pixel.G) shr 1;
    290       B := (Ptr.Pixel^.B + Pixel.B) shr 1;
    291       Ptr.Pixel^.ARGB := Color32(A, R, G, B);
     399      A := Ptr.PixelA; //(Ptr.PixelA + Pixel.A) shr 1;
     400      R := (Ptr.PixelR + Pixel.R) shr 1;
     401      G := (Ptr.PixelG + Pixel.G) shr 1;
     402      B := (Ptr.PixelB + Pixel.B) shr 1;
     403      Ptr.PixelARGB := Color32(A, R, G, B);
    292404      Ptr.NextPixel;
    293405    end;
Note: See TracChangeset for help on using the changeset viewer.