source: trunk/Packages/FastGraphics/UPixmapSpecialized.pas

Last change on this file was 26, checked in by chronos, 8 years ago
File size: 2.0 KB
Line 
1unit UPixmapSpecialized;
2
3{$mode delphi}
4
5interface
6
7uses
8 Classes, SysUtils, Graphics, UGGraphics;
9
10type
11 TColorGray16 = Word;
12 TColorGray32 = Cardinal;
13
14 { TColorRGB16 }
15
16 TColorRGB16 = record
17 R: Word;
18 B: Word;
19 G: Word;
20 function Create(R, G, B: Word): TColorRGB16;
21 end;
22
23 { TGrayVar }
24
25 TColorGrayVar = PByte;
26
27 TPixmapGray16 = class(TGPixmap<TColorGray16>)
28 function Gray16ToColor(Value: TColorGray16): TColor;
29 end;
30
31 TPixmapGray32 = class(TGPixmap<TColorGray32>)
32 function Gray32ToColor(Value: TColorGray32): TColor;
33 end;
34
35 TPixmapRGB16 = class(TGPixmap<TColorRGB16>)
36 function RGB16ToColor(Value: TColorRGB16): TColor;
37 end;
38
39 TPixmapGrayVar = class(TGPixmap<TColorGrayVar>)
40 function GrayVarToColor(Value: TColorGrayVar): TColor;
41 function GrayVarCreate(Value: QWord): TColorGrayVar;
42 end;
43
44
45
46implementation
47
48{ TColorRGB16 }
49
50function TColorRGB16.Create(R, G, B: Word): TColorRGB16;
51begin
52 Result.R := R;
53 Result.G := G;
54 Result.B := B;
55end;
56
57function TPixmapGray16.Gray16ToColor(Value: TColorGray16): TColor;
58begin
59 Value := (Value shr 8) and $ff;
60 Result := (Value shl 16) or (Value shl 8) or (Value shl 0);
61end;
62
63function TPixmapGray32.Gray32ToColor(Value: TColorGray32): TColor;
64begin
65 Value := (Value shr 24) and $ff;
66 Result := (Value shl 16) or (Value shl 8) or (Value shl 0);
67end;
68
69function TPixmapRGB16.RGB16ToColor(Value: TColorRGB16): TColor;
70begin
71 Result := ((Value.R shr 8) shl 16) or ((Value.G shr 8) shl 8) or
72 ((Value.B shr 8) shl 0);
73end;
74
75function TPixmapGrayVar.GrayVarToColor(Value: TColorGrayVar): TColor;
76var
77 ValuePart: Byte;
78begin
79 if Assigned(Value) then begin
80 ValuePart := PByte(Value + MemSize(Value) - 1)^;
81 Result := (ValuePart shl 16) or (ValuePart shl 8) or (ValuePart shl 0);
82 end else Result := clBlack;
83end;
84
85function TPixmapGrayVar.GrayVarCreate(Value: QWord): TColorGrayVar;
86begin
87 Result := GetMem(SizeOf(Value));
88 Move(Value, Result^, SizeOf(Value));
89end;
90
91
92end.
93
Note: See TracBrowser for help on using the repository browser.