diff options
author | crupest <crupest@outlook.com> | 2022-02-03 18:02:55 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-03 18:02:55 +0800 |
commit | be732c1027dda609569545d86aa636bc4507ef36 (patch) | |
tree | 22e70af87cfe28b14b90739380cb7532f0355d0c | |
parent | 03be170f6ebfd292b564b54448ff435990ce2f5c (diff) | |
download | cru-be732c1027dda609569545d86aa636bc4507ef36.tar.gz cru-be732c1027dda609569545d86aa636bc4507ef36.tar.bz2 cru-be732c1027dda609569545d86aa636bc4507ef36.zip |
...
-rw-r--r-- | src/win/graphics/direct/ImageFactory.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
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<IImage> 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<IWICStream> wic_stream; - hr = wic_imaging_factory_->CreateStream(&wic_stream); - ThrowIfFailed(hr); - - hr = wic_stream->InitializeFromMemory( - reinterpret_cast<unsigned char*>(buffer.data()), buffer.size()); - ThrowIfFailed(hr); + Microsoft::WRL::ComPtr<IStream> com_stream( + platform::win::ConvertStreamToComStream(stream)); Microsoft::WRL::ComPtr<IWICBitmapDecoder> wic_bitmap_decoder; hr = wic_imaging_factory_->CreateDecoderFromStream( - wic_stream.Get(), NULL, WICDecodeMetadataCacheOnDemand, + com_stream.Get(), NULL, WICDecodeMetadataCacheOnDemand, &wic_bitmap_decoder); ThrowIfFailed(hr); |