Coverage Report

Created: 2026-02-14 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/image-items/mask_image.h
Line
Count
Source
1
/*
2
 * HEIF mask image codec.
3
 *
4
 * Copyright (c) 2023 Dirk Farin <dirk.farin@gmail.com>
5
 * Copyright (c) 2023 Brad Hards <bradh@frogmouth.net>
6
 *
7
 * This file is part of libheif.
8
 *
9
 * libheif is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Lesser General Public License as
11
 * published by the Free Software Foundation, either version 3 of
12
 * the License, or (at your option) any later version.
13
 *
14
 * libheif is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with libheif.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
24
#ifndef LIBHEIF_MASK_IMAGE_H
25
#define LIBHEIF_MASK_IMAGE_H
26
27
#include "box.h"
28
#include "bitstream.h"
29
#include "pixelimage.h"
30
#include "file.h"
31
#include "context.h"
32
33
#include <memory>
34
#include <string>
35
#include <vector>
36
#include <set>
37
38
/**
39
  * Mask Configuration Property (mskC).
40
  *
41
  * Each mask image item (mski) shall have an associated MaskConfigurationProperty
42
  * that provides information required to generate the mask of the associated mask
43
  * item.
44
  */
45
class Box_mskC : public FullBox
46
{
47
public:
48
49
  Box_mskC()
50
37
  {
51
37
    set_short_type(fourcc("mskC"));
52
37
  }
53
54
0
  bool is_essential() const override { return true; }
55
56
  std::string dump(Indent&) const override;
57
58
  Error write(StreamWriter& writer) const override;
59
60
  uint8_t get_bits_per_pixel() const
61
0
  { return m_bits_per_pixel; }
62
63
  void set_bits_per_pixel(uint8_t bits_per_pixel)
64
0
  { m_bits_per_pixel = bits_per_pixel; }
65
66
protected:
67
  Error parse(BitstreamRange& range, const heif_security_limits* limits) override;
68
69
private:
70
  uint8_t m_bits_per_pixel = 0;
71
};
72
73
class MaskImageCodec
74
{
75
public:
76
  static Error decode_mask_image(const HeifContext* context,
77
                                  heif_item_id ID,
78
                                  std::shared_ptr<HeifPixelImage>& img,
79
                                  const std::vector<uint8_t>& data);
80
};
81
82
83
84
class ImageItem_mask : public ImageItem
85
{
86
public:
87
11
  ImageItem_mask(HeifContext* ctx, heif_item_id id) : ImageItem(ctx, id) {}
88
89
0
  ImageItem_mask(HeifContext* ctx) : ImageItem(ctx) {}
90
91
1
  uint32_t get_infe_type() const override { return fourcc("mski"); }
92
93
0
  heif_compression_format get_compression_format() const override { return heif_compression_mask; }
94
95
0
  bool is_ispe_essential() const override { return true; }
96
97
  int get_luma_bits_per_pixel() const override;
98
99
0
  int get_chroma_bits_per_pixel() const override { return 0; }
100
101
  Result<std::shared_ptr<HeifPixelImage>> decode_compressed_image(const heif_decoding_options& options,
102
                                                                  bool decode_tile_only, uint32_t tile_x0, uint32_t tile_y0,
103
                                                                  std::set<heif_item_id> processed_ids) const override;
104
105
  Result<Encoder::CodedImageData> encode(const std::shared_ptr<HeifPixelImage>& image,
106
                                         heif_encoder* encoder,
107
                                         const heif_encoding_options& options,
108
                                         heif_image_input_class input_class) override;
109
};
110
111
#endif //LIBHEIF_MASK_IMAGE_H