Skip to content

Commit

Permalink
Image: added option to use custom memory allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 5, 2024
1 parent 58a9a83 commit 598fc8a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
22 changes: 13 additions & 9 deletions TextureLoader/interface/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ struct ImageLoadInfo
///
/// \note This flag is only used if PermultiplyAlpha is true.
bool IsSRGB DEFAULT_INITIALIZER(false);

/// Memory allocator
struct IMemoryAllocator* pAllocator DEFAULT_INITIALIZER(nullptr);
};
typedef struct ImageLoadInfo ImageLoadInfo;

Expand Down Expand Up @@ -133,15 +136,16 @@ struct Image : public ObjectBase<IObject>

struct EncodeInfo
{
Uint32 Width = 0;
Uint32 Height = 0;
TEXTURE_FORMAT TexFormat = TEX_FORMAT_UNKNOWN;
bool KeepAlpha = false;
bool FlipY = false;
const void* pData = nullptr;
Uint32 Stride = 0;
IMAGE_FILE_FORMAT FileFormat = IMAGE_FILE_FORMAT_JPEG;
int JpegQuality = 95;
Uint32 Width = 0;
Uint32 Height = 0;
TEXTURE_FORMAT TexFormat = TEX_FORMAT_UNKNOWN;
bool KeepAlpha = false;
bool FlipY = false;
const void* pData = nullptr;
Uint32 Stride = 0;
IMAGE_FILE_FORMAT FileFormat = IMAGE_FILE_FORMAT_JPEG;
int JpegQuality = 95;
struct IMemoryAllocator* pAllocator = nullptr;
};
static void Encode(const EncodeInfo& Info, IDataBlob** ppEncodedData);

Expand Down
4 changes: 2 additions & 2 deletions TextureLoader/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Image::Image(IReferenceCounters* pRefCounters,
IDataBlob* pFileData,
const ImageLoadInfo& LoadInfo) :
TBase{pRefCounters},
m_pData{DataBlobImpl::Create()}
m_pData{DataBlobImpl::Create(LoadInfo.pAllocator)}
{
if (LoadInfo.Format == IMAGE_FILE_FORMAT_TIFF)
{
Expand Down Expand Up @@ -476,7 +476,7 @@ std::vector<Uint8> Image::ConvertImageData(Uint32 Width,

void Image::Encode(const EncodeInfo& Info, IDataBlob** ppEncodedData)
{
auto pEncodedData = DataBlobImpl::Create();
auto pEncodedData = DataBlobImpl::Create(Info.pAllocator);
if (Info.FileFormat == IMAGE_FILE_FORMAT_JPEG)
{
auto RGBData = ConvertImageData(Info.Width, Info.Height, reinterpret_cast<const Uint8*>(Info.pData), Info.Stride, Info.TexFormat, TEX_FORMAT_RGBA8_UNORM, false, Info.FlipY);
Expand Down
1 change: 1 addition & 0 deletions TextureLoader/src/TextureLoaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ TextureLoaderImpl::TextureLoaderImpl(IReferenceCounters* pRefCounters,
}
ImgLoadInfo.IsSRGB = TexLoadInfo.IsSRGB;
ImgLoadInfo.PermultiplyAlpha = TexLoadInfo.PermultiplyAlpha;
ImgLoadInfo.pAllocator = TexLoadInfo.pAllocator;
RefCntAutoPtr<Image> pImage;
Image::CreateFromDataBlob(m_pDataBlob, ImgLoadInfo, &pImage);
LoadFromImage(pImage, TexLoadInfo);
Expand Down

0 comments on commit 598fc8a

Please sign in to comment.