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"
|
2018-01-20 15:33:24 +00:00
|
|
|
#include "SkCommonFlags.h"
|
2016-03-01 20:12:27 +00:00
|
|
|
#include "SkData.h"
|
2018-01-20 15:33:24 +00:00
|
|
|
#include "SkEncodedImageFormat.h"
|
|
|
|
#include "SkImageEncoder.h"
|
|
|
|
#include "SkOSPath.h"
|
|
|
|
#include "SkStream.h"
|
2016-03-01 20:12:27 +00:00
|
|
|
|
|
|
|
inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(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;
|
|
|
|
}
|
2018-01-20 15:33:24 +00:00
|
|
|
|
|
|
|
inline void write_bm(const char* name, const SkBitmap& bm) {
|
|
|
|
if (FLAGS_writePath.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString filename = SkOSPath::Join(FLAGS_writePath[0], name);
|
|
|
|
filename.appendf(".png");
|
|
|
|
SkFILEWStream file(filename.c_str());
|
|
|
|
if (!SkEncodeImage(&file, bm, SkEncodedImageFormat::kPNG, 100)) {
|
|
|
|
SkDebugf("failed to write '%s'\n", filename.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 14:06:38 +00:00
|
|
|
#endif // CodecPriv_DEFINED
|