Coverage Report

Created: 2026-06-10 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libheif/libheif/compression.cc
Line
Count
Source
1
/*
2
 * HEIF codec.
3
 * Copyright (c) 2026 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 "compression.h"
22
#include "common_utils.h"
23
24
25
uint32_t unci_compression_to_fourcc(heif_unci_compression method)
26
0
{
27
0
  switch (method) {
28
0
    case heif_unci_compression_off:
29
0
      return 0;
30
0
    case heif_unci_compression_deflate:
31
0
      return fourcc("defl");
32
0
    case heif_unci_compression_zlib:
33
0
      return fourcc("zlib");
34
0
    case heif_unci_compression_brotli:
35
0
      return fourcc("brot");
36
0
    default:
37
0
      return 0;
38
0
  }
39
0
}
40
41
42
Result<std::vector<uint8_t>> compress_unci_fourcc(uint32_t fourcc_code,
43
                                                   const uint8_t* data, size_t size)
44
0
{
45
0
  switch (fourcc_code) {
46
0
#if HAVE_ZLIB
47
0
    case fourcc("defl"):
48
0
      return {compress_deflate(data, size)};
49
0
    case fourcc("zlib"):
50
0
      return {compress_zlib(data, size)};
51
0
#endif
52
0
#if HAVE_BROTLI
53
0
    case fourcc("brot"):
54
0
      return {compress_brotli(data, size)};
55
0
#endif
56
0
    default:
57
0
      return Error{heif_error_Unsupported_feature,
58
0
                   heif_suberror_Unsupported_generic_compression_method,
59
0
                   "Unsupported unci compression method."};
60
0
  }
61
0
}