Files
UnrealEngineUWP/Engine/Source/Runtime/ImageWrapper/Private/Formats/IcnsImageWrapper.cpp
charles bloom 04ffabc485 ImageWrapper and import/export refactor
FImage is now the standard preferred type for a bag of pixels
FImageView can point at pixels without owning an allocation
ERawImageFormat (FImage) converts to ETextureSourceFormat
FImageUtils provides generic load/save and get/set from FImage
major cleanup in the ImageWrappers
new preferred API is through ImageWrapperModule Compress/Decompress
SetRaw/GetRaw functions cleaned up to not have undefined behavior on unexpected formats
ImageWrapper output added for HDR,BMP,TGA
RGBA32F format added and supported throughout import/export
EditorFactories import/export made more generic, most image types handled the same way using FImage now
Deprecate old TSF RGBA order pixel formats
Fix many crashes or bad handling of unusual pixel formats
Pixel access functions should be used instead of switches on pixel type

#preflight 6230ade7e65a7e65d68a187c
#rb julien.stjean,martins.mozeiko,dan.thompson,fabian.giesen

[CL 19397199 by charles bloom in ue5-main branch]
2022-03-15 18:29:37 -04:00

100 lines
2.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "IcnsImageWrapper.h"
/* FIcnsImageWrapper structors
*****************************************************************************/
FIcnsImageWrapper::FIcnsImageWrapper()
: FImageWrapperBase()
{ }
/* FImageWrapper interface
*****************************************************************************/
bool FIcnsImageWrapper::SetCompressed(const void* InCompressedData, int64 InCompressedSize)
{
#if PLATFORM_MAC
return FImageWrapperBase::SetCompressed(InCompressedData, InCompressedSize);
#else
return false;
#endif
}
// CanSetRawFormat returns true if SetRaw will accept this format
bool FIcnsImageWrapper::CanSetRawFormat(const ERGBFormat InFormat, const int32 InBitDepth) const
{
//checkf(false, TEXT("ICNS compression not supported"));
return false;
}
// returns InFormat if supported, else maps to something supported
ERawImageFormat::Type FIcnsImageWrapper::GetSupportedRawFormat(const ERawImageFormat::Type InFormat) const
{
//checkf(false, TEXT("ICNS compression not supported"));
return ERawImageFormat::BGRA8;
}
bool FIcnsImageWrapper::SetRaw(const void* InRawData, int64 InRawSize, const int32 InWidth, const int32 InHeight, const ERGBFormat InFormat, const int32 InBitDepth, const int32 InBytesPerRow)
{
// Only support tightly packed
check(InBytesPerRow == 0);
#if PLATFORM_MAC
return FImageWrapperBase::SetRaw(InRawData, InRawSize, InWidth, InHeight, InFormat, InBitDepth, InBytesPerRow);
#else
return false;
#endif
}
void FIcnsImageWrapper::Compress(int32 Quality)
{
checkf(false, TEXT("ICNS compression not supported"));
}
void FIcnsImageWrapper::Uncompress(const ERGBFormat InFormat, const int32 InBitDepth)
{
#if PLATFORM_MAC
SCOPED_AUTORELEASE_POOL;
NSData* ImageData = [NSData dataWithBytesNoCopy:CompressedData.GetData() length:CompressedData.Num() freeWhenDone:NO];
NSImage* Image = [[NSImage alloc] initWithData:ImageData];
if (Image)
{
NSBitmapImageRep* Bitmap = [NSBitmapImageRep imageRepWithData:[Image TIFFRepresentation]];
if (Bitmap)
{
check(InFormat == ERGBFormat::BGRA || InFormat == ERGBFormat::RGBA);
check(InBitDepth == 8);
RawData.Empty();
RawData.Append([Bitmap bitmapData], [Bitmap bytesPerPlane]);
RawFormat = Format = InFormat;
RawBitDepth = BitDepth = InBitDepth;
Width = [Bitmap pixelsWide];
Height = [Bitmap pixelsHigh];
if (Format == ERGBFormat::BGRA)
{
for (int64 Index = 0; Index < [Bitmap bytesPerPlane]; Index += 4)
{
uint8 Byte = RawData[Index];
RawData[Index] = RawData[Index + 2];
RawData[Index + 2] = Byte;
}
}
}
[Image release];
}
#else
checkf(false, TEXT("ICNS uncompressing not supported on this platform"));
#endif
}