/src/skia/src/core/SkYUVAInfoLocation.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
11 | | #include "include/core/SkColor.h" |
12 | | #include "include/core/SkYUVAInfo.h" |
13 | | |
14 | | /** |
15 | | * The location of Y, U, V, or A values within the planes described by SkYUVAInfo. Computed from a |
16 | | * SkYUVAInfo and the set of channels present in a set of pixmaps/textures. |
17 | | */ |
18 | | struct SkYUVAInfo::YUVALocation { |
19 | | /** The index of the plane where the Y, U, V, or A value is to be found. */ |
20 | | int fPlane = -1; |
21 | | /** The channel in the plane that contains the Y, U, V, or A value. */ |
22 | | SkColorChannel fChannel = SkColorChannel::kA; |
23 | | |
24 | 0 | bool operator==(const YUVALocation& that) const { |
25 | 0 | return fPlane == that.fPlane && fChannel == that.fChannel; |
26 | 0 | } |
27 | 0 | bool operator!=(const YUVALocation& that) const { return !(*this == that); } |
28 | | |
29 | | static bool AreValidLocations(const SkYUVAInfo::YUVALocations& locations, |
30 | 0 | int* numPlanes = nullptr) { |
31 | 0 | int maxSlotUsed = -1; |
32 | 0 | bool used[SkYUVAInfo::kMaxPlanes] = {}; |
33 | 0 | bool valid = true; |
34 | 0 | for (int i = 0; i < SkYUVAInfo::kYUVAChannelCount; ++i) { |
35 | 0 | if (locations[i].fPlane < 0) { |
36 | 0 | if (i != SkYUVAInfo::YUVAChannels::kA) { |
37 | 0 | valid = false; // only the 'A' plane can be omitted |
38 | 0 | } |
39 | 0 | } else if (locations[i].fPlane >= SkYUVAInfo::kMaxPlanes) { |
40 | 0 | valid = false; // A maximum of four input textures is allowed |
41 | 0 | } else { |
42 | 0 | maxSlotUsed = std::max(locations[i].fPlane, maxSlotUsed); |
43 | 0 | used[i] = true; |
44 | 0 | } |
45 | 0 | } |
46 | 0 |
|
47 | 0 | // All the used slots should be packed starting at 0 with no gaps |
48 | 0 | for (int i = 0; i <= maxSlotUsed; ++i) { |
49 | 0 | if (!used[i]) { |
50 | 0 | valid = false; |
51 | 0 | } |
52 | 0 | } |
53 | 0 |
|
54 | 0 | if (numPlanes) { |
55 | 0 | *numPlanes = valid ? maxSlotUsed + 1 : 0; |
56 | 0 | } |
57 | 0 | return valid; |
58 | 0 | } |
59 | | }; |
60 | | |
61 | | #endif |