static void test_compressor_type(CompressorType compressor, CompressionLevel level, bool headerless, const Buffer &data, const set<CompressorType>::type &compressors) { OS_ASSERT(data.empty() == false); shared_ptr<Buffer> compressed(OS_NEW Buffer()); BOOST_CHECK(CryptManager::instance()->compress(compressor, data.getData(), data.getSize(), *compressed, level)); Buffer decompressed; BOOST_CHECK(CryptManager::instance()->decompress(compressor, compressed->getData(), compressed->getSize(), decompressed)); BOOST_CHECK(data == decompressed); compressed->seekToBegin(); shared_ptr<MemFile> stream(OS_NEW MemFile(compressed)); if(headerless == false) { BOOST_CHECK(CryptManager::instance()->detectCompressor(compressed->getData(), compressed->getSize()) == compressor); BOOST_CHECK(CryptManager::instance()->detectCompressor(stream) == compressor); } for(set<CompressorType>::type::const_iterator i = compressors.begin(); i != compressors.end(); ++i) { OS_ASSERT(*i != compressorTypeDeflate); if(*i == compressor) continue; BOOST_CHECK(CryptManager::instance()->matchCompressor(compressed->getData(), compressed->getSize(), *i) == false); BOOST_CHECK(CryptManager::instance()->matchCompressor(stream, *i) == false); } }
} 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;
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) { 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; }
void pimpl<PortalsImporterJob>::run() { m_result.reset(); m_status = String::EMPTY; if(m_stream != nullptr) { shared_ptr<Portal> portal = m_portal.lock(); if(portal == nullptr || m_stream == nullptr) return; m_status = "importing"; m_serializer->setStopped(false); m_result = m_serializer->importStream(portal, m_stream); m_stream->close(); m_stream.reset(); } else { m_status = "download"; shared_ptr<boost::asio::io_service> service = createAsioService(); shared_ptr<TCPSocket> socket = Engine::instance()->createTCPSocket(service, true, true); shared_ptr<HttpClient> httpClient(OS_NEW HttpClient(service, socket)); HttpUrl url(m_url.to_ascii()); bool result = httpClient->perform(url); if(result) { shared_ptr<HttpResponse> response = httpClient->getResponse(); //shared_ptr<HttpContent> responseContent = response->getContent(); if(response->getStatusCode() == 200) { m_status = "importing"; shared_ptr<MemFile> content(OS_NEW MemFile(response->getContent()->getContentPtr())); shared_ptr<Portal> portal = m_portal.lock(); if(portal == nullptr) return; m_serializer->setStopped(false); m_result = m_serializer->importStream(portal, content); } m_status = "completed"; } else { m_status = "failed"; } } //Engine::instance()->addBackgroundJob(shared_ptr<PortalsOptimizerJob>(OS_NEW PortalsOptimizerJob(Engine::instance()->peekBackgroundJobID(), portal))); }
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); }