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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 kIndex_8_SkColorType, // kIndex8_Config | 44 kIndex_8_SkColorType, // kIndex8_Config |
45 kRGB_565_SkColorType, // kRGB_565_Config | 45 kRGB_565_SkColorType, // kRGB_565_Config |
46 kARGB_4444_SkColorType, // kARGB_4444_Config | 46 kARGB_4444_SkColorType, // kARGB_4444_Config |
47 kN32_SkColorType, // kARGB_8888_Config | 47 kN32_SkColorType, // kARGB_8888_Config |
48 }; | 48 }; |
49 SkASSERT((unsigned)config < SK_ARRAY_COUNT(gCT)); | 49 SkASSERT((unsigned)config < SK_ARRAY_COUNT(gCT)); |
50 return gCT[config]; | 50 return gCT[config]; |
51 } | 51 } |
52 | 52 |
53 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { | 53 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { |
54 SkImageInfo info; | 54 const SkImageInfo info = bm.info(); |
55 if (!bm.asImageInfo(&info)) { | 55 if (kUnknown_SkColorType == info.colorType()) { |
56 return NULL; | 56 return NULL; |
57 } | 57 } |
58 | 58 |
59 SkImage* image = NULL; | 59 SkImage* image = NULL; |
60 if (canSharePixelRef || bm.isImmutable()) { | 60 if (canSharePixelRef || bm.isImmutable()) { |
61 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); | 61 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); |
62 } else { | 62 } else { |
63 bm.lockPixels(); | 63 bm.lockPixels(); |
64 if (bm.getPixels()) { | 64 if (bm.getPixels()) { |
65 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); | 65 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); |
66 } | 66 } |
67 bm.unlockPixels(); | 67 bm.unlockPixels(); |
68 } | 68 } |
69 return image; | 69 return image; |
70 } | 70 } |
OLD | NEW |