| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkImagePriv.h" | 8 #include "SkImagePriv.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
| 11 | 11 |
| 12 #ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG | |
| 13 SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType colorType) { | |
| 14 switch (colorType) { | |
| 15 case kAlpha_8_SkColorType: | |
| 16 return SkBitmap::kA8_Config; | |
| 17 | |
| 18 case kARGB_4444_SkColorType: | |
| 19 return SkBitmap::kARGB_4444_Config; | |
| 20 | |
| 21 case kRGB_565_SkColorType: | |
| 22 return SkBitmap::kRGB_565_Config; | |
| 23 | |
| 24 case kN32_SkColorType: | |
| 25 return SkBitmap::kARGB_8888_Config; | |
| 26 | |
| 27 case kIndex_8_SkColorType: | |
| 28 return SkBitmap::kIndex8_Config; | |
| 29 | |
| 30 default: | |
| 31 // break for unsupported colortypes | |
| 32 break; | |
| 33 } | |
| 34 return SkBitmap::kNo_Config; | |
| 35 } | |
| 36 | |
| 37 SkColorType SkBitmapConfigToColorType(SkBitmap::Config config) { | |
| 38 static const SkColorType gCT[] = { | |
| 39 kUnknown_SkColorType, // kNo_Config | |
| 40 kAlpha_8_SkColorType, // kA8_Config | |
| 41 kIndex_8_SkColorType, // kIndex8_Config | |
| 42 kRGB_565_SkColorType, // kRGB_565_Config | |
| 43 kARGB_4444_SkColorType, // kARGB_4444_Config | |
| 44 kN32_SkColorType, // kARGB_8888_Config | |
| 45 }; | |
| 46 SkASSERT((unsigned)config < SK_ARRAY_COUNT(gCT)); | |
| 47 return gCT[config]; | |
| 48 } | |
| 49 #endif | |
| 50 | |
| 51 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { | 12 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { |
| 52 const SkImageInfo info = bm.info(); | 13 const SkImageInfo info = bm.info(); |
| 53 if (kUnknown_SkColorType == info.colorType()) { | 14 if (kUnknown_SkColorType == info.colorType()) { |
| 54 return NULL; | 15 return NULL; |
| 55 } | 16 } |
| 56 | 17 |
| 57 SkImage* image = NULL; | 18 SkImage* image = NULL; |
| 58 if (canSharePixelRef || bm.isImmutable()) { | 19 if (canSharePixelRef || bm.isImmutable()) { |
| 59 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); | 20 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); |
| 60 } else { | 21 } else { |
| 61 bm.lockPixels(); | 22 bm.lockPixels(); |
| 62 if (bm.getPixels()) { | 23 if (bm.getPixels()) { |
| 63 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); | 24 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); |
| 64 } | 25 } |
| 65 bm.unlockPixels(); | 26 bm.unlockPixels(); |
| 66 } | 27 } |
| 67 return image; | 28 return image; |
| 68 } | 29 } |
| OLD | NEW |