Flutter Engine
The Flutter Engine
SkJpegEncoderImpl.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 SkJpegEncoderImpl_DEFINED
9#define SkJpegEncoderImpl_DEFINED
10
11#include "include/core/SkData.h"
15
16#include <cstdint>
17#include <memory>
18#include <optional>
19#include <utility>
20#include <vector>
21
22class SkColorSpace;
24class SkPixmap;
25class SkWStream;
26
27namespace SkJpegEncoder {
28struct Options;
29} // namespace SkJpegEncoder
30
31// JPEG metadata is included in marker-based segments in the header of the image (the part before
32// the first StartOfScan marker). These functions append these parameters to an SkJpegMarkerList.
33namespace SkJpegMetadataEncoder {
34
35// Metadata segments that will be added to the encoded file using
36struct Segment {
37 Segment(uint8_t marker, sk_sp<SkData> parameters)
38 : fMarker(marker), fParameters(std::move(parameters)) {}
39 uint8_t fMarker = 0;
41};
42
43using SegmentList = std::vector<Segment>;
44
45// Include an ICC profile in the image. If |colorSpace| is nullptr, then include no profile. If
46// |options| specifies ICC profile data, then use that data, otherwise, generate a profile for
47// |colorSpace|.
48void AppendICC(SegmentList& segmentList,
50 const SkColorSpace* colorSpace);
51
52// Include a standard (as opposed to extended) XMP metadata segment.
53void AppendXMPStandard(SegmentList& segmentList, const SkData* xmpMetadata);
54
55} // namespace SkJpegMetadataEncoder
56
58public:
59 // Make an encoder from RGB or YUV data. Encoding options are specified in |options|. Metadata
60 // markers are listed in |metadata|. The ICC profile and XMP metadata are read from |metadata|
61 // and not from |options|.
62 static std::unique_ptr<SkEncoder> MakeRGB(SkWStream* dst,
63 const SkPixmap& src,
66 static std::unique_ptr<SkEncoder> MakeYUV(SkWStream* dst,
67 const SkYUVAPixmaps& srcYUVA,
68 const SkColorSpace* srcYUVAColorSpace,
71
72 ~SkJpegEncoderImpl() override;
73
74protected:
75 bool onEncodeRows(int numRows) override;
76
77private:
78 SkJpegEncoderImpl(std::unique_ptr<SkJpegEncoderMgr>, const SkPixmap& src);
79 SkJpegEncoderImpl(std::unique_ptr<SkJpegEncoderMgr>, const SkYUVAPixmaps& srcYUVA);
80
81 std::unique_ptr<SkJpegEncoderMgr> fEncoderMgr;
82 std::optional<SkYUVAPixmaps> fSrcYUVA;
83};
84
85#endif
const char * options
static const char marker[]
Definition: SkData.h:25
static std::unique_ptr< SkEncoder > MakeRGB(SkWStream *dst, const SkPixmap &src, const SkJpegEncoder::Options &options, const SkJpegMetadataEncoder::SegmentList &metadata)
bool onEncodeRows(int numRows) override
static std::unique_ptr< SkEncoder > MakeYUV(SkWStream *dst, const SkYUVAPixmaps &srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options, const SkJpegMetadataEncoder::SegmentList &metadata)
void AppendICC(SegmentList &segmentList, const SkJpegEncoder::Options &options, const SkColorSpace *colorSpace)
void AppendXMPStandard(SegmentList &segmentList, const SkData *xmpMetadata)
std::vector< Segment > SegmentList
dst
Definition: cp.py:12
Definition: ref_ptr.h:256
Segment(uint8_t marker, sk_sp< SkData > parameters)