1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkConfig8888.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* 1.5 + * Copyright 2011 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkConfig8888_DEFINED 1.12 +#define SkConfig8888_DEFINED 1.13 + 1.14 +#include "SkCanvas.h" 1.15 +#include "SkColorPriv.h" 1.16 + 1.17 +/** 1.18 + * Converts pixels from one Config8888 to another Config8888 1.19 + */ 1.20 +void SkConvertConfig8888Pixels(uint32_t* dstPixels, 1.21 + size_t dstRowBytes, 1.22 + SkCanvas::Config8888 dstConfig, 1.23 + const uint32_t* srcPixels, 1.24 + size_t srcRowBytes, 1.25 + SkCanvas::Config8888 srcConfig, 1.26 + int width, 1.27 + int height); 1.28 + 1.29 +/** 1.30 + * Packs a, r, g, b, values into byte order specified by config. 1.31 + */ 1.32 +uint32_t SkPackConfig8888(SkCanvas::Config8888 config, 1.33 + uint32_t a, 1.34 + uint32_t r, 1.35 + uint32_t g, 1.36 + uint32_t b); 1.37 + 1.38 +/////////////////////////////////////////////////////////////////////////////// 1.39 +// Implementation 1.40 + 1.41 +namespace { 1.42 + 1.43 +/** 1.44 + Copies all pixels from a bitmap to a dst ptr with a given rowBytes and 1.45 + Config8888. The bitmap must have kARGB_8888_Config. 1.46 + */ 1.47 + 1.48 +static inline void SkCopyBitmapToConfig8888(uint32_t* dstPixels, 1.49 + size_t dstRowBytes, 1.50 + SkCanvas::Config8888 dstConfig8888, 1.51 + const SkBitmap& srcBmp) { 1.52 + SkASSERT(SkBitmap::kARGB_8888_Config == srcBmp.config()); 1.53 + SkAutoLockPixels alp(srcBmp); 1.54 + int w = srcBmp.width(); 1.55 + int h = srcBmp.height(); 1.56 + size_t srcRowBytes = srcBmp.rowBytes(); 1.57 + const uint32_t* srcPixels = reinterpret_cast<uint32_t*>(srcBmp.getPixels()); 1.58 + 1.59 + SkConvertConfig8888Pixels(dstPixels, dstRowBytes, dstConfig8888, srcPixels, srcRowBytes, SkCanvas::kNative_Premul_Config8888, w, h); 1.60 +} 1.61 + 1.62 +/** 1.63 + Copies over all pixels in a bitmap from a src ptr with a given rowBytes and 1.64 + Config8888. The bitmap must have pixels and be kARGB_8888_Config. 1.65 + */ 1.66 +static inline void SkCopyConfig8888ToBitmap(const SkBitmap& dstBmp, 1.67 + const uint32_t* srcPixels, 1.68 + size_t srcRowBytes, 1.69 + SkCanvas::Config8888 srcConfig8888) { 1.70 + SkASSERT(SkBitmap::kARGB_8888_Config == dstBmp.config()); 1.71 + SkAutoLockPixels alp(dstBmp); 1.72 + int w = dstBmp.width(); 1.73 + int h = dstBmp.height(); 1.74 + size_t dstRowBytes = dstBmp.rowBytes(); 1.75 + uint32_t* dstPixels = reinterpret_cast<uint32_t*>(dstBmp.getPixels()); 1.76 + 1.77 + SkConvertConfig8888Pixels(dstPixels, dstRowBytes, SkCanvas::kNative_Premul_Config8888, srcPixels, srcRowBytes, srcConfig8888, w, h); 1.78 +} 1.79 + 1.80 +} 1.81 + 1.82 +#endif