blob: 8362599e953b5af9eb60bbb01b1355f208178a39 [file] [log] [blame]
msarett7f7ec202016-03-01 12:12:27 -08001/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Hal Canary03a7f5f2017-02-10 09:06:38 -05007#ifndef CodecPriv_DEFINED
8#define CodecPriv_DEFINED
msarett7f7ec202016-03-01 12:12:27 -08009
10#include "SkBitmap.h"
11#include "SkCodec.h"
12#include "SkData.h"
13
14inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
Mike Reedede7bac2017-07-23 15:30:02 -040015 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(SkData::MakeWithoutCopy(mem, size)));
msarett7f7ec202016-03-01 12:12:27 -080016 if (!codec) {
17 return false;
18 }
19
Leon Scroggins571b30f2017-07-11 17:35:31 +000020 bm->allocPixels(codec->getInfo());
msarett7f7ec202016-03-01 12:12:27 -080021 const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPixels(),
Leon Scroggins571b30f2017-07-11 17:35:31 +000022 bm->rowBytes());
msarett7f7ec202016-03-01 12:12:27 -080023 return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput;
24}
Hal Canary03a7f5f2017-02-10 09:06:38 -050025#endif // CodecPriv_DEFINED