Flutter Engine
The Flutter Engine
SkYUVAInfoLocation.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
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 SkYUVAInfoLocation_DEFINED
9#define SkYUVAInfoLocation_DEFINED
10
13
14#include <algorithm>
15
16/**
17 * The location of Y, U, V, or A values within the planes described by SkYUVAInfo. Computed from a
18 * SkYUVAInfo and the set of channels present in a set of pixmaps/textures.
19 */
21 /** The index of the plane where the Y, U, V, or A value is to be found. */
22 int fPlane = -1;
23 /** The channel in the plane that contains the Y, U, V, or A value. */
25
26 bool operator==(const YUVALocation& that) const {
27 return fPlane == that.fPlane && fChannel == that.fChannel;
28 }
29 bool operator!=(const YUVALocation& that) const { return !(*this == that); }
30
31 static bool AreValidLocations(const SkYUVAInfo::YUVALocations& locations,
32 int* numPlanes = nullptr) {
33 int maxSlotUsed = -1;
34 bool used[SkYUVAInfo::kMaxPlanes] = {};
35 bool valid = true;
36 for (int i = 0; i < SkYUVAInfo::kYUVAChannelCount; ++i) {
37 if (locations[i].fPlane < 0) {
39 valid = false; // only the 'A' plane can be omitted
40 }
41 } else if (locations[i].fPlane >= SkYUVAInfo::kMaxPlanes) {
42 valid = false; // A maximum of four input textures is allowed
43 } else {
44 maxSlotUsed = std::max(locations[i].fPlane, maxSlotUsed);
45 used[i] = true;
46 }
47 }
48
49 // All the used slots should be packed starting at 0 with no gaps
50 for (int i = 0; i <= maxSlotUsed; ++i) {
51 if (!used[i]) {
52 valid = false;
53 }
54 }
55
56 if (numPlanes) {
57 *numPlanes = valid ? maxSlotUsed + 1 : 0;
58 }
59 return valid;
60 }
61};
62
63#endif
SkColorChannel
Definition: SkColor.h:228
int numPlanes() const
Definition: SkYUVAInfo.h:204
static constexpr int kMaxPlanes
Definition: SkYUVAInfo.h:98
std::array< YUVALocation, kYUVAChannelCount > YUVALocations
Definition: SkYUVAInfo.h:32
static constexpr int kYUVAChannelCount
Definition: SkYUVAInfo.h:29
static float max(float r, float g, float b)
Definition: hsl.cpp:49
const auto kA
bool operator!=(const YUVALocation &that) const
bool operator==(const YUVALocation &that) const
static bool AreValidLocations(const SkYUVAInfo::YUVALocations &locations, int *numPlanes=nullptr)