• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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_ULTRAHDR_H
18 #define ULTRAHDR_ULTRAHDR_H
19 
20 #include <string>
21 
22 namespace ultrahdr {
23 
24 // The current JPEGR version that we encode to
25 static const char* const kGainMapVersion = "1.0";
26 
27 // TODO (dichenzhang): rename these to "ULTRAHDR".
28 typedef enum {
29   JPEGR_NO_ERROR = 0,
30   JPEGR_UNKNOWN_ERROR = -1,
31 
32   JPEGR_IO_ERROR_BASE = -10000,
33   ERROR_JPEGR_BAD_PTR = JPEGR_IO_ERROR_BASE - 1,
34   ERROR_JPEGR_UNSUPPORTED_WIDTH_HEIGHT = JPEGR_IO_ERROR_BASE - 2,
35   ERROR_JPEGR_INVALID_COLORGAMUT = JPEGR_IO_ERROR_BASE - 3,
36   ERROR_JPEGR_INVALID_STRIDE = JPEGR_IO_ERROR_BASE - 4,
37   ERROR_JPEGR_INVALID_TRANS_FUNC = JPEGR_IO_ERROR_BASE - 5,
38   ERROR_JPEGR_RESOLUTION_MISMATCH = JPEGR_IO_ERROR_BASE - 6,
39   ERROR_JPEGR_INVALID_QUALITY_FACTOR = JPEGR_IO_ERROR_BASE - 7,
40   ERROR_JPEGR_INVALID_DISPLAY_BOOST = JPEGR_IO_ERROR_BASE - 8,
41   ERROR_JPEGR_INVALID_OUTPUT_FORMAT = JPEGR_IO_ERROR_BASE - 9,
42   ERROR_JPEGR_BAD_METADATA = JPEGR_IO_ERROR_BASE - 10,
43   ERROR_JPEGR_INVALID_CROPPING_PARAMETERS = JPEGR_IO_ERROR_BASE - 11,
44 
45   JPEGR_RUNTIME_ERROR_BASE = -20000,
46   ERROR_JPEGR_ENCODE_ERROR = JPEGR_RUNTIME_ERROR_BASE - 1,
47   ERROR_JPEGR_DECODE_ERROR = JPEGR_RUNTIME_ERROR_BASE - 2,
48   ERROR_JPEGR_GAIN_MAP_IMAGE_NOT_FOUND = JPEGR_RUNTIME_ERROR_BASE - 3,
49   ERROR_JPEGR_BUFFER_TOO_SMALL = JPEGR_RUNTIME_ERROR_BASE - 4,
50   ERROR_JPEGR_METADATA_ERROR = JPEGR_RUNTIME_ERROR_BASE - 5,
51   ERROR_JPEGR_NO_IMAGES_FOUND = JPEGR_RUNTIME_ERROR_BASE - 6,
52   ERROR_JPEGR_MULTIPLE_EXIFS_RECEIVED = JPEGR_RUNTIME_ERROR_BASE - 7,
53   ERROR_JPEGR_UNSUPPORTED_MAP_SCALE_FACTOR = JPEGR_RUNTIME_ERROR_BASE - 8,
54   ERROR_JPEGR_GAIN_MAP_SIZE_ERROR = JPEGR_RUNTIME_ERROR_BASE - 9,
55 
56   ERROR_JPEGR_UNSUPPORTED_FEATURE = -30000,
57 } status_t;
58 
59 // Color gamuts for image data
60 typedef enum {
61   ULTRAHDR_COLORGAMUT_UNSPECIFIED = -1,
62   ULTRAHDR_COLORGAMUT_BT709,
63   ULTRAHDR_COLORGAMUT_P3,
64   ULTRAHDR_COLORGAMUT_BT2100,
65   ULTRAHDR_COLORGAMUT_MAX = ULTRAHDR_COLORGAMUT_BT2100,
66 } ultrahdr_color_gamut;
67 
68 // Transfer functions for image data
69 // TODO: TF LINEAR is deprecated, remove this enum and the code surrounding it.
70 typedef enum {
71   ULTRAHDR_TF_UNSPECIFIED = -1,
72   ULTRAHDR_TF_LINEAR = 0,
73   ULTRAHDR_TF_HLG = 1,
74   ULTRAHDR_TF_PQ = 2,
75   ULTRAHDR_TF_SRGB = 3,
76   ULTRAHDR_TF_MAX = ULTRAHDR_TF_SRGB,
77 } ultrahdr_transfer_function;
78 
79 // Target output formats for decoder
80 typedef enum {
81   ULTRAHDR_OUTPUT_UNSPECIFIED = -1,
82   ULTRAHDR_OUTPUT_SDR,         // SDR in RGBA_8888 color format
83   ULTRAHDR_OUTPUT_HDR_LINEAR,  // HDR in F16 color format (linear)
84   ULTRAHDR_OUTPUT_HDR_PQ,      // HDR in RGBA_1010102 color format (PQ transfer function)
85   ULTRAHDR_OUTPUT_HDR_HLG,     // HDR in RGBA_1010102 color format (HLG transfer function)
86   ULTRAHDR_OUTPUT_MAX = ULTRAHDR_OUTPUT_HDR_HLG,
87 } ultrahdr_output_format;
88 
89 /*
90  * Holds information for gain map related metadata.
91  *
92  * Not: all values stored in linear. This differs from the metadata encoding in XMP, where
93  * maxContentBoost (aka gainMapMax), minContentBoost (aka gainMapMin), hdrCapacityMin, and
94  * hdrCapacityMax are stored in log2 space.
95  */
96 struct ultrahdr_metadata_struct {
97   // Ultra HDR format version
98   std::string version;
99   // Max Content Boost for the map
100   float maxContentBoost;
101   // Min Content Boost for the map
102   float minContentBoost;
103   // Gamma of the map data
104   float gamma;
105   // Offset for SDR data in map calculations
106   float offsetSdr;
107   // Offset for HDR data in map calculations
108   float offsetHdr;
109   // HDR capacity to apply the map at all
110   float hdrCapacityMin;
111   // HDR capacity to apply the map completely
112   float hdrCapacityMax;
113 };
114 typedef struct ultrahdr_metadata_struct* ultrahdr_metadata_ptr;
115 
116 }  // namespace ultrahdr
117 
118 #endif  // ULTRAHDR_ULTRAHDR_H
119