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 SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType colorType) { | 12 SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { |
13 switch (colorType) { | 13 switch (info.fColorType) { |
14 case kAlpha_8_SkColorType: | 14 case kAlpha_8_SkColorType: |
15 return SkBitmap::kA8_Config; | 15 return SkBitmap::kA8_Config; |
16 | 16 |
17 case kARGB_4444_SkColorType: | 17 case kARGB_4444_SkColorType: |
18 return SkBitmap::kARGB_4444_Config; | 18 return SkBitmap::kARGB_4444_Config; |
19 | 19 |
20 case kRGB_565_SkColorType: | 20 case kRGB_565_SkColorType: |
21 return SkBitmap::kRGB_565_Config; | 21 return SkBitmap::kRGB_565_Config; |
22 | 22 |
23 case kPMColor_SkColorType: | 23 case kPMColor_SkColorType: |
24 return SkBitmap::kARGB_8888_Config; | 24 return SkBitmap::kARGB_8888_Config; |
25 | 25 |
26 case kIndex_8_SkColorType: | 26 case kIndex_8_SkColorType: |
27 return SkBitmap::kIndex8_Config; | 27 return SkBitmap::kIndex8_Config; |
28 | 28 |
29 default: | 29 default: |
30 // break for unsupported colortypes | 30 // break for unsupported colortypes |
31 break; | 31 break; |
32 } | 32 } |
33 return SkBitmap::kNo_Config; | 33 return SkBitmap::kNo_Config; |
34 } | 34 } |
35 | 35 |
36 SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { | |
37 return SkColorTypeToBitmapConfig(info.fColorType); | |
38 } | |
39 | |
40 bool SkBitmapConfigToColorType(SkBitmap::Config config, SkColorType* ctOut) { | |
41 SkColorType ct; | |
42 switch (config) { | |
43 case SkBitmap::kA8_Config: | |
44 ct = kAlpha_8_SkColorType; | |
45 break; | |
46 case SkBitmap::kIndex8_Config: | |
47 ct = kIndex_8_SkColorType; | |
48 break; | |
49 case SkBitmap::kRGB_565_Config: | |
50 ct = kRGB_565_SkColorType; | |
51 break; | |
52 case SkBitmap::kARGB_4444_Config: | |
53 ct = kARGB_4444_SkColorType; | |
54 break; | |
55 case SkBitmap::kARGB_8888_Config: | |
56 ct = kPMColor_SkColorType; | |
57 break; | |
58 case SkBitmap::kNo_Config: | |
59 default: | |
60 return false; | |
61 } | |
62 if (ctOut) { | |
63 *ctOut = ct; | |
64 } | |
65 return true; | |
66 } | |
67 | |
68 | |
69 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { | 36 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { |
70 SkImageInfo info; | 37 SkImageInfo info; |
71 if (!bm.asImageInfo(&info)) { | 38 if (!bm.asImageInfo(&info)) { |
72 return NULL; | 39 return NULL; |
73 } | 40 } |
74 | 41 |
75 SkImage* image = NULL; | 42 SkImage* image = NULL; |
76 if (canSharePixelRef || bm.isImmutable()) { | 43 if (canSharePixelRef || bm.isImmutable()) { |
77 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); | 44 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); |
78 } else { | 45 } else { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 canvas->save(); | 101 canvas->save(); |
135 } | 102 } |
136 canvas->concat(matrix); | 103 canvas->concat(matrix); |
137 if (!paint || !needs_layer(*paint)) { | 104 if (!paint || !needs_layer(*paint)) { |
138 canvas->clipRect(tmpSrc); | 105 canvas->clipRect(tmpSrc); |
139 } | 106 } |
140 | 107 |
141 canvas->drawPicture(*picture); | 108 canvas->drawPicture(*picture); |
142 canvas->restoreToCount(saveCount); | 109 canvas->restoreToCount(saveCount); |
143 } | 110 } |
OLD | NEW |