2 * Copyright 2014 Google Inc.
3 * Copyright 2015 Xamarin Inc.
4 * Copyright 2017 Microsoft Corporation. All rights reserved.
6 * Use of this source code is governed by a BSD-style license that can be
7 * found in the LICENSE file.
10 #include "SkColorSpace.h"
12 #include "sk_colorspace.h"
14 #include "sk_types_priv.h"
16 void sk_colorspace_unref(sk_colorspace_t* cColorSpace) {
17 SkSafeUnref(AsColorSpace(cColorSpace));
20 sk_colorspace_t* sk_colorspace_new_srgb() {
21 return ToColorSpace(SkColorSpace::MakeSRGB().release());
24 sk_colorspace_t* sk_colorspace_new_srgb_linear() {
25 return ToColorSpace(SkColorSpace::MakeSRGBLinear().release());
28 sk_colorspace_t* sk_colorspace_new_icc(const void* input, size_t len) {
29 return ToColorSpace(SkColorSpace::MakeICC(input, len).release());
32 sk_colorspace_t* sk_colorspace_new_rgb_with_gamma(sk_colorspace_render_target_gamma_t gamma, const sk_matrix44_t* toXYZD50) {
33 return ToColorSpace(SkColorSpace::MakeRGB((SkColorSpace::RenderTargetGamma)gamma, AsMatrix44(*toXYZD50)).release());
36 sk_colorspace_t* sk_colorspace_new_rgb_with_gamma_and_gamut(sk_colorspace_render_target_gamma_t gamma, sk_colorspace_gamut_t gamut) {
37 return ToColorSpace(SkColorSpace::MakeRGB((SkColorSpace::RenderTargetGamma)gamma, (SkColorSpace::Gamut)gamut).release());
40 sk_colorspace_t* sk_colorspace_new_rgb_with_coeffs(const sk_colorspace_transfer_fn_t* coeffs, const sk_matrix44_t* toXYZD50) {
41 return ToColorSpace(SkColorSpace::MakeRGB(AsColorSpaceTransferFn(*coeffs), AsMatrix44(*toXYZD50)).release());
44 sk_colorspace_t* sk_colorspace_new_rgb_with_coeffs_and_gamut(const sk_colorspace_transfer_fn_t* coeffs, sk_colorspace_gamut_t gamut) {
45 return ToColorSpace(SkColorSpace::MakeRGB(AsColorSpaceTransferFn(*coeffs), (SkColorSpace::Gamut)gamut).release());
48 bool sk_colorspace_gamma_close_to_srgb(const sk_colorspace_t* cColorSpace) {
49 return AsColorSpace(cColorSpace)->gammaCloseToSRGB();
52 bool sk_colorspace_gamma_is_linear(const sk_colorspace_t* cColorSpace) {
53 return AsColorSpace(cColorSpace)->gammaIsLinear();
56 bool sk_colorspace_is_srgb(const sk_colorspace_t* cColorSpace) {
57 return AsColorSpace(cColorSpace)->isSRGB();
60 bool sk_colorspace_equals(const sk_colorspace_t* src, const sk_colorspace_t* dst) {
61 return SkColorSpace::Equals(AsColorSpace(src), AsColorSpace(dst));
64 bool sk_colorspace_to_xyzd50(const sk_colorspace_t* cColorSpace, sk_matrix44_t* toXYZD50) {
65 return AsColorSpace(cColorSpace)->toXYZD50(AsMatrix44(toXYZD50));
68 bool sk_colorspaceprimaries_to_xyzd50(const sk_colorspaceprimaries_t* primaries, sk_matrix44_t* toXYZD50) {
69 return AsColorSpacePrimaries(primaries)->toXYZD50(AsMatrix44(toXYZD50));
72 void sk_colorspace_transfer_fn_invert(const sk_colorspace_transfer_fn_t* transfer, sk_colorspace_transfer_fn_t* inverted) {
73 *inverted = ToColorSpaceTransferFn(AsColorSpaceTransferFn(transfer)->invert());