145dbcd165
Replace with std::unique_ptr. Change-Id: I5806cfbb30515fcb20e5e66ce13fb5f3b8728176 Reviewed-on: https://skia-review.googlesource.com/4381 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
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.
|
|
*/
|
|
|
|
#include "SkBitmap.h"
|
|
#include "SkCodec.h"
|
|
#include "SkData.h"
|
|
#include "SkImage.h"
|
|
|
|
static inline bool decode_file(const char* filename, SkBitmap* bitmap,
|
|
SkColorType colorType = kN32_SkColorType,
|
|
bool requireUnpremul = false) {
|
|
SkASSERT(kIndex_8_SkColorType != colorType);
|
|
sk_sp<SkData> data(SkData::MakeFromFileName(filename));
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
|
|
if (!codec) {
|
|
return false;
|
|
}
|
|
|
|
SkImageInfo info = codec->getInfo().makeColorType(colorType);
|
|
if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) {
|
|
info = info.makeAlphaType(kUnpremul_SkAlphaType);
|
|
}
|
|
|
|
if (!bitmap->tryAllocPixels(info)) {
|
|
return false;
|
|
}
|
|
|
|
return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitmap->rowBytes());
|
|
}
|
|
|
|
static inline sk_sp<SkImage> decode_file(const char filename[]) {
|
|
sk_sp<SkData> data(SkData::MakeFromFileName(filename));
|
|
return data ? SkImage::MakeFromEncoded(data) : nullptr;
|
|
}
|