source: trunk/Packages/CevoComponents/UPixelPointer.pas@ 331

Last change on this file since 331 was 331, checked in by chronos, 9 months ago
  • Modified: Player border tile preparation code for bitmap color replacement moved to ScreenTools.
File size: 2.9 KB
Line 
1unit UPixelPointer;
2
3interface
4
5uses
6 Classes, SysUtils, Graphics;
7
8type
9 TColor32 = type Cardinal;
10 TColor32Component = (ccBlue, ccGreen, ccRed, ccAlpha);
11
12 { TPixel32 }
13
14 TPixel32 = packed record
15 private
16 function GetRGB: Cardinal;
17 procedure SetRGB(AValue: Cardinal);
18 public
19 property RGB: Cardinal read GetRGB write SetRGB;
20 case Integer of
21 0: (B, G, R, A: Byte);
22 1: (ARGB: TColor32);
23 2: (Planes: array[0..3] of Byte);
24 3: (Components: array[TColor32Component] of Byte);
25 end;
26 PPixel32 = ^TPixel32;
27
28 { TPixelPointer }
29
30 TPixelPointer = record
31 Base: PPixel32;
32 Pixel: PPixel32;
33 Line: PPixel32;
34 RelLine: PPixel32;
35 BytesPerPixel: Integer;
36 BytesPerLine: Integer;
37 procedure NextLine; inline; // Move pointer to start of next line
38 procedure PreviousLine; inline; // Move pointer to start of previous line
39 procedure NextPixel; inline; // Move pointer to next pixel
40 procedure PreviousPixel; inline; // Move pointer to previous pixel
41 procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base
42 procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base
43 end;
44 PPixelPointer = ^TPixelPointer;
45
46 function PixelPointer(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; inline;
47 function SwapRedBlue(Color: TColor32): TColor32;
48
49implementation
50
51{ TPixel32 }
52
53function TPixel32.GetRGB: Cardinal;
54begin
55 Result := ARGB and $ffffff;
56end;
57
58procedure TPixel32.SetRGB(AValue: Cardinal);
59begin
60 R := (AValue shr 16) and $ff;
61 G := (AValue shr 8) and $ff;
62 B := (AValue shr 0) and $ff;
63end;
64
65{ TPixelPointer }
66
67procedure TPixelPointer.NextLine; inline;
68begin
69 Line := Pointer(Line) + BytesPerLine;
70 Pixel := Line;
71end;
72
73procedure TPixelPointer.PreviousLine;
74begin
75 Line := Pointer(Line) - BytesPerLine;
76 Pixel := Line;
77end;
78
79procedure TPixelPointer.NextPixel; inline;
80begin
81 Pixel := Pointer(Pixel) + BytesPerPixel;
82end;
83
84procedure TPixelPointer.PreviousPixel;
85begin
86 Pixel := Pointer(Pixel) - BytesPerPixel;
87end;
88
89procedure TPixelPointer.SetXY(X, Y: Integer); inline;
90begin
91 Line := Pointer(Base) + Y * BytesPerLine;
92 SetX(X);
93end;
94
95procedure TPixelPointer.SetX(X: Integer); inline;
96begin
97 Pixel := Pointer(Line) + X * BytesPerPixel;
98end;
99
100function PixelPointer(Bitmap: TRasterImage; BaseX: Integer;
101 BaseY: Integer): TPixelPointer;
102begin
103 Result.BytesPerLine := Bitmap.RawImage.Description.BytesPerLine;
104 Result.BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3;
105 Result.Base := PPixel32(Bitmap.RawImage.Data + BaseX * Result.BytesPerPixel +
106 BaseY * Result.BytesPerLine);
107 Result.SetXY(0, 0);
108end;
109
110function SwapRedBlue(Color: TColor32): TColor32;
111begin
112 Result := (Color and $ff00ff00) or ((Color and $ff) shl 16) or ((Color shr 16) and $ff);
113end;
114
115
116end.
117
Note: See TracBrowser for help on using the repository browser.