• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 #include "SkBitmap.h"
11 #include "SkCodec.h"
12 #include "SkCommonFlags.h"
13 #include "SkData.h"
14 #include "SkEncodedImageFormat.h"
15 #include "SkImageEncoder.h"
16 #include "SkOSPath.h"
17 #include "SkStream.h"
18 
decode_memory(const void * mem,size_t size,SkBitmap * bm)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 
25     bm->allocPixels(codec->getInfo());
26     const SkCodec::Result result = codec->getPixels(codec->getInfo(), bm->getPixels(),
27             bm->rowBytes());
28     return result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput;
29 }
30 
write_bm(const char * name,const SkBitmap & bm)31 inline void write_bm(const char* name, const SkBitmap& bm) {
32     if (FLAGS_writePath.isEmpty()) {
33         return;
34     }
35 
36     SkString filename = SkOSPath::Join(FLAGS_writePath[0], name);
37     filename.appendf(".png");
38     SkFILEWStream file(filename.c_str());
39     if (!SkEncodeImage(&file, bm, SkEncodedImageFormat::kPNG, 100)) {
40         SkDebugf("failed to write '%s'\n", filename.c_str());
41     }
42 }
43 
44 #endif  // CodecPriv_DEFINED
45