Home | History | Annotate | Download | only in core
      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 ///////////////////////////////////////////////////////////////////////////////
     35 // Implementation
     36 
     37 namespace {
     38 
     39 /**
     40   Copies all pixels from a bitmap to a dst ptr with a given rowBytes and
     41   Config8888. The bitmap must have kARGB_8888_Config.
     42  */
     43 
     44 static inline void SkCopyBitmapToConfig8888(uint32_t* dstPixels,
     45                                      size_t dstRowBytes,
     46                                      SkCanvas::Config8888 dstConfig8888,
     47                                      const SkBitmap& srcBmp) {
     48     SkASSERT(SkBitmap::kARGB_8888_Config == srcBmp.config());
     49     SkAutoLockPixels alp(srcBmp);
     50     int w = srcBmp.width();
     51     int h = srcBmp.height();
     52     size_t srcRowBytes = srcBmp.rowBytes();
     53     const uint32_t* srcPixels = reinterpret_cast<uint32_t*>(srcBmp.getPixels());
     54 
     55     SkConvertConfig8888Pixels(dstPixels, dstRowBytes, dstConfig8888, srcPixels, srcRowBytes, SkCanvas::kNative_Premul_Config8888, w, h);
     56 }
     57 
     58 /**
     59   Copies over all pixels in a bitmap from a src ptr with a given rowBytes and
     60   Config8888. The bitmap must have pixels and be kARGB_8888_Config.
     61  */
     62 static inline void SkCopyConfig8888ToBitmap(const SkBitmap& dstBmp,
     63                                      const uint32_t* srcPixels,
     64                                      size_t srcRowBytes,
     65                                      SkCanvas::Config8888 srcConfig8888) {
     66     SkASSERT(SkBitmap::kARGB_8888_Config == dstBmp.config());
     67     SkAutoLockPixels alp(dstBmp);
     68     int w = dstBmp.width();
     69     int h = dstBmp.height();
     70     size_t dstRowBytes = dstBmp.rowBytes();
     71     uint32_t* dstPixels = reinterpret_cast<uint32_t*>(dstBmp.getPixels());
     72 
     73     SkConvertConfig8888Pixels(dstPixels, dstRowBytes, SkCanvas::kNative_Premul_Config8888, srcPixels, srcRowBytes, srcConfig8888, w, h);
     74 }
     75 
     76 }
     77