• 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_ULTRAHDRCOMMON_H
18 #define ULTRAHDR_ULTRAHDRCOMMON_H
19 
20 //#define LOG_NDEBUG 0
21 
22 #include <deque>
23 #include <map>
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "ultrahdr_api.h"
29 
30 // ===============================================================================================
31 // Function Macros
32 // ===============================================================================================
33 
34 #ifdef __ANDROID__
35 
36 #ifdef LOG_NDEBUG
37 #include "android/log.h"
38 
39 #ifndef LOG_TAG
40 #define LOG_TAG "UHDR"
41 #endif
42 
43 #ifndef ALOGD
44 #define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
45 #endif
46 
47 #ifndef ALOGE
48 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
49 #endif
50 
51 #ifndef ALOGI
52 #define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
53 #endif
54 
55 #ifndef ALOGV
56 #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
57 #endif
58 
59 #ifndef ALOGW
60 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
61 #endif
62 
63 #else
64 
65 #define ALOGD(...) ((void)0)
66 #define ALOGE(...) ((void)0)
67 #define ALOGI(...) ((void)0)
68 #define ALOGV(...) ((void)0)
69 #define ALOGW(...) ((void)0)
70 
71 #endif
72 
73 #else
74 
75 #ifdef LOG_NDEBUG
76 #include <cstdio>
77 
78 #define ALOGD(...)                \
79   do {                            \
80     fprintf(stderr, __VA_ARGS__); \
81     fprintf(stderr, "\n");        \
82   } while (0)
83 
84 #define ALOGE(...)                \
85   do {                            \
86     fprintf(stderr, __VA_ARGS__); \
87     fprintf(stderr, "\n");        \
88   } while (0)
89 
90 #define ALOGI(...)                \
91   do {                            \
92     fprintf(stdout, __VA_ARGS__); \
93     fprintf(stdout, "\n");        \
94   } while (0)
95 
96 #define ALOGV(...)                \
97   do {                            \
98     fprintf(stdout, __VA_ARGS__); \
99     fprintf(stdout, "\n");        \
100   } while (0)
101 
102 #define ALOGW(...)                \
103   do {                            \
104     fprintf(stderr, __VA_ARGS__); \
105     fprintf(stderr, "\n");        \
106   } while (0)
107 
108 #else
109 
110 #define ALOGD(...) ((void)0)
111 #define ALOGE(...) ((void)0)
112 #define ALOGI(...) ((void)0)
113 #define ALOGV(...) ((void)0)
114 #define ALOGW(...) ((void)0)
115 
116 #endif
117 
118 #endif
119 
120 #define ALIGNM(x, m) ((((x) + ((m)-1)) / (m)) * (m))
121 
122 #if defined(_MSC_VER)
123 #define FORCE_INLINE __forceinline
124 #define INLINE __inline
125 #else
126 #define FORCE_INLINE __inline__ __attribute__((always_inline))
127 #define INLINE inline
128 #endif
129 
130 namespace ultrahdr {
131 
132 // ===============================================================================================
133 // Structure Definitions
134 // ===============================================================================================
135 
136 /**\brief uhdr memory block */
137 typedef struct uhdr_memory_block {
138   uhdr_memory_block(size_t capacity);
139 
140   std::unique_ptr<uint8_t[]> m_buffer; /**< data */
141   size_t m_capacity;                   /**< capacity */
142 } uhdr_memory_block_t;                 /**< alias for struct uhdr_memory_block */
143 
144 /**\brief extended raw image descriptor */
145 typedef struct uhdr_raw_image_ext : uhdr_raw_image_t {
146   uhdr_raw_image_ext(uhdr_img_fmt_t fmt, uhdr_color_gamut_t cg, uhdr_color_transfer_t ct,
147                      uhdr_color_range_t range, unsigned w, unsigned h, unsigned align_stride_to);
148 
149  private:
150   std::unique_ptr<ultrahdr::uhdr_memory_block> m_block;
151 } uhdr_raw_image_ext_t; /**< alias for struct uhdr_raw_image_ext */
152 
153 /**\brief extended compressed image descriptor */
154 typedef struct uhdr_compressed_image_ext : uhdr_compressed_image_t {
155   uhdr_compressed_image_ext(uhdr_color_gamut_t cg, uhdr_color_transfer_t ct,
156                             uhdr_color_range_t range, unsigned sz);
157 
158  private:
159   std::unique_ptr<ultrahdr::uhdr_memory_block> m_block;
160 } uhdr_compressed_image_ext_t; /**< alias for struct uhdr_compressed_image_ext */
161 
162 /*!\brief forward declaration for image effect descriptor */
163 typedef struct uhdr_effect_desc uhdr_effect_desc_t;
164 
165 }  // namespace ultrahdr
166 
167 // ===============================================================================================
168 // Extensions of ultrahdr api definitions, so outside ultrahdr namespace
169 // ===============================================================================================
170 
171 struct uhdr_codec_private {
172   std::deque<ultrahdr::uhdr_effect_desc_t*> m_effects;
173 
174   virtual ~uhdr_codec_private();
175 };
176 
177 struct uhdr_encoder_private : uhdr_codec_private {
178   // config data
179   std::map<uhdr_img_label, std::unique_ptr<ultrahdr::uhdr_raw_image_ext_t>> m_raw_images;
180   std::map<uhdr_img_label, std::unique_ptr<ultrahdr::uhdr_compressed_image_ext_t>>
181       m_compressed_images;
182   std::map<uhdr_img_label, int> m_quality;
183   std::vector<uint8_t> m_exif;
184   uhdr_gainmap_metadata_t m_metadata;
185   uhdr_codec_t m_output_format;
186 
187   // internal data
188   bool m_sailed;
189   std::unique_ptr<ultrahdr::uhdr_compressed_image_ext_t> m_compressed_output_buffer;
190   uhdr_error_info_t m_encode_call_status;
191 };
192 
193 struct uhdr_decoder_private : uhdr_codec_private {
194   // config data
195   std::unique_ptr<ultrahdr::uhdr_compressed_image_ext_t> m_uhdr_compressed_img;
196   uhdr_img_fmt_t m_output_fmt;
197   uhdr_color_transfer_t m_output_ct;
198   float m_output_max_disp_boost;
199 
200   // internal data
201   bool m_probed;
202   bool m_sailed;
203   std::unique_ptr<ultrahdr::uhdr_raw_image_ext_t> m_decoded_img_buffer;
204   std::unique_ptr<ultrahdr::uhdr_raw_image_ext_t> m_gainmap_img_buffer;
205   int m_img_wd, m_img_ht;
206   int m_gainmap_wd, m_gainmap_ht;
207   std::vector<uint8_t> m_exif;
208   uhdr_mem_block_t m_exif_block;
209   std::vector<uint8_t> m_icc;
210   uhdr_mem_block_t m_icc_block;
211   std::vector<uint8_t> m_base_xmp;
212   std::vector<uint8_t> m_gainmap_xmp;
213   uhdr_gainmap_metadata_t m_metadata;
214   uhdr_error_info_t m_probe_call_status;
215   uhdr_error_info_t m_decode_call_status;
216 };
217 
218 #endif  // ULTRAHDR_ULTRAHDRCOMMON_H
219