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