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 "SkImage_Base.h" | 8 #include "SkImage_Base.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 SkBitmap bitmap; | 58 SkBitmap bitmap; |
59 if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, | 59 if (!SkImageDecoder::DecodeMemory(data->bytes(), data->size(), &bitmap, |
60 SkBitmap::kNo_Config, | 60 SkBitmap::kNo_Config, |
61 SkImageDecoder::kDecodeBounds_Mode)) { | 61 SkImageDecoder::kDecodeBounds_Mode)) { |
62 return NULL; | 62 return NULL; |
63 } | 63 } |
64 | 64 |
65 return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height())); | 65 return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height())); |
66 } | 66 } |
| 67 |
| 68 /////////////////////////////////////////////////////////////////////////////// |
| 69 |
| 70 // FIXME: Temporarily move this here so chromium can still build until we truly |
| 71 // fix the core/images dependency issue (https://code.google.com/p/skia/issues/d
etail?id=1275) |
| 72 #include "SkImage.h" |
| 73 #include "../images/SkImageEncoder.h" |
| 74 |
| 75 static const SkImage_Base* asIB(const SkImage* image) { |
| 76 return static_cast<const SkImage_Base*>(image); |
| 77 } |
| 78 |
| 79 static const struct { |
| 80 SkImageEncoder::Type fIE; |
| 81 SkImage::EncodeType fET; |
| 82 } gTable[] = { |
| 83 { SkImageEncoder::kBMP_Type, SkImage::kBMP_EncodeType }, |
| 84 { SkImageEncoder::kGIF_Type, SkImage::kGIF_EncodeType }, |
| 85 { SkImageEncoder::kICO_Type, SkImage::kICO_EncodeType }, |
| 86 { SkImageEncoder::kJPEG_Type, SkImage::kJPEG_EncodeType }, |
| 87 { SkImageEncoder::kPNG_Type, SkImage::kPNG_EncodeType }, |
| 88 { SkImageEncoder::kWBMP_Type, SkImage::kWBMP_EncodeType }, |
| 89 { SkImageEncoder::kWEBP_Type, SkImage::kWEBP_EncodeType }, |
| 90 }; |
| 91 |
| 92 SkData* SkImage::encode(EncodeType et, int quality) const { |
| 93 for (size_t i = 0; i < SK_ARRAY_COUNT(gTable); ++i) { |
| 94 if (gTable[i].fET == et) { |
| 95 SkBitmap bm; |
| 96 if (asIB(this)->getROPixels(&bm)) { |
| 97 return SkImageEncoder::EncodeData(bm, gTable[i].fIE, quality); |
| 98 } |
| 99 break; |
| 100 } |
| 101 } |
| 102 return NULL; |
| 103 } |
OLD | NEW |