|
1 /* |
|
2 * Copyright 2011 Google 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 #ifndef SkConfig8888_DEFINED |
|
9 #define SkConfig8888_DEFINED |
|
10 |
|
11 #include "SkCanvas.h" |
|
12 #include "SkColorPriv.h" |
|
13 |
|
14 /** |
|
15 * Converts pixels from one Config8888 to another Config8888 |
|
16 */ |
|
17 void SkConvertConfig8888Pixels(uint32_t* dstPixels, |
|
18 size_t dstRowBytes, |
|
19 SkCanvas::Config8888 dstConfig, |
|
20 const uint32_t* srcPixels, |
|
21 size_t srcRowBytes, |
|
22 SkCanvas::Config8888 srcConfig, |
|
23 int width, |
|
24 int height); |
|
25 |
|
26 /** |
|
27 * Packs a, r, g, b, values into byte order specified by config. |
|
28 */ |
|
29 uint32_t SkPackConfig8888(SkCanvas::Config8888 config, |
|
30 uint32_t a, |
|
31 uint32_t r, |
|
32 uint32_t g, |
|
33 uint32_t b); |
|
34 |
|
35 /////////////////////////////////////////////////////////////////////////////// |
|
36 // Implementation |
|
37 |
|
38 namespace { |
|
39 |
|
40 /** |
|
41 Copies all pixels from a bitmap to a dst ptr with a given rowBytes and |
|
42 Config8888. The bitmap must have kARGB_8888_Config. |
|
43 */ |
|
44 |
|
45 static inline void SkCopyBitmapToConfig8888(uint32_t* dstPixels, |
|
46 size_t dstRowBytes, |
|
47 SkCanvas::Config8888 dstConfig8888, |
|
48 const SkBitmap& srcBmp) { |
|
49 SkASSERT(SkBitmap::kARGB_8888_Config == srcBmp.config()); |
|
50 SkAutoLockPixels alp(srcBmp); |
|
51 int w = srcBmp.width(); |
|
52 int h = srcBmp.height(); |
|
53 size_t srcRowBytes = srcBmp.rowBytes(); |
|
54 const uint32_t* srcPixels = reinterpret_cast<uint32_t*>(srcBmp.getPixels()); |
|
55 |
|
56 SkConvertConfig8888Pixels(dstPixels, dstRowBytes, dstConfig8888, srcPixels, srcRowBytes, SkCanvas::kNative_Premul_Config8888, w, h); |
|
57 } |
|
58 |
|
59 /** |
|
60 Copies over all pixels in a bitmap from a src ptr with a given rowBytes and |
|
61 Config8888. The bitmap must have pixels and be kARGB_8888_Config. |
|
62 */ |
|
63 static inline void SkCopyConfig8888ToBitmap(const SkBitmap& dstBmp, |
|
64 const uint32_t* srcPixels, |
|
65 size_t srcRowBytes, |
|
66 SkCanvas::Config8888 srcConfig8888) { |
|
67 SkASSERT(SkBitmap::kARGB_8888_Config == dstBmp.config()); |
|
68 SkAutoLockPixels alp(dstBmp); |
|
69 int w = dstBmp.width(); |
|
70 int h = dstBmp.height(); |
|
71 size_t dstRowBytes = dstBmp.rowBytes(); |
|
72 uint32_t* dstPixels = reinterpret_cast<uint32_t*>(dstBmp.getPixels()); |
|
73 |
|
74 SkConvertConfig8888Pixels(dstPixels, dstRowBytes, SkCanvas::kNative_Premul_Config8888, srcPixels, srcRowBytes, srcConfig8888, w, h); |
|
75 } |
|
76 |
|
77 } |
|
78 |
|
79 #endif |