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
|
|
|
|
2019-03-25 15:54:59 +00:00
|
|
|
#include "CommandLineFlags.h"
|
2016-03-01 20:12:27 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCodec.h"
|
|
|
|
#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
|
|
|
|
2019-03-25 15:54:59 +00:00
|
|
|
static DEFINE_string(codecWritePath, "",
|
|
|
|
"Dump image decodes from codec unit tests here.");
|
|
|
|
|
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) {
|
2019-03-25 15:54:59 +00:00
|
|
|
if (FLAGS_codecWritePath.isEmpty()) {
|
2018-01-20 15:33:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-25 15:54:59 +00:00
|
|
|
SkString filename = SkOSPath::Join(FLAGS_codecWritePath[0], name);
|
2018-01-20 15:33:24 +00:00
|
|
|
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
|