Changeset 35
- Timestamp:
- May 4, 2018, 12:56:52 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormMain.lfm
r33 r35 1 1 object FormMain: TFormMain 2 Left = 6 642 Left = 648 3 3 Height = 640 4 Top = 3 824 Top = 323 5 5 Width = 920 6 6 Caption = 'LibrePaint' 7 ClientHeight = 6 087 ClientHeight = 615 8 8 ClientWidth = 920 9 DesignTimePPI = 120 9 10 Menu = MainMenu1 10 11 OnActivate = FormActivate … … 13 14 OnDestroy = FormDestroy 14 15 OnShow = FormShow 15 LCLVersion = '1. 6.0.4'16 LCLVersion = '1.8.2.0' 16 17 object PaintBox1: TPaintBox 17 18 Left = 0 18 Height = 5 5419 Height = 561 19 20 Top = 26 20 21 Width = 920 … … 32 33 Left = 0 33 34 Height = 28 34 Top = 58 035 Top = 587 35 36 Width = 920 36 37 Panels = < 37 38 item 38 Width = 20039 Width = 300 39 40 end 40 41 item -
trunk/Forms/UFormMain.pas
r33 r35 135 135 StatusBar1.Panels[0].Text := '[' + IntToStr(Pos.X) + ', ' + IntToStr(Pos.Y) + '] Zoom:' + 136 136 FloatToStr(Core.Project.View.Zoom); 137 StatusBar1.Panels[1].Text := 'Src: ' + IntToStr(View.SrcRect.Right - View.SrcRect.Left) + ', ' + 137 StatusBar1.Panels[1].Text := 'Src: ' + IntToStr(View.SrcRect.Left) + ', ' + 138 IntToStr(View.SrcRect.Top) + ', ' + 139 IntToStr(View.SrcRect.Right - View.SrcRect.Left) + ', ' + 138 140 IntToStr(View.SrcRect.Bottom - View.SrcRect.Top); 139 StatusBar1.Panels[2].Text := 'Dst: ' + IntToStr(View.DestRect.Right - View.DestRect.Left) + ', ' + 141 StatusBar1.Panels[2].Text := 'Dst: ' + IntToStr(View.DestRect.Left) + ', ' + 142 IntToStr(View.DestRect.Top) + ', ' + 143 IntToStr(View.DestRect.Right - View.DestRect.Left) + ', ' + 140 144 IntToStr(View.DestRect.Bottom - View.DestRect.Top); 141 145 end; … … 150 154 begin 151 155 with Core.Project do begin 152 TempBitmap.SetSize(View.SrcRect.Right - View.SrcRect.Left, 153 View.SrcRect.Bottom - View.SrcRect.Top); 156 //TempBitmap.SetSize(View.SrcRect.Right - View.SrcRect.Left, 157 // View.SrcRect.Bottom - View.SrcRect.Top); 158 TempBitmap.SetSize(PaintBox1.Width, PaintBox1.Height); 154 159 //TempBitmap.BeginUpdate(True); 155 160 TempBitmap.Canvas.Brush.Color := clBlack; … … 158 163 // Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect); 159 164 // if EnableDraw then 160 Bitmap.PaintToBitmap(TempBitmap, View.SrcRect); 165 Bitmap.PaintToBitmap(TempBitmap, View.SrcRect); 166 //StatusBar1.Panels[0].Text := IntToStr(TempBitmap.Width) + ', ' + IntToStr(TempBitmap.Height); 161 167 //TempBitmap.EndUpdate(False); 162 PaintBox1.Canvas. StretchDraw(View.DestRect, TempBitmap);168 PaintBox1.Canvas.Draw(0, 0, TempBitmap); 163 169 //PaintBox1.Canvas.Draw(0, 0, TempBitmap); 164 170 end; -
trunk/LibrePaint.lpi
r30 r35 2 2 <CONFIG> 3 3 <ProjectOptions> 4 <Version Value=" 9"/>4 <Version Value="10"/> 5 5 <General> 6 6 <SessionStorage Value="InProjectDir"/> … … 14 14 <EnableI18N LFM="False"/> 15 15 </i18n> 16 <VersionInfo>17 <StringTable ProductVersion=""/>18 </VersionInfo>19 16 <BuildModes Count="2"> 20 17 <Item1 Name="Debug" Default="True"/> -
trunk/Packages/FastGraphics/UGGraphics.pas
r34 r35 51 51 TGConvertFromColor = function (Color: TColor): TGColor of object; 52 52 TGGetColor = function (Position: TPoint): TGColor of object; 53 PGColor = ^TGColor; 53 54 protected 54 55 FData: PByte; 55 56 FSize: TPoint; 56 57 FCanvas: TGCanvas<TGColor>; 58 FBytesPerLine: Integer; 59 FBytesPerPixel: Integer; 57 60 function GetPixel(X, Y: Integer): TGColor; virtual; 58 61 function GetSize: TPoint; virtual; … … 66 69 procedure PaintToCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertColor); overload; 67 70 procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect; ColorConvertFunc: TGConvertColor); overload; 68 procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect; ColorConvertFunc: TGConvertColor); 71 procedure PaintToBitmap(Bitmap: TBitmap; Pos: TPoint; ColorConvertFunc: TGConvertColor); overload; 72 procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect; ColorConvertFunc: TGConvertColor); overload; 69 73 procedure LoadFromCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertFromColor); overload; 70 74 procedure LoadFromBitmap(Bitmap: TBitmap; ColorConvertFunc: TGConvertFromColor); … … 96 100 end; 97 101 102 { TPixelPointer } 103 104 TPixelPointer = record 105 Base: Pointer; 106 Pixel: Pointer; 107 Line: Pointer; 108 BytesPerPixel: Integer; 109 BytesPerLine: Integer; 110 procedure NextLine; inline; // Move pointer to start of new base line 111 procedure NextPixel; inline; // Move pointer to next pixel 112 procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base 113 procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base 114 procedure Init(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0); inline; overload; 115 procedure Init(Base: Pointer; BytesPerLine, BytesPerPixel: Integer; BaseX: Integer = 0; BaseY: Integer = 0); inline; overload; 116 end; 117 98 118 99 119 implementation 100 120 121 { TPixelPointer } 122 123 procedure TPixelPointer.NextLine; inline; 124 begin 125 Line := Pointer(Line) + BytesPerLine; 126 Pixel := Line; 127 end; 128 129 procedure TPixelPointer.NextPixel; inline; 130 begin 131 Pixel := Pointer(Pixel) + BytesPerPixel; 132 end; 133 134 procedure TPixelPointer.SetXY(X, Y: integer); inline; 135 begin 136 Line := Pointer(Base) + Y * BytesPerLine; 137 SetX(X); 138 end; 139 140 procedure TPixelPointer.SetX(X: Integer); inline; 141 begin 142 Pixel := Pointer(Line) + X * BytesPerPixel; 143 end; 144 145 procedure TPixelPointer.Init(Bitmap: TRasterImage; BaseX: Integer = 0; 146 BaseY: Integer = 0); inline; 147 begin 148 Init(Bitmap.RawImage.Data, Bitmap.RawImage.Description.BytesPerLine, Bitmap.RawImage.Description.BitsPerPixel shr 3, BaseX, BaseY); 149 end; 150 151 procedure TPixelPointer.Init(Base: Pointer; BytesPerLine, BytesPerPixel: Integer; BaseX: Integer = 0; BaseY: Integer = 0); inline; overload; 152 begin 153 Self.BytesPerLine := BytesPerLine; 154 Self.BytesPerPixel := BytesPerPixel; 155 Self.Base := Pointer(Base + BaseX * BytesPerPixel + BaseY * BytesPerLine); 156 SetXY(0, 0); 157 end; 158 101 159 { TGPixmap } 102 160 … … 104 162 begin 105 163 CheckLimits(X, Y); 106 Move(PByte(FData + (X + Y * FSize.X) * SizeOf(TGColor))^, Result, SizeOf(TGColor));164 Move(PByte(FData + X * FBytesPerPixel + Y * FBytesPerLine)^, Result, SizeOf(TGColor)); 107 165 end; 108 166 … … 110 168 begin 111 169 CheckLimits(X, Y); 112 Move(AValue, PByte(FData + (X + Y * FSize.X) * SizeOf(TGColor))^, SizeOf(TGColor));170 Move(AValue, PByte(FData + X * FBytesPerPixel + Y * FBytesPerLine)^, SizeOf(TGColor)); 113 171 end; 114 172 … … 122 180 if (FSize.X <> AValue.X) and (FSize.Y <> AValue.Y) then begin 123 181 FSize := AValue; 124 ReAllocMem(FData, FSize.X * FSize.Y * SizeOf(TGColor)); 182 FBytesPerPixel := SizeOf(TGColor); 183 FBytesPerLine := AValue.X * FBytesPerPixel; 184 ReAllocMem(FData, FSize.X * FBytesPerLine); 125 185 end; 126 186 end; … … 128 188 constructor TGPixmap<TGColor>.Create; 129 189 begin 190 Size := Point(0, 0); 130 191 FCanvas := TGCanvas<TGColor>.Create; 131 192 FCanvas.Bitmap := Self; … … 195 256 end; 196 257 258 procedure TGPixmap<TGColor>.PaintToBitmap(Bitmap: TBitmap; Pos: TPoint; 259 ColorConvertFunc: TGConvertColor); 260 var 261 X, Y: Integer; 262 DstPtr: TPixelPointer; 263 SrcPtr: TPixelPointer; 264 begin 265 try 266 Bitmap.BeginUpdate(False); 267 DstPtr.Init(Bitmap); 268 SrcPtr.Init(FData, FBytesPerLine, FBytesPerPixel, Pos.X, Pos.Y); 269 for Y := 0 to Bitmap.Height - 1 do begin 270 for X := 0 to Bitmap.Width - 1 do begin 271 if ((X + Pos.X) >= 0) and ((X + Pos.X) < FSize.X) and 272 ((Y + Pos.Y) >= 0) and ((Y + Pos.Y) < FSize.Y) then begin 273 PInteger(DstPtr.Pixel)^ := ColorConvertFunc(PGColor(SrcPtr.Pixel)^); 274 end; 275 DstPtr.NextPixel; 276 SrcPtr.NextPixel; 277 end; 278 DstPtr.NextLine; 279 SrcPtr.NextLine; 280 end; 281 finally 282 Bitmap.EndUpdate(False); 283 end; 284 end; 285 197 286 procedure TGPixmap<TGColor>.PaintToBitmap(Bitmap: TBitmap; Rect: TRect; 198 287 ColorConvertFunc: TGConvertColor); 199 288 var 200 289 X, Y: Integer; 201 PixelPtr: PInteger; 202 PixelPtrMax: PInteger; 203 PixelPtrMin: PInteger; 204 PixelRowPtr: PInteger; 205 RawImage: TRawImage; 206 BytePerPixel: Integer; 290 DstPtr: TPixelPointer; 291 ZoomX: Single; 292 ZoomY: Single; 293 SrcX: Integer; 294 SrcY: Integer; 207 295 begin 208 296 try 209 297 Bitmap.BeginUpdate(False); 210 RawImage := Bitmap.RawImage; 211 PixelRowPtr := PInteger(RawImage.Data); 212 BytePerPixel := RawImage.Description.BitsPerPixel div 8; 213 PixelPtrMin := PixelRowPtr; 214 PixelPtrMax := PixelRowPtr + RawImage.Description.Width * RawImage.Description.Height * BytePerPixel; 298 DstPtr.Init(Bitmap); 299 ZoomX := Bitmap.Width / (Rect.Right - Rect.Left); 300 ZoomY := Bitmap.Height / (Rect.Bottom - Rect.Top); 215 301 for Y := 0 to Bitmap.Height - 1 do begin 216 PixelPtr := PixelRowPtr;302 SrcY := Trunc(Y / ZoomY + Rect.Top); 217 303 for X := 0 to Bitmap.Width - 1 do begin 218 if ((X + Rect.Left) >= 0) and ((X + Rect.Left) < FSize.X) and219 ((Y + Rect.Top) >= 0) and ((Y + Rect.Top) < FSize.Y) and220 ( PixelPtr < PixelPtrMax) and (PixelPtr >= PixelPtrMin) then begin221 P ixelPtr^ := ColorConvertFunc(Pixels[X + Rect.Left, Y + Rect.Top]);304 SrcX := Trunc(X / ZoomX + Rect.Left); 305 if (SrcX >= 0) and (SrcX < FSize.X) and 306 (SrcY >= 0) and (SrcY < FSize.Y) then begin 307 PInteger(DstPtr.Pixel)^ := ColorConvertFunc(Pixels[SrcX, SrcY]); 222 308 end; 223 Inc(PByte(PixelPtr), BytePerPixel);309 DstPtr.NextPixel; 224 310 end; 225 Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine);311 DstPtr.NextLine; 226 312 end; 227 313 finally … … 248 334 var 249 335 X, Y: Integer; 250 PixelPtr: PInteger; 251 PixelPtrMax: PInteger; 252 PixelRowPtr: PInteger; 253 P: TPixelFormat; 254 RawImage: TRawImage; 255 BytePerPixel: Integer; 336 SrcPtr: TPixelPointer; 337 DstPtr: TPixelPointer; 256 338 begin 257 339 try 258 340 Bitmap.BeginUpdate(False); 259 RawImage := Bitmap.RawImage; 260 PixelRowPtr := PInteger(RawImage.Data); 261 BytePerPixel := RawImage.Description.BitsPerPixel div 8; 262 PixelPtrMax := PixelRowPtr + RawImage.Description.Width * RawImage.Description.Height * BytePerPixel; 341 SrcPtr.Init(Bitmap); 342 DstPtr.Init(FData, FBytesPerLine, FBytesPerPixel); 263 343 for Y := 0 to FSize.Y - 1 do begin 264 PixelPtr := PixelRowPtr;265 344 for X := 0 to FSize.X - 1 do begin 266 if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and (PixelPtr < PixelPtrMax) then 267 Pixels[X, Y] := ColorConvertFunc(PixelPtr^); 268 Inc(PByte(PixelPtr), BytePerPixel); 345 if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) then 346 PInteger(DstPtr.Pixel)^ := ColorConvertFunc(PInteger(SrcPtr.Pixel)^); 347 SrcPtr.NextPixel; 348 DstPtr.NextPixel; 269 349 end; 270 Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine); 350 SrcPtr.NextLine; 351 DstPtr.NextLine; 271 352 end; 272 353 finally … … 277 358 function TGPixmap<TGColor>.GetDataSize: Int64; 278 359 begin 279 Result := FSize. X * FSize.Y * SizeOf(TGColor);360 Result := FSize.Y * FBytesPerLine; 280 361 end; 281 362
Note:
See TracChangeset
for help on using the changeset viewer.