gfx/skia/trunk/src/core/SkDither.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkDither.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +#include "SkDither.h"
    1.12 +
    1.13 +/*  The base dither matrix we use to derive optimized ones for 565 and 4444
    1.14 +
    1.15 +    { 0,  32, 8,  40, 2,  34, 10, 42 },
    1.16 +    { 48, 16, 56, 24, 50, 18, 58, 26 },
    1.17 +    { 12, 44, 4,  36, 14, 46, 6,  38 },
    1.18 +    { 60, 28, 52, 20, 62, 30, 54, 22 },
    1.19 +    { 3,  35, 11, 43, 1,  33, 9,  41 },
    1.20 +    { 51, 19, 59, 27, 49, 17, 57, 25 },
    1.21 +    { 15, 47, 7,  39, 13, 45, 5,  37 },
    1.22 +    { 63, 31, 55, 23, 61, 29, 53, 21 }
    1.23 +
    1.24 +    The 4444 version only needs 4 bits, and given that we can reduce its size
    1.25 +    since the other 4x4 sub pieces all look the same once we truncate the bits.
    1.26 +
    1.27 +    The 565 version only needs 3 bits for red/blue, and only 2 bits for green.
    1.28 +    For simplicity, we store 3 bits, and have the dither macros for green know
    1.29 +    this, and they shift the dither value down by 1 to make it 2 bits.
    1.30 + */
    1.31 +
    1.32 +#ifdef ENABLE_DITHER_MATRIX_4X4
    1.33 +
    1.34 +const uint8_t gDitherMatrix_4Bit_4X4[4][4] = {
    1.35 +    {  0,  8,  2, 10 },
    1.36 +    { 12,  4, 14,  6 },
    1.37 +    {  3, 11,  1,  9 },
    1.38 +    { 15,  7, 13,  5 }
    1.39 +};
    1.40 +
    1.41 +const uint8_t gDitherMatrix_3Bit_4X4[4][4] = {
    1.42 +    {  0,  4,  1,  5 },
    1.43 +    {  6,  2,  7,  3 },
    1.44 +    {  1,  5,  0,  4 },
    1.45 +    {  7,  3,  6,  2 }
    1.46 +};
    1.47 +
    1.48 +#else   // used packed shorts for a scanlines worth of dither values
    1.49 +
    1.50 +const uint16_t gDitherMatrix_4Bit_16[4] = {
    1.51 +    0xA280, 0x6E4C, 0x91B3, 0x5D7F
    1.52 +};
    1.53 +
    1.54 +const uint16_t gDitherMatrix_3Bit_16[4] = {
    1.55 +    0x5140, 0x3726, 0x4051, 0x2637
    1.56 +};
    1.57 +
    1.58 +#endif

mercurial