Valentin Shergin 9d08e2afae Fabric: Using ColorComponents in colorFromComponents function
Summary: Trivial. We have a special data structure for it, why do not use it here?

Reviewed By: mdvacca

Differential Revision: D7738577

fbshipit-source-id: 750aa649b06f17d27906d44df07172a907cde2e5
2018-04-26 18:03:07 -07:00

46 lines
1.1 KiB
C++

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "Color.h"
#include <CoreGraphics/CoreGraphics.h>
#include <CoreGraphics/CGColor.h>
#include <cassert>
namespace facebook {
namespace react {
SharedColor colorFromComponents(ColorComponents components) {
const CGFloat componentsArray[] = {
components.red,
components.green,
components.blue,
components.alpha
};
CGColorRef color = CGColorCreate(
CGColorSpaceCreateDeviceRGB(),
componentsArray
);
return SharedColor(color, CFRelease);
}
ColorComponents colorComponentsFromColor(SharedColor color) {
int numberOfComponents = CGColorGetNumberOfComponents(color.get());
assert(numberOfComponents == 4);
const CGFloat *components = CGColorGetComponents(color.get());
return ColorComponents {
(float)components[0],
(float)components[1],
(float)components[2],
(float)components[3]
};
}
} // namespace react
} // namespace facebook