2 * Copyright 2016 Xamarin Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBitmapScaler.h"
10 #include "SkImageEncoder.h"
11 #include "SkSwizzle.h"
13 #include "sk_pixmap.h"
15 #include "sk_types_priv.h"
18 void sk_pixmap_destructor(sk_pixmap_t* cpixmap)
20 delete AsPixmap(cpixmap);
23 sk_pixmap_t* sk_pixmap_new()
25 return ToPixmap(new SkPixmap());
28 sk_pixmap_t* sk_pixmap_new_with_params(const sk_imageinfo_t* cinfo, const void* addr, size_t rowBytes, sk_colortable_t* ctable)
31 from_c(*cinfo, &info);
33 return ToPixmap(new SkPixmap(info, addr, rowBytes, AsColorTable(ctable)));
36 void sk_pixmap_reset(sk_pixmap_t* cpixmap)
38 AsPixmap(cpixmap)->reset();
41 void sk_pixmap_reset_with_params(sk_pixmap_t* cpixmap, const sk_imageinfo_t* cinfo, const void* addr, size_t rowBytes, sk_colortable_t* ctable)
44 from_c(*cinfo, &info);
46 AsPixmap(cpixmap)->reset(info, addr, rowBytes, AsColorTable(ctable));
49 void sk_pixmap_get_info(sk_pixmap_t* cpixmap, sk_imageinfo_t* cinfo)
51 from_sk(AsPixmap(cpixmap)->info(), cinfo);
54 size_t sk_pixmap_get_row_bytes(sk_pixmap_t* cpixmap)
56 return AsPixmap(cpixmap)->rowBytes();
59 const void* sk_pixmap_get_pixels(sk_pixmap_t* cpixmap)
61 return AsPixmap(cpixmap)->addr();
64 sk_colortable_t* sk_pixmap_get_colortable(sk_pixmap_t* cpixmap)
66 return ToColorTable(AsPixmap(cpixmap)->ctable());
69 bool sk_bitmapscaler_resize(const sk_pixmap_t* cdst, const sk_pixmap_t* csrc, sk_bitmapscaler_resizemethod_t method)
71 const SkPixmap& dst = AsPixmap(*cdst);
72 const SkPixmap& src = AsPixmap(*csrc);
73 return SkBitmapScaler::Resize(dst, src, (SkBitmapScaler::ResizeMethod)method);
76 sk_color_t sk_color_unpremultiply(const sk_pmcolor_t pmcolor)
78 return SkUnPreMultiply::PMColorToColor(pmcolor);
81 sk_pmcolor_t sk_color_premultiply(const sk_color_t color)
83 return SkPreMultiplyColor(color);
86 void sk_color_unpremultiply_array(const sk_pmcolor_t* pmcolors, int size, sk_color_t* colors)
88 for (int i = 0; i < size; ++i) {
89 colors[i] = SkUnPreMultiply::PMColorToColor(pmcolors[i]);
93 void sk_color_premultiply_array(const sk_color_t* colors, int size, sk_pmcolor_t* pmcolors)
95 for (int i = 0; i < size; ++i) {
96 pmcolors[i] = SkPreMultiplyColor(colors[i]);
100 void sk_color_get_bit_shift(int* a, int* r, int* g, int* b)
102 *a = (int)SK_A32_SHIFT;
103 *r = (int)SK_R32_SHIFT;
104 *g = (int)SK_G32_SHIFT;
105 *b = (int)SK_B32_SHIFT;
108 bool sk_pixmap_encode_image(sk_wstream_t* dst, const sk_pixmap_t* src, sk_encoded_image_format_t encoder, int quality)
110 return SkEncodeImage(AsWStream(dst), AsPixmap(*src), (SkEncodedImageFormat)encoder, quality);
113 bool sk_pixmap_read_pixels(const sk_pixmap_t* cpixmap, const sk_imageinfo_t* dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY)
116 from_c(*dstInfo, &info);
118 return AsPixmap(cpixmap)->readPixels(info, dstPixels, dstRowBytes, srcX, srcY);
121 void sk_swizzle_swap_rb(uint32_t* dest, const uint32_t* src, int count)
123 SkSwapRB(dest, src, count);