Flutter Engine
The Flutter Engine
SkJpegEncoder.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 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 SkJpegEncoder_DEFINED
9#define SkJpegEncoder_DEFINED
10
13
14#include <memory>
15
16class SkColorSpace;
17class SkData;
18class SkEncoder;
19class SkPixmap;
20class SkWStream;
21class SkImage;
22class GrDirectContext;
23class SkYUVAPixmaps;
24struct skcms_ICCProfile;
25
26namespace SkJpegEncoder {
27
28enum class AlphaOption {
29 kIgnore,
31};
32
33enum class Downsample {
34 /**
35 * Reduction by a factor of two in both the horizontal and vertical directions.
36 */
37 k420,
38
39 /**
40 * Reduction by a factor of two in the horizontal direction.
41 */
42 k422,
43
44 /**
45 * No downsampling.
46 */
47 k444,
48};
49
50struct Options {
51 /**
52 * |fQuality| must be in [0, 100] where 0 corresponds to the lowest quality.
53 */
54 int fQuality = 100;
55
56 /**
57 * Choose the downsampling factor for the U and V components. This is only
58 * meaningful if the |src| is not kGray, since kGray will not be encoded as YUV.
59 * This is ignored in favor of |src|'s subsampling when |src| is an SkYUVAPixmaps.
60 *
61 * Our default value matches the libjpeg-turbo default.
62 */
64
65 /**
66 * Jpegs must be opaque. This instructs the encoder on how to handle input
67 * images with alpha.
68 *
69 * The default is to ignore the alpha channel and treat the image as opaque.
70 * Another option is to blend the pixels onto a black background before encoding.
71 * In the second case, the encoder supports linear or legacy blending.
72 */
74
75 /**
76 * Optional XMP metadata.
77 */
78 const SkData* xmpMetadata = nullptr;
79
80 /**
81 * An optional ICC profile to override the default behavior.
82 *
83 * The default behavior is to generate an ICC profile using a primary matrix and
84 * analytic transfer function. If the color space of |src| cannot be represented
85 * in this way (e.g, it is HLG or PQ), then no profile will be embedded.
86 */
87 const skcms_ICCProfile* fICCProfile = nullptr;
88 const char* fICCProfileDescription = nullptr;
89};
90
91/**
92 * Encode the |src| pixels to the |dst| stream.
93 * |options| may be used to control the encoding behavior.
94 *
95 * Returns true on success. Returns false on an invalid or unsupported |src|.
96 */
97SK_API bool Encode(SkWStream* dst, const SkPixmap& src, const Options& options);
99 const SkYUVAPixmaps& src,
100 const SkColorSpace* srcColorSpace,
101 const Options& options);
102
103/**
104* Encode the provided image and return the resulting bytes. If the image was created as
105* a texture-backed image on a GPU context, that |ctx| must be provided so the pixels
106* can be read before being encoded. For raster-backed images, |ctx| can be nullptr.
107* |options| may be used to control the encoding behavior.
108*
109* Returns nullptr if the pixels could not be read or encoding otherwise fails.
110*/
112
113/**
114 * Create a jpeg encoder that will encode the |src| pixels to the |dst| stream.
115 * |options| may be used to control the encoding behavior.
116 *
117 * |dst| is unowned but must remain valid for the lifetime of the object.
118 *
119 * This returns nullptr on an invalid or unsupported |src|.
120 */
121SK_API std::unique_ptr<SkEncoder> Make(SkWStream* dst, const SkPixmap& src, const Options& options);
122SK_API std::unique_ptr<SkEncoder> Make(SkWStream* dst,
123 const SkYUVAPixmaps& src,
124 const SkColorSpace* srcColorSpace,
125 const Options& options);
126} // namespace SkJpegEncoder
127
128#endif
const char * options
#define SK_API
Definition: SkAPI.h:35
Definition: SkData.h:25
SK_API std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
dst
Definition: cp.py:12
const skcms_ICCProfile * fICCProfile
Definition: SkJpegEncoder.h:87
AlphaOption fAlphaOption
Definition: SkJpegEncoder.h:73
const SkData * xmpMetadata
Definition: SkJpegEncoder.h:78
const char * fICCProfileDescription
Definition: SkJpegEncoder.h:88