1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10 #include "SkCanvas.h"
11 #include "SkColorPriv.h"
12
13 /**
14 * Converts pixels from one Config8888 to another Config8888
15 */
16 void SkConvertConfig8888Pixels(uint32_t* dstPixels,
17 size_t dstRowBytes,
18 SkCanvas::Config8888 dstConfig,
19 const uint32_t* srcPixels,
20 size_t srcRowBytes,
21 SkCanvas::Config8888 srcConfig,
22 int width,
23 int height);
24
25 /**
26 * Packs a, r, g, b, values into byte order specified by config.
27 */
28 uint32_t SkPackConfig8888(SkCanvas::Config8888 config,
29 uint32_t a,
30 uint32_t r,
31 uint32_t g,
32 uint32_t b);
33
34 namespace {
35
36 /**
37 Copies all pixels from a bitmap to a dst ptr with a given rowBytes and
38 Config8888. The bitmap must have kARGB_8888_Config.
39 */
40 inline void SkCopyBitmapToConfig8888(uint32_t* dstPixels,
41 size_t dstRowBytes,
42 SkCanvas::Config8888 dstConfig8888,
43 const SkBitmap& srcBmp);
44
45 /**
46 Copies over all pixels in a bitmap from a src ptr with a given rowBytes and
47 Config8888. The bitmap must have pixels and be kARGB_8888_Config.
48 */
49 inline void SkCopyConfig8888ToBitmap(const SkBitmap& dstBmp,
50 const uint32_t* srcPixels,
51 size_t srcRowBytes,
52 SkCanvas::Config8888 srcConfig8888);
53
54 }
55
56 ///////////////////////////////////////////////////////////////////////////////
57 // Implementation
58
59 namespace {
60
SkCopyBitmapToConfig8888(uint32_t * dstPixels,size_t dstRowBytes,SkCanvas::Config8888 dstConfig8888,const SkBitmap & srcBmp)61 inline void SkCopyBitmapToConfig8888(uint32_t* dstPixels,
62 size_t dstRowBytes,
63 SkCanvas::Config8888 dstConfig8888,
64 const SkBitmap& srcBmp) {
65 SkASSERT(SkBitmap::kARGB_8888_Config == srcBmp.config());
66 SkAutoLockPixels alp(srcBmp);
67 int w = srcBmp.width();
68 int h = srcBmp.height();
69 size_t srcRowBytes = srcBmp.rowBytes();
70 const uint32_t* srcPixels = reinterpret_cast<uint32_t*>(srcBmp.getPixels());
71
72 SkConvertConfig8888Pixels(dstPixels, dstRowBytes, dstConfig8888, srcPixels, srcRowBytes, SkCanvas::kNative_Premul_Config8888, w, h);
73 }
74
SkCopyConfig8888ToBitmap(const SkBitmap & dstBmp,const uint32_t * srcPixels,size_t srcRowBytes,SkCanvas::Config8888 srcConfig8888)75 inline void SkCopyConfig8888ToBitmap(const SkBitmap& dstBmp,
76 const uint32_t* srcPixels,
77 size_t srcRowBytes,
78 SkCanvas::Config8888 srcConfig8888) {
79 SkASSERT(SkBitmap::kARGB_8888_Config == dstBmp.config());
80 SkAutoLockPixels alp(dstBmp);
81 int w = dstBmp.width();
82 int h = dstBmp.height();
83 size_t dstRowBytes = dstBmp.rowBytes();
84 uint32_t* dstPixels = reinterpret_cast<uint32_t*>(dstBmp.getPixels());
85
86 SkConvertConfig8888Pixels(dstPixels, dstRowBytes, SkCanvas::kNative_Premul_Config8888, srcPixels, srcRowBytes, srcConfig8888, w, h);
87 }
88
89 }
90