Changeset 487 for trunk/Packages/DpiControls/Dpi.PixelPointer.pas
- Timestamp:
- Dec 8, 2023, 11:39:45 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/DpiControls/Dpi.PixelPointer.pas
r468 r487 4 4 5 5 uses 6 Classes, SysUtils, Dpi.Graphics ;6 Classes, SysUtils, Dpi.Graphics, Dpi.Common; 7 7 8 8 type … … 35 35 BytesPerPixel: Integer; 36 36 BytesPerLine: Integer; 37 Data: PPixel32; 38 Width: Integer; 39 Height: Integer; 37 40 procedure NextLine; inline; // Move pointer to start of next line 38 41 procedure PreviousLine; inline; // Move pointer to start of previous line … … 41 44 procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base 42 45 procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base 43 class function Create(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; inline; static; 46 procedure CheckRange; inline; // Check if current pixel position is not out of range 47 class function Create(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; static; 44 48 end; 45 49 PPixelPointer = ^TPixelPointer; … … 63 67 implementation 64 68 69 resourcestring 70 SOutOfRange = 'Pixel pointer out of range'; 71 SWrongBitmapSize = 'Wrong bitmap size [width: %d, height: %d]'; 72 65 73 { TPixel32 } 66 74 … … 83 91 Line := Pointer(Line) + BytesPerLine; 84 92 Pixel := Line; 93 CheckRange; 85 94 end; 86 95 … … 89 98 Line := Pointer(Line) - BytesPerLine; 90 99 Pixel := Line; 100 CheckRange; 91 101 end; 92 102 … … 94 104 begin 95 105 Pixel := Pointer(Pixel) + BytesPerPixel; 106 CheckRange; 96 107 end; 97 108 … … 99 110 begin 100 111 Pixel := Pointer(Pixel) - BytesPerPixel; 112 CheckRange; 101 113 end; 102 114 … … 110 122 begin 111 123 Pixel := Pointer(Line) + X * BytesPerPixel; 124 CheckRange; 125 end; 126 127 procedure TPixelPointer.CheckRange; 128 begin 129 {$IFOPT R+} 130 if (PByte(Pixel) < PByte(Data)) or 131 (PByte(Pixel) >= PByte(Data) + (Width + Height * BytesPerLine) * BytesPerPixel) then 132 raise Exception.Create(SOutOfRange); 133 {$ENDIF} 112 134 end; 113 135 … … 298 320 BaseY: Integer): TPixelPointer; 299 321 begin 322 Result.Width := ScaleToNative(Bitmap.Width); 323 Result.Height := ScaleToNative(Bitmap.Height); 324 if (Result.Width < 0) or (Result.Height < 0) then 325 raise Exception.Create(Format(SWrongBitmapSize, [Result.Width, Result.Height])); 300 326 Result.BytesPerLine := Bitmap.RawImage.Description.BytesPerLine; 301 327 Result.BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3; 328 Result.Data := PPixel32(Bitmap.RawImage.Data); 302 329 Result.Base := PPixel32(Bitmap.RawImage.Data + BaseX * Result.BytesPerPixel + 303 330 BaseY * Result.BytesPerLine);
Note:
See TracChangeset
for help on using the changeset viewer.