#pragma once #include #include #include #include "JsiSkHostObjects.h" #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" #include "SkImageInfo.h" #pragma clang diagnostic pop namespace RNSkia { namespace jsi = facebook::jsi; class JsiSkImageInfo : public JsiSkWrappingSharedPtrHostObject { public: JsiSkImageInfo(std::shared_ptr context, const SkImageInfo &imageInfo) : JsiSkWrappingSharedPtrHostObject( std::move(context), std::make_shared(imageInfo)) {} /** Returns the underlying object from a host object of this type */ static std::shared_ptr fromValue(jsi::Runtime &runtime, const jsi::Value &obj) { const auto &object = obj.asObject(runtime); if (object.isHostObject(runtime)) { return object.asHostObject(runtime)->getObject(); } else { auto width = object.getProperty(runtime, "width").asNumber(); auto height = object.getProperty(runtime, "height").asNumber(); auto colorType = static_cast( object.getProperty(runtime, "colorType").asNumber()); auto alphaType = static_cast( object.getProperty(runtime, "alphaType").asNumber()); // TODO: color space not supported yet return std::make_shared( SkImageInfo::Make(width, height, colorType, alphaType)); } } /** Returns the jsi object from a host object of this type */ static jsi::Value toValue(jsi::Runtime &runtime, std::shared_ptr context, const SkImageInfo &imageInfo) { return jsi::Object::createFromHostObject( runtime, std::make_shared(std::move(context), imageInfo)); } }; } // namespace RNSkia