10
TByteRGB = packed record
22
constructor Create(const L_: Byte); overload;
23
constructor Create(const R_, G_, B_: Byte); overload;
24
class operator Positive(const V_: TByteRGB): TByteRGB;
25
class operator Add(const A_, B_: TByteRGB): TByteRGB;
26
class operator Subtract(const A_, B_: TByteRGB): TByteRGB;
27
class operator Multiply(const A_: Byte; const B_: TByteRGB): TByteRGB;
28
class operator Multiply(const A_: TByteRGB; const B_: Byte): TByteRGB;
29
class operator Divide(const A_: TByteRGB; const B_: Byte): TByteRGB;
30
class operator Implicit(const L_: Byte): TByteRGB;
31
class operator Implicit(const C_: TAlphaColor): TByteRGB;
32
class operator Implicit(const C_: TByteRGB): TAlphaColor;
35
PByteRGBA = ^TByteRGBA;
37
TByteRGBA = packed record
40
procedure SetR(const R_: Byte);
42
procedure SetG(const G_: Byte);
44
procedure SetB(const B_: Byte);
53
constructor Create(const L_: Byte; const A_: Byte = $FF); overload;
54
constructor Create(const R_, G_, B_: Byte; const A_: Byte = $FF); overload;
55
property R: Byte read GetR write SetR;
56
property G: Byte read GetG write SetG;
57
property B: Byte read GetB write SetB;
58
class operator Positive(const V_: TByteRGBA): TByteRGBA;
59
class operator Add(const A_, B_: TByteRGBA): TByteRGBA;
60
class operator Subtract(const A_, B_: TByteRGBA): TByteRGBA;
61
class operator Multiply(const A_: Byte; const B_: TByteRGBA): TByteRGBA;
62
class operator Multiply(const A_: TByteRGBA; const B_: Byte): TByteRGBA;
63
class operator Divide(const A_: TByteRGBA; const B_: Byte): TByteRGBA;
64
class operator Implicit(const L_: Byte): TByteRGBA;
65
class operator Implicit(const C_: TByteRGB): TByteRGBA;
66
class operator Explicit(const C_: TByteRGBA): TByteRGB;
67
class operator Implicit(const C_: TAlphaColor): TByteRGBA;
68
class operator Implicit(const C_: TByteRGBA): TAlphaColor;
77
constructor Create(const L_: Single); overload;
78
constructor Create(const R_, G_, B_: Single); overload;
79
class operator Negative(const V_: TSingleRGB): TSingleRGB;
80
class operator Positive(const V_: TSingleRGB): TSingleRGB;
81
class operator Add(const A_, B_: TSingleRGB): TSingleRGB;
82
class operator Subtract(const A_, B_: TSingleRGB): TSingleRGB;
83
class operator Multiply(const A_: Single; const B_: TSingleRGB): TSingleRGB;
84
class operator Multiply(const A_: TSingleRGB; const B_: Single): TSingleRGB;
85
class operator Divide(const A_: TSingleRGB; const B_: Single): TSingleRGB;
86
class operator Implicit(const L_: Single): TSingleRGB;
87
class operator Implicit(const C_: TByteRGB): TSingleRGB;
88
class operator Implicit(const C_: TSingleRGB): TByteRGB;
89
function Gamma(const C_: Single = 2.2): TSingleRGB;
90
function ToneMap(const W_: Single = 1): TSingleRGB;
95
function GetR: Single;
96
procedure SetR(const R_: Single);
97
function GetG: Single;
98
procedure SetG(const G_: Single);
99
function GetB: Single;
100
procedure SetB(const B_: Single);
104
constructor Create(const L_: Single; const A_: Single = 1); overload;
105
constructor Create(const R_, G_, B_: Single; const A_: Single = 1);
107
property R: Single read GetR write SetR;
108
property G: Single read GetG write SetG;
109
property B: Single read GetB write SetB;
110
class operator Negative(const V_: TSingleRGBA): TSingleRGBA;
111
class operator Positive(const V_: TSingleRGBA): TSingleRGBA;
112
class operator Add(const A_, B_: TSingleRGBA): TSingleRGBA;
113
class operator Subtract(const A_, B_: TSingleRGBA): TSingleRGBA;
114
class operator Multiply(const A_: Single; const B_: TSingleRGBA)
116
class operator Multiply(const A_: TSingleRGBA; const B_: Single)
118
class operator Divide(const A_: TSingleRGBA; const B_: Single): TSingleRGBA;
119
class operator Implicit(const L_: Single): TSingleRGBA;
120
class operator Implicit(const C_: TByteRGBA): TSingleRGBA;
121
class operator Explicit(const C_: TSingleRGBA): TByteRGBA;
122
class operator Implicit(const C_: TSingleRGB): TSingleRGBA;
123
class operator Explicit(const C_: TSingleRGBA): TSingleRGB;
124
class operator Implicit(const C_: TSingleRGBA): TAlphaColorF;
125
class operator Implicit(const C_: TAlphaColorF): TSingleRGBA;
126
function Gamma(const C_: Single = 2.2): TSingleRGBA;
127
function ToneMap(const W_: Single = 1): TSingleRGBA;
130
TByteRGBE = packed record
133
procedure SetR(const R_: Byte);
135
procedure SetG(const G_: Byte);
137
procedure SetB(const B_: Byte);
141
constructor Create(const L_: Byte; const E_: Byte = 128); overload;
142
constructor Create(const R_, G_, B_: Byte; const E_: Byte = 128); overload;
143
property R: Byte read GetR write SetR;
144
property G: Byte read GetG write SetG;
145
property B: Byte read GetB write SetB;
146
class operator Implicit(const L_: Byte): TByteRGBE;
147
class operator Implicit(const C_: TByteRGBE): TSingleRGB;
148
class operator Implicit(const C_: TSingleRGB): TByteRGBE;
155
constructor TByteRGB.Create(const L_: Byte);
162
constructor TByteRGB.Create(const R_, G_, B_: Byte);
169
class operator TByteRGB.Positive(const V_: TByteRGB): TByteRGB;
179
class operator TByteRGB.Add(const A_, B_: TByteRGB): TByteRGB;
189
class operator TByteRGB.Subtract(const A_, B_: TByteRGB): TByteRGB;
199
class operator TByteRGB.Multiply(const A_: Byte; const B_: TByteRGB): TByteRGB;
209
class operator TByteRGB.Multiply(const A_: TByteRGB; const B_: Byte): TByteRGB;
219
class operator TByteRGB.Divide(const A_: TByteRGB; const B_: Byte): TByteRGB;
229
class operator TByteRGB.Implicit(const L_: Byte): TByteRGB;
239
class operator TByteRGB.Implicit(const C_: TAlphaColor): TByteRGB;
241
Result := TByteRGBA(C_).C;
244
class operator TByteRGB.Implicit(const C_: TByteRGB): TAlphaColor;
246
Result := TByteRGBA(C_);
249
function TByteRGBA.GetR: Byte;
254
procedure TByteRGBA.SetR(const R_: Byte);
259
function TByteRGBA.GetG: Byte;
264
procedure TByteRGBA.SetG(const G_: Byte);
269
function TByteRGBA.GetB: Byte;
274
procedure TByteRGBA.SetB(const B_: Byte);
279
constructor TByteRGBA.Create(const L_: Byte; const A_: Byte);
285
constructor TByteRGBA.Create(const R_, G_, B_: Byte; const A_: Byte);
293
class operator TByteRGBA.Positive(const V_: TByteRGBA): TByteRGBA;
302
class operator TByteRGBA.Add(const A_, B_: TByteRGBA): TByteRGBA;
311
class operator TByteRGBA.Subtract(const A_, B_: TByteRGBA): TByteRGBA;
320
class operator TByteRGBA.Multiply(const A_: Byte; const B_: TByteRGBA)
330
class operator TByteRGBA.Multiply(const A_: TByteRGBA; const B_: Byte)
340
class operator TByteRGBA.Divide(const A_: TByteRGBA; const B_: Byte): TByteRGBA;
344
// C := A_.C div B_; //E2015 この型には指定した演算子は使えません
353
class operator TByteRGBA.Implicit(const L_: Byte): TByteRGBA;
362
class operator TByteRGBA.Implicit(const C_: TByteRGB): TByteRGBA;
371
class operator TByteRGBA.Explicit(const C_: TByteRGBA): TByteRGB;
376
class operator TByteRGBA.Implicit(const C_: TAlphaColor): TByteRGBA;
378
Result := PByteRGBA(@C_)^;
381
class operator TByteRGBA.Implicit(const C_: TByteRGBA): TAlphaColor;
383
Result := PAlphaColor(@C_)^;
386
constructor TSingleRGB.Create(const L_: Single);
393
constructor TSingleRGB.Create(const R_, G_, B_: Single);
400
class operator TSingleRGB.Negative(const V_: TSingleRGB): TSingleRGB;
410
class operator TSingleRGB.Positive(const V_: TSingleRGB): TSingleRGB;
420
class operator TSingleRGB.Add(const A_, B_: TSingleRGB): TSingleRGB;
430
class operator TSingleRGB.Subtract(const A_, B_: TSingleRGB): TSingleRGB;
440
class operator TSingleRGB.Multiply(const A_: Single; const B_: TSingleRGB)
451
class operator TSingleRGB.Multiply(const A_: TSingleRGB; const B_: Single)
462
class operator TSingleRGB.Divide(const A_: TSingleRGB; const B_: Single)
473
class operator TSingleRGB.Implicit(const L_: Single): TSingleRGB;
483
class operator TSingleRGB.Implicit(const C_: TByteRGB): TSingleRGB;
493
class operator TSingleRGB.Implicit(const C_: TSingleRGB): TByteRGB;
497
R := Round(255 * Clamp(C_.R, 0, 1));
498
G := Round(255 * Clamp(C_.G, 0, 1));
499
B := Round(255 * Clamp(C_.B, 0, 1));
503
function TSingleRGB.Gamma(const C_: Single = 2.2): TSingleRGB;
509
Result.R := Power(R, C);
510
Result.G := Power(G, C);
511
Result.B := Power(B, C);
514
// ------------------------------------------------------------------------------
516
function TSingleRGB.ToneMap(const W_: Single = 1): TSingleRGB;
522
Result.R := Clamp(R * (1 + R / W2) / (1 + R), 0, 1);
523
Result.G := Clamp(G * (1 + G / W2) / (1 + G), 0, 1);
524
Result.B := Clamp(B * (1 + B / W2) / (1 + B), 0, 1);
527
function TSingleRGBA.GetR: Single;
532
procedure TSingleRGBA.SetR(const R_: Single);
537
function TSingleRGBA.GetG: Single;
542
procedure TSingleRGBA.SetG(const G_: Single);
547
function TSingleRGBA.GetB: Single;
552
procedure TSingleRGBA.SetB(const B_: Single);
557
constructor TSingleRGBA.Create(const L_: Single; const A_: Single = 1);
563
constructor TSingleRGBA.Create(const R_, G_, B_: Single; const A_: Single = 1);
571
class operator TSingleRGBA.Negative(const V_: TSingleRGBA): TSingleRGBA;
580
class operator TSingleRGBA.Positive(const V_: TSingleRGBA): TSingleRGBA;
589
class operator TSingleRGBA.Add(const A_, B_: TSingleRGBA): TSingleRGBA;
598
class operator TSingleRGBA.Subtract(const A_, B_: TSingleRGBA): TSingleRGBA;
607
class operator TSingleRGBA.Multiply(const A_: Single; const B_: TSingleRGBA)
617
class operator TSingleRGBA.Multiply(const A_: TSingleRGBA; const B_: Single)
627
class operator TSingleRGBA.Divide(const A_: TSingleRGBA; const B_: Single)
637
class operator TSingleRGBA.Implicit(const L_: Single): TSingleRGBA;
646
// ------------------------------------------------------------------------------
648
class operator TSingleRGBA.Implicit(const C_: TByteRGBA): TSingleRGBA;
658
class operator TSingleRGBA.Explicit(const C_: TSingleRGBA): TByteRGBA;
664
A := Round(255 * Clamp(C_.A, 0, 1));
668
// ------------------------------------------------------------------------------
670
class operator TSingleRGBA.Implicit(const C_: TSingleRGB): TSingleRGBA;
676
class operator TSingleRGBA.Explicit(const C_: TSingleRGBA): TSingleRGB;
681
// ------------------------------------------------------------------------------
683
class operator TSingleRGBA.Implicit(const C_: TSingleRGBA): TAlphaColorF;
694
class operator TSingleRGBA.Implicit(const C_: TAlphaColorF): TSingleRGBA;
705
function TSingleRGBA.Gamma(const C_: Single = 2.2): TSingleRGBA;
707
Result.C := C.Gamma(C_);
711
// ------------------------------------------------------------------------------
713
function TSingleRGBA.ToneMap(const W_: Single = 1): TSingleRGBA;
715
Result.C := C.ToneMap(W_);
719
function TByteRGBE.GetR: Byte;
724
procedure TByteRGBE.SetR(const R_: Byte);
729
function TByteRGBE.GetG: Byte;
734
procedure TByteRGBE.SetG(const G_: Byte);
739
function TByteRGBE.GetB: Byte;
744
procedure TByteRGBE.SetB(const B_: Byte);
749
constructor TByteRGBE.Create(const L_: Byte; const E_: Byte = 128);
755
constructor TByteRGBE.Create(const R_, G_, B_: Byte; const E_: Byte = 128);
763
class operator TByteRGBE.Implicit(const L_: Byte): TByteRGBE;
772
class operator TByteRGBE.Implicit(const C_: TByteRGBE): TSingleRGB;
779
S := IntPower(2, +E) / 255;
781
Result.R := S * C_.R;
782
Result.G := S * C_.G;
783
Result.B := S * C_.B;
786
class operator TByteRGBE.Implicit(const C_: TSingleRGB): TByteRGBE;
797
S := IntPower(2, -E) * 255;
799
Result.R := Round(S * C_.R);
800
Result.G := Round(S * C_.G);
801
Result.B := Round(S * C_.B);