diff options
author | crupest <crupest@outlook.com> | 2022-01-30 20:40:59 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-30 20:40:59 +0800 |
commit | c1f8ea13524f398f8d1720e5f03a17dd66352ebf (patch) | |
tree | 0e27ed132cd82d1a690aa9534df38beec0c77d45 /src/osx/graphics/quartz/ImageFactory.cpp | |
parent | a6dd823a94f0e6338545a4885e9d428e83a56593 (diff) | |
download | cru-c1f8ea13524f398f8d1720e5f03a17dd66352ebf.tar.gz cru-c1f8ea13524f398f8d1720e5f03a17dd66352ebf.tar.bz2 cru-c1f8ea13524f398f8d1720e5f03a17dd66352ebf.zip |
...
Diffstat (limited to 'src/osx/graphics/quartz/ImageFactory.cpp')
-rw-r--r-- | src/osx/graphics/quartz/ImageFactory.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/osx/graphics/quartz/ImageFactory.cpp b/src/osx/graphics/quartz/ImageFactory.cpp new file mode 100644 index 00000000..c59ff126 --- /dev/null +++ b/src/osx/graphics/quartz/ImageFactory.cpp @@ -0,0 +1,31 @@ +#include "cru/osx/graphics/quartz/ImageFactory.hpp" +#include "cru/osx/graphics/quartz/Convert.hpp" +#include "cru/osx/graphics/quartz/Image.hpp" +#include "cru/platform/graphics/Image.hpp" + +#include <ImageIO/ImageIO.h> + +namespace cru::platform::graphics::osx::quartz { +QuartzImageFactory::QuartzImageFactory(IGraphicsFactory* graphics_factory) + : OsxQuartzResource(graphics_factory) {} + +QuartzImageFactory::~QuartzImageFactory() {} + +std::unique_ptr<IImage> QuartzImageFactory::DecodeFromStream( + io::Stream* stream) { + CGDataProviderRef data_provider = ConvertStreamToCGDataProvider(stream); + CGImageSourceRef image_source = + CGImageSourceCreateWithDataProvider(data_provider, nullptr); + + CGImageRef cg_image = + CGImageSourceCreateImageAtIndex(image_source, 0, nullptr); + + QuartzImage* image = + new QuartzImage(GetGraphicsFactory(), this, cg_image, true); + + CFRelease(cg_image); + CGDataProviderRelease(data_provider); + + return std::unique_ptr<IImage>(image); +} +} // namespace cru::platform::graphics::osx::quartz |