/src/libheif/libheif/image-items/jpeg.cc
Line | Count | Source |
1 | | /* |
2 | | * HEIF JPEG codec. |
3 | | * Copyright (c) 2023 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 "jpeg.h" |
22 | | #include "codecs/jpeg_dec.h" |
23 | | #include "codecs/jpeg_enc.h" |
24 | | #include "codecs/jpeg_boxes.h" |
25 | | #include "security_limits.h" |
26 | | #include "pixelimage.h" |
27 | | #include "api_structs.h" |
28 | | #include <cstring> |
29 | | #include <utility> |
30 | | |
31 | | |
32 | | ImageItem_JPEG::ImageItem_JPEG(HeifContext* ctx, heif_item_id id) |
33 | 18 | : ImageItem(ctx, id) |
34 | 18 | { |
35 | 18 | m_encoder = std::make_shared<Encoder_JPEG>(); |
36 | 18 | } |
37 | | |
38 | | ImageItem_JPEG::ImageItem_JPEG(HeifContext* ctx) |
39 | 0 | : ImageItem(ctx) |
40 | 0 | { |
41 | 0 | m_encoder = std::make_shared<Encoder_JPEG>(); |
42 | 0 | } |
43 | | |
44 | | |
45 | | Result<std::vector<uint8_t>> ImageItem_JPEG::read_bitstream_configuration_data() const |
46 | 0 | { |
47 | 0 | return m_decoder->read_bitstream_configuration_data(); |
48 | 0 | } |
49 | | |
50 | | |
51 | | Result<std::shared_ptr<Decoder>> ImageItem_JPEG::get_decoder() const |
52 | 17 | { |
53 | 17 | return {m_decoder}; |
54 | 17 | } |
55 | | |
56 | | |
57 | | std::shared_ptr<Encoder> ImageItem_JPEG::get_encoder() const |
58 | 0 | { |
59 | 0 | return m_encoder; |
60 | 0 | } |
61 | | |
62 | | |
63 | | Error ImageItem_JPEG::initialize_decoder() |
64 | 13 | { |
65 | | // Note: jpgC box is optional. NULL is a valid value. |
66 | 13 | auto jpgC_box = get_property<Box_jpgC>(); |
67 | | |
68 | 13 | m_decoder = std::make_shared<Decoder_JPEG>(jpgC_box); |
69 | | |
70 | 13 | return Error::Ok; |
71 | 13 | } |
72 | | |
73 | | |
74 | | void ImageItem_JPEG::set_decoder_input_data() |
75 | 13 | { |
76 | 13 | DataExtent extent; |
77 | 13 | extent.set_from_image_item(get_context()->get_heif_file(), get_id()); |
78 | | |
79 | 13 | m_decoder->set_data_extent(std::move(extent)); |
80 | 13 | } |
81 | | |
82 | | |
83 | | heif_brand2 ImageItem_JPEG::get_compatible_brand() const |
84 | 0 | { |
85 | 0 | return heif_brand2_jpeg; |
86 | 0 | } |