| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 | 11 |
| 12 inline bool decode_file(const char* filename, SkBitmap* bitmap, | 12 inline bool decode_file(const char* filename, SkBitmap* bitmap, |
| 13 SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false)
{ | 13 SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false)
{ |
| 14 SkASSERT(kIndex_8_SkColorType != colorType); | 14 SkASSERT(kIndex_8_SkColorType != colorType); |
| 15 SkAutoTUnref<SkData> data(SkData::NewFromFileName(filename)); | 15 sk_sp<SkData> data(SkData::MakeFromFileName(filename)); |
| 16 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); | 16 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get())); |
| 17 if (!codec) { | 17 if (!codec) { |
| 18 return false; | 18 return false; |
| 19 } | 19 } |
| 20 | 20 |
| 21 SkImageInfo info = codec->getInfo().makeColorType(colorType); | 21 SkImageInfo info = codec->getInfo().makeColorType(colorType); |
| 22 if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) { | 22 if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) { |
| 23 info = info.makeAlphaType(kUnpremul_SkAlphaType); | 23 info = info.makeAlphaType(kUnpremul_SkAlphaType); |
| 24 } | 24 } |
| 25 | 25 |
| 26 if (!bitmap->tryAllocPixels(info)) { | 26 if (!bitmap->tryAllocPixels(info)) { |
| 27 return false; | 27 return false; |
| 28 } | 28 } |
| 29 | 29 |
| 30 return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitm
ap->rowBytes()); | 30 return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitm
ap->rowBytes()); |
| 31 } | 31 } |
| OLD | NEW |