Files
UnrealEngineUWP/Engine/Source/Runtime/ImageWrapper/Private/ImageWrapperBase.cpp
Julien StJean 547c7f160d Optimisation to the legacy texture import and improvement to texture wrapper
Minor change to FImageWrapperBase. GetRaw and GetCompressed now consume the array with the same name instead of having to do a copy of it.
I changed the api IImageWrapper::GetCompressed to return a TArray64<uint8> instead of returning a const TArray64<uint8>&.
Added the format RGBAF to the struct ERGBFormat. Changed the engine code using the EXR image wrapper to reflect that.
The EXR image wrapper now avoid doing an unessary copy of the compressed image when calling compress.

Improvement to the performence of the function UTextureFactory::ImportImage. We now use the magic bytes of the file for certains format to skip some tests.

Here is some performance metrics I captured on my desktop (6 core, 12 threads XEON)

Importing a folder of tiff files (22 files, 4.16 GB Total)
Before: 66.152738 seconds
After: 43.609245 seconds

#jira UEENT-3822
#rb Alexis.Matte

[CL 16128765 by Julien StJean in ue5-main branch]
2021-04-27 11:59:02 -04:00

119 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ImageWrapperBase.h"
/* FImageWrapperBase structors
*****************************************************************************/
FImageWrapperBase::FImageWrapperBase()
: RawFormat(ERGBFormat::Invalid)
, RawBitDepth(0)
, Format(ERGBFormat::Invalid)
, BitDepth(0)
, Width(0)
, Height(0)
, NumFrames(1)
, Framerate(0)
{ }
/* FImageWrapperBase interface
*****************************************************************************/
void FImageWrapperBase::Reset()
{
LastError.Empty();
RawFormat = ERGBFormat::Invalid;
RawBitDepth = 0;
Format = ERGBFormat::Invalid;
BitDepth = 0;
Width = 0;
Height = 0;
NumFrames = 1;
Framerate = 0;
}
void FImageWrapperBase::SetError(const TCHAR* ErrorMessage)
{
LastError = ErrorMessage;
}
/* IImageWrapper structors
*****************************************************************************/
TArray64<uint8> FImageWrapperBase::GetCompressed(int32 Quality)
{
LastError.Empty();
Compress(Quality);
return MoveTemp(CompressedData);
}
bool FImageWrapperBase::GetRaw(const ERGBFormat InFormat, int32 InBitDepth, TArray64<uint8>& OutRawData)
{
LastError.Empty();
Uncompress(InFormat, InBitDepth);
if (LastError.IsEmpty())
{
OutRawData = MoveTemp(RawData);
}
return LastError.IsEmpty();
}
bool FImageWrapperBase::SetCompressed(const void* InCompressedData, int64 InCompressedSize)
{
if(InCompressedSize > 0 && InCompressedData != nullptr)
{
Reset();
RawData.Empty(); // Invalidates the raw data too
CompressedData.Empty(InCompressedSize);
CompressedData.AddUninitialized(InCompressedSize);
FMemory::Memcpy(CompressedData.GetData(), InCompressedData, InCompressedSize);
return true;
}
return false;
}
bool FImageWrapperBase::SetRaw(const void* InRawData, int64 InRawSize, const int32 InWidth, const int32 InHeight, const ERGBFormat InFormat, const int32 InBitDepth)
{
check(InRawData != NULL);
check(InRawSize > 0);
check(InWidth > 0);
check(InHeight > 0);
Reset();
CompressedData.Empty(); // Invalidates the compressed data too
RawData.Empty(InRawSize);
RawData.AddUninitialized(InRawSize);
FMemory::Memcpy(RawData.GetData(), InRawData, InRawSize);
RawFormat = InFormat;
RawBitDepth = InBitDepth;
Width = InWidth;
Height = InHeight;
return true;
}
bool FImageWrapperBase::SetAnimationInfo(int32 InNumFrames, int32 InFramerate)
{
NumFrames = InNumFrames;
Framerate = InFramerate;
return true;
}