Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include "SkDither.h" |
michael@0 | 9 | |
michael@0 | 10 | /* The base dither matrix we use to derive optimized ones for 565 and 4444 |
michael@0 | 11 | |
michael@0 | 12 | { 0, 32, 8, 40, 2, 34, 10, 42 }, |
michael@0 | 13 | { 48, 16, 56, 24, 50, 18, 58, 26 }, |
michael@0 | 14 | { 12, 44, 4, 36, 14, 46, 6, 38 }, |
michael@0 | 15 | { 60, 28, 52, 20, 62, 30, 54, 22 }, |
michael@0 | 16 | { 3, 35, 11, 43, 1, 33, 9, 41 }, |
michael@0 | 17 | { 51, 19, 59, 27, 49, 17, 57, 25 }, |
michael@0 | 18 | { 15, 47, 7, 39, 13, 45, 5, 37 }, |
michael@0 | 19 | { 63, 31, 55, 23, 61, 29, 53, 21 } |
michael@0 | 20 | |
michael@0 | 21 | The 4444 version only needs 4 bits, and given that we can reduce its size |
michael@0 | 22 | since the other 4x4 sub pieces all look the same once we truncate the bits. |
michael@0 | 23 | |
michael@0 | 24 | The 565 version only needs 3 bits for red/blue, and only 2 bits for green. |
michael@0 | 25 | For simplicity, we store 3 bits, and have the dither macros for green know |
michael@0 | 26 | this, and they shift the dither value down by 1 to make it 2 bits. |
michael@0 | 27 | */ |
michael@0 | 28 | |
michael@0 | 29 | #ifdef ENABLE_DITHER_MATRIX_4X4 |
michael@0 | 30 | |
michael@0 | 31 | const uint8_t gDitherMatrix_4Bit_4X4[4][4] = { |
michael@0 | 32 | { 0, 8, 2, 10 }, |
michael@0 | 33 | { 12, 4, 14, 6 }, |
michael@0 | 34 | { 3, 11, 1, 9 }, |
michael@0 | 35 | { 15, 7, 13, 5 } |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | const uint8_t gDitherMatrix_3Bit_4X4[4][4] = { |
michael@0 | 39 | { 0, 4, 1, 5 }, |
michael@0 | 40 | { 6, 2, 7, 3 }, |
michael@0 | 41 | { 1, 5, 0, 4 }, |
michael@0 | 42 | { 7, 3, 6, 2 } |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | #else // used packed shorts for a scanlines worth of dither values |
michael@0 | 46 | |
michael@0 | 47 | const uint16_t gDitherMatrix_4Bit_16[4] = { |
michael@0 | 48 | 0xA280, 0x6E4C, 0x91B3, 0x5D7F |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | const uint16_t gDitherMatrix_3Bit_16[4] = { |
michael@0 | 52 | 0x5140, 0x3726, 0x4051, 0x2637 |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | #endif |