• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 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 
8 #ifndef SkImageEncoder_DEFINED
9 #define SkImageEncoder_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/core/SkTypes.h"
13 
14 class SkBitmap;
15 class SkData;
16 class SkPixmap;
17 class SkWStream;
18 enum class SkEncodedImageFormat;
19 
20 /**
21  * Encode SkPixmap in the given binary image format.
22  *
23  * @param  dst     results are written to this stream.
24  * @param  src     source pixels.
25  * @param  format  image format, not all formats are supported.
26  * @param  quality range from 0-100, this is supported by jpeg and webp.
27  *                 higher values correspond to improved visual quality, but less compression.
28  *
29  * @return false iff input is bad or format is unsupported.
30  *
31  * Will always return false if Skia is compiled without image
32  * encoders.
33  *
34  * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise
35  * it will use lossy.
36  *
37  * For examples of encoding an image to a file or to a block of memory,
38  * see tools/ToolUtils.h.
39  */
40 SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src,
41                           SkEncodedImageFormat format, int quality);
42 
43 /**
44  * The following helper function wraps SkEncodeImage().
45  */
46 SK_API bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q);
47 
48 /**
49  * Encode SkPixmap in the given binary image format.
50  *
51  * @param  src     source pixels.
52  * @param  format  image format, not all formats are supported.
53  * @param  quality range from 0-100, this is supported by jpeg and webp.
54  *                 higher values correspond to improved visual quality, but less compression.
55  *
56  * @return encoded data or nullptr if input is bad or format is unsupported.
57  *
58  * Will always return nullptr if Skia is compiled without image
59  * encoders.
60  *
61  * For SkEncodedImageFormat::kWEBP, if quality is 100, it will use lossless compression. Otherwise
62  * it will use lossy.
63  */
64 SK_API sk_sp<SkData> SkEncodePixmap(const SkPixmap& src, SkEncodedImageFormat format, int quality);
65 
66 /**
67  *  Helper that extracts the pixmap from the bitmap, and then calls SkEncodePixmap()
68  */
69 SK_API sk_sp<SkData> SkEncodeBitmap(const SkBitmap& src, SkEncodedImageFormat format, int quality);
70 
71 #endif  // SkImageEncoder_DEFINED
72