SK_C_PLUS_PLUS_BEGIN_GUARD
-/**
- * Return a new image that has made a copy of the provided pixels, or NULL on failure.
- * Balance with a call to sk_image_unref().
- */
-SK_C_API sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes);
-/**
- * If the specified data can be interpreted as a compressed image (e.g. PNG or JPEG) then this
- * returns an image. If the encoded data is not supported, returns NULL.
- *
- * On success, the encoded data may be processed immediately, or it may be ref()'d for later
- * use.
- */
-SK_C_API sk_image_t* sk_image_new_from_encoded(const sk_data_t* encoded, const sk_irect_t* subset);
-/**
- * Encode the image's pixels and return the result as a new PNG in a
- * sk_data_t, which the caller must manage: call sk_data_unref() when
- * they are done.
- *
- * If the image type cannot be encoded, this will return NULL.
- */
-SK_C_API sk_data_t* sk_image_encode(const sk_image_t*);
-/**
- * Increment the reference count on the given sk_image_t. Must be
- * balanced by a call to sk_image_unref().
-*/
SK_C_API void sk_image_ref(const sk_image_t*);
-/**
- * Decrement the reference count. If the reference count is 1 before
- * the decrement, then release both the memory holding the sk_image_t
- * and the memory it is managing. New sk_image_t are created with a
- * reference count of 1.
-*/
SK_C_API void sk_image_unref(const sk_image_t*);
-/**
- * Return the width of the sk_image_t/
- */
+SK_C_API sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t*, const void* pixels, size_t rowBytes);
+SK_C_API sk_image_t* sk_image_new_raster_copy_with_pixmap(const sk_pixmap_t* pixmap);
+SK_C_API sk_image_t* sk_image_new_raster_copy_with_colortable(const sk_imageinfo_t* cinfo, const void* pixels, size_t rowBytes, sk_colortable_t* ctable);
+SK_C_API sk_image_t* sk_image_new_raster_data(const sk_imageinfo_t* cinfo, sk_data_t* pixels, size_t rowBytes);
+SK_C_API sk_image_t* sk_image_new_raster(const sk_pixmap_t* pixmap, sk_image_raster_release_proc releaseProc, void* context);
+SK_C_API sk_image_t* sk_image_new_from_bitmap(const sk_bitmap_t *cbitmap);
+SK_C_API sk_image_t* sk_image_new_from_encoded(const sk_data_t* encoded, const sk_irect_t* subset);
+SK_C_API sk_image_t* sk_image_new_from_texture(gr_context_t* context, const gr_backend_texture_desc_t* desc, sk_alphatype_t alpha, sk_colorspace_t* colorSpace, sk_image_texture_release_proc releaseProc, void* releaseContext);
+SK_C_API sk_image_t* sk_image_new_from_adopted_texture(gr_context_t* context, const gr_backend_texture_desc_t* desc, sk_alphatype_t alpha, sk_colorspace_t* colorSpace);
+SK_C_API sk_image_t* sk_image_new_from_picture(sk_picture_t* picture, const sk_isize_t* dimensions, const sk_matrix_t* matrix, const sk_paint_t* paint);
SK_C_API int sk_image_get_width(const sk_image_t*);
-/**
- * Return the height of the sk_image_t/
- */
SK_C_API int sk_image_get_height(const sk_image_t*);
-/**
- * Returns a non-zero value unique among all images.
- */
SK_C_API uint32_t sk_image_get_unique_id(const sk_image_t*);
-/**
- * Encode the image's pixels using the specified format and quality
- * and return the result as a new image in a
- * sk_data_t, which the caller must manage: call sk_data_unref() when
- * they are done.
- *
- * If the image type cannot be encoded, this will return NULL.
- */
-SK_C_API sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_image_encoder_t encoder, int quality);
-/**
- * Construct a new image from the specified bitmap. If the bitmap is marked immutable, and
- * its pixel memory is shareable, it may be shared instead of copied.
- */
-SK_C_API sk_image_t* sk_image_new_from_bitmap (const sk_bitmap_t *cbitmap);
+SK_C_API sk_alphatype_t sk_image_get_alpha_type(const sk_image_t*);
+SK_C_API bool sk_image_is_alpha_only(const sk_image_t*);
+SK_C_API sk_shader_t* sk_image_make_shader(const sk_image_t*, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_matrix_t* localMatrix);
+SK_C_API bool sk_image_peek_pixels(const sk_image_t* image, sk_pixmap_t* pixmap);
+SK_C_API bool sk_image_is_texture_backed(const sk_image_t* image);
+SK_C_API bool sk_image_read_pixels(const sk_image_t* image, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, sk_image_caching_hint_t cachingHint);
+SK_C_API bool sk_image_read_pixels_into_pixmap(const sk_image_t* image, const sk_pixmap_t* dst, int srcX, int srcY, sk_image_caching_hint_t cachingHint);
+SK_C_API bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, sk_filter_quality_t quality, sk_image_caching_hint_t cachingHint);
+SK_C_API sk_data_t* sk_image_encode(const sk_image_t*);
+SK_C_API sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_image_encoder_type_t encoder, int quality);
+SK_C_API sk_image_t* sk_image_make_subset(const sk_image_t* cimage, const sk_irect_t* subset);
+SK_C_API sk_image_t* sk_image_make_texture_image(const sk_image_t* cimage, gr_context_t* context);
+SK_C_API sk_image_t* sk_image_make_non_texture_image(const sk_image_t* cimage);
+SK_C_API sk_image_t* sk_image_make_with_filter(const sk_image_t* cimage, const sk_imagefilter_t* filter, const sk_irect_t* subset, const sk_irect_t* clipBounds, sk_irect_t* outSubset, sk_ipoint_t* outOffset);
SK_C_PLUS_PLUS_END_GUARD
WBMP_SK_IMAGE_ENCODER_TYPE,
WEBP_SK_IMAGE_ENCODER_TYPE,
KTX_SK_IMAGE_ENCODER_TYPE,
-} sk_image_encoder_t;
+} sk_image_encoder_type_t;
typedef enum {
CLAMP_SK_MATRIX_CONVOLUTION_TILEMODE,
typedef void (*sk_bitmap_release_proc)(void* addr, void* context);
+typedef void (*sk_image_raster_release_proc)(const void* addr, void* context);
+typedef void (*sk_image_texture_release_proc)(void* context);
+
+typedef enum {
+ ALLOW_SK_IMAGE_CACHING_HINT,
+ DISALLOW_SK_IMAGE_CACHING_HINT,
+} sk_image_caching_hint_t;
+
typedef struct {
int16_t fTimeZoneMinutes;
uint16_t fYear;
static_assert ((int)SkMatrixConvolutionImageFilter::TileMode::kRepeat_TileMode == (int)REPEAT_SK_MATRIX_CONVOLUTION_TILEMODE, ASSERT_MSG(SkMatrixConvolutionImageFilter::TileMode, sk_matrix_convolution_tilemode_t));
static_assert ((int)SkMatrixConvolutionImageFilter::TileMode::kClampToBlack_TileMode == (int)CLAMP_TO_BLACK_SK_MATRIX_CONVOLUTION_TILEMODE, ASSERT_MSG(SkMatrixConvolutionImageFilter::TileMode, sk_matrix_convolution_tilemode_t));
-// sk_image_encoder_t
-static_assert ((int)SkImageEncoder::Type::kUnknown_Type == (int)UNKNOWN_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kBMP_Type == (int)BMP_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kGIF_Type == (int)GIF_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kICO_Type == (int)ICO_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kJPEG_Type == (int)JPEG_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kPNG_Type == (int)PNG_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kWBMP_Type == (int)WBMP_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kWEBP_Type == (int)WEBP_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
-static_assert ((int)SkImageEncoder::Type::kKTX_Type == (int)KTX_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_t));
+// sk_image_encoder_type_t
+static_assert ((int)SkImageEncoder::Type::kUnknown_Type == (int)UNKNOWN_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kBMP_Type == (int)BMP_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kGIF_Type == (int)GIF_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kICO_Type == (int)ICO_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kJPEG_Type == (int)JPEG_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kPNG_Type == (int)PNG_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kWBMP_Type == (int)WBMP_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kWEBP_Type == (int)WEBP_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
+static_assert ((int)SkImageEncoder::Type::kKTX_Type == (int)KTX_SK_IMAGE_ENCODER_TYPE, ASSERT_MSG(SkImageEncoder::Type, sk_image_encoder_type_t));
// sk_blendmode_t
static_assert ((int)SkBlendMode::kClear == (int)CLEAR_SK_BLENDMODE, ASSERT_MSG(SkBlendMode, sk_blendmode_t));
static_assert ((int)SkCanvas::VertexMode::kTriangleStrip_VertexMode == (int)TRIANGLE_STRIP_SK_VERTEX_MODE, ASSERT_MSG(SkCanvas::VertexMode, sk_vertex_mode_t));
static_assert ((int)SkCanvas::VertexMode::kTriangleFan_VertexMode == (int)TRIANGLE_FAN_SK_VERTEX_MODE, ASSERT_MSG(SkCanvas::VertexMode, sk_vertex_mode_t));
+// sk_image_caching_hint_t
+static_assert ((int)SkImage::CachingHint::kAllow_CachingHint == (int)ALLOW_SK_IMAGE_CACHING_HINT, ASSERT_MSG(SkImage::CachingHint, sk_image_caching_hint_t));
+static_assert ((int)SkImage::CachingHint::kDisallow_CachingHint == (int)DISALLOW_SK_IMAGE_CACHING_HINT, ASSERT_MSG(SkImage::CachingHint, sk_image_caching_hint_t));
+
#endif
#include "sk_types_priv.h"
-sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_image_encoder_t encoder, int quality) {
- return ToData(AsImage(cimage)->encode((SkImageEncoder::Type)encoder, quality));
+void sk_image_ref(const sk_image_t* cimage) {
+ AsImage(cimage)->ref();
}
-sk_image_t* sk_image_new_from_bitmap (const sk_bitmap_t* cbitmap)
-{
- return ToImage(SkImage::MakeFromBitmap(*AsBitmap(cbitmap)).release());
+void sk_image_unref(const sk_image_t* cimage) {
+ SkSafeUnref(AsImage(cimage));
+}
+
+sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels, size_t rowBytes) {
+ return sk_image_new_raster_copy_with_colortable(cinfo, pixels, rowBytes, nullptr);
}
-sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels,
- size_t rowBytes) {
+sk_image_t* sk_image_new_raster_copy_with_pixmap(const sk_pixmap_t* pixmap) {
+ auto image = SkImage::MakeRasterCopy(AsPixmap(*pixmap));
+ return ToImage(image.release());
+}
+
+sk_image_t* sk_image_new_raster_copy_with_colortable(const sk_imageinfo_t* cinfo, const void* pixels, size_t rowBytes, sk_colortable_t* ctable) {
SkImageInfo info;
from_c(*cinfo, &info);
- return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(info, pixels, rowBytes)).release();
+ auto image = SkImage::MakeRasterCopy(SkPixmap(info, pixels, rowBytes, AsColorTable(ctable)));
+ return ToImage(image.release());
+}
+
+sk_image_t* sk_image_new_raster_data(const sk_imageinfo_t* cinfo, sk_data_t* pixels, size_t rowBytes) {
+ SkImageInfo info;
+ from_c(*cinfo, &info);
+ return ToImage(SkImage::MakeRasterData(info, sk_ref_sp(AsData(pixels)), rowBytes).release());
+}
+
+sk_image_t* sk_image_new_raster(const sk_pixmap_t* pixmap, sk_image_raster_release_proc releaseProc, void* context) {
+ auto image = SkImage::MakeFromRaster(AsPixmap(*pixmap), releaseProc, context);
+ return ToImage(image.release());
+}
+
+sk_image_t* sk_image_new_from_bitmap(const sk_bitmap_t* cbitmap) {
+ return ToImage(SkImage::MakeFromBitmap(*AsBitmap(cbitmap)).release());
}
sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata, const sk_irect_t* subset) {
- return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata)),
- reinterpret_cast<const SkIRect*>(subset)).release());
+ return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata)), AsIRect(subset)).release());
}
-sk_data_t* sk_image_encode(const sk_image_t* cimage) {
- return ToData(AsImage(cimage)->encode());
+sk_image_t* sk_image_new_from_texture(gr_context_t* context, const gr_backend_texture_desc_t* desc, sk_alphatype_t alpha, sk_colorspace_t* colorSpace, sk_image_texture_release_proc releaseProc, void* releaseContext) {
+ return ToImage(SkImage::MakeFromTexture(AsGrContext(context), AsGrBackendTextureDesc(*desc), (SkAlphaType)alpha, sk_ref_sp(AsColorSpace(colorSpace)), releaseProc, releaseContext).release());
}
-void sk_image_ref(const sk_image_t* cimage) {
- AsImage(cimage)->ref();
+sk_image_t* sk_image_new_from_adopted_texture(gr_context_t* context, const gr_backend_texture_desc_t* desc, sk_alphatype_t alpha, sk_colorspace_t* colorSpace) {
+ return ToImage(SkImage::MakeFromAdoptedTexture(AsGrContext(context), AsGrBackendTextureDesc(*desc), (SkAlphaType)alpha, sk_ref_sp(AsColorSpace(colorSpace))).release());
}
-void sk_image_unref(const sk_image_t* cimage) {
- SkSafeUnref(AsImage(cimage));
+sk_image_t* sk_image_new_from_picture(sk_picture_t* picture, const sk_isize_t* dimensions, const sk_matrix_t* cmatrix, const sk_paint_t* paint) {
+ SkMatrix matrix;
+ if (cmatrix) {
+ from_c(cmatrix, &matrix);
+ }
+ return ToImage(SkImage::MakeFromPicture(sk_ref_sp(AsPicture(picture)), AsISize(*dimensions), &matrix, AsPaint(paint)).release());
}
int sk_image_get_width(const sk_image_t* cimage) {
uint32_t sk_image_get_unique_id(const sk_image_t* cimage) {
return AsImage(cimage)->uniqueID();
}
+
+sk_alphatype_t sk_image_get_alpha_type(const sk_image_t* image) {
+ return (sk_alphatype_t) AsImage(image)->alphaType();
+}
+
+bool sk_image_is_alpha_only(const sk_image_t* image) {
+ return AsImage(image)->isAlphaOnly();
+}
+
+sk_shader_t* sk_image_make_shader(const sk_image_t* image, sk_shader_tilemode_t tileX, sk_shader_tilemode_t tileY, const sk_matrix_t* cmatrix) {
+ sk_sp<SkShader> shader;
+ if (cmatrix) {
+ SkMatrix matrix;
+ from_c(cmatrix, &matrix);
+ shader = AsImage(image)->makeShader((SkShader::TileMode)tileX, (SkShader::TileMode)tileY, &matrix);
+ } else {
+ shader = AsImage(image)->makeShader((SkShader::TileMode)tileX, (SkShader::TileMode)tileY, nullptr);
+ }
+ return ToShader(shader.release());
+}
+
+bool sk_image_peek_pixels(const sk_image_t* image, sk_pixmap_t* pixmap) {
+ return AsImage(image)->peekPixels(AsPixmap(pixmap));
+}
+
+bool sk_image_is_texture_backed(const sk_image_t* image) {
+ return AsImage(image)->isTextureBacked();
+}
+
+bool sk_image_read_pixels(const sk_image_t* image, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY, sk_image_caching_hint_t cachingHint) {
+ SkImageInfo info;
+ from_c(*dstInfo, &info);
+ return AsImage(image)->readPixels(info, dstPixels, dstRowBytes, srcX, srcY, (SkImage::CachingHint)cachingHint);
+}
+
+bool sk_image_read_pixels_into_pixmap(const sk_image_t* image, const sk_pixmap_t* dst, int srcX, int srcY, sk_image_caching_hint_t cachingHint) {
+ return AsImage(image)->readPixels(AsPixmap(*dst), srcX, srcY, (SkImage::CachingHint)cachingHint);
+}
+
+bool sk_image_scale_pixels(const sk_image_t* image, const sk_pixmap_t* dst, sk_filter_quality_t quality, sk_image_caching_hint_t cachingHint) {
+ return AsImage(image)->scalePixels(AsPixmap(*dst), (SkFilterQuality)quality, (SkImage::CachingHint)cachingHint);
+}
+
+sk_data_t* sk_image_encode(const sk_image_t* cimage) {
+ return ToData(AsImage(cimage)->encode());
+}
+
+sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_image_encoder_type_t encoder, int quality) {
+ return ToData(AsImage(cimage)->encode((SkImageEncoder::Type)encoder, quality));
+}
+
+sk_image_t* sk_image_make_subset(const sk_image_t* cimage, const sk_irect_t* subset) {
+ return ToImage(AsImage(cimage)->makeSubset(AsIRect(*subset)).release());
+}
+
+sk_image_t* sk_image_make_texture_image(const sk_image_t* cimage, gr_context_t* context) {
+ return ToImage(AsImage(cimage)->makeTextureImage(AsGrContext(context)).release());
+}
+
+sk_image_t* sk_image_make_non_texture_image(const sk_image_t* cimage) {
+ return ToImage(AsImage(cimage)->makeNonTextureImage().release());
+}
+
+sk_image_t* sk_image_make_with_filter(const sk_image_t* cimage, const sk_imagefilter_t* filter, const sk_irect_t* subset, const sk_irect_t* clipBounds, sk_irect_t* outSubset, sk_ipoint_t* outOffset) {
+ return ToImage(AsImage(cimage)->makeWithFilter(AsImageFilter(filter), AsIRect(*subset), AsIRect(*clipBounds), AsIRect(outSubset), AsIPoint(outOffset)).release());
+}
return reinterpret_cast<SkImageFilter*>(cfilter);
}
+static inline const SkImageFilter* AsImageFilter(const sk_imagefilter_t* cfilter) {
+ return reinterpret_cast<const SkImageFilter*>(cfilter);
+}
+
static inline SkImageFilter** AsImageFilters(sk_imagefilter_t** cfilter) {
return reinterpret_cast<SkImageFilter**>(cfilter);
}
return reinterpret_cast<sk_colorspace_t*>(colorspace);
}
+static inline SkColorSpace* AsColorSpace(sk_colorspace_t* colorspace) {
+ return reinterpret_cast<SkColorSpace*>(colorspace);
+}
+
static inline sk_shader_t* ToShader(SkShader* shader) {
return reinterpret_cast<sk_shader_t*>(shader);
}