Changeset 487 for trunk/Packages/DpiControls/NativePixelPointer.pas
- Timestamp:
- Dec 8, 2023, 11:39:45 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/DpiControls/NativePixelPointer.pas
r468 r487 32 32 BytesPerPixel: Integer; 33 33 BytesPerLine: Integer; 34 Data: PPixel32; 35 Width: Integer; 36 Height: Integer; 34 37 procedure NextLine; inline; // Move pointer to start of next line 35 38 procedure PreviousLine; inline; // Move pointer to start of previous line … … 38 41 procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base 39 42 procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base 43 procedure CheckRange; inline; // Check if current pixel position is not out of range 44 class function Create(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; static; 40 45 end; 41 46 PPixelPointer = ^TPixelPointer; 42 47 43 function PixelPointer(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; inline;44 48 function Color32ToColor(Color: TColor32): TColor; 45 49 function ColorToColor32(Color: TColor): TColor32; … … 48 52 implementation 49 53 50 { TPixel32 } 54 resourcestring 55 SOutOfRange = 'Pixel pointer out of range'; 56 SWrongBitmapSize = 'Wrong bitmap size [width: %d, height: %d]'; 57 58 { TPixel32 } 51 59 52 60 procedure TPixel32.SetRGB(Color: TColor32); … … 97 105 end; 98 106 99 function PixelPointer(Bitmap: TRasterImage; BaseX: Integer; 107 procedure TPixelPointer.CheckRange; 108 begin 109 {$IFOPT R+} 110 if (PByte(Pixel) < PByte(Data)) or 111 (PByte(Pixel) >= PByte(Data) + (Width + Height * BytesPerLine) * BytesPerPixel) then 112 raise Exception.Create(SOutOfRange); 113 {$ENDIF} 114 end; 115 116 class function TPixelPointer.Create(Bitmap: TRasterImage; BaseX: Integer; 100 117 BaseY: Integer): TPixelPointer; 101 118 begin 119 Result.Width := Bitmap.Width; 120 Result.Height := Bitmap.Height; 121 if (Result.Width < 0) or (Result.Height < 0) then 122 raise Exception.Create(Format(SWrongBitmapSize, [Result.Width, Result.Height])); 102 123 Result.BytesPerLine := Bitmap.RawImage.Description.BytesPerLine; 103 124 Result.BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3; 125 Result.Data := PPixel32(Bitmap.RawImage.Data); 104 126 Result.Base := PPixel32(Bitmap.RawImage.Data + BaseX * Result.BytesPerPixel + 105 127 BaseY * Result.BytesPerLine);
Note:
See TracChangeset
for help on using the changeset viewer.