Added a few more filters and effects
authorMatthew Leibowitz <mattleibow@live.com>
Tue, 16 May 2017 15:18:54 +0000 (17:18 +0200)
committerMatthew Leibowitz <mattleibow@live.com>
Tue, 16 May 2017 15:18:54 +0000 (17:18 +0200)
include/c/sk_colorfilter.h
include/c/sk_imagefilter.h
include/c/sk_patheffect.h
include/c/sk_types.h
src/c/sk_colorfilter.cpp
src/c/sk_enums.cpp
src/c/sk_imagefilter.cpp
src/c/sk_patheffect.cpp
src/c/sk_structs.cpp
src/c/sk_types_priv.h

index 3f7bdc6..f8f0533 100644 (file)
@@ -21,6 +21,7 @@ SK_C_API sk_colorfilter_t* sk_colorfilter_new_lighting(sk_color_t mul, sk_color_
 SK_C_API sk_colorfilter_t* sk_colorfilter_new_compose(sk_colorfilter_t* outer, sk_colorfilter_t* inner);
 SK_C_API sk_colorfilter_t* sk_colorfilter_new_color_matrix(const float array[20]);
 SK_C_API sk_colorfilter_t* sk_colorfilter_new_luma_color(void);
+SK_C_API sk_colorfilter_t* sk_colorfilter_new_high_contrast(const sk_highcontrastconfig_t* config);
 SK_C_API sk_colorfilter_t* sk_colorfilter_new_table(const uint8_t table[256]);
 SK_C_API sk_colorfilter_t* sk_colorfilter_new_table_argb(const uint8_t tableA[256], const uint8_t tableR[256], const uint8_t tableG[256], const uint8_t tableB[256]);
 
index 0bca27c..b055c58 100644 (file)
@@ -112,7 +112,8 @@ SK_C_API sk_imagefilter_t* sk_imagefilter_new_spot_lit_specular(
 SK_C_API sk_imagefilter_t* sk_imagefilter_new_magnifier(
     const sk_rect_t* src, 
     float inset,
-    sk_imagefilter_t* input /*NULL*/);
+    sk_imagefilter_t* input, /*NULL*/
+    const sk_imagefilter_croprect_t* cropRect /*NULL*/);
 SK_C_API sk_imagefilter_t* sk_imagefilter_new_matrix_convolution(
     const sk_isize_t* kernelSize,
     const float kernel[],
@@ -167,6 +168,16 @@ SK_C_API sk_imagefilter_t* sk_imagefilter_new_arithmetic(
     sk_imagefilter_t* background,
     sk_imagefilter_t* foreground /*NULL*/,
     const sk_imagefilter_croprect_t* cropRect /*NULL*/);
+SK_C_API sk_imagefilter_t* sk_imagefilter_new_image_source(
+    sk_image_t* image,
+    const sk_rect_t* srcRect,
+    const sk_rect_t* dstRect,
+    sk_filter_quality_t filterQuality);
+SK_C_API sk_imagefilter_t* sk_imagefilter_new_image_source_default(
+    sk_image_t* image);
+SK_C_API sk_imagefilter_t* sk_imagefilter_new_paint(
+    const sk_paint_t* paint,
+    const sk_imagefilter_croprect_t* cropRect /*NULL*/);
 
 SK_C_PLUS_PLUS_END_GUARD
 
index cacdfed..8600bb3 100644 (file)
@@ -20,6 +20,7 @@ SK_C_API sk_path_effect_t* sk_path_effect_create_compose(sk_path_effect_t* outer
 SK_C_API sk_path_effect_t* sk_path_effect_create_sum(sk_path_effect_t* first, sk_path_effect_t* second);
 SK_C_API sk_path_effect_t* sk_path_effect_create_discrete(float segLength, float deviation, uint32_t seedAssist /*0*/);
 SK_C_API sk_path_effect_t* sk_path_effect_create_corner(float radius);
+SK_C_API sk_path_effect_t* sk_path_effect_create_arc_to(float radius);
 SK_C_API sk_path_effect_t* sk_path_effect_create_1d_path(const sk_path_t* path, float advance, float phase, sk_path_effect_1d_style_t style);
 SK_C_API sk_path_effect_t* sk_path_effect_create_2d_line(float width, const sk_matrix_t* matrix);
 SK_C_API sk_path_effect_t* sk_path_effect_create_2d_path(const sk_matrix_t* matrix, const sk_path_t* path);
index 08396ae..1fbbb86 100644 (file)
@@ -851,6 +851,18 @@ typedef struct {
     float fWX, fWY;
 } sk_colorspaceprimaries_t;
 
+typedef enum {
+    NO_INVERT_SK_HIGH_CONTRAST_CONFIG_INVERT_STYLE,
+    INVERT_BRIGHTNESS_SK_HIGH_CONTRAST_CONFIG_INVERT_STYLE,
+    INVERT_LIGHTNESS_SK_HIGH_CONTRAST_CONFIG_INVERT_STYLE,
+} sk_highcontrastconfig_invertstyle_t;
+
+typedef struct {
+    bool fGrayscale;
+    sk_highcontrastconfig_invertstyle_t fInvertStyle;
+    float fContrast;
+} sk_highcontrastconfig_t;
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index b7751f3..86222fb 100644 (file)
@@ -52,6 +52,12 @@ sk_colorfilter_t* sk_colorfilter_new_luma_color() {
     return ToColorFilter(filter.release());
 }
 
+sk_colorfilter_t* sk_colorfilter_new_high_contrast(const sk_highcontrastconfig_t* config) {
+
+    sk_sp<SkColorFilter> filter = SkHighContrastFilter::Make(AsHighContrastConfig(*config));
+    return ToColorFilter(filter.release());
+}
+
 sk_colorfilter_t* sk_colorfilter_new_table(const uint8_t table[256]) {
 
     sk_sp<SkColorFilter> filter = SkTableColorFilter::Make(table);
index 200a879..fa52365 100644 (file)
@@ -356,6 +356,11 @@ static_assert ((int)SkColorSpace::ColorSpaceFlags::kNonLinearBlending_ColorSpace
 static_assert ((int)SkColorSpace::RenderTargetGamma::kLinear_RenderTargetGamma   == (int)LINEAR_SK_COLORSPACE_RENDER_TARGET_GAMMA,   ASSERT_MSG(SkColorSpace::RenderTargetGamma, sk_colorspace_render_target_gamma_t));
 static_assert ((int)SkColorSpace::RenderTargetGamma::kSRGB_RenderTargetGamma     == (int)SRGB_SK_COLORSPACE_RENDER_TARGET_GAMMA,     ASSERT_MSG(SkColorSpace::RenderTargetGamma, sk_colorspace_render_target_gamma_t));
 
+// sk_highcontrastconfig_invertstyle_t
+static_assert ((int)SkHighContrastConfig::InvertStyle::kNoInvert           == (int)NO_INVERT_SK_HIGH_CONTRAST_CONFIG_INVERT_STYLE,           ASSERT_MSG(SkHighContrastConfig::InvertStyle, sk_highcontrastconfig_invertstyle_t));
+static_assert ((int)SkHighContrastConfig::InvertStyle::kInvertBrightness   == (int)INVERT_BRIGHTNESS_SK_HIGH_CONTRAST_CONFIG_INVERT_STYLE,   ASSERT_MSG(SkHighContrastConfig::InvertStyle, sk_highcontrastconfig_invertstyle_t));
+static_assert ((int)SkHighContrastConfig::InvertStyle::kInvertLightness    == (int)INVERT_LIGHTNESS_SK_HIGH_CONTRAST_CONFIG_INVERT_STYLE,    ASSERT_MSG(SkHighContrastConfig::InvertStyle, sk_highcontrastconfig_invertstyle_t));
+
 #if SK_SUPPORT_GPU
 
 // gr_surfaceorigin_t
index 840e0ac..11214a6 100644 (file)
@@ -23,6 +23,8 @@
 #include "SkTileImageFilter.h"
 #include "SkXfermodeImageFilter.h"
 #include "SkArithmeticImageFilter.h"
+#include "SkImageSource.h"
+#include "SkPaintImageFilter.h"
 
 #include "sk_imagefilter.h"
 
@@ -274,12 +276,14 @@ sk_imagefilter_t* sk_imagefilter_new_spot_lit_specular(
 sk_imagefilter_t* sk_imagefilter_new_magnifier(
     const sk_rect_t* src,
     float inset,
-    sk_imagefilter_t* input /*NULL*/) {
+    sk_imagefilter_t* input, /*NULL*/
+    const sk_imagefilter_croprect_t* cropRect) {
 
     sk_sp<SkImageFilter> filter = SkMagnifierImageFilter::Make(
         *AsRect(src),
         inset,
-        sk_ref_sp(AsImageFilter(input)));
+        sk_ref_sp(AsImageFilter(input)),
+        AsImageFilterCropRect(cropRect));
     return ToImageFilter(filter.release());
 }
 
@@ -440,3 +444,35 @@ SK_API sk_imagefilter_t* sk_imagefilter_new_arithmetic(
         AsImageFilterCropRect(cropRect));
     return ToImageFilter(filter.release());
 }
+
+sk_imagefilter_t* sk_imagefilter_new_image_source(
+    sk_image_t* image,
+    const sk_rect_t* srcRect,
+    const sk_rect_t* dstRect,
+    sk_filter_quality_t filterQuality) {
+
+    sk_sp<SkImageFilter> filter = SkImageSource::Make(
+        sk_ref_sp(AsImage(image)),
+        *AsRect(srcRect),
+        *AsRect(dstRect),
+        (SkFilterQuality)filterQuality);
+    return ToImageFilter(filter.release());
+}
+
+sk_imagefilter_t* sk_imagefilter_new_image_source_default(
+    sk_image_t* image) {
+
+    sk_sp<SkImageFilter> filter = SkImageSource::Make(
+        sk_ref_sp(AsImage(image)));
+    return ToImageFilter(filter.release());
+}
+
+sk_imagefilter_t* sk_imagefilter_new_paint(
+    const sk_paint_t* paint,
+    const sk_imagefilter_croprect_t* cropRect /*NULL*/) {
+
+    sk_sp<SkImageFilter> filter = SkPaintImageFilter::Make(
+        AsPaint(*paint),
+        AsImageFilterCropRect(cropRect));
+    return ToImageFilter(filter.release());
+}
index b05a3ee..764b997 100644 (file)
@@ -11,6 +11,7 @@
 #include "Sk1DPathEffect.h"
 #include "Sk2DPathEffect.h"
 #include "SkDashPathEffect.h"
+#include "SkArcToPathEffect.h"
 #include "SkPath.h"
 
 #include "sk_patheffect.h"
@@ -42,6 +43,11 @@ sk_path_effect_t* sk_path_effect_create_corner(float radius)
     return ToPathEffect(SkCornerPathEffect::Make(radius).release());
 }
 
+sk_path_effect_t* sk_path_effect_create_arc_to(float radius)
+{
+    return ToPathEffect(SkArcToPathEffect::Make(radius).release());
+}
+
 sk_path_effect_t* sk_path_effect_create_1d_path(const sk_path_t* path, float advance, float phase, sk_path_effect_1d_style_t style)
 {
     return ToPathEffect(SkPath1DPathEffect::Make(AsPath(*path), advance, phase, (SkPath1DPathEffect::Style)style).release());
index ecf646d..d7cbc74 100644 (file)
@@ -54,6 +54,7 @@ static_assert (sizeof (sk_encodedinfo_t) == sizeof (SkEncodedInfo), ASSERT_MSG(S
 static_assert (sizeof (sk_codec_frameinfo_t) == sizeof (SkCodec::FrameInfo), ASSERT_MSG(SkCodec::FrameInfo, sk_codec_frameinfo_t));
 static_assert (sizeof (sk_colorspace_transfer_fn_t) == sizeof (SkColorSpaceTransferFn), ASSERT_MSG(SkColorSpaceTransferFn, sk_colorspace_transfer_fn_t));
 static_assert (sizeof (sk_colorspaceprimaries_t) == sizeof (SkColorSpacePrimaries), ASSERT_MSG(SkColorSpacePrimaries, sk_colorspaceprimaries_t));
+static_assert (sizeof (sk_highcontrastconfig_t) == sizeof (SkHighContrastConfig), ASSERT_MSG(SkHighContrastConfig, sk_highcontrastconfig_t));
 
 #if SK_SUPPORT_GPU
 static_assert (sizeof (gr_backend_rendertarget_desc_t) == sizeof (GrBackendRenderTargetDesc), ASSERT_MSG(GrBackendRenderTargetDesc, gr_backend_rendertarget_desc_t));
index cf4dad1..b43a07b 100644 (file)
@@ -36,6 +36,7 @@
 #include "SkEncodedInfo.h"
 #include "SkTime.h"
 #include "SkCamera.h"
+#include "SkHighContrastFilter.h"
 
 #include "sk_path.h"
 #include "sk_paint.h"
@@ -199,6 +200,10 @@ static inline const SkImage* AsImage(const sk_image_t* cimage) {
     return reinterpret_cast<const SkImage*>(cimage);
 }
 
+static inline SkImage* AsImage(sk_image_t* cimage) {
+    return reinterpret_cast<SkImage*>(cimage);
+}
+
 static inline sk_image_t* ToImage(SkImage* cimage) {
     return reinterpret_cast<sk_image_t*>(cimage);
 }
@@ -791,6 +796,38 @@ static inline const sk_matrix44_t* ToMatrix44(const SkMatrix44* p) {
     return reinterpret_cast<const sk_matrix44_t*>(p);
 }
 
+static inline const SkHighContrastConfig* AsHighContrastConfig(const sk_highcontrastconfig_t* p) {
+    return reinterpret_cast<const SkHighContrastConfig*>(p);
+}
+
+static inline const SkHighContrastConfig& AsHighContrastConfig(const sk_highcontrastconfig_t& p) {
+    return reinterpret_cast<const SkHighContrastConfig&>(p);
+}
+
+static inline SkHighContrastConfig* AsHighContrastConfig(sk_highcontrastconfig_t* p) {
+    return reinterpret_cast<SkHighContrastConfig*>(p);
+}
+
+static inline SkHighContrastConfig& AsHighContrastConfig(sk_highcontrastconfig_t& p) {
+    return reinterpret_cast<SkHighContrastConfig&>(p);
+}
+
+static inline sk_highcontrastconfig_t* ToHighContrastConfig(SkHighContrastConfig *p) {
+    return reinterpret_cast<sk_highcontrastconfig_t*>(p);
+}
+
+static inline sk_highcontrastconfig_t& ToHighContrastConfig(SkHighContrastConfig &p) {
+    return reinterpret_cast<sk_highcontrastconfig_t&>(p);
+}
+
+static inline const sk_highcontrastconfig_t* ToHighContrastConfig(const SkHighContrastConfig *p) {
+    return reinterpret_cast<const sk_highcontrastconfig_t*>(p);
+}
+
+static inline const sk_highcontrastconfig_t& ToHighContrastConfig(const SkHighContrastConfig &p) {
+    return reinterpret_cast<const sk_highcontrastconfig_t&>(p);
+}
+
 static inline void from_c(const sk_matrix_t* cmatrix, SkMatrix* matrix) {
     matrix->setAll(
         cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],