1*09537850SAkhilesh Sanikop /*
2*09537850SAkhilesh Sanikop * Copyright 2020 The libgav1 Authors
3*09537850SAkhilesh Sanikop *
4*09537850SAkhilesh Sanikop * Licensed under the Apache License, Version 2.0 (the "License");
5*09537850SAkhilesh Sanikop * you may not use this file except in compliance with the License.
6*09537850SAkhilesh Sanikop * You may obtain a copy of the License at
7*09537850SAkhilesh Sanikop *
8*09537850SAkhilesh Sanikop * http://www.apache.org/licenses/LICENSE-2.0
9*09537850SAkhilesh Sanikop *
10*09537850SAkhilesh Sanikop * Unless required by applicable law or agreed to in writing, software
11*09537850SAkhilesh Sanikop * distributed under the License is distributed on an "AS IS" BASIS,
12*09537850SAkhilesh Sanikop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*09537850SAkhilesh Sanikop * See the License for the specific language governing permissions and
14*09537850SAkhilesh Sanikop * limitations under the License.
15*09537850SAkhilesh Sanikop */
16*09537850SAkhilesh Sanikop
17*09537850SAkhilesh Sanikop #ifndef LIBGAV1_SRC_FRAME_BUFFER_UTILS_H_
18*09537850SAkhilesh Sanikop #define LIBGAV1_SRC_FRAME_BUFFER_UTILS_H_
19*09537850SAkhilesh Sanikop
20*09537850SAkhilesh Sanikop #include <cassert>
21*09537850SAkhilesh Sanikop #include <cstdint>
22*09537850SAkhilesh Sanikop
23*09537850SAkhilesh Sanikop #include "src/gav1/decoder_buffer.h"
24*09537850SAkhilesh Sanikop
25*09537850SAkhilesh Sanikop namespace libgav1 {
26*09537850SAkhilesh Sanikop
27*09537850SAkhilesh Sanikop // The following table is from Section 6.4.2 of the spec.
28*09537850SAkhilesh Sanikop //
29*09537850SAkhilesh Sanikop // subsampling_x subsampling_y mono_chrome Description
30*09537850SAkhilesh Sanikop // -----------------------------------------------------------
31*09537850SAkhilesh Sanikop // 0 0 0 YUV 4:4:4
32*09537850SAkhilesh Sanikop // 1 0 0 YUV 4:2:2
33*09537850SAkhilesh Sanikop // 1 1 0 YUV 4:2:0
34*09537850SAkhilesh Sanikop // 1 1 1 Monochrome 4:0:0
35*09537850SAkhilesh Sanikop
ComposeImageFormat(bool is_monochrome,int8_t subsampling_x,int8_t subsampling_y)36*09537850SAkhilesh Sanikop inline Libgav1ImageFormat ComposeImageFormat(bool is_monochrome,
37*09537850SAkhilesh Sanikop int8_t subsampling_x,
38*09537850SAkhilesh Sanikop int8_t subsampling_y) {
39*09537850SAkhilesh Sanikop Libgav1ImageFormat image_format;
40*09537850SAkhilesh Sanikop if (subsampling_x == 0) {
41*09537850SAkhilesh Sanikop assert(subsampling_y == 0 && !is_monochrome);
42*09537850SAkhilesh Sanikop image_format = kLibgav1ImageFormatYuv444;
43*09537850SAkhilesh Sanikop } else if (subsampling_y == 0) {
44*09537850SAkhilesh Sanikop assert(!is_monochrome);
45*09537850SAkhilesh Sanikop image_format = kLibgav1ImageFormatYuv422;
46*09537850SAkhilesh Sanikop } else if (!is_monochrome) {
47*09537850SAkhilesh Sanikop image_format = kLibgav1ImageFormatYuv420;
48*09537850SAkhilesh Sanikop } else {
49*09537850SAkhilesh Sanikop image_format = kLibgav1ImageFormatMonochrome400;
50*09537850SAkhilesh Sanikop }
51*09537850SAkhilesh Sanikop return image_format;
52*09537850SAkhilesh Sanikop }
53*09537850SAkhilesh Sanikop
DecomposeImageFormat(Libgav1ImageFormat image_format,bool * is_monochrome,int8_t * subsampling_x,int8_t * subsampling_y)54*09537850SAkhilesh Sanikop inline void DecomposeImageFormat(Libgav1ImageFormat image_format,
55*09537850SAkhilesh Sanikop bool* is_monochrome, int8_t* subsampling_x,
56*09537850SAkhilesh Sanikop int8_t* subsampling_y) {
57*09537850SAkhilesh Sanikop *is_monochrome = false;
58*09537850SAkhilesh Sanikop *subsampling_x = 1;
59*09537850SAkhilesh Sanikop *subsampling_y = 1;
60*09537850SAkhilesh Sanikop switch (image_format) {
61*09537850SAkhilesh Sanikop case kLibgav1ImageFormatYuv420:
62*09537850SAkhilesh Sanikop break;
63*09537850SAkhilesh Sanikop case kLibgav1ImageFormatYuv422:
64*09537850SAkhilesh Sanikop *subsampling_y = 0;
65*09537850SAkhilesh Sanikop break;
66*09537850SAkhilesh Sanikop case kLibgav1ImageFormatYuv444:
67*09537850SAkhilesh Sanikop *subsampling_x = *subsampling_y = 0;
68*09537850SAkhilesh Sanikop break;
69*09537850SAkhilesh Sanikop default:
70*09537850SAkhilesh Sanikop assert(image_format == kLibgav1ImageFormatMonochrome400);
71*09537850SAkhilesh Sanikop *is_monochrome = true;
72*09537850SAkhilesh Sanikop break;
73*09537850SAkhilesh Sanikop }
74*09537850SAkhilesh Sanikop }
75*09537850SAkhilesh Sanikop
76*09537850SAkhilesh Sanikop } // namespace libgav1
77*09537850SAkhilesh Sanikop
78*09537850SAkhilesh Sanikop #endif // LIBGAV1_SRC_FRAME_BUFFER_UTILS_H_
79