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_memory(const void* mem, size_t size, SkBitmap* bm) { | 12 inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) { |
13 sk_sp<SkData> data(SkData::MakeWithoutCopy(mem, size)); | 13 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(SkData::MakeWithoutCopy(me
m, size))); |
14 | |
15 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get())); | |
16 if (!codec) { | 14 if (!codec) { |
17 return false; | 15 return false; |
18 } | 16 } |
19 | 17 |
20 // Construct a color table for the decode if necessary | 18 // Construct a color table for the decode if necessary |
21 SkAutoTUnref<SkColorTable> colorTable(nullptr); | 19 SkAutoTUnref<SkColorTable> colorTable(nullptr); |
22 SkPMColor* colorPtr = nullptr; | 20 SkPMColor* colorPtr = nullptr; |
23 int* colorCountPtr = nullptr; | 21 int* colorCountPtr = nullptr; |
24 int maxColors = 256; | 22 int maxColors = 256; |
25 if (kIndex_8_SkColorType == codec->getInfo().colorType()) { | 23 if (kIndex_8_SkColorType == codec->getInfo().colorType()) { |
26 SkPMColor colors[256]; | 24 SkPMColor colors[256]; |
27 colorTable.reset(new SkColorTable(colors, maxColors)); | 25 colorTable.reset(new SkColorTable(colors, maxColors)); |
28 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); | 26 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); |
29 colorCountPtr = &maxColors; | 27 colorCountPtr = &maxColors; |
30 } | 28 } |
31 | 29 |
32 bm->allocPixels(codec->getInfo(), nullptr, colorTable.get()); | 30 bm->allocPixels(codec->getInfo(), nullptr, colorTable.get()); |
33 const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPix
els(), | 31 const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPix
els(), |
34 bm->rowBytes(), nullptr, colorPtr, colorCountPtr); | 32 bm->rowBytes(), nullptr, colorPtr, colorCountPtr); |
35 return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput; | 33 return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput; |
36 } | 34 } |
OLD | NEW |