UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IImageWrapper.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
7#include "CoreTypes.h"
9#include "ImageCore.h"
11
26enum class EImageFormat : int8
27{
29 Invalid = -1,
30
32 PNG = 0,
33
35 JPEG,
36
39
41 BMP,
42
44 ICO,
45
47 EXR,
48
50 ICNS,
51
53 TGA,
54
56 HDR,
57
59 TIFF,
60
62 DDS,
63
65 UEJPEG,
66
69};
70
71
75enum class ERGBFormat : int8
76{
77 Invalid = -1,
78
79 // Red, Green, Blue and Alpha ; requires RB swap from FColor
80 RGBA = 0,
81
82 // Blue, Green, Red and Alpha ; is ERawImageFormat::BGRA8 and Fcolor
83 BGRA = 1,
84
85 // Gray scale
86 Gray = 2,
87
88 // Red, Green, Blue and Alpha using IEEE Floating-Point Arithmetic (see IEEE754). The format is always binary.
89 RGBAF = 3,
90
91 // Blue, Green, Red and Exponent (Similar to the RGBE format from radiance but with the blue and red channel inversed)
92 BGRE = 4,
93
94 // Gray scale using IEEE Floating-Point Arithmetic (see IEEE754). The format is always binary.
95 GrayF = 5,
96};
97
98
113{
114 Default = 0,
115 Uncompressed = 1,
116 Max = 100,
117};
118
119
132{
133protected:
134 // debug image name string for any errors or warnings
135 const TCHAR* DebugImageName = nullptr;
136
137public:
138
139
151 virtual bool SetCompressed(const void* InCompressedData, int64 InCompressedSize) = 0;
152
171 virtual bool SetRaw(const void* InRawData, int64 InRawSize, const int32 InWidth, const int32 InHeight, const ERGBFormat InFormat, const int32 InBitDepth, const int32 InBytesPerRow = 0) = 0;
172
174 virtual bool CanSetRawFormat(const ERGBFormat InFormat, const int32 InBitDepth) const = 0;
175
181
182
190 virtual TArray64<uint8> GetCompressed(int32 Quality = 0) = 0;
191
200 {
201 return GetCompressed(Quality);
202 }
203
214 {
216 int32 BitDepth = GetBitDepth();
217
218 // Format and BitDepth should have been set by SetCompressed
219 if ( Format == ERGBFormat::Invalid || BitDepth == 0 )
220 {
221 return false;
222 }
223
224 return GetRaw(Format,BitDepth,OutRawData);
225 }
226
238 {
240 int32 BitDepth = GetBitDepth();
241
242 // Format and BitDepth should have been set by SetCompressed
243 if (Format == ERGBFormat::Invalid || BitDepth == 0)
244 {
245 return false;
246 }
247
248 return GetRaw(Format, BitDepth, OutDecompressedImage);
249 }
250
263
277
278
292
307
322 {
324 if (GetRaw(InFormat, InBitDepth, TmpRawData) && ensureMsgf(TmpRawData.Num() == (int32)TmpRawData.Num(), TEXT("Tried to get %" INT64_FMT "x%" INT64_FMT " %dbpp image with format %d into 32-bit TArray (%lld bytes)"), GetWidth(), GetHeight(), InBitDepth, InFormat, (long long int)TmpRawData.Num()))
325 {
327 return true;
328 }
329 else
330 {
331 return false;
332 }
333 }
334
348 {
351 {
352 if (ensureMsgf(TmpRawData.Num() == OutRawData.Num(), TEXT("The view doesn't have the proper size to receive the texture.")))
353 {
354 FPlatformMemory::Memcpy(OutRawData.GetData(), TmpRawData.GetData(), OutRawData.Num());
355 return true;
356 }
357 }
358
359 return false;
360 }
361
368 virtual int64 GetWidth() const = 0;
369
376 virtual int64 GetHeight() const = 0;
377
386 virtual int32 GetBitDepth() const = 0;
387
394 virtual ERGBFormat GetFormat() const = 0;
395
396
397 /* Should the pixels be treated as sRGB encoded? (or Linear)
398 *
399 * note: ImageWrapper Format does not track if pixels are Gamma/SRGB or not
400 * assume they are ERawImageFormat::GetDefaultGammaSpace gammaspace
401 * eg. U8 is SRGB and everything else is Linear
402 */
403 bool GetSRGB() const
404 {
405 // sRGB is guessed from bit depth
406 // 8 = on (except BGRE)
407 // must match ERawImageFormat::GetDefaultGammaSpace
408 return GetBitDepth() == 8 && GetFormat() != ERGBFormat::BGRE;
409 }
410
411 // external users call these from ImageWrapperModule.h , see documentation there
413 IMAGEWRAPPER_API static ERawImageFormat::Type ConvertRGBFormat(ERGBFormat RGBFormat,int BitDepth,bool * bIsExactMatch = nullptr);
414
416
417 /* get the current image format, mapped to an ERawImageFormat
418 * if ! *bIsExactMatch , conversion is needed
419 * can call after SetCompressed()
420 */
421 ERawImageFormat::Type GetClosestRawImageFormat(bool * bIsExactMatch = nullptr) const
422 {
424 int BitDepth = GetBitDepth();
425 ERawImageFormat::Type Ret = ConvertRGBFormat(Format,BitDepth,bIsExactMatch);
426 return Ret;
427 }
428
429 /* Set the debug image name
430 */
435
441 virtual bool SupportsMetadata() const = 0;
442
449 virtual void AddMetadata(const FString& InKey, const FString& InValue) = 0;
450
457 virtual void GetMetadata(TStringMap& OutMetadata) const = 0;
458
459public:
460
462 virtual ~IImageWrapper() { }
463};
#define INT64_FMT
Definition AndroidPlatformString.h:59
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EImageFormat
Definition IImageWrapper.h:27
ERGBFormat
Definition IImageWrapper.h:76
EImageCompressionQuality
Definition IImageWrapper.h:113
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition IImageWrapper.h:132
virtual bool SupportsMetadata() const =0
static IMAGEWRAPPER_API ERawImageFormat::Type ConvertRGBFormat(ERGBFormat RGBFormat, int BitDepth, bool *bIsExactMatch=nullptr)
Definition ImageWrapperBase.cpp:250
static IMAGEWRAPPER_API int64 GetRGBFormatBytesPerPel(ERGBFormat RGBFormat, int BitDepth)
Definition ImageWrapperBase.cpp:185
virtual void AddMetadata(const FString &InKey, const FString &InValue)=0
virtual TArray64< uint8 > GetExportData(int32 Quality=0)
Definition IImageWrapper.h:199
ERawImageFormat::Type GetClosestRawImageFormat(bool *bIsExactMatch=nullptr) const
Definition IImageWrapper.h:421
virtual int64 GetWidth() const =0
bool GetRaw(FDecompressedImageOutput &OutDecompressedImage)
Definition IImageWrapper.h:237
virtual bool CanSetRawFormat(const ERGBFormat InFormat, const int32 InBitDepth) const =0
virtual bool GetRaw(const ERGBFormat InFormat, int32 InBitDepth, FDecompressedImageOutput &OutDecompressedImage)=0
static IMAGEWRAPPER_API void ConvertRawImageFormat(ERawImageFormat::Type RawFormat, ERGBFormat &OutFormat, int &OutBitDepth)
Definition ImageWrapperBase.cpp:343
bool GetRaw(TArray64< uint8 > &OutRawData)
Definition IImageWrapper.h:213
virtual int32 GetBitDepth() const =0
const TCHAR * DebugImageName
Definition IImageWrapper.h:135
virtual int64 GetHeight() const =0
void SetDebugImageName(const TCHAR *InDebugImageName)
Definition IImageWrapper.h:431
virtual ERawImageFormat::Type GetSupportedRawFormat(const ERawImageFormat::Type InFormat) const =0
bool GetRawImage(FImage &OutImage)
Definition ImageWrapperBase.cpp:420
bool GetRaw(const ERGBFormat InFormat, int32 InBitDepth, TArray< uint8 > &OutRawData)
Definition IImageWrapper.h:321
bool GetRaw(const ERGBFormat InFormat, int32 InBitDepth, TArrayView64< uint8 > OutRawData)
Definition IImageWrapper.h:347
virtual ERGBFormat GetFormat() const =0
virtual bool SetRaw(const void *InRawData, int64 InRawSize, const int32 InWidth, const int32 InHeight, const ERGBFormat InFormat, const int32 InBitDepth, const int32 InBytesPerRow=0)=0
virtual ~IImageWrapper()
Definition IImageWrapper.h:462
virtual bool GetRaw(const ERGBFormat InFormat, int32 InBitDepth, TArray64< uint8 > &OutRawData)=0
virtual bool SetCompressed(const void *InCompressedData, int64 InCompressedSize)=0
virtual void GetMetadata(TStringMap &OutMetadata) const =0
virtual TArray64< uint8 > GetCompressed(int32 Quality=0)=0
bool GetSRGB() const
Definition IImageWrapper.h:403
Definition Array.h:670
Type
Definition ImageCore.h:57
Definition ImageWrapperOutputTypes.h:11
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition GenericPlatformMemory.h:591
Definition ImageCore.h:416