From be732c1027dda609569545d86aa636bc4507ef36 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 3 Feb 2022 18:02:55 +0800 Subject: ... --- src/win/graphics/direct/ImageFactory.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/win/graphics/direct/ImageFactory.cpp b/src/win/graphics/direct/ImageFactory.cpp index ced590ec..7d297ff8 100644 --- a/src/win/graphics/direct/ImageFactory.cpp +++ b/src/win/graphics/direct/ImageFactory.cpp @@ -1,4 +1,5 @@ #include "cru/win/graphics/direct/ImageFactory.hpp" +#include "cru/common/platform/win/StreamConvert.hpp" #include "cru/win/graphics/direct/Exception.hpp" #include "cru/win/graphics/direct/Factory.hpp" #include "cru/win/graphics/direct/Image.hpp" @@ -17,23 +18,14 @@ WinImageFactory::WinImageFactory(DirectGraphicsFactory* graphics_factory) WinImageFactory::~WinImageFactory() {} std::unique_ptr WinImageFactory::DecodeFromStream(io::Stream* stream) { - // TODO: The correct way to do this is to implement a IStream wrapper. - - auto buffer = stream->ReadAll(); - HRESULT hr; - Microsoft::WRL::ComPtr wic_stream; - hr = wic_imaging_factory_->CreateStream(&wic_stream); - ThrowIfFailed(hr); - - hr = wic_stream->InitializeFromMemory( - reinterpret_cast(buffer.data()), buffer.size()); - ThrowIfFailed(hr); + Microsoft::WRL::ComPtr com_stream( + platform::win::ConvertStreamToComStream(stream)); Microsoft::WRL::ComPtr wic_bitmap_decoder; hr = wic_imaging_factory_->CreateDecoderFromStream( - wic_stream.Get(), NULL, WICDecodeMetadataCacheOnDemand, + com_stream.Get(), NULL, WICDecodeMetadataCacheOnDemand, &wic_bitmap_decoder); ThrowIfFailed(hr); -- cgit v1.2.3