Ocean
Loading...
Searching...
No Matches
platform/apple/macos/Image.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_APPLE_MACOS_IMAGE_H
9#define META_OCEAN_PLATFORM_APPLE_MACOS_IMAGE_H
10
12
13#include "ocean/base/Frame.h"
14
15#ifndef __OBJC__
16 #error Platform::Apple::MacOS::Image.h needs to be included from an ObjectiveC++ file
17#endif
18
19#include <AppKit/AppKit.h>
20
21namespace Ocean
22{
23
24namespace Platform
25{
26
27namespace Apple
28{
29
30namespace MacOS
31{
32
33/**
34 * This class implements a wrapper for the NSImage object.
35 * @ingroup platformapplemacos
36 */
37class Image
38{
39 public:
40
41 /**
42 * Creates a new but empty image object.
43 */
44 Image() = default;
45
46 /**
47 * Move constructor.
48 * @param image The image object to be moved
49 */
50 Image(Image&& image) noexcept;
51
52 /**
53 * Not existing copy constructor.
54 * @param image The image object to be copied
55 */
56 Image(const Image& image) = delete;
57
58 /**
59 * Creates a new image object from a given frame.
60 * The frame data of the given frame will be copied.<br>
61 * Beware: Ensure that the resulting image is valid before using the wrapped object.
62 * @param frame The frame for which a corresponding NSImage object will be wrapped.
63 * @param scaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
64 * @see isValid().
65 */
66 explicit Image(const Frame& frame, const double scaleFactor = 1.0);
67
68 /**
69 * Destructs an image object.
70 */
72
73 /**
74 * Returns the scale factor of this image.
75 * @return imageScaleFactor The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity)
76 */
77 inline double scaleFactor() const;
78
79 /**
80 * Returns the wrapped NSImage object.
81 * @return The NSImage object, nullptr if no object is wrapped
82 */
83 inline NSImage* nsImage();
84
85 /**
86 * Returns whether this object is valid and holds a valid wrapped NSImage object.
87 * @return True, if so
88 */
89 inline bool isValid() const;
90
91 /**
92 * Returns whether this object is valid and holds a valid wrapped NSImage object.
93 * @return True, if so
94 */
95 explicit inline operator bool() const;
96
97 /**
98 * Move operator.
99 * @param image The image object to be moved
100 * @return Reference to this object
101 */
102 Image& operator=(Image&& image) noexcept;
103
104 /**
105 * Not existing copy operator.
106 * @param image The image object to be copied
107 * @return Reference to this object
108 */
109 Image& operator=(const Image& image) = delete;
110
111 protected:
112
113 /// The wrapped MacOS specific NSImage object of this image.
114 NSImage* imageObject_ = nullptr;
115
116 /// The scale factor converting the number of pixels in the (virtual) display coordinate system to the number of pixels in the (native/pyhsical) screen coordinate system, with range (0, infinity).
117 double imageScaleFactor_ = 1.0;
118};
119
120inline double Image::scaleFactor() const
121{
122 return imageScaleFactor_;
123}
124
125inline NSImage* Image::nsImage()
126{
127 return imageObject_;
128}
129
130inline bool Image::isValid() const
131{
132 return imageObject_ != nullptr;
133}
134
135inline Image::operator bool() const
136{
137 return isValid();
138}
139
140}
141
142}
143
144}
145
146}
147
148#endif // META_OCEAN_PLATFORM_APPLE_MACOS_IMAGE_H
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements a wrapper for the NSImage object.
Definition platform/apple/macos/Image.h:38
Image(const Frame &frame, const double scaleFactor=1.0)
Creates a new image object from a given frame.
Image & operator=(Image &&image) noexcept
Move operator.
bool isValid() const
Returns whether this object is valid and holds a valid wrapped NSImage object.
Definition platform/apple/macos/Image.h:130
double scaleFactor() const
Returns the scale factor of this image.
Definition platform/apple/macos/Image.h:120
Image(Image &&image) noexcept
Move constructor.
NSImage * imageObject_
The wrapped MacOS specific NSImage object of this image.
Definition platform/apple/macos/Image.h:114
NSImage * nsImage()
Returns the wrapped NSImage object.
Definition platform/apple/macos/Image.h:125
double imageScaleFactor_
The scale factor converting the number of pixels in the (virtual) display coordinate system to the nu...
Definition platform/apple/macos/Image.h:117
Image & operator=(const Image &image)=delete
Not existing copy operator.
Image()=default
Creates a new but empty image object.
~Image()
Destructs an image object.
Image(const Image &image)=delete
Not existing copy constructor.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15