Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
YUVUtils.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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 YUVUtils_DEFINED
9#define YUVUtils_DEFINED
10
16
17#include <tuple>
18
19class SkData;
20#if defined(SK_GRAPHITE)
21namespace skgpu::graphite { class Recorder; }
22#endif
23
24namespace sk_gpu_test {
25
26// Splits an input image into A8 YUV[A] planes using the passed subsampling and YUV color space. If
27// the src image is opaque there will be three planes (Y, U, and V) and if not there will be a
28// fourth A plane. The planes are returned along with a SkYUVAInfo describing the resulting planar
29// image. Images are made as textures if GrRecordingContext is not null, otherwise as cpu images.
30std::tuple<std::array<sk_sp<SkImage>, SkYUVAInfo::kMaxPlanes>, SkYUVAInfo>
31MakeYUVAPlanesAsA8(SkImage*,
35
36// Utility that decodes a JPEG but preserves the YUVA8 planes in the image, and uses
37// MakeFromYUVAPixmaps to create a GPU multiplane YUVA image for a context. It extracts the planar
38// data once, and lazily creates the actual SkImage when the GrContext is provided (and refreshes
39// the image if the context has changed, as in Viewer)
41public:
42 // Returns null if the data could not be extracted into YUVA planes
43 static std::unique_ptr<LazyYUVImage> Make(sk_sp<SkData> data,
44 skgpu::Mipmapped = skgpu::Mipmapped::kNo,
45 sk_sp<SkColorSpace> = nullptr);
46 static std::unique_ptr<LazyYUVImage> Make(SkYUVAPixmaps,
47 skgpu::Mipmapped = skgpu::Mipmapped::kNo,
48 sk_sp<SkColorSpace> = nullptr);
49
51
52 SkISize dimensions() const { return fPixmaps.yuvaInfo().dimensions(); }
53
55#if defined(SK_GRAPHITE)
57#endif
58
59private:
60 // Decoded YUV data
61 SkYUVAPixmaps fPixmaps;
62
63 skgpu::Mipmapped fMipmapped;
64
65 sk_sp<SkColorSpace> fColorSpace;
66
67 // Memoized SkImages formed with planes, one for each Type.
68 sk_sp<SkImage> fYUVImage[4];
69
70 LazyYUVImage() = default;
71
74
75 bool ensureYUVImage(GrRecordingContext* rContext, Type type);
76#if defined(SK_GRAPHITE)
77 bool ensureYUVImage(skgpu::graphite::Recorder* recorder, Type type);
78#endif
79};
80
81} // namespace sk_gpu_test
82
83#endif // YUVUtils_DEFINED
m reset()
SkYUVColorSpace
Definition SkImageInfo.h:68
static constexpr int kMaxPlanes
Definition SkYUVAInfo.h:98
SkISize dimensions() const
Definition SkYUVAInfo.h:171
const SkYUVAInfo & yuvaInfo() const
sk_sp< SkImage > refImage(GrRecordingContext *rContext, Type)
Definition YUVUtils.cpp:222
SkISize dimensions() const
Definition YUVUtils.h:52
static std::unique_ptr< LazyYUVImage > Make(sk_sp< SkData > data, skgpu::Mipmapped=skgpu::Mipmapped::kNo, sk_sp< SkColorSpace >=nullptr)
Definition YUVUtils.cpp:200
Mipmapped
Definition GpuTypes.h:53