Coverage Report

Created: 2025-08-12 07:37

/src/libheif/libheif/image-items/mask_image.h
Line
Count
Source (jump to first uncovered line)
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
37
/**
38
  * Mask Configuration Property (mskC).
39
  *
40
  * Each mask image item (mski) shall have an associated MaskConfigurationProperty
41
  * that provides information required to generate the mask of the associated mask
42
  * item.
43
  */
44
class Box_mskC : public FullBox
45
{
46
public:
47
48
  Box_mskC()
49
12
  {
50
12
    set_short_type(fourcc("mskC"));
51
12
  }
52
53
0
  bool is_essential() const override { return true; }
54
55
  std::string dump(Indent&) const override;
56
57
  Error write(StreamWriter& writer) const override;
58
59
  uint8_t get_bits_per_pixel() const
60
0
  { return m_bits_per_pixel; }
61
62
  void set_bits_per_pixel(uint8_t bits_per_pixel)
63
0
  { m_bits_per_pixel = bits_per_pixel; }
64
65
protected:
66
  Error parse(BitstreamRange& range, const heif_security_limits* limits) override;
67
68
private:
69
  uint8_t m_bits_per_pixel = 0;
70
};
71
72
class MaskImageCodec
73
{
74
public:
75
  static Error decode_mask_image(const HeifContext* context,
76
                                  heif_item_id ID,
77
                                  std::shared_ptr<HeifPixelImage>& img,
78
                                  const std::vector<uint8_t>& data);
79
};
80
81
82
83
class ImageItem_mask : public ImageItem
84
{
85
public:
86
13
  ImageItem_mask(HeifContext* ctx, heif_item_id id) : ImageItem(ctx, id) {}
87
88
0
  ImageItem_mask(HeifContext* ctx) : ImageItem(ctx) {}
89
90
0
  uint32_t get_infe_type() const override { return fourcc("mski"); }
91
92
0
  heif_compression_format get_compression_format() const override { return heif_compression_mask; }
93
94
0
  bool is_ispe_essential() const override { return true; }
95
96
  int get_luma_bits_per_pixel() const override;
97
98
0
  int get_chroma_bits_per_pixel() const override { return 0; }
99
100
  Result<std::shared_ptr<HeifPixelImage>> decode_compressed_image(const struct heif_decoding_options& options,
101
                                                                  bool decode_tile_only, uint32_t tile_x0, uint32_t tile_y0) const override;
102
103
  Result<Encoder::CodedImageData> encode(const std::shared_ptr<HeifPixelImage>& image,
104
                                         struct heif_encoder* encoder,
105
                                         const struct heif_encoding_options& options,
106
                                         enum heif_image_input_class input_class) override;
107
};
108
109
#endif //LIBHEIF_MASK_IMAGE_H