/src/libheif/libheif/codecs/avc_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 "avc_dec.h" |
22 | | #include "avc_boxes.h" |
23 | | #include "error.h" |
24 | | #include "context.h" |
25 | | |
26 | | #include <string> |
27 | | |
28 | | |
29 | | Result<std::vector<uint8_t>> Decoder_AVC::read_bitstream_configuration_data() const |
30 | 0 | { |
31 | 0 | std::vector<uint8_t> data; |
32 | 0 | m_avcC->get_header_nals(data); |
33 | |
|
34 | 0 | return data; |
35 | 0 | } |
36 | | |
37 | | |
38 | | int Decoder_AVC::get_luma_bits_per_pixel() const |
39 | 0 | { |
40 | 0 | return m_avcC->get_configuration().bit_depth_luma; |
41 | 0 | } |
42 | | |
43 | | |
44 | | int Decoder_AVC::get_chroma_bits_per_pixel() const |
45 | 0 | { |
46 | 0 | return m_avcC->get_configuration().bit_depth_chroma; |
47 | 0 | } |
48 | | |
49 | | |
50 | | Result<std::optional<ImageSize>> Decoder_AVC::get_coded_image_size_from_config() const |
51 | 0 | { |
52 | 0 | const auto& sps_set = m_avcC->getSequenceParameterSets(); |
53 | |
|
54 | 0 | for (const auto& sps : sps_set) { |
55 | 0 | if (sps.empty()) continue; |
56 | 0 | Box_avcC::configuration scratch = m_avcC->get_configuration(); |
57 | 0 | uint32_t cropped_w = 0, cropped_h = 0; |
58 | 0 | ImageSize coded{}; |
59 | |
|
60 | 0 | Error e = parse_sps_for_avcC_configuration(sps.data(), sps.size(), &scratch, |
61 | 0 | &cropped_w, &cropped_h, &coded); |
62 | 0 | if (e) { |
63 | 0 | return e; |
64 | 0 | } |
65 | | |
66 | 0 | return std::optional<ImageSize>{coded}; |
67 | 0 | } |
68 | | |
69 | 0 | return std::optional<ImageSize>{}; |
70 | 0 | } |
71 | | |
72 | | |
73 | | Error Decoder_AVC::get_coded_image_colorspace(heif_colorspace* out_colorspace, heif_chroma* out_chroma) const |
74 | 0 | { |
75 | 0 | *out_chroma = m_avcC->get_configuration().chroma_format; |
76 | |
|
77 | 0 | if (*out_chroma == heif_chroma_monochrome) { |
78 | 0 | *out_colorspace = heif_colorspace_monochrome; |
79 | 0 | } |
80 | 0 | else { |
81 | 0 | *out_colorspace = heif_colorspace_YCbCr; |
82 | 0 | } |
83 | |
|
84 | 0 | return Error::Ok; |
85 | 0 | } |