skia2/tests/CodecPriv.h
Mike Reed ede7bac43f use unique_ptr for codec factories
Will need guards for android (at least)

Bug: skia:
Change-Id: I2bb8e656997984489ef1f2e41cd3d301c4e7b947
Reviewed-on: https://skia-review.googlesource.com/26040
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
2017-07-25 15:35:23 +00:00

26 lines
740 B
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef CodecPriv_DEFINED
#define CodecPriv_DEFINED
#include "SkBitmap.h"
#include "SkCodec.h"
#include "SkData.h"
inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(SkData::MakeWithoutCopy(mem, size)));
if (!codec) {
return false;
}
bm->allocPixels(codec->getInfo());
const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPixels(),
bm->rowBytes());
return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput;
}
#endif // CodecPriv_DEFINED