Coverage Report

Created: 2026-09-28 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/codecs/jpeg_dec.h
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
#ifndef HEIF_JPEG_DEC_H
22
#define HEIF_JPEG_DEC_H
23
24
#include "libheif/heif.h"
25
#include "box.h"
26
#include "error.h"
27
#include "codecs/decoder.h"
28
29
#include <memory>
30
#include <vector>
31
#include <optional>
32
33
class Box_jpgC;
34
35
36
class Decoder_JPEG : public Decoder
37
{
38
public:
39
233
  explicit Decoder_JPEG(const std::shared_ptr<const Box_jpgC>& jpgC) : m_jpgC(jpgC) {}
40
41
48
  heif_compression_format get_compression_format() const override { return heif_compression_JPEG; }
42
43
  int get_luma_bits_per_pixel() const override;
44
45
  int get_chroma_bits_per_pixel() const override;
46
47
  Error get_coded_image_colorspace(heif_colorspace*, heif_chroma*) const override;
48
49
  Result<std::vector<uint8_t>> read_bitstream_configuration_data() const override;
50
51
  Result<std::optional<ImageSize>> get_max_coded_image_size(const std::vector<uint8_t>& compressed_data) const override;
52
53
private:
54
  const std::shared_ptr<const Box_jpgC> m_jpgC; // Optional jpgC box. May be NULL.
55
56
  struct ConfigInfo {
57
    uint8_t sample_precision = 0;
58
    heif_chroma chroma = heif_chroma_undefined;
59
60
    uint8_t nComponents = 0;
61
    uint8_t h_sampling[3]{};
62
    uint8_t v_sampling[3]{};
63
64
    // Coded frame size from the SOF marker (the buffer the decoder allocates).
65
    uint32_t coded_width = 0;
66
    uint32_t coded_height = 0;
67
  };
68
69
  std::optional<ConfigInfo> m_config;
70
71
  Error parse_SOF();
72
  Error parse_SOF(const std::vector<uint8_t>& data);
73
};
74
75
#endif