| 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 SkImageInfo& info) { | 12 SkBitmap::Config SkImageInfoToBitmapConfig(const SkImageInfo& info) { |
| 13 switch (info.fColorType) { | 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: |
| 18 return SkBitmap::kARGB_4444_Config; |
| 19 |
| 17 case kRGB_565_SkColorType: | 20 case kRGB_565_SkColorType: |
| 18 return SkBitmap::kRGB_565_Config; | 21 return SkBitmap::kRGB_565_Config; |
| 19 | 22 |
| 20 case kPMColor_SkColorType: | 23 case kPMColor_SkColorType: |
| 21 return SkBitmap::kARGB_8888_Config; | 24 return SkBitmap::kARGB_8888_Config; |
| 22 | 25 |
| 23 case kIndex8_SkColorType: | 26 case kIndex_8_SkColorType: |
| 24 return SkBitmap::kIndex8_Config; | 27 return SkBitmap::kIndex8_Config; |
| 25 | 28 |
| 26 default: | 29 default: |
| 27 // break for unsupported colortypes | 30 // break for unsupported colortypes |
| 28 break; | 31 break; |
| 29 } | 32 } |
| 30 return SkBitmap::kNo_Config; | 33 return SkBitmap::kNo_Config; |
| 31 } | 34 } |
| 32 | 35 |
| 33 int SkImageBytesPerPixel(SkColorType ct) { | |
| 34 static const uint8_t gColorTypeBytesPerPixel[] = { | |
| 35 1, // kAlpha_8_SkColorType | |
| 36 2, // kRGB_565_SkColorType | |
| 37 4, // kRGBA_8888_SkColorType | |
| 38 4, // kBGRA_8888_SkColorType | |
| 39 4, // kPMColor_SkColorType | |
| 40 1, // kIndex8_SkColorType | |
| 41 }; | |
| 42 | |
| 43 SkASSERT((size_t)ct < SK_ARRAY_COUNT(gColorTypeBytesPerPixel)); | |
| 44 return gColorTypeBytesPerPixel[ct]; | |
| 45 } | |
| 46 | |
| 47 bool SkBitmapToImageInfo(const SkBitmap& bm, SkImageInfo* info) { | |
| 48 switch (bm.config()) { | |
| 49 case SkBitmap::kA8_Config: | |
| 50 info->fColorType = kAlpha_8_SkColorType; | |
| 51 break; | |
| 52 | |
| 53 case SkBitmap::kIndex8_Config: | |
| 54 info->fColorType = kIndex8_SkColorType; | |
| 55 break; | |
| 56 | |
| 57 case SkBitmap::kRGB_565_Config: | |
| 58 info->fColorType = kRGB_565_SkColorType; | |
| 59 break; | |
| 60 | |
| 61 case SkBitmap::kARGB_8888_Config: | |
| 62 info->fColorType = kPMColor_SkColorType; | |
| 63 break; | |
| 64 | |
| 65 default: | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 info->fWidth = bm.width(); | |
| 70 info->fHeight = bm.height(); | |
| 71 info->fAlphaType = bm.isOpaque() ? kOpaque_SkAlphaType : | |
| 72 kPremul_SkAlphaType; | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { | 36 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) { |
| 77 SkImageInfo info; | 37 SkImageInfo info; |
| 78 if (!SkBitmapToImageInfo(bm, &info)) { | 38 if (!bm.asImageInfo(&info)) { |
| 79 return NULL; | 39 return NULL; |
| 80 } | 40 } |
| 81 | 41 |
| 82 SkImage* image = NULL; | 42 SkImage* image = NULL; |
| 83 if (canSharePixelRef || bm.isImmutable()) { | 43 if (canSharePixelRef || bm.isImmutable()) { |
| 84 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); | 44 image = SkNewImageFromPixelRef(info, bm.pixelRef(), bm.rowBytes()); |
| 85 } else { | 45 } else { |
| 86 bm.lockPixels(); | 46 bm.lockPixels(); |
| 87 if (bm.getPixels()) { | 47 if (bm.getPixels()) { |
| 88 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); | 48 image = SkImage::NewRasterCopy(info, bm.getPixels(), bm.rowBytes()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 canvas->save(); | 101 canvas->save(); |
| 142 } | 102 } |
| 143 canvas->concat(matrix); | 103 canvas->concat(matrix); |
| 144 if (!paint || !needs_layer(*paint)) { | 104 if (!paint || !needs_layer(*paint)) { |
| 145 canvas->clipRect(tmpSrc); | 105 canvas->clipRect(tmpSrc); |
| 146 } | 106 } |
| 147 | 107 |
| 148 canvas->drawPicture(*picture); | 108 canvas->drawPicture(*picture); |
| 149 canvas->restoreToCount(saveCount); | 109 canvas->restoreToCount(saveCount); |
| 150 } | 110 } |
| OLD | NEW |