1 | unit UPixmapSpecialized;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, Graphics, UGGraphics;
|
---|
9 |
|
---|
10 | type
|
---|
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 |
|
---|
46 | implementation
|
---|
47 |
|
---|
48 | { TColorRGB16 }
|
---|
49 |
|
---|
50 | function TColorRGB16.Create(R, G, B: Word): TColorRGB16;
|
---|
51 | begin
|
---|
52 | Result.R := R;
|
---|
53 | Result.G := G;
|
---|
54 | Result.B := B;
|
---|
55 | end;
|
---|
56 |
|
---|
57 | function TPixmapGray16.Gray16ToColor(Value: TColorGray16): TColor;
|
---|
58 | begin
|
---|
59 | Value := (Value shr 8) and $ff;
|
---|
60 | Result := (Value shl 16) or (Value shl 8) or (Value shl 0);
|
---|
61 | end;
|
---|
62 |
|
---|
63 | function TPixmapGray32.Gray32ToColor(Value: TColorGray32): TColor;
|
---|
64 | begin
|
---|
65 | Value := (Value shr 24) and $ff;
|
---|
66 | Result := (Value shl 16) or (Value shl 8) or (Value shl 0);
|
---|
67 | end;
|
---|
68 |
|
---|
69 | function TPixmapRGB16.RGB16ToColor(Value: TColorRGB16): TColor;
|
---|
70 | begin
|
---|
71 | Result := ((Value.R shr 8) shl 16) or ((Value.G shr 8) shl 8) or
|
---|
72 | ((Value.B shr 8) shl 0);
|
---|
73 | end;
|
---|
74 |
|
---|
75 | function TPixmapGrayVar.GrayVarToColor(Value: TColorGrayVar): TColor;
|
---|
76 | var
|
---|
77 | ValuePart: Byte;
|
---|
78 | begin
|
---|
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;
|
---|
83 | end;
|
---|
84 |
|
---|
85 | function TPixmapGrayVar.GrayVarCreate(Value: QWord): TColorGrayVar;
|
---|
86 | begin
|
---|
87 | Result := GetMem(SizeOf(Value));
|
---|
88 | Move(Value, Result^, SizeOf(Value));
|
---|
89 | end;
|
---|
90 |
|
---|
91 |
|
---|
92 | end.
|
---|
93 |
|
---|