Merge from google/chrome/m55
[platform/upstream/libSkiaSharp.git] / src / c / sk_codec.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 "SkCodec.h"
9
10 #include "sk_codec.h"
11
12 #include "sk_types_priv.h"
13
14 size_t sk_codec_min_buffered_bytes_needed()
15 {
16     return SkCodec::MinBufferedBytesNeeded();
17 }
18
19 sk_codec_t* sk_codec_new_from_stream(sk_stream_t* stream)
20 {
21     return ToCodec(SkCodec::NewFromStream(AsStream(stream)));
22 }
23
24 sk_codec_t* sk_codec_new_from_data(sk_data_t* data)
25 {
26     return ToCodec(SkCodec::NewFromData(AsData(data)));
27 }
28
29 void sk_codec_destroy(sk_codec_t* codec)
30 {
31     delete AsCodec(codec);
32 }
33
34 void sk_codec_get_info(sk_codec_t* codec, sk_imageinfo_t* info)
35 {
36     from_sk(AsCodec(codec)->getInfo(), info);
37 }
38
39 sk_codec_origin_t sk_codec_get_origin(sk_codec_t* codec)
40 {
41     return (sk_codec_origin_t)AsCodec(codec)->getOrigin();
42 }
43
44 void sk_codec_get_scaled_dimensions(sk_codec_t* codec, float desiredScale, sk_isize_t* dimensions)
45 {
46     *dimensions = ToISize(AsCodec(codec)->getScaledDimensions(desiredScale));
47 }
48
49 void sk_codec_get_valid_subset(sk_codec_t* codec, sk_irect_t* desiredSubset)
50 {
51     AsCodec(codec)->getValidSubset(AsIRect(desiredSubset));
52 }
53
54 sk_encoded_format_t sk_codec_get_encoded_format(sk_codec_t* codec)
55 {
56     return (sk_encoded_format_t)AsCodec(codec)->getEncodedFormat();
57 }
58
59 sk_codec_result_t sk_codec_get_pixels(sk_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes, const sk_codec_options_t* coptions, sk_color_t ctable[], int* ctableCount)
60 {
61     SkImageInfo info;
62     from_c(*cinfo, &info);
63     SkCodec::Options options;
64     if (!from_c(*coptions, &options)) {
65         return INVALID_PARAMETERS_SK_CODEC_RESULT;
66     }
67     return (sk_codec_result_t)AsCodec(codec)->getPixels(info, pixels, rowBytes, &options, ctable, ctableCount);
68 }
69
70 sk_codec_result_t sk_codec_get_pixels_using_defaults(sk_codec_t* codec, const sk_imageinfo_t* cinfo, void* pixels, size_t rowBytes)
71 {
72     SkImageInfo info;
73     from_c(*cinfo, &info);
74     return (sk_codec_result_t)AsCodec(codec)->getPixels(info, pixels, rowBytes);
75 }