Changeset 10 for trunk/UCore.pas
- Timestamp:
- Mar 19, 2011, 4:30:27 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UCore.pas
r8 r10 7 7 uses 8 8 Dialogs, Classes, SysUtils, Contnrs, Graphics, SpecializedMatrix, SpecializedList, 9 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType ;9 IntfGraphics, FPImage, LCLType, SpecializedBitmap, GraphType, Math; 10 10 11 11 const … … 115 115 end; 116 116 117 TFastBitmapPixelComponents = packed record 118 B, G, R, A: Byte; 119 end; 120 117 121 const 118 122 SurfaceMatterColors: array[TSurfaceMatter] of TColor = (clBlack, $0756b0, … … 127 131 Engine: TEngine; 128 132 133 function SwapBRComponent(Value: Integer): Integer; inline; 134 129 135 implementation 136 137 function SwapBRComponent(Value: Integer): Integer; 138 begin 139 // Result := (Value and $00ff00) or ((Value shr 16) and $ff) or ((Value and $ff) shl 16); 140 Result := Value; 141 TFastBitmapPixelComponents(Result).R := TFastBitmapPixelComponents(Value).B; 142 TFastBitmapPixelComponents(Result).B := TFastBitmapPixelComponents(Value).R; 143 end; 130 144 131 145 { TTank } … … 635 649 I: Integer; 636 650 X, Y: Integer; 637 H, W: Integer; 638 Ratio: Single; 651 PixelX, PixelY: Integer; 652 SubPixelPtr: PInteger; 653 SubPixelRowPtr: PInteger; 654 SubPixelSizeX: Integer; 655 SubPixelSizeY: Integer; 639 656 PixelPtr: PInteger; 640 657 PixelRowPtr: PInteger; 658 BytePerPixel: Integer; 659 BytePerRow: Integer; 641 660 RawImage: TRawImage; 642 BytePerPixel: Integer; 643 P: Integer; 644 begin 645 if FRedrawPending then begin 646 FBitmapLower.FillAll(0); 661 Color: Integer; 662 Shift: TPoint; 663 XDiv, XMod, XAcc: Integer; 664 YDiv, YMod, YAcc: Integer; 665 Ratio: Real; 666 TargetHeight: Integer; 667 TargetWidth: Integer; 668 begin 669 if FRedrawPending then 670 begin 671 FRedrawPending := False; 672 //FBitmapLower.FillAll(0); 647 673 for I := 0 to Players.Count - 1 do begin 648 674 TPlayer(Players[I]).Paint; 649 675 end; 650 if Assigned(FBitmap) then try 651 Bitmap.BeginUpdate(False); 676 if Assigned(FBitmap) then 677 try 678 Bitmap.BeginUpdate; 652 679 RawImage := Bitmap.RawImage; 653 PixelRowPtr := PInteger(RawImage.Data);654 680 BytePerPixel := RawImage.Description.BitsPerPixel div 8; 655 if (IntfImage.Width <> FBitmap.Width) or (IntfImage.Height <> FBitmap.Height) then 656 IntfImage.SetSize(FBitmap.Width, FBitmap.Height); 681 BytePerRow := RawImage.Description.BytesPerLine; 682 FillChar(RawImage.Data^, Bitmap.Height * BytePerRow, 0); 683 657 684 if (FBitmap.Width / FBitmapLower.Width) < (FBitmap.Height / FBitmapLower.Height) then 658 685 Ratio := FBitmap.Width / FBitmapLower.Width 659 686 else Ratio := FBitmap.Height / FBitmapLower.Height; 660 for Y := 0 to Trunc(FBitmapLower.Height * Ratio) - 1 do begin 661 PixelPtr := PixelRowPtr; 662 for X := 0 to Trunc(FBitmapLower.Width * Ratio) - 1 do begin 663 P := FBitmapLower.Pixels[Trunc(X / Ratio), Trunc(Y / Ratio)]; 664 PixelPtr^ := ((P and $ff) shl 16) or (P and $00ff00) or ((P shr 16) and $ff); 665 Inc(PByte(PixelPtr), BytePerPixel); 687 688 // Preserve aspect ratio 689 TargetWidth := Trunc(FBitmapLower.Width * Ratio); 690 TargetHeight := Trunc(FBitmapLower.Height * Ratio); 691 692 Shift.X := Trunc((Bitmap.Width - TargetWidth) / 2); 693 Shift.Y := Trunc((Bitmap.Height - TargetHeight) / 2); 694 695 XDiv := TargetWidth div FBitmapLower.Width; 696 XMod := TargetWidth mod FBitmapLower.Width; 697 YDiv := TargetHeight div FBitmapLower.Height; 698 YMod := TargetHeight mod FBitmapLower.Height; 699 700 PixelRowPtr := PInteger(RawImage.Data + BytePerRow * Shift.Y); 701 YAcc := FBitmapLower.Height div 2; 702 for Y := 0 to FBitmapLower.Height - 1 do begin 703 SubPixelSizeY := YDiv; 704 Inc(YAcc, YMod); 705 if YAcc >= FBitmapLower.Height then begin 706 Dec(YAcc, FBitmapLower.Height); 707 Inc(SubPixelSizeY); 666 708 end; 667 Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine); 709 710 PixelPtr := PixelRowPtr + Shift.X; 711 XAcc := FBitmapLower.Width div 2; 712 for X := 0 to FBitmapLower.Width - 1 do begin 713 SubPixelSizeX := XDiv; 714 Inc(XAcc, XMod); 715 if XAcc >= FBitmapLower.Width then begin 716 Dec(XAcc, FBitmapLower.Width); 717 Inc(SubPixelSizeX); 718 end; 719 720 Color := SwapBRComponent(FBitmapLower.Pixels[X, Y]); 721 722 // Draw large pixel 723 SubPixelRowPtr := PixelPtr; 724 for PixelY := 0 to SubPixelSizeY - 1 do begin 725 SubPixelPtr := SubPixelRowPtr; 726 for PixelX := 0 to SubPixelSizeX - 1 do begin 727 SubPixelPtr^ := Color; 728 Inc(PByte(SubPixelPtr), BytePerPixel); 729 end; 730 Inc(PByte(SubPixelRowPtr), BytePerRow); 731 end; 732 Inc(PByte(PixelPtr), BytePerPixel * SubPixelSizeX); 733 end; 734 Inc(PByte(PixelRowPtr), BytePerRow * SubPixelSizeY); 668 735 end; 669 736 finally 670 FBitmap.EndUpdate(False); 671 end; 672 FRedrawPending := False; 737 FBitmap.EndUpdate; 738 end; 673 739 end; 674 740 end;
Note:
See TracChangeset
for help on using the changeset viewer.