Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ObjectThumbnail.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"
6#include "Containers/Map.h"
7#include "CoreTypes.h"
8#include "Serialization/Archive.h"
9#include "Serialization/StructuredArchive.h"
10#include "UObject/NameTypes.h"
11
12/**
13 * Thumbnail compression interface for packages. The engine registers a class that can compress and
14 * decompress thumbnails that the package linker uses while loading and saving data.
15 */
17{
18public:
19
20 /**
21 * Compresses an image
22 *
23 * @param InUncompressedData The uncompressed image data
24 * @param InWidth Width of the image
25 * @param InHeight Height of the image
26 * @param OutCompressedData [Out] Compressed image data
27 * @return true if the image was compressed successfully, otherwise false if an error occurred
28 */
29 virtual bool CompressImage( const TArray< uint8 >& InUncompressedData, const int32 InWidth, const int32 InHeight, TArray< uint8 >& OutCompressedData ) = 0;
30
31 /**
32 * Decompresses an image
33 *
34 * @param InCompressedData The compressed image data
35 * @param InWidth Width of the image
36 * @param InHeight Height of the image
37 * @param OutUncompressedData [Out] Uncompressed image data
38 * @return true if the image was decompressed successfully, otherwise false if an error occurred
39 */
40 virtual bool DecompressImage( const TArray< uint8 >& InCompressedData, const int32 InWidth, const int32 InHeight, TArray< uint8 >& OutUncompressedData ) = 0;
41
42 /** Get name of compressor
43 *
44 * @return Name of thumbnail compressor
45 */
46 virtual FName GetThumbnailCompressorName() const = 0;
47
48 /** Is lossless compression
49 *
50 * @return true if compression is lossless
51 */
52 virtual bool IsLosslessCompression() const = 0;
53};
54
55
56/**
57 * Thumbnail image data for an object.
58 */
60{
61public:
62
63 /**
64 * Static: Sets the thumbnail compressor to use when loading/saving packages. The caller is
65 * responsible for the object's lifespan.
66 *
67 * @param InThumbnailCompressor A class derived from FThumbnailCompressionInterface.
68 */
69 static void SetThumbnailCompressors( FThumbnailCompressionInterface* InPNGThumbnailCompressor,
70 FThumbnailCompressionInterface* InJPEGThumbnailCompressor)
71 {
72 PNGThumbnailCompressor = InPNGThumbnailCompressor;
73 JPEGThumbnailCompressor = InJPEGThumbnailCompressor;
74 }
75
76private:
77
78 /** Static: Thumbnail compressor. */
81
82public:
83
84 /** Default constructor. */
86
87 /** Returns the width of the thumbnail. */
88 int32 GetImageWidth() const
89 {
90 return ImageWidth;
91 }
92
93 /** Returns the height of the thumbnail. */
94 int32 GetImageHeight() const
95 {
96 return ImageHeight;
97 }
98
99 /** @return the number of bytes in this thumbnail's compressed image data. */
101 {
102 return CompressedImageData.Num();
103 }
104
105 /** Sets the image dimensions. */
106 void SetImageSize( int32 InWidth, int32 InHeight )
107 {
108 ImageWidth = InWidth;
109 ImageHeight = InHeight;
110 }
111
112 /** Returns true if the thumbnail was loaded from disk and not dynamically generated. */
113 bool IsLoadedFromDisk(void) const { return bLoadedFromDisk; }
114
115 /** Returns true if the thumbnail was saved AFTER custom-thumbnails for shared thumbnail asset types was supported. */
117
118 /** For newly generated custom thumbnails, mark it as valid in the future. */
120
121 /** Returns true if the thumbnail is dirty and needs to be regenerated at some point. */
122 bool IsDirty() const
123 {
124 return bIsDirty;
125 }
126
127 /** Marks the thumbnail as dirty. */
129 {
130 bIsDirty = true;
131 }
132
133 /** Access the image data in place (does not decompress). */
135 {
136 return ImageData;
137 }
138
139 /** Access the image data in place (does not decompress) const version. */
140 const TArray< uint8 >& AccessImageData() const
141 {
142 return ImageData;
143 }
144
145 /** Access the compressed image data. */
147 {
148 return CompressedImageData;
149 }
150
151 /** Returns true if this is an empty thumbnail. */
152 bool IsEmpty() const
153 {
154 return ImageWidth == 0 || ImageHeight == 0;
155 }
156
157 /** Returns thumbnail compressor used on current compressed image data. */
159
160 /** Returns thumbnail compressor that would be used on current uncompressed image data. */
162
163 /** Returns uncompressed image data, decompressing it on demand if needed. */
165
166 /** Serializers */
168 void Serialize(FStructuredArchive::FSlot Slot);
169
170 /** Compress image data. */
172
173 /** Decompress image data. */
175
176 /**
177 * Calculates the memory usage of this FObjectThumbnail.
178 *
179 * @param Ar the FArchiveCountMem (or similar) archive that will store the results of the memory usage calculation.
180 */
181 void CountBytes( FArchive& Ar ) const;
182
183 /**
184 * Calculates the amount of memory used by the compressed bytes array.
185 *
186 * @param Ar the FArchiveCountMem (or similar) archive that will store the results of the memory usage calculation.
187 */
189
190 /**
191 * Calculates the amount of memory used by the uncompressed bytes array.
192 *
193 * @param Ar the FArchiveCountMem (or similar) archive that will store the results of the memory usage calculation.
194 */
196
197 /** I/O operator */
198 friend FArchive& operator<<( FArchive& Ar, FObjectThumbnail& Thumb )
199 {
200 if ( Ar.IsCountingMemory() )
201 {
202 Thumb.CountBytes(Ar);
203 }
204 else
205 {
206 Thumb.Serialize(Ar);
207 }
208 return Ar;
209 }
210
211 friend FArchive& operator<<( FArchive& Ar, const FObjectThumbnail& Thumb )
212 {
213 Thumb.CountBytes(Ar);
214 return Ar;
215 }
216
217 /** Comparison operator */
218 bool operator ==( const FObjectThumbnail& Other ) const
219 {
220 return ImageWidth == Other.ImageWidth
221 && ImageHeight == Other.ImageHeight
222 && bIsDirty == Other.bIsDirty
223 && CompressedImageData == Other.CompressedImageData;
224 }
225
226 bool operator !=( const FObjectThumbnail& Other ) const
227 {
228 return ImageWidth != Other.ImageWidth
229 || ImageHeight != Other.ImageHeight
230 || bIsDirty != Other.bIsDirty
231 || CompressedImageData != Other.CompressedImageData;
232 }
233
234private:
235
236 /** Thumbnail width (serialized) */
238
239 /** Thumbnail height (serialized) */
241
242 /** Compressed image data (serialized) */
244
245 /** Image data bytes */
247
248 /** True if the thumbnail is dirty and should be regenerated at some point */
250
251 /** Whether the thumbnail has a backup on disk*/
253
254 /** Whether compressed data is JPEG (else PNG) */
256
257 /** Whether this was saved AFTER custom-thumbnails for shared thumbnail asset types was supported */
259};
260
261
262/** Maps an object's full name to a thumbnail */
264
265
266/** Wraps an object's full name and thumbnail */
268{
269 /** Full name of the object */
271
272 /** Thumbnail data */
274
275 /** Offset in the file where the data is stored */
277
278 /** Constructor */
281 ObjectThumbnail( nullptr ),
282 FileOffset( 0 )
283 { }
284
285 /** Constructor */
286 FObjectFullNameAndThumbnail( const FName InFullName, const FObjectThumbnail* InThumbnail )
287 : ObjectFullName( InFullName ),
288 ObjectThumbnail( InThumbnail ),
289 FileOffset( 0 )
290 { }
291
292 /**
293 * Calculates the memory usage of this FObjectFullNameAndThumbnail.
294 *
295 * @param Ar the FArchiveCountMem (or similar) archive that will store the results of the memory usage calculation.
296 */
297 void CountBytes( FArchive& Ar ) const;
298
299 /** I/O operator */
300 friend FArchive& operator<<( FArchive& Ar, FObjectFullNameAndThumbnail& NameThumbPair )
301 {
302 if ( Ar.IsCountingMemory() )
303 {
304 NameThumbPair.CountBytes(Ar);
305 }
306 else
307 {
308 Ar << NameThumbPair.ObjectFullName << NameThumbPair.FileOffset;
309 }
310 return Ar;
311 }
312
313 friend FArchive& operator<<( FArchive& Ar, const FObjectFullNameAndThumbnail& NameThumbPair )
314 {
315 NameThumbPair.CountBytes(Ar);
316 return Ar;
317 }
318};
TMap< FName, FObjectThumbnail > FThumbnailMap
FORCEINLINE FName()
Definition NameTypes.h:974
static FThumbnailCompressionInterface * JPEGThumbnailCompressor
void Serialize(FArchive &Ar)
void DecompressImageData()
void Serialize(FStructuredArchive::FSlot Slot)
static void SetThumbnailCompressors(FThumbnailCompressionInterface *InPNGThumbnailCompressor, FThumbnailCompressionInterface *InJPEGThumbnailCompressor)
void SetImageSize(int32 InWidth, int32 InHeight)
void CountImageBytes_Uncompressed(FArchive &Ar) const
int32 GetCompressedDataSize() const
int32 GetImageWidth() const
void SetCreatedAfterCustomThumbsEnabled(void)
FThumbnailCompressionInterface * ChooseNewCompressor() const
TArray< uint8 > ImageData
bool IsCreatedAfterCustomThumbsEnabled(void) const
bool bCreatedAfterCustomThumbForSharedTypesEnabled
bool operator==(const FObjectThumbnail &Other) const
int32 GetImageHeight() const
void CountBytes(FArchive &Ar) const
FThumbnailCompressionInterface * GetCompressor() const
bool IsLoadedFromDisk(void) const
void CountImageBytes_Compressed(FArchive &Ar) const
const TArray< uint8 > & GetUncompressedImageData() const
static FThumbnailCompressionInterface * PNGThumbnailCompressor
const TArray< uint8 > & AccessImageData() const
bool IsEmpty() const
TArray< uint8 > CompressedImageData
TArray< uint8 > & AccessCompressedImageData()
TArray< uint8 > & AccessImageData()
bool IsDirty() const
bool operator!=(const FObjectThumbnail &Other) const
void CompressImageData()
virtual FName GetThumbnailCompressorName() const =0
virtual bool CompressImage(const TArray< uint8 > &InUncompressedData, const int32 InWidth, const int32 InHeight, TArray< uint8 > &OutCompressedData)=0
virtual bool IsLosslessCompression() const =0
virtual bool DecompressImage(const TArray< uint8 > &InCompressedData, const int32 InWidth, const int32 InHeight, TArray< uint8 > &OutUncompressedData)=0
FORCEINLINE bool IsCountingMemory() const
Definition Archive.h:441
void CountBytes(FArchive &Ar) const
const FObjectThumbnail * ObjectThumbnail
FObjectFullNameAndThumbnail(const FName InFullName, const FObjectThumbnail *InThumbnail)