/src/libheif/libheif/codecs/avif_dec.cc
Line | Count | Source |
1 | | /* |
2 | | * HEIF codec. |
3 | | * Copyright (c) 2024 Dirk Farin <dirk.farin@gmail.com> |
4 | | * |
5 | | * This file is part of libheif. |
6 | | * |
7 | | * libheif is free software: you can redistribute it and/or modify |
8 | | * it under the terms of the GNU Lesser General Public License as |
9 | | * published by the Free Software Foundation, either version 3 of |
10 | | * the License, or (at your option) any later version. |
11 | | * |
12 | | * libheif is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with libheif. If not, see <http://www.gnu.org/licenses/>. |
19 | | */ |
20 | | |
21 | | #include "avif_dec.h" |
22 | | #include "avif_boxes.h" |
23 | | #include "error.h" |
24 | | #include "context.h" |
25 | | |
26 | | #include <string> |
27 | | |
28 | | |
29 | | Result<std::vector<uint8_t>> Decoder_AVIF::read_bitstream_configuration_data() const |
30 | 37.0k | { |
31 | 37.0k | std::vector<uint8_t> data; |
32 | 37.0k | if (!m_av1C->get_headers(&data)) { |
33 | 0 | return Error{heif_error_Invalid_input, |
34 | 0 | heif_suberror_No_item_data}; |
35 | 0 | } |
36 | | |
37 | 37.0k | return data; |
38 | 37.0k | } |
39 | | |
40 | | |
41 | | int Decoder_AVIF::get_luma_bits_per_pixel() const |
42 | 120k | { |
43 | 120k | Box_av1C::configuration config = m_av1C->get_configuration(); |
44 | 120k | if (!config.high_bitdepth) { |
45 | 89.1k | return 8; |
46 | 89.1k | } |
47 | 31.2k | else if (config.twelve_bit) { |
48 | 7.52k | return 12; |
49 | 7.52k | } |
50 | 23.7k | else { |
51 | 23.7k | return 10; |
52 | 23.7k | } |
53 | 120k | } |
54 | | |
55 | | |
56 | | int Decoder_AVIF::get_chroma_bits_per_pixel() const |
57 | 41.5k | { |
58 | 41.5k | return get_luma_bits_per_pixel(); |
59 | 41.5k | } |
60 | | |
61 | | |
62 | | Error Decoder_AVIF::get_coded_image_colorspace(heif_colorspace* out_colorspace, heif_chroma* out_chroma) const |
63 | 115k | { |
64 | 115k | *out_chroma = m_av1C->get_configuration().get_heif_chroma(); |
65 | | |
66 | 115k | if (*out_chroma == heif_chroma_monochrome) { |
67 | 10.9k | *out_colorspace = heif_colorspace_monochrome; |
68 | 10.9k | } |
69 | 104k | else { |
70 | 104k | *out_colorspace = heif_colorspace_YCbCr; |
71 | 104k | } |
72 | | |
73 | 115k | return Error::Ok; |
74 | 115k | } |