Coverage Report

Created: 2025-07-01 07:53

/src/libultrahdr/lib/include/ultrahdr/gainmapmetadata.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2024 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#ifndef ULTRAHDR_GAINMAPMETADATA_H
18
#define ULTRAHDR_GAINMAPMETADATA_H
19
20
#include "ultrahdr/ultrahdrcommon.h"
21
22
#include <memory>
23
#include <vector>
24
25
namespace ultrahdr {
26
constexpr uint8_t kIsMultiChannelMask = (1u << 7);
27
constexpr uint8_t kUseBaseColorSpaceMask = (1u << 6);
28
29
// Gain map metadata, for tone mapping between SDR and HDR.
30
// This is the fraction version of {@code uhdr_gainmap_metadata_ext_t}.
31
struct uhdr_gainmap_metadata_frac {
32
  int32_t gainMapMinN[3];
33
  uint32_t gainMapMinD[3];
34
  int32_t gainMapMaxN[3];
35
  uint32_t gainMapMaxD[3];
36
  uint32_t gainMapGammaN[3];
37
  uint32_t gainMapGammaD[3];
38
39
  int32_t baseOffsetN[3];
40
  uint32_t baseOffsetD[3];
41
  int32_t alternateOffsetN[3];
42
  uint32_t alternateOffsetD[3];
43
44
  uint32_t baseHdrHeadroomN;
45
  uint32_t baseHdrHeadroomD;
46
  uint32_t alternateHdrHeadroomN;
47
  uint32_t alternateHdrHeadroomD;
48
49
  bool backwardDirection;
50
  bool useBaseColorSpace;
51
52
  static uhdr_error_info_t encodeGainmapMetadata(const uhdr_gainmap_metadata_frac* in_metadata,
53
                                                 std::vector<uint8_t>& out_data);
54
55
  static uhdr_error_info_t decodeGainmapMetadata(const std::vector<uint8_t>& in_data,
56
                                                 uhdr_gainmap_metadata_frac* out_metadata);
57
58
  static uhdr_error_info_t gainmapMetadataFractionToFloat(const uhdr_gainmap_metadata_frac* from,
59
                                                          uhdr_gainmap_metadata_ext_t* to);
60
61
  static uhdr_error_info_t gainmapMetadataFloatToFraction(const uhdr_gainmap_metadata_ext_t* from,
62
                                                          uhdr_gainmap_metadata_frac* to);
63
64
  bool allChannelsIdentical() const;
65
66
0
  void dump() const {
67
0
    ALOGD("GAIN MAP METADATA: \n");
68
0
    ALOGD("min numerator:                       %d, %d, %d\n", gainMapMinN[0], gainMapMinN[1],
69
0
          gainMapMinN[2]);
70
0
    ALOGD("min denominator:                     %d, %d, %d\n", gainMapMinD[0], gainMapMinD[1],
71
0
          gainMapMinD[2]);
72
0
    ALOGD("max numerator:                       %d, %d, %d\n", gainMapMaxN[0], gainMapMaxN[1],
73
0
          gainMapMaxN[2]);
74
0
    ALOGD("max denominator:                     %d, %d, %d\n", gainMapMaxD[0], gainMapMaxD[1],
75
0
          gainMapMaxD[2]);
76
0
    ALOGD("gamma numerator:                     %d, %d, %d\n", gainMapGammaN[0], gainMapGammaN[1],
77
0
          gainMapGammaN[2]);
78
0
    ALOGD("gamma denominator:                   %d, %d, %d\n", gainMapGammaD[0], gainMapGammaD[1],
79
0
          gainMapGammaD[2]);
80
0
    ALOGD("SDR offset numerator:                %d, %d, %d\n", baseOffsetN[0], baseOffsetN[1],
81
0
          baseOffsetN[2]);
82
0
    ALOGD("SDR offset denominator:              %d, %d, %d\n", baseOffsetD[0], baseOffsetD[1],
83
0
          baseOffsetD[2]);
84
0
    ALOGD("HDR offset numerator:                %d, %d, %d\n", alternateOffsetN[0],
85
0
          alternateOffsetN[1], alternateOffsetN[2]);
86
0
    ALOGD("HDR offset denominator:              %d, %d, %d\n", alternateOffsetD[0],
87
0
          alternateOffsetD[1], alternateOffsetD[2]);
88
0
    ALOGD("base HDR head room numerator:        %d\n", baseHdrHeadroomN);
89
0
    ALOGD("base HDR head room denominator:      %d\n", baseHdrHeadroomD);
90
0
    ALOGD("alternate HDR head room numerator:   %d\n", alternateHdrHeadroomN);
91
0
    ALOGD("alternate HDR head room denominator: %d\n", alternateHdrHeadroomD);
92
0
    ALOGD("backwardDirection:                   %s\n", backwardDirection ? "true" : "false");
93
0
    ALOGD("use base color space:                %s\n", useBaseColorSpace ? "true" : "false");
94
0
  }
95
};
96
97
}  // namespace ultrahdr
98
99
#endif  // ULTRAHDR_GAINMAPMETADATA_H