Changeset 487 for trunk/Packages/DpiControls
- Timestamp:
- Dec 8, 2023, 11:39:45 PM (12 months ago)
- Location:
- trunk/Packages/DpiControls
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/DpiControls/Dpi.Graphics.pas
r477 r487 270 270 procedure ScreenChanged; override; 271 271 public 272 procedure Assign(Source: TPersistent); override; 272 273 procedure SetSize(AWidth, AHeight: Integer); override; 273 274 end; … … 293 294 constructor Create; override; 294 295 destructor Destroy; override; 295 procedure Assign(Source: TPersistent); override;296 296 property ScanLine[Row: Integer]: Pointer read GetScanLine; 297 297 published … … 418 418 end; 419 419 420 procedure TCustomBitmap.Assign(Source: TPersistent); 421 begin 422 if Source is TCustomBitmap then begin 423 GetNativeCustomBitmap.Assign(TCustomBitmap(Source).GetNativeCustomBitmap); 424 FWidth := TCustomBitmap(Source).FWidth; 425 FHeight := TCustomBitmap(Source).FHeight 426 end else inherited; 427 end; 428 420 429 procedure TCustomBitmap.SetSize(AWidth, AHeight: Integer); 421 430 begin … … 691 700 //Exit; 692 701 Dst.BeginUpdate; 693 SrcPtr := PixelPointer(Src, 0, 0);694 DstPtr := PixelPointer(Dst, 0, 0);702 SrcPtr := TPixelPointer.Create(Src, 0, 0); 703 DstPtr := TPixelPointer.Create(Dst, 0, 0); 695 704 {for yy := 0 to Dst.Height - 1 do begin 696 705 for xx := 0 to Dst.Width - 1 do begin … … 841 850 end; 842 851 843 procedure TBitmap.Assign(Source: TPersistent);844 begin845 if Source is TBitmap then begin846 GetNativeBitmap.Assign((Source as TBitmap).GetNativeBitmap);847 end else inherited;848 end;849 850 852 { TPen } 851 853 -
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); -
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.