OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPixelInfo_DEFINED | 8 #ifndef SkConfig8888_DEFINED |
9 #define SkPixelInfo_DEFINED | 9 #define SkConfig8888_DEFINED |
10 | 10 |
11 #include "SkImageInfo.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkColorPriv.h" |
12 | 13 |
13 struct SkPixelInfo { | 14 /** |
14 SkColorType fColorType; | 15 * Converts pixels from one Config8888 to another Config8888 |
15 SkAlphaType fAlphaType; | 16 */ |
16 size_t fRowBytes; | 17 void SkConvertConfig8888Pixels(uint32_t* dstPixels, |
17 }; | 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); |
18 | 25 |
19 struct SkDstPixelInfo : SkPixelInfo { | 26 /** |
20 void* fPixels; | 27 * Packs a, r, g, b, values into byte order specified by config. |
21 }; | 28 */ |
| 29 uint32_t SkPackConfig8888(SkCanvas::Config8888 config, |
| 30 uint32_t a, |
| 31 uint32_t r, |
| 32 uint32_t g, |
| 33 uint32_t b); |
22 | 34 |
23 struct SkSrcPixelInfo : SkPixelInfo { | 35 /////////////////////////////////////////////////////////////////////////////// |
24 const void* fPixels; | 36 // Implementation |
25 | 37 |
26 // Guaranteed to work even if src.fPixels and dst.fPixels are the same | 38 namespace { |
27 // (but not if they overlap partially) | 39 |
28 bool convertPixelsTo(SkDstPixelInfo* dst, int width, int height) const; | 40 /** |
29 }; | 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_C
onfig8888, srcPixels, srcRowBytes, srcConfig8888, w, h); |
| 75 } |
| 76 |
| 77 } |
30 | 78 |
31 #endif | 79 #endif |
OLD | NEW |