source: branches/AlphaChannel/Packages/CevoComponents/UPixelPointer.pas

Last change on this file was 230, checked in by chronos, 5 years ago
  • Modified: Optimized drawing in Wonders window.
File size: 2.3 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 TPixel32 = packed record
12 case Integer of
13 0: (B, G, R, A: Byte);
14 1: (ARGB: TColor32);
15 2: (Planes: array[0..3] of Byte);
16 3: (Components: array[TColor32Component] of Byte);
17 end;
18 PPixel32 = ^TPixel32;
19
20 { TPixelPointer }
21
22 TPixelPointer = record
23 Base: PPixel32;
24 Pixel: PPixel32;
25 Line: PPixel32;
26 RelLine: PPixel32;
27 BytesPerPixel: Integer;
28 BytesPerLine: Integer;
29 procedure NextLine; inline; // Move pointer to start of next line
30 procedure PreviousLine; inline; // Move pointer to start of previous line
31 procedure NextPixel; inline; // Move pointer to next pixel
32 procedure PreviousPixel; inline; // Move pointer to previous pixel
33 procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base
34 procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base
35 end;
36 PPixelPointer = ^TPixelPointer;
37
38 function PixelPointer(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; inline;
39
40
41implementation
42
43{ TPixelPointer }
44
45procedure TPixelPointer.NextLine; inline;
46begin
47 Line := Pointer(Line) + BytesPerLine;
48 Pixel := Line;
49end;
50
51procedure TPixelPointer.PreviousLine;
52begin
53 Line := Pointer(Line) - BytesPerLine;
54 Pixel := Line;
55end;
56
57procedure TPixelPointer.NextPixel; inline;
58begin
59 Pixel := Pointer(Pixel) + BytesPerPixel;
60end;
61
62procedure TPixelPointer.PreviousPixel;
63begin
64 Pixel := Pointer(Pixel) - BytesPerPixel;
65end;
66
67procedure TPixelPointer.SetXY(X, Y: Integer); inline;
68begin
69 Line := Pointer(Base) + Y * BytesPerLine;
70 SetX(X);
71end;
72
73procedure TPixelPointer.SetX(X: Integer); inline;
74begin
75 Pixel := Pointer(Line) + X * BytesPerPixel;
76end;
77
78function PixelPointer(Bitmap: TRasterImage; BaseX: Integer;
79 BaseY: Integer): TPixelPointer;
80begin
81 Result.BytesPerLine := Bitmap.RawImage.Description.BytesPerLine;
82 Result.BytesPerPixel := Bitmap.RawImage.Description.BitsPerPixel shr 3;
83 Result.Base := PPixel32(Bitmap.RawImage.Data + BaseX * Result.BytesPerPixel +
84 BaseY * Result.BytesPerLine);
85 Result.SetXY(0, 0);
86end;
87
88
89end.
90
Note: See TracBrowser for help on using the repository browser.