Changeset 487 for trunk/Packages/Common/PixelPointer.pas
- Timestamp:
- Dec 8, 2023, 11:39:45 PM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/PixelPointer.pas
r456 r487 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 … … 110 118 begin 111 119 Pixel := Pointer(Line) + X * BytesPerPixel; 120 end; 121 122 procedure TPixelPointer.CheckRange; 123 begin 124 {$IFOPT R+} 125 if (PByte(Pixel) < PByte(Data)) or 126 (PByte(Pixel) >= PByte(Data) + (Width + Height * BytesPerLine) * BytesPerPixel) then 127 raise Exception.Create(SOutOfRange); 128 {$ENDIF} 112 129 end; 113 130 … … 298 315 BaseY: Integer): TPixelPointer; 299 316 begin 317 Result.Width := Bitmap.Width; 318 Result.Height := Bitmap.Height; 319 if (Result.Width < 0) or (Result.Height < 0) then 320 raise Exception.Create(Format(SWrongBitmapSize, [Result.Width, Result.Height])); 300 321 Result.BytesPerLine := Bitmap.RawImage.Description.BytesPerLine; 301 322 Result.BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3; 323 Result.Data := PPixel32(Bitmap.RawImage.Data); 302 324 Result.Base := PPixel32(Bitmap.RawImage.Data + BaseX * Result.BytesPerPixel + 303 325 BaseY * Result.BytesPerLine);
Note:
See TracChangeset
for help on using the changeset viewer.