CodecPriv.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef CodecPriv_DEFINED
  8. #define CodecPriv_DEFINED
  9. #include "include/codec/SkCodec.h"
  10. #include "include/core/SkBitmap.h"
  11. #include "include/core/SkData.h"
  12. #include "include/core/SkEncodedImageFormat.h"
  13. #include "include/core/SkImageEncoder.h"
  14. #include "include/core/SkStream.h"
  15. #include "src/utils/SkOSPath.h"
  16. #include "tools/flags/CommandLineFlags.h"
  17. static DEFINE_string(codecWritePath, "",
  18. "Dump image decodes from codec unit tests here.");
  19. inline bool decode_memory(const void* mem, size_t size, SkBitmap* bm) {
  20. std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(SkData::MakeWithoutCopy(mem, size)));
  21. if (!codec) {
  22. return false;
  23. }
  24. bm->allocPixels(codec->getInfo());
  25. const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPixels(),
  26. bm->rowBytes());
  27. return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput;
  28. }
  29. inline void write_bm(const char* name, const SkBitmap& bm) {
  30. if (FLAGS_codecWritePath.isEmpty()) {
  31. return;
  32. }
  33. SkString filename = SkOSPath::Join(FLAGS_codecWritePath[0], name);
  34. filename.appendf(".png");
  35. SkFILEWStream file(filename.c_str());
  36. if (!SkEncodeImage(&file, bm, SkEncodedImageFormat::kPNG, 100)) {
  37. SkDebugf("failed to write '%s'\n", filename.c_str());
  38. }
  39. }
  40. #endif // CodecPriv_DEFINED