OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkEndian.h" | 10 #include "SkEndian.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 248 |
249 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); | 249 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); |
250 | 250 |
251 // Make sure that it all matches a given block encoding. Since we have | 251 // Make sure that it all matches a given block encoding. Since we have |
252 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us
ing | 252 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us
ing |
253 // an approximation scheme that optimizes for speed against coverage map
s. | 253 // an approximation scheme that optimizes for speed against coverage map
s. |
254 // That means that each palette in the encoded block is exactly the same
, | 254 // That means that each palette in the encoded block is exactly the same
, |
255 // and that the three bits saved per pixel are computed from the top thr
ee | 255 // and that the three bits saved per pixel are computed from the top thr
ee |
256 // bits of the luminance value. | 256 // bits of the luminance value. |
257 const uint64_t kIndexEncodingMap[8] = { 1, 7, 6, 5, 4, 3, 2, 0 }; | 257 const uint64_t kIndexEncodingMap[8] = { 1, 7, 6, 5, 4, 3, 2, 0 }; |
258 const uint64_t kIndex = kIndexEncodingMap[lum >> 5]; | 258 |
| 259 // Quantize to three bits in the same way that we do our LATC compressio
n: |
| 260 // 1. Divide by two |
| 261 // 2. Add 9 |
| 262 // 3. Divide by two |
| 263 // 4. Approximate division by three twice |
| 264 uint32_t quant = static_cast<uint32_t>(lum); |
| 265 quant >>= 1; // 1 |
| 266 quant += 9; // 2 |
| 267 quant >>= 1; // 3 |
| 268 |
| 269 uint32_t a, b, c, ar, br, cr; |
| 270 |
| 271 // First division by three |
| 272 a = quant >> 2; |
| 273 ar = (quant & 0x3) << 4; |
| 274 b = quant >> 4; |
| 275 br = (quant & 0xF) << 2; |
| 276 c = quant >> 6; |
| 277 cr = (quant & 0x3F); |
| 278 quant = (a + b + c) + ((ar + br + cr) >> 6); |
| 279 |
| 280 // Second division by three |
| 281 a = quant >> 2; |
| 282 ar = (quant & 0x3) << 4; |
| 283 b = quant >> 4; |
| 284 br = (quant & 0xF) << 2; |
| 285 c = quant >> 6; |
| 286 cr = (quant & 0x3F); |
| 287 quant = (a + b + c) + ((ar + br + cr) >> 6); |
| 288 |
| 289 const uint64_t kIndex = kIndexEncodingMap[quant]; |
| 290 |
259 const uint64_t kConstColorEncoding = | 291 const uint64_t kConstColorEncoding = |
260 SkEndian_SwapLE64( | 292 SkEndian_SwapLE64( |
261 255 | | 293 255 | |
262 (kIndex << 16) | (kIndex << 19) | (kIndex << 22) | (kIndex << 25
) | | 294 (kIndex << 16) | (kIndex << 19) | (kIndex << 22) | (kIndex << 25
) | |
263 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 295 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
264 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 296 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
265 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 297 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
266 | 298 |
267 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 299 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
268 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 300 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
269 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 301 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
270 } | 302 } |
271 } | 303 } |
272 } | 304 } |
OLD | NEW |