UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ImagePixelData.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Misc/CoreDefines.h"
6#include "Math/IntPoint.h"
7#include "IImageWrapper.h"
9#include "ImageCore.h"
10
11class FFloat16Color;
12template<typename PixelType> struct TImagePixelDataTraits;
13
14
15// todo : use ImageCore ERawImageFormat instead
17{
18 Color,
19 Float16,
20 Float32,
21};
22
27
29
30
31// @todo Oodle : use ImageCore FImage instead
32// get rid of this whole class and TImagePixelData too
33// just use an FImage instead
35{
36 virtual ~FImagePixelData() {}
37
38 // NOTE : before, U8 would be written to EXR *linear*
39 // now it will get gamma corrected if bSRGB (which is on by default)
40
45 {
46 return Type;
47 }
48
53 {
54 return Size;
55 }
56
61 {
62 return PixelLayout;
63 }
64
69 {
70 return BitDepth;
71 }
72
77 {
78 return NumChannels;
79 }
80
85 {
86 const void* RawPtr = nullptr;
87 int64 SizeBytes = 0;
88
89 FImageView Ret;
90
91 if ( ! GetRawData(RawPtr, SizeBytes) )
92 {
93 return FImageView();
94 }
95
96 check( NumChannels == 4 );
97
98 switch(Type)
99 {
101 check(PixelLayout == ERGBFormat::BGRA );
102 check(BitDepth == 8 );
103 Ret = FImageView( (const FColor *)RawPtr, Size.X, Size.Y, bSRGB ? EGammaSpace::sRGB : EGammaSpace::Linear );
104 break;
105
107 check(PixelLayout == ERGBFormat::RGBAF );
108 check(BitDepth == 16 );
109 Ret = FImageView( (const FFloat16Color *)RawPtr, Size.X, Size.Y );
110 break;
111
113 check(PixelLayout == ERGBFormat::RGBAF );
114 check(BitDepth == 32 );
115 Ret = FImageView( (const FLinearColor *)RawPtr, Size.X, Size.Y );
116 break;
117
118 default:
119 check(0);
120 return FImageView();
121 }
122
123 check( Ret.GetImageSizeBytes() == SizeBytes );
124 return Ret;
125 }
126
134
138 bool IsDataWellFormed() const
139 {
140 const void* RawPtr = nullptr;
141 int64 SizeBytes = 0;
142
143 return GetRawData(RawPtr, SizeBytes);
144 }
145
149 bool GetRawData(const void*& OutRawData, int64& OutSizeBytes) const
150 {
151 const void* RawPtr = nullptr;
152 int64 SizeBytes = 0;
153
154 RetrieveData(RawPtr, SizeBytes);
155
156 int64 FoundTotalSize = int64(Size.X)*int64(Size.Y)*int64(BitDepth / 8)*int64(NumChannels);
157 if (RawPtr && SizeBytes == FoundTotalSize)
158 {
159 OutRawData = RawPtr;
160 OutSizeBytes = SizeBytes;
161 return true;
162 }
163 return false;
164 }
165
170 {
171 const void* RawPtr = nullptr;
172 int64 SizeBytes = 0;
173
174 RetrieveData(RawPtr, SizeBytes);
175 return SizeBytes;
176 }
177
182 {
183 return Copy();
184 }
185
190 {
191 return Move();
192 }
193
197 template<typename T>
198 T* GetPayload() { return static_cast<T*>(Payload.Get()); }
199
203 template<typename T>
204 const T* GetPayload() const { return static_cast<T*>(Payload.Get()); }
205
209 void SetPayload(FImagePixelPayloadPtr NewPayload) { Payload = NewPayload; }
210
211 bool GetSRGB() const { return bSRGB; }
212 void SetSRGB(bool InSRGB) { bSRGB = InSRGB; }
213
214protected:
215
217 : Size(InSize)
218 , Type(InPixelType)
219 , PixelLayout(InPixelLayout)
220 , BitDepth(InBitDepth)
221 , NumChannels(InNumChannels)
222 , Payload(InPayload)
223 {
224 // FColor is sRGB by default, floats are Linear
225 bSRGB = ( InPixelType == EImagePixelType::Color );
226 }
227
228private:
229
233 virtual void RetrieveData(const void*& OutDataPtr, int64& OutSizeBytes) const = 0;
234 virtual TUniquePtr<FImagePixelData> Copy() const = 0;
235 virtual TUniquePtr<FImagePixelData> Move() = 0;
236
238 FIntPoint Size;
239
241 EImagePixelType Type;
242
244 ERGBFormat PixelLayout;
245
247 uint8 BitDepth;
248
250 uint8 NumChannels;
251
253 bool bSRGB;
254
256 FImagePixelPayloadPtr Payload;
257};
258
262template<typename PixelType>
264{
266
268 : FImagePixelData(InSize, TImagePixelDataTraits<PixelType>::PixelType, TImagePixelDataTraits<PixelType>::PixelLayout, TImagePixelDataTraits<PixelType>::BitDepth, TImagePixelDataTraits<PixelType>::NumChannels, nullptr)
269 {}
270
272 : FImagePixelData(InSize, TImagePixelDataTraits<PixelType>::PixelType, TImagePixelDataTraits<PixelType>::PixelLayout, TImagePixelDataTraits<PixelType>::BitDepth, TImagePixelDataTraits<PixelType>::NumChannels, nullptr)
274 {}
275
277 : FImagePixelData(InSize, TImagePixelDataTraits<PixelType>::PixelType, TImagePixelDataTraits<PixelType>::PixelLayout, TImagePixelDataTraits<PixelType>::BitDepth, TImagePixelDataTraits<PixelType>::NumChannels, InPayload)
278 {}
279
284
286 {
288 }
289
290 virtual TUniquePtr<FImagePixelData> Copy() const override
291 {
293 }
294
295 virtual void RetrieveData(const void*& OutDataPtr, int64& OutSizeBytes) const override
296 {
297 OutDataPtr = static_cast<const void*>(&Pixels[0]);
298 OutSizeBytes = Pixels.Num() * sizeof(PixelType);
299 }
300};
301
303{
304 static const ERGBFormat PixelLayout = ERGBFormat::BGRA;
305 static const EImagePixelType PixelType = EImagePixelType::Color;
306
307 enum { BitDepth = 8, NumChannels = 4 };
308};
309
311{
312 static const ERGBFormat PixelLayout = ERGBFormat::RGBAF;
314
315 enum { BitDepth = 16, NumChannels = 4 };
316};
317
319{
320 static const ERGBFormat PixelLayout = ERGBFormat::RGBAF;
322
323 enum { BitDepth = 32, NumChannels = 4 };
324};
325
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
ERGBFormat
Definition IImageWrapper.h:76
TSharedPtr< IImagePixelDataPayload, ESPMode::ThreadSafe > FImagePixelPayloadPtr
Definition ImagePixelData.h:28
EImagePixelType
Definition ImagePixelData.h:17
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Float16Color.h:13
Definition SharedPointer.h:692
UE_FORCEINLINE_HINT ObjectType * Get() const
Definition SharedPointer.h:1065
Definition UniquePtr.h:107
IMAGECORE_API void SetAlphaOpaque(const FImageView &InImage)
Definition ImageCore.cpp:1733
Definition Color.h:486
int64 GetImageSizeBytes() const
Definition ImageCore.h:205
Definition ImagePixelData.h:35
T * GetPayload()
Definition ImagePixelData.h:198
FImagePixelData(const FIntPoint &InSize, EImagePixelType InPixelType, ERGBFormat InPixelLayout, uint8 InBitDepth, uint8 InNumChannels, FImagePixelPayloadPtr InPayload)
Definition ImagePixelData.h:216
void SetSRGB(bool InSRGB)
Definition ImagePixelData.h:212
FImageView GetImageView() const
Definition ImagePixelData.h:84
void SetAlphaOpaque()
Definition ImagePixelData.h:130
bool GetSRGB() const
Definition ImagePixelData.h:211
int64 GetRawDataSizeInBytes() const
Definition ImagePixelData.h:169
EImagePixelType GetType() const
Definition ImagePixelData.h:44
virtual ~FImagePixelData()
Definition ImagePixelData.h:36
bool GetRawData(const void *&OutRawData, int64 &OutSizeBytes) const
Definition ImagePixelData.h:149
bool IsDataWellFormed() const
Definition ImagePixelData.h:138
const T * GetPayload() const
Definition ImagePixelData.h:204
FIntPoint GetSize() const
Definition ImagePixelData.h:52
ERGBFormat GetPixelLayout() const
Definition ImagePixelData.h:60
TUniquePtr< FImagePixelData > MoveImageDataToNew()
Definition ImagePixelData.h:189
void SetPayload(FImagePixelPayloadPtr NewPayload)
Definition ImagePixelData.h:209
uint8 GetNumChannels() const
Definition ImagePixelData.h:76
TUniquePtr< FImagePixelData > CopyImageData() const
Definition ImagePixelData.h:181
uint8 GetBitDepth() const
Definition ImagePixelData.h:68
Definition ImageCore.h:264
Definition Color.h:48
Definition ImagePixelData.h:24
virtual ~IImagePixelDataPayload()
Definition ImagePixelData.h:25
Definition ImagePixelData.h:12
Definition ImagePixelData.h:264
TArray64< PixelType > Pixels
Definition ImagePixelData.h:265
TImagePixelData(const FIntPoint &InSize, TArray64< PixelType > &&InPixels, FImagePixelPayloadPtr InPayload)
Definition ImagePixelData.h:280
TImagePixelData(const FIntPoint &InSize, FImagePixelPayloadPtr InPayload)
Definition ImagePixelData.h:276
TImagePixelData(const FIntPoint &InSize, TArray64< PixelType > &&InPixels)
Definition ImagePixelData.h:271
TImagePixelData(const FIntPoint &InSize)
Definition ImagePixelData.h:267
virtual TUniquePtr< FImagePixelData > Move() override
Definition ImagePixelData.h:285
virtual void RetrieveData(const void *&OutDataPtr, int64 &OutSizeBytes) const override
Definition ImagePixelData.h:295
virtual TUniquePtr< FImagePixelData > Copy() const override
Definition ImagePixelData.h:290
Definition IntPoint.h:25
IntType Y
Definition IntPoint.h:37
IntType X
Definition IntPoint.h:34