Adding bindings for SkXxxEncoder::Encode
authorMatthew Leibowitz <mattleibow@live.com>
Thu, 24 May 2018 23:39:08 +0000 (01:39 +0200)
committerMatthew Leibowitz <mattleibow@live.com>
Thu, 24 May 2018 23:39:08 +0000 (01:39 +0200)
include/c/sk_pixmap.h
include/c/sk_types.h
src/c/sk_enums.cpp
src/c/sk_pixmap.cpp
src/c/sk_structs.cpp
src/c/sk_types_priv.h

index f775ac4728872578acefeb0ee5c811ab76c7ea1c..977d9bfffa29ad7458b9b8a5657d0688261a89e6 100644 (file)
@@ -39,6 +39,10 @@ SK_C_API bool sk_pixmap_read_pixels(const sk_pixmap_t* cpixmap, const sk_imagein
 
 SK_C_API void sk_swizzle_swap_rb(uint32_t* dest, const uint32_t* src, int count);
 
+SK_C_API bool sk_webpencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_webpencoder_options_t options);
+SK_C_API bool sk_jpegencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_jpegencoder_options_t options);
+SK_C_API bool sk_pngencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_pngencoder_options_t options);
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 905bd5b5939a2d2b9b982b77a33c40ed8e3e64db..eda8aab37951e667886f4b169072b58b02324d04 100644 (file)
@@ -924,6 +924,55 @@ typedef struct {
     float fContrast;
 } sk_highcontrastconfig_t;
 
+typedef enum {
+    ZERO_SK_PNGENCODER_FILTER_FLAGS  = 0x00,
+    NONE_SK_PNGENCODER_FILTER_FLAGS  = 0x08,
+    SUB_SK_PNGENCODER_FILTER_FLAGS   = 0x10,
+    UP_SK_PNGENCODER_FILTER_FLAGS    = 0x20,
+    AVG_SK_PNGENCODER_FILTER_FLAGS   = 0x40,
+    PAETH_SK_PNGENCODER_FILTER_FLAGS = 0x80,
+    ALL_SK_PNGENCODER_FILTER_FLAGS   = NONE_SK_PNGENCODER_FILTER_FLAGS |
+                                       SUB_SK_PNGENCODER_FILTER_FLAGS |
+                                       UP_SK_PNGENCODER_FILTER_FLAGS | 
+                                       AVG_SK_PNGENCODER_FILTER_FLAGS | 
+                                       PAETH_SK_PNGENCODER_FILTER_FLAGS,
+} sk_pngencoder_filterflags_t;
+
+typedef struct {
+    sk_pngencoder_filterflags_t fFilterFlags;
+    int fZLibLevel;
+    sk_transfer_function_behavior_t fUnpremulBehavior;
+} sk_pngencoder_options_t;
+
+typedef enum {
+    DOWNSAMPLE_420_SK_JPEGENCODER_DOWNSAMPLE,
+    DOWNSAMPLE_422_SK_JPEGENCODER_DOWNSAMPLE,
+    DOWNSAMPLE_444_SK_JPEGENCODER_DOWNSAMPLE,
+} sk_jpegencoder_downsample_t;
+
+typedef enum {
+    IGNORE_SK_JPEGENCODER_ALPHA_OPTION,
+    BLEND_ON_BLACK_SK_JPEGENCODER_ALPHA_OPTION,
+} sk_jpegencoder_alphaoption_t;
+
+typedef struct {
+    int fQuality;
+    sk_jpegencoder_downsample_t fDownsample;
+    sk_jpegencoder_alphaoption_t fAlphaOption;
+    sk_transfer_function_behavior_t fBlendBehavior;
+} sk_jpegencoder_options_t;
+
+typedef enum {
+    LOSSY_SK_WEBPENCODER_COMPTRESSION,
+    LOSSLESS_SK_WEBPENCODER_COMPTRESSION,
+} sk_webpencoder_compression_t;
+
+typedef struct {
+    sk_webpencoder_compression_t fCompression;
+    float fQuality;
+    sk_transfer_function_behavior_t fUnpremulBehavior;
+} sk_webpencoder_options_t;
+
 SK_C_PLUS_PLUS_END_GUARD
 
 #endif
index 42cb866016484b52b214bcb3cb834c5d9006b04a..0ad8786aadefba5b9960f084cf9d24d376402794 100644 (file)
@@ -9,6 +9,9 @@
 #include "SkMatrix44.h"
 #include "SkBitmapScaler.h"
 #include "SkBlurMaskFilter.h"
+#include "SkPngEncoder.h"
+#include "SkJpegEncoder.h"
+#include "SkWebpEncoder.h"
 
 #if SK_SUPPORT_GPU
 #include "GrTypes.h"
@@ -361,6 +364,28 @@ static_assert ((int)SkHighContrastConfig::InvertStyle::kInvertLightness    == (i
 // sk_bitmap_allocflags_t
 static_assert ((int)SkBitmap::AllocFlags::kZeroPixels_AllocFlag   == (int)ZERO_PIXELS_SK_BITMAP_ALLOC_FLAGS,   ASSERT_MSG(SkBitmap::AllocFlags, sk_bitmap_allocflags_t));
 
+// sk_pngencoder_filterflags_t
+static_assert ((int)SkPngEncoder::FilterFlag::kZero    == (int)ZERO_SK_PNGENCODER_FILTER_FLAGS,    ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+static_assert ((int)SkPngEncoder::FilterFlag::kNone    == (int)NONE_SK_PNGENCODER_FILTER_FLAGS,    ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+static_assert ((int)SkPngEncoder::FilterFlag::kSub     == (int)SUB_SK_PNGENCODER_FILTER_FLAGS,     ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+static_assert ((int)SkPngEncoder::FilterFlag::kUp      == (int)UP_SK_PNGENCODER_FILTER_FLAGS,      ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+static_assert ((int)SkPngEncoder::FilterFlag::kAvg     == (int)AVG_SK_PNGENCODER_FILTER_FLAGS,     ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+static_assert ((int)SkPngEncoder::FilterFlag::kPaeth   == (int)PAETH_SK_PNGENCODER_FILTER_FLAGS,   ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+static_assert ((int)SkPngEncoder::FilterFlag::kAll     == (int)ALL_SK_PNGENCODER_FILTER_FLAGS,     ASSERT_MSG(SkPngEncoder::FilterFlag, sk_pngencoder_filterflags_t));
+
+// sk_jpegencoder_downsample_t
+static_assert ((int)SkJpegEncoder::Downsample::k420   == (int)DOWNSAMPLE_420_SK_JPEGENCODER_DOWNSAMPLE,   ASSERT_MSG(SkJpegEncoder::Downsample, sk_jpegencoder_downsample_t));
+static_assert ((int)SkJpegEncoder::Downsample::k422   == (int)DOWNSAMPLE_422_SK_JPEGENCODER_DOWNSAMPLE,   ASSERT_MSG(SkJpegEncoder::Downsample, sk_jpegencoder_downsample_t));
+static_assert ((int)SkJpegEncoder::Downsample::k444   == (int)DOWNSAMPLE_444_SK_JPEGENCODER_DOWNSAMPLE,   ASSERT_MSG(SkJpegEncoder::Downsample, sk_jpegencoder_downsample_t));
+
+// sk_jpegencoder_alphaoption_t
+static_assert ((int)SkJpegEncoder::AlphaOption::kIgnore         == (int)IGNORE_SK_JPEGENCODER_ALPHA_OPTION,           ASSERT_MSG(SkJpegEncoder::AlphaOption, sk_jpegencoder_alphaoption_t));
+static_assert ((int)SkJpegEncoder::AlphaOption::kBlendOnBlack   == (int)BLEND_ON_BLACK_SK_JPEGENCODER_ALPHA_OPTION,   ASSERT_MSG(SkJpegEncoder::AlphaOption, sk_jpegencoder_alphaoption_t));
+
+// sk_webpencoder_compression_t
+static_assert ((int)SkWebpEncoder::Compression::kLossy      == (int)LOSSY_SK_WEBPENCODER_COMPTRESSION,      ASSERT_MSG(SkWebpEncoder::Compression, sk_webpencoder_compression_t));
+static_assert ((int)SkWebpEncoder::Compression::kLossless   == (int)LOSSLESS_SK_WEBPENCODER_COMPTRESSION,   ASSERT_MSG(SkWebpEncoder::Compression, sk_webpencoder_compression_t));
+
 #if SK_SUPPORT_GPU
 
 // gr_surfaceorigin_t
index db0d02f9c4d196d34791109b1e8d309febf50379..6be46eeb998bcb626ea4b6083bc3d365ce4bb630 100644 (file)
@@ -122,3 +122,15 @@ void sk_swizzle_swap_rb(uint32_t* dest, const uint32_t* src, int count)
 {
     SkSwapRB(dest, src, count);
 }
+
+bool sk_webpencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_webpencoder_options_t options) {
+    return SkWebpEncoder::Encode(AsWStream(dst), AsPixmap(*src), AsWebpEncoderOptions(options));
+}
+
+bool sk_jpegencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_jpegencoder_options_t options) {
+    return SkJpegEncoder::Encode(AsWStream(dst), AsPixmap(*src), AsJpegEncoderOptions(options));
+}
+
+bool sk_pngencoder_encode(sk_wstream_t* dst, const sk_pixmap_t* src, sk_pngencoder_options_t options) {
+    return SkPngEncoder::Encode(AsWStream(dst), AsPixmap(*src), AsPngEncoderOptions(options));
+}
index d7cbc74cb02eff7cc0bff168a081a314704112b8..d0b00861cb7ac19eb89ed1163c282c0d4d8a28b5 100644 (file)
@@ -55,6 +55,9 @@ static_assert (sizeof (sk_codec_frameinfo_t) == sizeof (SkCodec::FrameInfo), ASS
 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));
+static_assert (sizeof (sk_pngencoder_options_t) == sizeof (SkPngEncoder::Options), ASSERT_MSG(SkPngEncoder::Options, sk_pngencoder_options_t));
+static_assert (sizeof (sk_jpegencoder_options_t) == sizeof (SkJpegEncoder::Options), ASSERT_MSG(SkJpegEncoder::Options, sk_jpegencoder_options_t));
+static_assert (sizeof (sk_webpencoder_options_t) == sizeof (SkWebpEncoder::Options), ASSERT_MSG(SkWebpEncoder::Options, sk_webpencoder_options_t));
 
 #if SK_SUPPORT_GPU
 static_assert (sizeof (gr_backend_rendertarget_desc_t) == sizeof (GrBackendRenderTargetDesc), ASSERT_MSG(GrBackendRenderTargetDesc, gr_backend_rendertarget_desc_t));
index dd345457871e11c6488533e8c644d41f15697127..6ab1b76bfba354c50b41b09610837055c76bcd28 100644 (file)
@@ -40,6 +40,9 @@
 #include "SkTime.h"
 #include "SkCamera.h"
 #include "SkHighContrastFilter.h"
+#include "SkPngEncoder.h"
+#include "SkJpegEncoder.h"
+#include "SkWebpEncoder.h"
 
 #include "sk_path.h"
 #include "sk_paint.h"
@@ -863,6 +866,30 @@ static inline const sk_vertices_t* ToVertices(const SkVertices* p) {
     return reinterpret_cast<const sk_vertices_t*>(p);
 }
 
+static inline const SkPngEncoder::Options& AsPngEncoderOptions(const sk_pngencoder_options_t& p) {
+    return reinterpret_cast<const SkPngEncoder::Options&>(p);
+}
+
+static inline const SkPngEncoder::Options* AsPngEncoderOptions(const sk_pngencoder_options_t* p) {
+    return reinterpret_cast<const SkPngEncoder::Options*>(p);
+}
+
+static inline const SkJpegEncoder::Options& AsJpegEncoderOptions(const sk_jpegencoder_options_t& p) {
+    return reinterpret_cast<const SkJpegEncoder::Options&>(p);
+}
+
+static inline const SkJpegEncoder::Options* AsJpegEncoderOptions(const sk_jpegencoder_options_t* p) {
+    return reinterpret_cast<const SkJpegEncoder::Options*>(p);
+}
+
+static inline const SkWebpEncoder::Options& AsWebpEncoderOptions(const sk_webpencoder_options_t& p) {
+    return reinterpret_cast<const SkWebpEncoder::Options&>(p);
+}
+
+static inline const SkWebpEncoder::Options* AsWebpEncoderOptions(const sk_webpencoder_options_t* p) {
+    return reinterpret_cast<const SkWebpEncoder::Options*>(p);
+}
+
 static inline void from_c(const sk_matrix_t* cmatrix, SkMatrix* matrix) {
     matrix->setAll(
         cmatrix->mat[0], cmatrix->mat[1], cmatrix->mat[2],