UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SlateTextureData.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Stats/Stats.h"
7#include "SlateGlobals.h"
8#include "ImageCore.h"
9
11
19{
21 : Bytes(InBytes)
22 , Width(InWidth)
23 , Height(InHeight)
24 , BytesPerPixel(InBytesPerPixel)
25 {
27 }
28
29 // Move from TArray :
31 : Bytes(InBytes)
32 , Width(InWidth)
33 , Height(InHeight)
34 , BytesPerPixel(InBytesPerPixel)
35 {
37 }
38
47 : Width(InWidth)
48 , Height(InHeight)
49 , BytesPerPixel(InBytesPerPixel)
50 {
51 const uint32 BufferSize = Width*Height*BytesPerPixel;
52 Bytes.SetNumUninitialized(BufferSize);
53 if (InBuffer != nullptr)
54 {
55 FMemory::Memcpy(Bytes.GetData(), InBuffer, BufferSize);
56 }
58 }
59
61 : Bytes( Other.Bytes )
62 , Width( Other.Width )
63 , Height( Other.Height )
64 , BytesPerPixel( Other.BytesPerPixel )
65 {
67 }
68
70 : Bytes()
71 , Width(0)
72 , Height(0)
73 , BytesPerPixel(0)
74 {
76 }
77
79 : Bytes()
80 , Width(0)
81 , Height(0)
82 , BytesPerPixel(0)
83 {
85 }
86
88 {
89 if( this != &Other )
90 {
91 SetRawData( Other.Width, Other.Height, Other.BytesPerPixel, Other.Bytes );
92 }
93 return *this;
94 }
95
100
102 {
104
105 Width = InWidth;
106 Height = InHeight;
107 BytesPerPixel = InBytesPerPixel;
108 Bytes = InBytes;
109
111 }
112
113 // copy FImageView into the FSlateTextureData
114 // convert to BGRA8-SRGB if not already in that format
115 void SetImage( const FImageView & Image )
116 {
117 // if Image is already BGRA8-SRGB then this is just a memcpy
118 // which is what we need anyway to copy the bytes into a new array
119 // so there is no inefficiency in just always using the FImage copy here
123 }
124
125 // move FImage into the FSlateTextureData
126 // convert to BGRA8-SRGB if not already in that format
127 void SetImage( FImage && MoveFrom )
128 {
129 // change format if needed, nop if not
130 // MoveFrom is discardable so it's okay if we just change it in place
131 MoveFrom.ChangeFormat(ERawImageFormat::BGRA8,EGammaSpace::sRGB);
132
134
135 Width = MoveFrom.SizeX;
136 Height = MoveFrom.SizeY;
137 BytesPerPixel = 4;
138 Bytes = MoveTemp(MoveFrom.RawData);
139
141
142 MoveFrom.Reset();
143 }
144
145 void Empty()
146 {
148 Bytes.Empty();
149 }
150
152 {
153 return Width;
154 }
155
157 {
158 return Height;
159 }
160
162 {
163 return BytesPerPixel;
164 }
165
167 {
168 return Bytes;
169 }
170
173 {
174 return Bytes.GetData();
175 }
176
177private:
178
180 TArray<uint8> Bytes;
181
183 uint32 Width;
184
186 uint32 Height;
187
189 uint32 BytesPerPixel;
190};
191
192
#define TEXT(x)
Definition Platform.h:1272
#define INC_MEMORY_STAT_BY(StatId, Amount)
Definition Stats.h:700
#define DEC_MEMORY_STAT_BY(StatId, Amount)
Definition Stats.h:705
#define DECLARE_MEMORY_STAT_EXTERN(CounterName, StatId, GroupId, API)
Definition Stats.h:687
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
TSharedPtr< FSlateTextureData, ESPMode::ThreadSafe > FSlateTextureDataPtr
Definition SlateTextureData.h:193
TSharedRef< FSlateTextureData, ESPMode::ThreadSafe > FSlateTextureDataRef
Definition SlateTextureData.h:194
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
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
UE_NODEBUG UE_FORCEINLINE_HINT SIZE_T GetAllocatedSize(void) const
Definition Array.h:1059
void SetNumUninitialized(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2369
void Empty(SizeType Slack=0)
Definition Array.h:2273
Definition SharedPointer.h:692
Definition SharedPointer.h:153
@ BGRA8
Definition ImageCore.h:59
Definition ImageCore.h:264
Definition ImageCore.h:416
IMAGECORE_API void CopyTo(FImage &DestImage, ERawImageFormat::Type DestFormat, EGammaSpace DestGammaSpace) const
Definition ImageCore.cpp:1016
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition SlateTextureData.h:19
FSlateTextureData(const uint8 *InBuffer, uint32 InWidth, uint32 InHeight, uint32 InBytesPerPixel)
Definition SlateTextureData.h:46
~FSlateTextureData()
Definition SlateTextureData.h:96
void SetImage(const FImageView &Image)
Definition SlateTextureData.h:115
uint32 GetWidth() const
Definition SlateTextureData.h:151
uint32 GetBytesPerPixel() const
Definition SlateTextureData.h:161
FSlateTextureData(uint32 InWidth=0, uint32 InHeight=0, uint32 InBytesPerPixel=0, const TArray< uint8 > &InBytes=TArray< uint8 >())
Definition SlateTextureData.h:20
const TArray< uint8 > & GetRawBytes() const
Definition SlateTextureData.h:166
FSlateTextureData(const FImageView &Other)
Definition SlateTextureData.h:69
FSlateTextureData(const FSlateTextureData &Other)
Definition SlateTextureData.h:60
void Empty()
Definition SlateTextureData.h:145
void SetRawData(uint32 InWidth, uint32 InHeight, uint32 InBytesPerPixel, const TArray< uint8 > &InBytes)
Definition SlateTextureData.h:101
FSlateTextureData(FImage &&Other)
Definition SlateTextureData.h:78
FSlateTextureData & operator=(const FSlateTextureData &Other)
Definition SlateTextureData.h:87
FSlateTextureData(uint32 InWidth, uint32 InHeight, uint32 InBytesPerPixel, TArray< uint8 > &&InBytes)
Definition SlateTextureData.h:30
uint8 * GetRawBytesPtr()
Definition SlateTextureData.h:172
void SetImage(FImage &&MoveFrom)
Definition SlateTextureData.h:127
uint32 GetHeight() const
Definition SlateTextureData.h:156