/src/libheif/libheif/image-items/jpeg2000.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * HEIF JPEG 2000 codec. |
3 | | * Copyright (c) 2023 Brad Hards <bradh@frogmouth.net> |
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 "jpeg2000.h" |
22 | | #include "api_structs.h" |
23 | | #include "codecs/jpeg2000_dec.h" |
24 | | #include "codecs/jpeg2000_enc.h" |
25 | | #include "codecs/jpeg2000_boxes.h" |
26 | | #include <cstdint> |
27 | | #include <utility> |
28 | | |
29 | | |
30 | | ImageItem_JPEG2000::ImageItem_JPEG2000(HeifContext* ctx, heif_item_id id) |
31 | 0 | : ImageItem(ctx, id) |
32 | 0 | { |
33 | 0 | m_encoder = std::make_shared<Encoder_JPEG2000>(); |
34 | 0 | } |
35 | | |
36 | | |
37 | | ImageItem_JPEG2000::ImageItem_JPEG2000(HeifContext* ctx) |
38 | 0 | : ImageItem(ctx) |
39 | 0 | { |
40 | 0 | m_encoder = std::make_shared<Encoder_JPEG2000>(); |
41 | 0 | } |
42 | | |
43 | | |
44 | | Result<std::vector<uint8_t>> ImageItem_JPEG2000::read_bitstream_configuration_data() const |
45 | 0 | { |
46 | | // --- get codec configuration |
47 | |
|
48 | 0 | std::shared_ptr<Box_j2kH> j2kH_box = get_property<Box_j2kH>(); |
49 | 0 | if (!j2kH_box) |
50 | 0 | { |
51 | | // TODO - Correctly Find the j2kH box |
52 | | // return Error(heif_error_Invalid_input, |
53 | | // heif_suberror_Unspecified); |
54 | 0 | } |
55 | | // else if (!j2kH_box->get_headers(data)) { |
56 | | // return Error(heif_error_Invalid_input, |
57 | | // heif_suberror_No_item_data); |
58 | | // } |
59 | |
|
60 | 0 | return std::vector<uint8_t>{}; |
61 | 0 | } |
62 | | |
63 | | |
64 | | Result<std::shared_ptr<Decoder>> ImageItem_JPEG2000::get_decoder() const |
65 | 0 | { |
66 | 0 | return {m_decoder}; |
67 | 0 | } |
68 | | |
69 | | |
70 | | std::shared_ptr<class Encoder> ImageItem_JPEG2000::get_encoder() const |
71 | 0 | { |
72 | 0 | return m_encoder; |
73 | 0 | } |
74 | | |
75 | | |
76 | | Error ImageItem_JPEG2000::initialize_decoder() |
77 | 0 | { |
78 | 0 | auto j2kH = get_property<Box_j2kH>(); |
79 | 0 | if (!j2kH) { |
80 | 0 | return Error{heif_error_Invalid_input, |
81 | 0 | heif_suberror_Unspecified, |
82 | 0 | "No j2kH box found."}; |
83 | 0 | } |
84 | | |
85 | 0 | m_decoder = std::make_shared<Decoder_JPEG2000>(j2kH); |
86 | |
|
87 | 0 | return Error::Ok; |
88 | 0 | } |
89 | | |
90 | | |
91 | | void ImageItem_JPEG2000::set_decoder_input_data() |
92 | 0 | { |
93 | 0 | DataExtent extent; |
94 | 0 | extent.set_from_image_item(get_context()->get_heif_file(), get_id()); |
95 | |
|
96 | 0 | m_decoder->set_data_extent(std::move(extent)); |
97 | 0 | } |
98 | | |
99 | | heif_brand2 ImageItem_JPEG2000::get_compatible_brand() const |
100 | 0 | { |
101 | 0 | return heif_brand2_j2ki; |
102 | 0 | } |