aboutsummaryrefslogtreecommitdiff
path: root/src/osx/graphics/quartz/Image.cpp
blob: e26643224ca6b92b0ac606b748a4f8ee0728d635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "cru/osx/graphics/quartz/Image.hpp"
#include "cru/osx/graphics/quartz/Convert.hpp"

namespace cru::platform::graphics::osx::quartz {
QuartzImage::QuartzImage(IGraphicsFactory* graphics_factory,
                         IImageFactory* image_factory, CGImageRef image,
                         bool auto_release)
    : OsxQuartzResource(graphics_factory),
      image_factory_(image_factory),
      image_(image),
      auto_release_(auto_release) {}

QuartzImage::~QuartzImage() {
  if (auto_release_) {
    CGImageRelease(image_);
  }
}

float QuartzImage::GetWidth() { return CGImageGetWidth(image_); }

float QuartzImage::GetHeight() { return CGImageGetHeight(image_); }

std::unique_ptr<IImage> QuartzImage::CreateWithRect(const Rect& rect) {
  auto new_cg_image = CGImageCreateWithImageInRect(image_, Convert(rect));

  return std::make_unique<QuartzImage>(GetGraphicsFactory(), image_factory_,
                                       new_cg_image, true);
}
}  // namespace cru::platform::graphics::osx::quartz