• 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 "SkBitmap.h"
12 #include "SkEncodedImageFormat.h"
13 #include "SkStream.h"
14 
15 /**
16  * Encode SkPixmap in the given binary image format.
17  *
18  * @param  dst     results are written to this stream.
19  * @param  src     source pixels.
20  * @param  format  image format, not all formats are supported.
21  * @param  quality range from 0-100, this is supported by jpeg and webp.
22  *                 higher values correspond to improved visual quality, but less compression.
23  *
24  * @return false iff input is bad or format is unsupported.
25  *
26  * Will always return false if Skia is compiled without image
27  * encoders.
28  *
29  * Note that webp encodes will use webp lossy compression.
30  *
31  * For examples of encoding an image to a file or to a block of memory,
32  * see tools/sk_tool_utils.h.
33  */
34 SK_API bool SkEncodeImage(SkWStream* dst, const SkPixmap& src,
35                           SkEncodedImageFormat format, int quality);
36 /**
37  * The following helper function wraps SkEncodeImage().
38  */
SkEncodeImage(SkWStream * dst,const SkBitmap & src,SkEncodedImageFormat f,int q)39 inline bool SkEncodeImage(SkWStream* dst, const SkBitmap& src, SkEncodedImageFormat f, int q) {
40     SkPixmap pixmap;
41     return src.peekPixels(&pixmap) && SkEncodeImage(dst, pixmap, f, q);
42 }
43 
44 #endif  // SkImageEncoder_DEFINED
45