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 SkImageInfoToBitmapConfig(const SkImage::Info& info) { | 12 SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { |
13 switch (info.fColorType) { | 13 switch (info.fColorType) { |
14 case SkImage::kAlpha_8_ColorType: | 14 case kAlpha_8_SkColorType: |
15 return SkBitmap::kA8_Config; | 15 return SkBitmap::kA8_Config; |
16 | 16 |
17 case SkImage::kRGB_565_ColorType: | 17 case kRGB_565_SkColorType: |
18 return SkBitmap::kRGB_565_Config; | 18 return SkBitmap::kRGB_565_Config; |
19 | 19 |
20 case SkImage::kPMColor_ColorType: | 20 case kPMColor_SkColorType: |
21 return SkBitmap::kARGB_8888_Config; | 21 return SkBitmap::kARGB_8888_Config; |
22 | 22 |
23 default: | 23 default: |
24 // break for unsupported colortypes | 24 // break for unsupported colortypes |
25 break; | 25 break; |
26 } | 26 } |
27 return SkBitmap::kNo_Config; | 27 return SkBitmap::kNo_Config; |
28 } | 28 } |
29 | 29 |
30 int SkImageBytesPerPixel(SkImage::ColorType ct) { | 30 int SkImageBytesPerPixel(SkColorType ct) { |
31 static const uint8_t gColorTypeBytesPerPixel[] = { | 31 static const uint8_t gColorTypeBytesPerPixel[] = { |
32 1, // kAlpha_8_ColorType | 32 1, // kAlpha_8_SkColorType |
33 2, // kRGB_565_ColorType | 33 2, // kRGB_565_SkColorType |
34 4, // kRGBA_8888_ColorType | 34 4, // kRGBA_8888_SkColorType |
35 4, // kBGRA_8888_ColorType | 35 4, // kBGRA_8888_SkColorType |
36 4, // kPMColor_ColorType | 36 4, // kPMColor_SkColorType |
37 }; | 37 }; |
38 | 38 |
39 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gColorTypeBytesPerPixel)); | 39 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gColorTypeBytesPerPixel)); |
40 return gColorTypeBytesPerPixel[ct]; | 40 return gColorTypeBytesPerPixel[ct]; |
41 } | 41 } |
42 | 42 |
43 bool SkBitmapToImageInfo(const SkBitmap& bm, SkImage::Info* info) { | 43 bool SkBitmapToImageInfo(const SkBitmap& bm, SkImageInfo* info) { |
44 switch (bm.config()) { | 44 switch (bm.config()) { |
45 case SkBitmap::kA8_Config: | 45 case SkBitmap::kA8_Config: |
46 info->fColorType = SkImage::kAlpha_8_ColorType; | 46 info->fColorType = kAlpha_8_SkColorType; |
47 break; | 47 break; |
48 | 48 |
49 case SkBitmap::kRGB_565_Config: | 49 case SkBitmap::kRGB_565_Config: |
50 info->fColorType = SkImage::kRGB_565_ColorType; | 50 info->fColorType = kRGB_565_SkColorType; |
51 break; | 51 break; |
52 | 52 |
53 case SkBitmap::kARGB_8888_Config: | 53 case SkBitmap::kARGB_8888_Config: |
54 info->fColorType = SkImage::kPMColor_ColorType; | 54 info->fColorType = kPMColor_SkColorType; |
55 break; | 55 break; |
56 | 56 |
57 default: | 57 default: |
58 return false; | 58 return false; |
59 } | 59 } |
60 | 60 |
61 info->fWidth = bm.width(); | 61 info->fWidth = bm.width(); |
62 info->fHeight = bm.height(); | 62 info->fHeight = bm.height(); |
63 info->fAlphaType = bm.isOpaque() ? kOpaque_SkAlphaType : | 63 info->fAlphaType = bm.isOpaque() ? kOpaque_SkAlphaType : |
64 kPremul_SkAlphaType; | 64 kPremul_SkAlphaType; |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { | 68 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { |
69 SkImage::Info info; | 69 SkImageInfo info; |
70 if (!SkBitmapToImageInfo(bm, &info)) { | 70 if (!SkBitmapToImageInfo(bm, &info)) { |
71 return NULL; | 71 return NULL; |
72 } | 72 } |
73 | 73 |
74 SkImage* image = NULL; | 74 SkImage* image = NULL; |
75 if (canSharePixelRef || bm.isImmutable()) { | 75 if (canSharePixelRef || bm.isImmutable()) { |
76 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); | 76 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); |
77 } else { | 77 } else { |
78 bm.lockPixels(); | 78 bm.lockPixels(); |
79 if (bm.getPixels()) { | 79 if (bm.getPixels()) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 canvas->save(); | 133 canvas->save(); |
134 } | 134 } |
135 canvas->concat(matrix); | 135 canvas->concat(matrix); |
136 if (!paint || !needs_layer(*paint)) { | 136 if (!paint || !needs_layer(*paint)) { |
137 canvas->clipRect(tmpSrc); | 137 canvas->clipRect(tmpSrc); |
138 } | 138 } |
139 | 139 |
140 canvas->drawPicture(*picture); | 140 canvas->drawPicture(*picture); |
141 canvas->restoreToCount(saveCount); | 141 canvas->restoreToCount(saveCount); |
142 } | 142 } |
OLD | NEW |