Changeset 501 for trunk


Ignore:
Timestamp:
Dec 23, 2023, 11:11:19 AM (4 months ago)
Author:
chronos
Message:
  • Fixed: TPixelPointer range check.
Location:
trunk/Packages
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r492 r501  
    4040procedure MakeBlue(Dst: TBitmap; X, Y, Width, Height: Integer);
    4141procedure MakeRed(Dst: TBitmap; X, Y, Width, Height: Integer);
    42 procedure ImageOp_B(dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer);
     42procedure ImageOp_B(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer);
    4343procedure ImageOp_BCC(Dst, Src: TBitmap;
    4444  xDst, yDst, xSrc, ySrc, Width, Height, Color1, Color2: Integer); overload;
     
    4747procedure ImageOp_CBC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
    4848  Color0, Color2: Integer);
    49 procedure ImageOp_CCC(bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
     49procedure ImageOp_CCC(Bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
    5050function BitBltCanvas(DestCanvas: TCanvas; X, Y, Width, Height: Integer;
    5151  SrcCanvas: TCanvas; XSrc, YSrc: Integer; Rop: DWORD = SRCCOPY): Boolean; overload;
     
    627627end;
    628628
    629 procedure ImageOp_B(dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer);
     629procedure ImageOp_B(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height: Integer);
    630630// Src is template
    631631// X channel = background amp (old Dst content), 128=original brightness
     
    643643  Height := ScaleToNative(Height);
    644644  //Assert(Src.PixelFormat = pf8bit);
    645   Assert(dst.PixelFormat = TPixelFormat.pf24bit);
     645  Assert(Dst.PixelFormat = TPixelFormat.pf24bit);
    646646  if xDst < 0 then begin
    647647    Width := Width + xDst;
     
    654654    yDst := 0;
    655655  end;
    656   if xDst + Width > ScaleToNative(dst.Width) then
    657     Width := ScaleToNative(dst.Width) - xDst;
    658   if yDst + Height > ScaleToNative(dst.Height) then
    659     Height := ScaleToNative(dst.Height) - yDst;
     656  if xDst + Width > ScaleToNative(Dst.Width) then
     657    Width := ScaleToNative(Dst.Width) - xDst;
     658  if yDst + Height > ScaleToNative(Dst.Height) then
     659    Height := ScaleToNative(Dst.Height) - yDst;
    660660  if (Width < 0) or (Height < 0) then
    661661    Exit;
    662662
    663   dst.BeginUpdate;
     663  Dst.BeginUpdate;
    664664  Src.BeginUpdate;
    665665  PixelDst := TPixelPointer.Create(Dst, xDst, yDst);
     
    690690  end;
    691691  src.EndUpdate;
    692   dst.EndUpdate;
    693 end;
    694 
    695 procedure ImageOp_BCC(dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
     692  Dst.EndUpdate;
     693end;
     694
     695procedure ImageOp_BCC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, Width, Height,
    696696  Color1, Color2: Integer);
    697697// Src is template
     
    720720    yDst := 0;
    721721  end;
    722   if xDst + Width > ScaleToNative(dst.Width) then
    723     Width := ScaleToNative(dst.Width) - xDst;
    724   if yDst + Height > ScaleToNative(dst.Height) then
    725     Height := ScaleToNative(dst.Height) - yDst;
     722  if xDst + Width > ScaleToNative(Dst.Width) then
     723    Width := ScaleToNative(Dst.Width) - xDst;
     724  if yDst + Height > ScaleToNative(Dst.Height) then
     725    Height := ScaleToNative(Dst.Height) - yDst;
    726726  if (Width < 0) or (Height < 0) then
    727727    Exit;
    728728
    729729  Src.BeginUpdate;
    730   dst.BeginUpdate;
     730  Dst.BeginUpdate;
    731731  SrcPixel := TPixelPointer.Create(Src, xSrc, ySrc);
    732732  DstPixel := TPixelPointer.Create(Dst, xDst, yDst);
     
    757757  end;
    758758  Src.EndUpdate;
    759   dst.EndUpdate;
     759  Dst.EndUpdate;
    760760end;
    761761
     
    816816end;
    817817
    818 procedure ImageOp_CCC(bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
     818procedure ImageOp_CCC(Bmp: TBitmap; X, Y, Width, Height, Color0, Color1, Color2: Integer);
    819819// Bmp is template
    820820// B channel = Color0 amp, 128=original brightness
     
    822822// R channel = Color2 amp, 128=original brightness
    823823var
    824   I, Red, Green: Integer;
     824  XX, YY: Integer;
     825  Red, Green: Integer;
    825826  PixelPtr: TPixelPointer;
    826827begin
    827828  X := ScaleToNative(X);
    828829  Y := ScaleToNative(Y);
    829   Width := ScaleToNative(Width);
    830   Height := ScaleToNative(Height);
    831   bmp.BeginUpdate;
    832   Assert(bmp.PixelFormat = TPixelFormat.pf24bit);
    833   Height := Y + Height;
     830  Width := ScaleToNativeDist(X, Width);
     831  Height := ScaleToNativeDist(Y, Height);
     832
     833  if X + Width > ScaleToNative(Bmp.Width) then
     834    Width := ScaleToNative(Bmp.Width) - X;
     835  if Y + Height > ScaleToNative(Bmp.Height) then
     836    Height := ScaleToNative(Bmp.Height) - Y;
     837  if (Width < 0) or (Height < 0) then
     838    Exit;
     839
     840  Bmp.BeginUpdate;
     841  Assert(Bmp.PixelFormat = TPixelFormat.pf24bit);
    834842  PixelPtr := TPixelPointer.Create(Bmp, X, Y);
    835   while Y < Height do begin
    836     for I := 0 to Width - 1 do begin
     843  for YY := 0 to Height - 1 do begin
     844    for XX := 0 to Width - 1 do begin
    837845      Red := ((PixelPtr.Pixel^.B * (Color0 and $0000FF) + PixelPtr.Pixel^.G *
    838846        (Color1 and $0000FF) + PixelPtr.Pixel^.R * (Color2 and $0000FF)) shr 8) and $ff;
     
    847855      PixelPtr.NextPixel;
    848856    end;
    849     Inc(Y);
    850857    PixelPtr.NextLine;
    851858  end;
    852   bmp.EndUpdate;
     859  Bmp.EndUpdate;
    853860end;
    854861
  • trunk/Packages/DpiControls/Dpi.PixelPointer.pas

    r487 r501  
    44
    55uses
    6   Classes, SysUtils, Dpi.Graphics, Dpi.Common;
     6  Math, Classes, SysUtils, Dpi.Graphics, Dpi.Common;
    77
    88type
     
    6868
    6969resourcestring
    70   SOutOfRange = 'Pixel pointer out of range';
     70  SOutOfRange = 'Pixel pointer out of range [X: %d. Y: %d]';
    7171  SWrongBitmapSize = 'Wrong bitmap size [width: %d, height: %d]';
    7272
     
    126126
    127127procedure TPixelPointer.CheckRange;
     128var
     129  X: Integer;
     130  Y: Integer;
    128131begin
    129132  {$IFOPT R+}
    130133  if (PByte(Pixel) < PByte(Data)) or
    131     (PByte(Pixel) >= PByte(Data) + (Width + Height * BytesPerLine) * BytesPerPixel) then
    132     raise Exception.Create(SOutOfRange);
     134    (PByte(Pixel) >= PByte(Data) + Height * BytesPerLine + BytesPerLine) then begin
     135    X := PByte(Pixel) - PByte(Data);
     136    Y := Floor(X / BytesPerLine);
     137    X := X - Y * BytesPerLine;
     138    X := Floor(X / BytesPerPixel);
     139    raise Exception.Create(Format(SOutOfRange, [X, Y]));
     140  end;
    133141  {$ENDIF}
    134142end;
Note: See TracChangeset for help on using the changeset viewer.