Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Sources/OpenRenderBoxCxx/Color/ColorSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace ORB {

std::optional<ColorSpace> color_space_from_cg_name(CFStringRef name) {
ORB::Optional<ColorSpace> color_space_from_cg_name(CFStringRef name) {
if (name == nullptr) {
return std::nullopt;
return ORB::nullopt;
} else if (CFEqual(name, kCGColorSpaceSRGB) ||
CFEqual(name, kCGColorSpaceExtendedSRGB)) {
return ColorSpace::SRGB;
Expand All @@ -26,13 +26,13 @@ std::optional<ColorSpace> color_space_from_cg_name(CFStringRef name) {
CFEqual(name, kCGColorSpaceExtendedLinearDisplayP3)) {
return ColorSpace::LinearDisplayP3;
} else {
return std::nullopt;
return ORB::nullopt;
}
}

std::optional<ColorSpace> color_space_from_cg(CGColorSpaceRef colorSpace) {
ORB::Optional<ColorSpace> color_space_from_cg(CGColorSpaceRef colorSpace) {
if (colorSpace == nullptr) {
return std::nullopt;
return ORB::nullopt;
}
CFStringRef name = CGColorSpaceGetName(colorSpace);
return color_space_from_cg_name(name);
Expand Down Expand Up @@ -107,10 +107,10 @@ CGColorSpaceRef gray_colorspace() {

} /* namespace ORB */

std::optional<ORB::ColorSpace> orb_color_space(ORBColorSpace orbColorSpace) {
ORB::Optional<ORB::ColorSpace> orb_color_space(ORBColorSpace orbColorSpace) {
switch (orbColorSpace) {
case ORBColorSpaceDefault:
return std::nullopt;
return ORB::nullopt;
case ORBColorSpaceSRGB:
return ORB::ColorSpace::SRGB;
case ORBColorSpaceLinearSRGB:
Expand All @@ -120,15 +120,15 @@ std::optional<ORB::ColorSpace> orb_color_space(ORBColorSpace orbColorSpace) {
case ORBColorSpaceLinearDisplayP3:
return ORB::ColorSpace::LinearDisplayP3;
default:
return std::nullopt;
return ORB::nullopt;
}
}

ORBColorSpace orb_color_space(std::optional<ORB::ColorSpace> colorSpace) {
if (!colorSpace.has_value()) {
ORBColorSpace orb_color_space(ORB::Optional<ORB::ColorSpace> colorSpace) {
if (!colorSpace) {
return ORBColorSpaceDefault;
}
switch (colorSpace.value()) {
switch (*colorSpace) {
case ORB::ColorSpace::LinearSRGB:
return ORBColorSpaceLinearSRGB;
case ORB::ColorSpace::SRGB:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
#include <CoreGraphics/CGColorSpace.h>
#include <CoreFoundation/CFString.h>
#endif /* ORB_TARGET_OS_DARWIN */
#if __has_include(<optional>)
#include <optional>
namespace ORB {
template <typename T> using Optional = std::optional<T>;
constexpr auto nullopt = std::nullopt;
}
#else
#include <experimental/optional>
namespace ORB {
template <typename T> using Optional = std::experimental::optional<T>;
constexpr auto nullopt = std::experimental::nullopt;
}
#endif

namespace ORB {

Expand All @@ -27,13 +39,13 @@ enum class ColorSpace : uint32_t {
#if ORB_TARGET_OS_DARWIN
/// Converts a CGColorSpace name (CFStringRef) to internal ColorSpace enum.
/// @param name The color space name from CGColorSpaceGetName.
/// @return The ColorSpace if recognized, or std::nullopt if not.
std::optional<ColorSpace> color_space_from_cg_name(CFStringRef name);
/// @return The ColorSpace if recognized, or ORB::nullopt if not.
Optional<ColorSpace> color_space_from_cg_name(CFStringRef name);

/// Converts a CGColorSpaceRef to internal ColorSpace enum.
/// @param colorSpace The CGColorSpace to convert.
/// @return The ColorSpace if recognized, or std::nullopt if not.
std::optional<ColorSpace> color_space_from_cg(CGColorSpaceRef colorSpace);
/// @return The ColorSpace if recognized, or ORB::nullopt if not.
Optional<ColorSpace> color_space_from_cg(CGColorSpaceRef colorSpace);

/// Returns a CGColorSpaceRef for the given internal color space.
/// @param colorSpace The internal color space enum value.
Expand Down Expand Up @@ -74,6 +86,6 @@ CGColorSpaceRef gray_colorspace();

} /* namespace ORB */

std::optional<ORB::ColorSpace> orb_color_space(ORBColorSpace orbColorSpace);
ORB::Optional<ORB::ColorSpace> orb_color_space(ORBColorSpace orbColorSpace);

ORBColorSpace orb_color_space(std::optional<ORB::ColorSpace> colorSpace);
ORBColorSpace orb_color_space(ORB::Optional<ORB::ColorSpace> colorSpace);