Ignore:
Timestamp:
Dec 23, 2023, 11:11:19 AM (12 months ago)
Author:
chronos
Message:
  • Fixed: TPixelPointer range check.
File:
1 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
Note: See TracChangeset for help on using the changeset viewer.