| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 REPORTER_ASSERT(reporter, setInfoSuccess); | 127 REPORTER_ASSERT(reporter, setInfoSuccess); |
| 128 | 128 |
| 129 bitmap.allocPixels(info); | 129 bitmap.allocPixels(info); |
| 130 bitmap.unlockPixels(); | 130 bitmap.unlockPixels(); |
| 131 | 131 |
| 132 // Populate bitmap | 132 // Populate bitmap |
| 133 { | 133 { |
| 134 SkAutoLockPixels alp(bitmap); | 134 SkAutoLockPixels alp(bitmap); |
| 135 | 135 |
| 136 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | 136 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); |
| 137 REPORTER_ASSERT(reporter, NULL != pixels); | 137 REPORTER_ASSERT(reporter, pixels); |
| 138 if (NULL == pixels) { | 138 if (NULL == pixels) { |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 | 141 |
| 142 for (int y = 0; y < kHeight; ++y) { | 142 for (int y = 0; y < kHeight; ++y) { |
| 143 for (int x = 0; x < kWidth; ++x) { | 143 for (int x = 0; x < kWidth; ++x) { |
| 144 if ((x ^ y) & 1) { | 144 if ((x ^ y) & 1) { |
| 145 pixels[x] = 0xFF; | 145 pixels[x] = 0xFF; |
| 146 } else { | 146 } else { |
| 147 pixels[x] = 0; | 147 pixels[x] = 0; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 pixels += bitmap.rowBytes(); | 150 pixels += bitmap.rowBytes(); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 SkAutoMalloc decompMemory(kWidth*kHeight); | 154 SkAutoMalloc decompMemory(kWidth*kHeight); |
| 155 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get()); | 155 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get()); |
| 156 REPORTER_ASSERT(reporter, NULL != decompBuffer); | 156 REPORTER_ASSERT(reporter, decompBuffer); |
| 157 if (NULL == decompBuffer) { | 157 if (NULL == decompBuffer) { |
| 158 return; | 158 return; |
| 159 } | 159 } |
| 160 | 160 |
| 161 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 161 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
| 162 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 162 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
| 163 | 163 |
| 164 // Ignore formats for RGBA data, since the decompressed buffer | 164 // Ignore formats for RGBA data, since the decompressed buffer |
| 165 // won't match the size and contents of the original. | 165 // won't match the size and contents of the original. |
| 166 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { | 166 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { |
| 167 continue; | 167 continue; |
| 168 } | 168 } |
| 169 | 169 |
| 170 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 170 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
| 171 REPORTER_ASSERT(reporter, NULL != data); | 171 REPORTER_ASSERT(reporter, data); |
| 172 if (NULL == data) { | 172 if (NULL == data) { |
| 173 continue; | 173 continue; |
| 174 } | 174 } |
| 175 | 175 |
| 176 bool decompResult = | 176 bool decompResult = |
| 177 SkTextureCompressor::DecompressBufferFromFormat( | 177 SkTextureCompressor::DecompressBufferFromFormat( |
| 178 decompBuffer, kWidth, | 178 decompBuffer, kWidth, |
| 179 data->bytes(), | 179 data->bytes(), |
| 180 kWidth, kHeight, fmt); | 180 kWidth, kHeight, fmt); |
| 181 REPORTER_ASSERT(reporter, decompResult); | 181 REPORTER_ASSERT(reporter, decompResult); |
| 182 | 182 |
| 183 SkAutoLockPixels alp(bitmap); | 183 SkAutoLockPixels alp(bitmap); |
| 184 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | 184 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); |
| 185 REPORTER_ASSERT(reporter, NULL != pixels); | 185 REPORTER_ASSERT(reporter, pixels); |
| 186 if (NULL == pixels) { | 186 if (NULL == pixels) { |
| 187 continue; | 187 continue; |
| 188 } | 188 } |
| 189 | 189 |
| 190 for (int y = 0; y < kHeight; ++y) { | 190 for (int y = 0; y < kHeight; ++y) { |
| 191 for (int x = 0; x < kWidth; ++x) { | 191 for (int x = 0; x < kWidth; ++x) { |
| 192 bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWid
th + x]; | 192 bool ok = pixels[y*bitmap.rowBytes() + x] == decompBuffer[y*kWid
th + x]; |
| 193 REPORTER_ASSERT(reporter, ok); | 193 REPORTER_ASSERT(reporter, ok); |
| 194 } | 194 } |
| 195 } | 195 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 221 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0); | 221 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0); |
| 222 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0); | 222 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0); |
| 223 const size_t kSizeToBe = | 223 const size_t kSizeToBe = |
| 224 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight)
; | 224 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight)
; |
| 225 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz
e)/16)); | 225 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz
e)/16)); |
| 226 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); | 226 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); |
| 227 | 227 |
| 228 for (int lum = 0; lum < 256; ++lum) { | 228 for (int lum = 0; lum < 256; ++lum) { |
| 229 bitmap.lockPixels(); | 229 bitmap.lockPixels(); |
| 230 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | 230 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); |
| 231 REPORTER_ASSERT(reporter, NULL != pixels); | 231 REPORTER_ASSERT(reporter, pixels); |
| 232 if (NULL == pixels) { | 232 if (NULL == pixels) { |
| 233 bitmap.unlockPixels(); | 233 bitmap.unlockPixels(); |
| 234 continue; | 234 continue; |
| 235 } | 235 } |
| 236 | 236 |
| 237 for (int i = 0; i < kWidth*kHeight; ++i) { | 237 for (int i = 0; i < kWidth*kHeight; ++i) { |
| 238 pixels[i] = lum; | 238 pixels[i] = lum; |
| 239 } | 239 } |
| 240 bitmap.unlockPixels(); | 240 bitmap.unlockPixels(); |
| 241 | 241 |
| 242 SkAutoDataUnref latcData( | 242 SkAutoDataUnref latcData( |
| 243 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); | 243 SkTextureCompressor::CompressBitmapToFormat(bitmap, kLATCFormat)); |
| 244 REPORTER_ASSERT(reporter, NULL != latcData); | 244 REPORTER_ASSERT(reporter, latcData); |
| 245 if (NULL == latcData) { | 245 if (NULL == latcData) { |
| 246 continue; | 246 continue; |
| 247 } | 247 } |
| 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 const uint64_t kIndex = kIndexEncodingMap[lum >> 5]; |
| 259 const uint64_t kConstColorEncoding = | 259 const uint64_t kConstColorEncoding = |
| 260 SkEndian_SwapLE64( | 260 SkEndian_SwapLE64( |
| 261 255 | | 261 255 | |
| 262 (kIndex << 16) | (kIndex << 19) | (kIndex << 22) | (kIndex << 25
) | | 262 (kIndex << 16) | (kIndex << 19) | (kIndex << 22) | (kIndex << 25
) | |
| 263 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 263 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
| 264 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 264 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
| 265 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 265 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
| 266 | 266 |
| 267 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 267 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
| 268 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 268 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
| 269 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 269 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 } | 272 } |
| OLD | NEW |