| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
| 9 #include "SkConfig8888.h" |
| 9 | 10 |
| 10 /* Fill out buffer with the compressed format Ganesh expects from a colortable | 11 /* Fill out buffer with the compressed format Ganesh expects from a colortable |
| 11 based bitmap. [palette (colortable) + indices]. | 12 based bitmap. [palette (colortable) + indices]. |
| 12 | 13 |
| 13 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 14 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
| 14 we could detect that the colortable.count is <= 16, and then repack the | 15 we could detect that the colortable.count is <= 16, and then repack the |
| 15 indices as nibbles to save RAM, but it would take more time (i.e. a lot | 16 indices as nibbles to save RAM, but it would take more time (i.e. a lot |
| 16 slower than memcpy), so skipping that for now. | 17 slower than memcpy), so skipping that for now. |
| 17 | 18 |
| 18 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big | 19 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big |
| 19 as the colortable.count says it is. | 20 as the colortable.count says it is. |
| 20 */ | 21 */ |
| 21 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { | 22 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { |
| 22 SkASSERT(SkBitmap::kIndex8_Config == bitmap.config()); | 23 SkASSERT(SkBitmap::kIndex8_Config == bitmap.config()); |
| 23 | 24 |
| 24 SkAutoLockPixels alp(bitmap); | 25 SkAutoLockPixels alp(bitmap); |
| 25 if (!bitmap.readyToDraw()) { | 26 if (!bitmap.readyToDraw()) { |
| 26 SkDEBUGFAIL("bitmap not ready to draw!"); | 27 SkDEBUGFAIL("bitmap not ready to draw!"); |
| 27 return; | 28 return; |
| 28 } | 29 } |
| 29 | 30 |
| 30 SkColorTable* ctable = bitmap.getColorTable(); | 31 SkColorTable* ctable = bitmap.getColorTable(); |
| 31 char* dst = (char*)buffer; | 32 char* dst = (char*)buffer; |
| 32 | 33 |
| 33 memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor)); | 34 uint32_t* colorTableDst = reinterpret_cast<uint32_t*>(dst); |
| 35 const uint32_t* colorTableSrc = reinterpret_cast<const uint32_t*>(ctable->lo
ckColors()); |
| 36 SkConvertConfig8888Pixels(colorTableDst, 0, SkCanvas::kRGBA_Premul_Config888
8, |
| 37 colorTableSrc, 0, SkCanvas::kNative_Premul_Config8
888, |
| 38 ctable->count(), 1); |
| 34 ctable->unlockColors(); | 39 ctable->unlockColors(); |
| 35 | 40 |
| 36 // always skip a full 256 number of entries, even if we memcpy'd fewer | 41 // always skip a full 256 number of entries, even if we memcpy'd fewer |
| 37 dst += kGrColorTableSize; | 42 dst += kGrColorTableSize; |
| 38 | 43 |
| 39 if ((unsigned)bitmap.width() == bitmap.rowBytes()) { | 44 if ((unsigned)bitmap.width() == bitmap.rowBytes()) { |
| 40 memcpy(dst, bitmap.getPixels(), bitmap.getSize()); | 45 memcpy(dst, bitmap.getPixels(), bitmap.getSize()); |
| 41 } else { | 46 } else { |
| 42 // need to trim off the extra bytes per row | 47 // need to trim off the extra bytes per row |
| 43 size_t width = bitmap.width(); | 48 size_t width = bitmap.width(); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 return kRGB_565_GrPixelConfig; | 212 return kRGB_565_GrPixelConfig; |
| 208 case SkBitmap::kARGB_4444_Config: | 213 case SkBitmap::kARGB_4444_Config: |
| 209 return kRGBA_4444_GrPixelConfig; | 214 return kRGBA_4444_GrPixelConfig; |
| 210 case SkBitmap::kARGB_8888_Config: | 215 case SkBitmap::kARGB_8888_Config: |
| 211 return kSkia8888_GrPixelConfig; | 216 return kSkia8888_GrPixelConfig; |
| 212 default: | 217 default: |
| 213 // kNo_Config, kA1_Config missing | 218 // kNo_Config, kA1_Config missing |
| 214 return kUnknown_GrPixelConfig; | 219 return kUnknown_GrPixelConfig; |
| 215 } | 220 } |
| 216 } | 221 } |
| OLD | NEW |