Ignore:
Timestamp:
Dec 23, 2023, 11:11:19 AM (11 months ago)
Author:
chronos
Message:
  • Fixed: TPixelPointer range check.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.