Merge from google/chrome/m55
[platform/upstream/libSkiaSharp.git] / src / c / sk_image.cpp
1 /*
2  * Copyright 2016 Xamarin Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "SkImageEncoder.h"
9
10 #include "sk_image.h"
11
12 #include "sk_types_priv.h"
13
14 sk_data_t* sk_image_encode_specific(const sk_image_t* cimage, sk_image_encoder_t encoder, int quality) {
15     return ToData(AsImage(cimage)->encode((SkImageEncoder::Type)encoder, quality));
16 }
17
18 sk_image_t* sk_image_new_from_bitmap (const sk_bitmap_t* cbitmap)
19 {
20     return ToImage(SkImage::MakeFromBitmap(*AsBitmap(cbitmap)).release());
21 }
22
23 sk_image_t* sk_image_new_raster_copy(const sk_imageinfo_t* cinfo, const void* pixels,
24                                      size_t rowBytes) {
25     SkImageInfo info;
26     from_c(*cinfo, &info);
27     return (sk_image_t*)SkImage::MakeRasterCopy(SkPixmap(info, pixels, rowBytes)).release();
28 }
29
30 sk_image_t* sk_image_new_from_encoded(const sk_data_t* cdata, const sk_irect_t* subset) {
31     return ToImage(SkImage::MakeFromEncoded(sk_ref_sp(AsData(cdata)),
32                                            reinterpret_cast<const SkIRect*>(subset)).release());
33 }
34
35 sk_data_t* sk_image_encode(const sk_image_t* cimage) {
36     return ToData(AsImage(cimage)->encode());
37 }
38
39 void sk_image_ref(const sk_image_t* cimage) {
40     AsImage(cimage)->ref();
41 }
42
43 void sk_image_unref(const sk_image_t* cimage) {
44     AsImage(cimage)->unref();
45 }
46
47 int sk_image_get_width(const sk_image_t* cimage) {
48     return AsImage(cimage)->width();
49 }
50
51 int sk_image_get_height(const sk_image_t* cimage) {
52     return AsImage(cimage)->height();
53 }
54
55 uint32_t sk_image_get_unique_id(const sk_image_t* cimage) {
56     return AsImage(cimage)->uniqueID();
57 }