2016-03-01 20:12:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2017-02-10 14:06:38 +00:00
|
|
|
#ifndef CodecPriv_DEFINED
|
|
|
|
#define CodecPriv_DEFINED
|
2016-03-01 20:12:27 +00:00
|
|
|
|
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCodec.h"
|
|
|
|
#include "SkData.h"
|
|
|
|
|
|
|
|
inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(SkData::MakeWithoutCopy(mem, size)));
|
2016-03-01 20:12:27 +00:00
|
|
|
if (!codec) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-11 17:35:31 +00:00
|
|
|
bm->allocPixels(codec->getInfo());
|
2016-03-01 20:12:27 +00:00
|
|
|
const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPixels(),
|
2017-07-11 17:35:31 +00:00
|
|
|
bm->rowBytes());
|
2016-03-01 20:12:27 +00:00
|
|
|
return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput;
|
|
|
|
}
|
2017-02-10 14:06:38 +00:00
|
|
|
#endif // CodecPriv_DEFINED
|