示例#1
0
}

bool FExrImageWrapper::SetCompressed( const void* InCompressedData, int32 InCompressedSize )
{
	if(!FImageWrapperBase::SetCompressed( InCompressedData, InCompressedSize))
	{
		return false;
	}

	FMemFileIn MemFile(InCompressedData, InCompressedSize);

	if(!IsThisAnOpenExrFile(MemFile))
	{
		return false;
	}

	Imf::RgbaInputFile ImfFile(MemFile);
	Imath::Box2i win = ImfFile.dataWindow();

	Imath::V2i dim(win.max.x - win.min.x + 1, win.max.y - win.min.y + 1);

	BitDepth = 16;

	Width = dim.x;
	Height = dim.y;

	// ideally we can specify float here
	Format = ERGBFormat::RGBA;
示例#2
0
void FExrImageWrapper::CompressRaw(const sourcetype* SrcData, bool bIgnoreAlpha)
{
	uint32 NumWriteComponents = GetNumChannelsFromFormat(RawFormat);
	if (bIgnoreAlpha && NumWriteComponents == 4)
	{
		NumWriteComponents = 3;
	}

	Imf::Header Header(Width, Height);

	for (uint32 Channel = 0; Channel < NumWriteComponents; Channel++)
	{
		Header.channels().insert(GetRawChannelName(Channel), Imf::Channel(OutputFormat));
	}

	FMemFileOut MemFile("");
	Imf::FrameBuffer ImfFrameBuffer;

	TArray<uint8> ChannelOutputBuffers[4];

	for (uint32 Channel = 0; Channel < NumWriteComponents; Channel++)
	{
		WriteFrameBufferChannel<OutputFormat>(ImfFrameBuffer, GetRawChannelName(Channel), SrcData + Channel, ChannelOutputBuffers[Channel]);
	}

	Imf::OutputFile ImfFile(MemFile, Header);
	ImfFile.setFrameBuffer(ImfFrameBuffer);
	ImfFile.writePixels(Height);

	CompressedData = MemFile.Data;
}
示例#3
0
void FExrImageWrapper::Uncompress( const ERGBFormat::Type InFormat, const int32 InBitDepth )
{
	// Ensure we haven't already uncompressed the file.
	if ( RawData.Num() != 0 )
	{
		return;
	}

	FMemFileIn MemFile(&CompressedData[0], CompressedData.Num());

	Imf::RgbaInputFile ImfFile(MemFile);
	Imath::Box2i win = ImfFile.dataWindow();

	check(BitDepth == 16);
	check(Width);
	check(Height);

	uint32 Channels = 4;

	RawData.Empty();
	RawData.AddUninitialized( Width * Height * Channels * (BitDepth / 8) );

	int dx = win.min.x;
	int dy = win.min.y;

	ImfFile.setFrameBuffer((Imf::Rgba*)&RawData[0] - dx - dy * Width, 1, Width);
	ImfFile.readPixels(win.min.y, win.max.y);
}
void FExrImageWrapper::CompressRaw(const sourcetype* SrcData, bool bIgnoreAlpha)
{
	const double StartTime = FPlatformTime::Seconds();
	uint32 NumWriteComponents = GetNumChannelsFromFormat(RawFormat);
	if (bIgnoreAlpha && NumWriteComponents == 4)
	{
		NumWriteComponents = 3;
	}

	Imf::Compression Comp = bUseCompression ? Imf::Compression::ZIP_COMPRESSION : Imf::Compression::NO_COMPRESSION;
	Imf::Header Header(Width, Height, 1, Imath::V2f(0, 0), 1, Imf::LineOrder::INCREASING_Y, Comp);
	
	for (uint32 Channel = 0; Channel < NumWriteComponents; Channel++)
	{
		Header.channels().insert(GetRawChannelName(Channel), Imf::Channel(OutputFormat));
	}

	FMemFileOut MemFile("");
	const int32 OutputPixelSize = ((OutputFormat == Imf::HALF && bUseCompression) ? 2 : 4);
	MemFile.Data.AddUninitialized(Width * Height * NumWriteComponents * OutputPixelSize);

	Imf::FrameBuffer ImfFrameBuffer;
	TArray<uint8> ChannelOutputBuffers[4];

	for (uint32 Channel = 0; Channel < NumWriteComponents; Channel++)
	{
		WriteFrameBufferChannel<OutputFormat>(ImfFrameBuffer, GetRawChannelName(Channel), SrcData + Channel, ChannelOutputBuffers[Channel]);
	}

	Imf::OutputFile ImfFile(MemFile, Header);
	ImfFile.setFrameBuffer(ImfFrameBuffer);
	ImfFile.writePixels(Height);

	CompressedData.AddUninitialized(MemFile.tellp());
	FMemory::Memcpy(CompressedData.GetData(), MemFile.Data.GetData(), MemFile.tellp());

	const double DeltaTime = FPlatformTime::Seconds() - StartTime;
	UE_LOG(LogImageWrapper, Verbose, TEXT("Compressed image in %.3f seconds"), DeltaTime);
}