From 7b4b334e777e573040569801d3b4ab28a606a127 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 5 May 2022 19:31:18 +0800 Subject: ... --- src/osx/graphics/quartz/ImageFactory.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/osx/graphics/quartz/ImageFactory.cpp') diff --git a/src/osx/graphics/quartz/ImageFactory.cpp b/src/osx/graphics/quartz/ImageFactory.cpp index 7796ef3a..95315e1a 100644 --- a/src/osx/graphics/quartz/ImageFactory.cpp +++ b/src/osx/graphics/quartz/ImageFactory.cpp @@ -1,4 +1,5 @@ #include "cru/osx/graphics/quartz/ImageFactory.h" +#include "cru/common/Exception.h" #include "cru/osx/graphics/quartz/Convert.h" #include "cru/osx/graphics/quartz/Image.h" #include "cru/platform/graphics/Image.h" @@ -20,12 +21,27 @@ std::unique_ptr QuartzImageFactory::DecodeFromStream( CGImageRef cg_image = CGImageSourceCreateImageAtIndex(image_source, 0, nullptr); - QuartzImage* image = - new QuartzImage(GetGraphicsFactory(), this, cg_image, true); - - CFRelease(cg_image); + CFRelease(image_source); CGDataProviderRelease(data_provider); - return std::unique_ptr(image); + return std::unique_ptr( + new QuartzImage(GetGraphicsFactory(), this, cg_image, true)); +} + +std::unique_ptr QuartzImageFactory::CreateBitmap(int width, + int height) { + if (width <= 0) throw Exception(u"Image width should be greater than 0."); + if (height <= 0) throw Exception(u"Image height should be greater than 0."); + + CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); + + auto cg_image = CGImageCreate(width, height, 8, 32, 4 * width, color_space, + kCGImageAlphaLast, nullptr, nullptr, true, + kCGRenderingIntentDefault); + + CGColorSpaceRelease(color_space); + + return std::unique_ptr( + new QuartzImage(GetGraphicsFactory(), this, cg_image, true)); } } // namespace cru::platform::graphics::osx::quartz -- cgit v1.2.3