michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkConfig8888_DEFINED michael@0: #define SkConfig8888_DEFINED michael@0: michael@0: #include "SkCanvas.h" michael@0: #include "SkColorPriv.h" michael@0: michael@0: /** michael@0: * Converts pixels from one Config8888 to another Config8888 michael@0: */ michael@0: void SkConvertConfig8888Pixels(uint32_t* dstPixels, michael@0: size_t dstRowBytes, michael@0: SkCanvas::Config8888 dstConfig, michael@0: const uint32_t* srcPixels, michael@0: size_t srcRowBytes, michael@0: SkCanvas::Config8888 srcConfig, michael@0: int width, michael@0: int height); michael@0: michael@0: /** michael@0: * Packs a, r, g, b, values into byte order specified by config. michael@0: */ michael@0: uint32_t SkPackConfig8888(SkCanvas::Config8888 config, michael@0: uint32_t a, michael@0: uint32_t r, michael@0: uint32_t g, michael@0: uint32_t b); michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: // Implementation michael@0: michael@0: namespace { michael@0: michael@0: /** michael@0: Copies all pixels from a bitmap to a dst ptr with a given rowBytes and michael@0: Config8888. The bitmap must have kARGB_8888_Config. michael@0: */ michael@0: michael@0: static inline void SkCopyBitmapToConfig8888(uint32_t* dstPixels, michael@0: size_t dstRowBytes, michael@0: SkCanvas::Config8888 dstConfig8888, michael@0: const SkBitmap& srcBmp) { michael@0: SkASSERT(SkBitmap::kARGB_8888_Config == srcBmp.config()); michael@0: SkAutoLockPixels alp(srcBmp); michael@0: int w = srcBmp.width(); michael@0: int h = srcBmp.height(); michael@0: size_t srcRowBytes = srcBmp.rowBytes(); michael@0: const uint32_t* srcPixels = reinterpret_cast(srcBmp.getPixels()); michael@0: michael@0: SkConvertConfig8888Pixels(dstPixels, dstRowBytes, dstConfig8888, srcPixels, srcRowBytes, SkCanvas::kNative_Premul_Config8888, w, h); michael@0: } michael@0: michael@0: /** michael@0: Copies over all pixels in a bitmap from a src ptr with a given rowBytes and michael@0: Config8888. The bitmap must have pixels and be kARGB_8888_Config. michael@0: */ michael@0: static inline void SkCopyConfig8888ToBitmap(const SkBitmap& dstBmp, michael@0: const uint32_t* srcPixels, michael@0: size_t srcRowBytes, michael@0: SkCanvas::Config8888 srcConfig8888) { michael@0: SkASSERT(SkBitmap::kARGB_8888_Config == dstBmp.config()); michael@0: SkAutoLockPixels alp(dstBmp); michael@0: int w = dstBmp.width(); michael@0: int h = dstBmp.height(); michael@0: size_t dstRowBytes = dstBmp.rowBytes(); michael@0: uint32_t* dstPixels = reinterpret_cast(dstBmp.getPixels()); michael@0: michael@0: SkConvertConfig8888Pixels(dstPixels, dstRowBytes, SkCanvas::kNative_Premul_Config8888, srcPixels, srcRowBytes, srcConfig8888, w, h); michael@0: } michael@0: michael@0: } michael@0: michael@0: #endif