UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TransferFunctions.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreTypes.h"
8#include "Math/Color.h"
10#include "Templates/Function.h"
11
12namespace UE { namespace Color {
13
14inline float Linear(float Value)
15{
16 return Value;
17}
18
24inline float EncodeSRGB(float Value)
25{
26 if (Value <= 0.04045f / 12.92f)
27 {
28 return Value * 12.92f;
29 }
30 else
31 {
32 return FGenericPlatformMath::Pow(Value, (1.0f / 2.4f)) * 1.055f - 0.055f;
33 }
34}
35
41inline float DecodeSRGB(float Value)
42{
43 if (Value <= 0.04045f)
44 {
45 return Value / 12.92f;
46 }
47 else
48 {
49 return FGenericPlatformMath::Pow((Value + 0.055f) / 1.055f, 2.4f);
50 }
51}
52
58inline float EncodeST2084(float Value)
59{
60 const float Lp = 10000.0f;
61 const float m1 = 2610 / 4096.0f * (1.0f / 4.0f);
62 const float m2 = 2523 / 4096.0f * 128.0f;
63 const float c1 = 3424 / 4096.0f;
64 const float c2 = 2413 / 4096.0f * 32.f;
65 const float c3 = 2392 / 4096.0f * 32.f;
66
68 return FGenericPlatformMath::Pow((c1 + c2 * Value) / (c3 * Value + 1), m2);
69}
70
76inline float DecodeST2084(float Value)
77{
78 const float Lp = 10000.0f;
79 const float m1 = 2610 / 4096.0f * (1.0f / 4.0f);
80 const float m2 = 2523 / 4096.0f * 128.0f;
81 const float c1 = 3424 / 4096.0f;
82 const float c2 = 2413 / 4096.0f * 32.f;
83 const float c3 = 2392 / 4096.0f * 32.f;
84
85 const float Vp = FGenericPlatformMath::Pow(Value, 1.0f / m2);
87 return FGenericPlatformMath::Pow((Value / (c2 - c3 * Vp)), 1.0f / m1) * Lp;
88}
89
95inline float EncodeGamma22(float Value)
96{
97 return FGenericPlatformMath::Pow(Value, 1.0f / 2.2f);
98}
99
100
106inline float DecodeGamma22(float Value)
107{
108 return FGenericPlatformMath::Pow(Value, 2.2f);
109}
110
116inline float EncodeBT1886(float Value)
117{
118 const float L_B = 0;
119 const float L_W = 1;
120 float Gamma = 2.40f;
121 float GammaInv = 1.0f / Gamma;
123 float A = FGenericPlatformMath::Pow(N, Gamma);
126}
127
133inline float EncodeGamma26(float Value)
134{
135 return FGenericPlatformMath::Pow(Value, 1.0f / 2.6f);
136}
137
138
144inline float DecodeGamma26(float Value)
145{
146 return FGenericPlatformMath::Pow(Value, 2.6f);
147}
148
154inline float DecodeBT1886(float Value)
155{
156 const float L_B = 0;
157 const float L_W = 1;
158 float Gamma = 2.40f;
159 float GammaInv = 1.0f / Gamma;
161 float A = FGenericPlatformMath::Pow(N, Gamma);
164}
165
171inline float EncodeCineon(float Value)
172{
173 const float BlackOffset = FGenericPlatformMath::Pow(10.0f, (95.0f - 685.0f) / 300.0f);
174 return (685.0f + 300.0f * FGenericPlatformMath::LogX(10.0f, Value * (1.0f - BlackOffset) + BlackOffset)) / 1023.0f;
175}
176
182inline float DecodeCineon(float Value)
183{
184 const float BlackOffset = FGenericPlatformMath::Pow(10.0f, (95.0f - 685.0f) / 300.0f);
185 return (FGenericPlatformMath::Pow(10.0f, (1023.0f * Value - 685.0f) / 300.0f) - BlackOffset) / (1.0f - BlackOffset);
186}
187
193inline float EncodeREDLog(float Value)
194{
195 const float BlackOffset = FGenericPlatformMath::Pow(10.0f, (0.0f - 1023.0f) / 511.0f);
196 return (1023.0f + 511.0f * FGenericPlatformMath::LogX(10.0f, Value * (1.0f - BlackOffset) + BlackOffset)) / 1023.0f;
197}
198
204inline float DecodeREDLog(float Value)
205{
206 const float BlackOffset = FGenericPlatformMath::Pow(10.0f, (0.0f - 1023.0f) / 511.0f);
207 return (FGenericPlatformMath::Pow(10.0f, (1023.0f * Value - 1023.0f) / 511.0f) - BlackOffset) / (1.0f - BlackOffset);
208}
209
215inline float EncodeREDLog3G10(float Value)
216{
217 const float A = 0.224282f;
218 const float B = 155.975327f;
219 const float C = 0.01f;
220 const float G = 15.1927f;
221
222 Value += C;
223
224 if (Value < 0.0f)
225 {
226 return Value * G;
227 }
228 else
229 {
231 }
232}
233
239inline float DecodeREDLog3G10(float Value)
240{
241 const float A = 0.224282f;
242 const float B = 155.975327f;
243 const float C = 0.01f;
244 const float G = 15.1927f;
245
246 if (Value < 0.0f)
247 {
248 Value /= G;
249 }
250 else
251 {
253 }
254
255 return Value - C;
256}
257
263inline float EncodeSLog1(float Value)
264{
265 Value /= 0.9f;
266 Value = 0.432699f * FGenericPlatformMath::LogX(10.0f, Value + 0.037584f) + 0.616596f + 0.03f;
267 return (Value * 219.0f + 16.0f) * 4.0f / 1023.0f;
268}
269
275inline float DecodeSLog1(float Value)
276{
277 Value = ((Value * 1023.f) / 4.0f - 16.0f) / 219.0f;
278 Value = FGenericPlatformMath::Pow(10.0f, (Value - 0.616596f - 0.03f) / 0.432699f) - 0.037584f;
279 return Value * 0.9f;
280}
281
287inline float EncodeSLog2(float Value)
288{
289 if (Value >= 0.0f)
290 {
291 return (64.0f + 876.0f * (0.432699f * FGenericPlatformMath::LogX(10.0f, 155.0f * Value / 197.1f + 0.037584f) + 0.646596f)) / 1023.f;
292 }
293 else
294 {
295 return (64.0f +876.0f * (Value * 3.53881278538813f / 0.9f) + 0.646596f + 0.030001222851889303f) / 1023.f;
296 }
297}
298
304inline float DecodeSLog2(float Value)
305{
306 if (Value >= (64.f + 0.030001222851889303f * 876.f) / 1023.f)
307 {
308 return 197.1f * (FGenericPlatformMath::Pow(10.0f, ((Value * 1023.f - 64.f) / 876.f - 0.646596f) / 0.432699f) - 0.037584f) / 155.f;
309 }
310 else
311 {
312 return 0.9f * ((Value * 1023.f - 64.f) / 876.f - 0.030001222851889303f) / 3.53881278538813f;
313 }
314}
315
321inline float EncodeSLog3(float Value)
322{
323 if (Value >= 0.01125000f)
324 {
325 return (420.0f + FGenericPlatformMath::LogX(10.0f, (Value + 0.01f) / 0.19f) * 261.5f) / 1023.0f;
326 }
327 else
328 {
329 return (Value * 76.2102946929f / 0.01125f + 95.0f) / 1023.0f;
330 }
331}
332
338inline float DecodeSLog3(float Value)
339{
340 if (Value >= 171.2102946929f / 1023.0f)
341 {
342 return (FGenericPlatformMath::Pow(10.0f, (Value * 1023.0f - 420.f) / 261.5f)) * 0.19f - 0.01f;
343 }
344 else
345 {
346 return (Value * 1023.0f - 95.0f) * 0.01125000f / (171.2102946929f - 95.0f);
347 }
348}
349
355inline float EncodeArriAlexaV3LogC(float Value)
356{
357 const float cut = 0.010591f;
358 const float a = 5.555556f;
359 const float b = 0.052272f;
360 const float c = 0.247190f;
361 const float d = 0.385537f;
362 const float e = 5.367655f;
363 const float f = 0.092809f;
364
365 if (Value > cut)
366 {
367 return c * FGenericPlatformMath::LogX(10.0f, a * Value + b) + d;
368 }
369 else
370 {
371 return e * Value + f;
372 }
373}
374
380inline float DecodeArriAlexaV3LogC(float Value)
381{
382 const float cut = 0.010591f;
383 const float a = 5.555556f;
384 const float b = 0.052272f;
385 const float c = 0.247190f;
386 const float d = 0.385537f;
387 const float e = 5.367655f;
388 const float f = 0.092809f;
389
390 if (Value > e * cut + f)
391 {
392 return (FGenericPlatformMath::Pow(10.0f, (Value - d) / c) - b) / a;
393 }
394 else
395 {
396 return (Value - f) / e;
397 }
398}
399
405inline float EncodeCanonLog(float Value)
406{
407 if (Value < 0.0f)
408 {
409 return -(0.529136f * (FGenericPlatformMath::LogX(10.0f, -Value * 10.1596f + 1.0f)) - 0.0730597f);
410 }
411 else
412 {
413 return 0.529136f * FGenericPlatformMath::LogX(10.0f, 10.1596f * Value + 1.0f) + 0.0730597f;
414 }
415}
416
417
423inline float DecodeCanonLog(float Value)
424{
425 if (Value < 0.0730597f)
426 {
427 return -(FGenericPlatformMath::Pow(10.0f, (0.0730597f - Value) / 0.529136f) - 1.0f) / 10.1596f;
428 }
429 else
430 {
431 return (FGenericPlatformMath::Pow(10.0f, (Value - 0.0730597f) / 0.529136f) - 1.0f) / 10.1596f;
432 }
433}
434
440inline float EncodeGoProProTune(float Value)
441{
442 return FGenericPlatformMath::Loge(Value * 112.f + 1.0f) / FGenericPlatformMath::Loge(113.0f);
443}
444
450inline float DecodeGoProProTune(float Value)
451{
452 return (FGenericPlatformMath::Pow(113.f, Value) - 1.0f) / 112.f;
453}
454
460inline float EncodePanasonicVLog(float Value)
461{
462 const float b = 0.00873f;
463 const float c = 0.241514f;
464 const float d = 0.598206f;
465
466 if( Value < 0.01f)
467 {
468 return 5.6f * Value + 0.125f;
469 }
470 else
471 {
472 return c * FGenericPlatformMath::LogX(10.0f, Value + b) + d;
473 }
474}
475
481inline float DecodePanasonicVLog(float Value)
482{
483 const float b = 0.00873f;
484 const float c = 0.241514f;
485 const float d = 0.598206f;
486
487 if (Value < 0.181f)
488 {
489 return (Value - 0.125f) / 5.6f;
490 }
491 else
492 {
493 return FGenericPlatformMath::Pow(10.0f, (Value - d) / c) - b;
494 }
495}
496
499
502
504CORE_API float Encode(EEncoding Encoding, float Value);
505
507CORE_API float Decode(EEncoding Encoding, float Value);
508
511
514
516CORE_API FLinearColor Encode(EEncoding Encoding, const FLinearColor& Color);
517
519CORE_API FLinearColor Decode(EEncoding Encoding, const FLinearColor& Color);
520
521} } // end namespace UE::Color
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition AndroidPlatformMisc.h:14
float EncodeREDLog3G10(float Value)
Definition TransferFunctions.h:215
float DecodeST2084(float Value)
Definition TransferFunctions.h:76
float EncodeGamma22(float Value)
Definition TransferFunctions.h:95
float EncodeArriAlexaV3LogC(float Value)
Definition TransferFunctions.h:355
TFunction< FLinearColor(const FLinearColor &)> GetColorEncodeFunction(EEncoding SourceEncoding)
Definition TransferFunctions.cpp:75
float EncodeCineon(float Value)
Definition TransferFunctions.h:171
float EncodeGamma26(float Value)
Definition TransferFunctions.h:133
float Encode(EEncoding SourceEncoding, float Value)
Definition TransferFunctions.cpp:51
float EncodeBT1886(float Value)
Definition TransferFunctions.h:116
float DecodeSLog2(float Value)
Definition TransferFunctions.h:304
float DecodeCineon(float Value)
Definition TransferFunctions.h:182
float DecodePanasonicVLog(float Value)
Definition TransferFunctions.h:481
float EncodePanasonicVLog(float Value)
Definition TransferFunctions.h:460
float EncodeSLog2(float Value)
Definition TransferFunctions.h:287
float EncodeREDLog(float Value)
Definition TransferFunctions.h:193
float DecodeBT1886(float Value)
Definition TransferFunctions.h:154
float DecodeGoProProTune(float Value)
Definition TransferFunctions.h:450
TFunction< float(float)> GetDecodeFunction(EEncoding SourceEncoding)
Definition TransferFunctions.cpp:46
TFunction< float(float)> GetEncodeFunction(EEncoding SourceEncoding)
Definition TransferFunctions.cpp:41
EEncoding
Definition ColorManagementDefines.h:20
float DecodeSLog1(float Value)
Definition TransferFunctions.h:275
float DecodeGamma26(float Value)
Definition TransferFunctions.h:144
float DecodeSRGB(float Value)
Definition TransferFunctions.h:41
float Decode(EEncoding SourceEncoding, float Value)
Definition TransferFunctions.cpp:63
float DecodeGamma22(float Value)
Definition TransferFunctions.h:106
TFunction< FLinearColor(const FLinearColor &)> GetColorDecodeFunction(EEncoding SourceEncoding)
Definition TransferFunctions.cpp:90
float EncodeSLog3(float Value)
Definition TransferFunctions.h:321
float EncodeGoProProTune(float Value)
Definition TransferFunctions.h:440
float EncodeSRGB(float Value)
Definition TransferFunctions.h:24
float EncodeSLog1(float Value)
Definition TransferFunctions.h:263
float DecodeREDLog3G10(float Value)
Definition TransferFunctions.h:239
float EncodeCanonLog(float Value)
Definition TransferFunctions.h:405
float EncodeST2084(float Value)
Definition TransferFunctions.h:58
float DecodeREDLog(float Value)
Definition TransferFunctions.h:204
float DecodeArriAlexaV3LogC(float Value)
Definition TransferFunctions.h:380
float DecodeSLog3(float Value)
Definition TransferFunctions.h:338
float DecodeCanonLog(float Value)
Definition TransferFunctions.h:423
Definition AdvancedWidgetsModule.cpp:13
static UE_FORCEINLINE_HINT float Pow(float A, float B)
Definition GenericPlatformMath.h:555
static constexpr UE_FORCEINLINE_HINT T Abs(const T A)
Definition GenericPlatformMath.h:949
static UE_FORCEINLINE_HINT float LogX(float Base, float Value)
Definition GenericPlatformMath.h:498
static constexpr UE_FORCEINLINE_HINT T Sign(const T A)
Definition GenericPlatformMath.h:956
static constexpr UE_FORCEINLINE_HINT T Max(T A, T B)
Definition GenericPlatformMath.h:963
static UE_FORCEINLINE_HINT float Loge(float Value)
Definition GenericPlatformMath.h:495
Definition Color.h:48