| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 17 | #ifndef ANDROID_JPEGRECOVERYMAP_RECOVERYMAP_H |
| 18 | #define ANDROID_JPEGRECOVERYMAP_RECOVERYMAP_H |
| 19 | |
| Dichen Zhang | 80b7248 | 2022-11-02 01:55:35 +0000 | [diff] [blame] | 20 | #include "jpegrerrorcode.h" |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 21 | |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 22 | namespace android::recoverymap { |
| 23 | |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 24 | typedef enum { |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 25 | JPEGR_COLORGAMUT_UNSPECIFIED, |
| 26 | JPEGR_COLORGAMUT_BT709, |
| 27 | JPEGR_COLORGAMUT_P3, |
| 28 | JPEGR_COLORGAMUT_BT2100, |
| 29 | } jpegr_color_gamut; |
| 30 | |
| 31 | // Transfer functions as defined for XMP metadata |
| 32 | typedef enum { |
| 33 | JPEGR_TF_HLG = 0, |
| 34 | JPEGR_TF_PQ = 1, |
| 35 | } jpegr_transfer_function; |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 36 | |
| Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame^] | 37 | struct jpegr_info_struct { |
| 38 | size_t width; |
| 39 | size_t height; |
| 40 | std::vector<uint8_t>* iccData; |
| 41 | std::vector<uint8_t>* exifData; |
| 42 | }; |
| 43 | |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 44 | /* |
| 45 | * Holds information for uncompressed image or recovery map. |
| 46 | */ |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 47 | struct jpegr_uncompressed_struct { |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 48 | // Pointer to the data location. |
| 49 | void* data; |
| 50 | // Width of the recovery map or image in pixels. |
| 51 | int width; |
| 52 | // Height of the recovery map or image in pixels. |
| 53 | int height; |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 54 | // Color gamut. |
| 55 | jpegr_color_gamut colorGamut; |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * Holds information for compressed image or recovery map. |
| 60 | */ |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 61 | struct jpegr_compressed_struct { |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 62 | // Pointer to the data location. |
| 63 | void* data; |
| Dichen Zhang | 0b9f7de | 2022-11-18 06:52:46 +0000 | [diff] [blame] | 64 | // Used data length in bytes. |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 65 | int length; |
| Dichen Zhang | 0b9f7de | 2022-11-18 06:52:46 +0000 | [diff] [blame] | 66 | // Maximum available data length in bytes. |
| 67 | int maxLength; |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 68 | // Color gamut. |
| 69 | jpegr_color_gamut colorGamut; |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* |
| 73 | * Holds information for EXIF metadata. |
| 74 | */ |
| 75 | struct jpegr_exif_struct { |
| 76 | // Pointer to the data location. |
| 77 | void* data; |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 78 | // Data length; |
| 79 | int length; |
| 80 | }; |
| 81 | |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 82 | struct chromaticity_coord { |
| 83 | float x; |
| 84 | float y; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | struct st2086_metadata { |
| 89 | // xy chromaticity coordinate of the red primary of the mastering display |
| 90 | chromaticity_coord redPrimary; |
| 91 | // xy chromaticity coordinate of the green primary of the mastering display |
| 92 | chromaticity_coord greenPrimary; |
| 93 | // xy chromaticity coordinate of the blue primary of the mastering display |
| 94 | chromaticity_coord bluePrimary; |
| 95 | // xy chromaticity coordinate of the white point of the mastering display |
| 96 | chromaticity_coord whitePoint; |
| 97 | // Maximum luminance in nits of the mastering display |
| 98 | uint32_t maxLuminance; |
| 99 | // Minimum luminance in nits of the mastering display |
| 100 | float minLuminance; |
| 101 | }; |
| 102 | |
| 103 | struct hdr10_metadata { |
| 104 | // Mastering display color volume |
| 105 | st2086_metadata st2086Metadata; |
| 106 | // Max frame average light level in nits |
| 107 | float maxFALL; |
| 108 | // Max content light level in nits |
| 109 | float maxCLL; |
| 110 | }; |
| 111 | |
| 112 | struct jpegr_metadata { |
| 113 | // JPEG/R version |
| 114 | uint32_t version; |
| 115 | // Range scaling factor for the map |
| 116 | float rangeScalingFactor; |
| 117 | // The transfer function for decoding the HDR representation of the image |
| 118 | jpegr_transfer_function transferFunction; |
| 119 | // HDR10 metadata, only applicable for transferFunction of JPEGR_TF_PQ |
| 120 | hdr10_metadata hdr10Metadata; |
| 121 | }; |
| 122 | |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 123 | typedef struct jpegr_uncompressed_struct* jr_uncompressed_ptr; |
| 124 | typedef struct jpegr_compressed_struct* jr_compressed_ptr; |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 125 | typedef struct jpegr_exif_struct* jr_exif_ptr; |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 126 | typedef struct jpegr_metadata* jr_metadata_ptr; |
| Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame^] | 127 | typedef struct jpegr_info_struct* jr_info_ptr; |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 128 | |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 129 | class RecoveryMap { |
| 130 | public: |
| 131 | /* |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 132 | * Compress JPEGR image from 10-bit HDR YUV and 8-bit SDR YUV. |
| 133 | * |
| 134 | * Generate recovery map from the HDR and SDR inputs, compress SDR YUV to 8-bit JPEG and append |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 135 | * the recovery map to the end of the compressed JPEG. HDR and SDR inputs must be the same |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 136 | * resolution. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 137 | * @param uncompressed_p010_image uncompressed HDR image in P010 color format |
| 138 | * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 139 | * @param hdr_tf transfer function of the HDR image |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 140 | * @param dest destination of the compressed JPEGR image |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 141 | * @param quality target quality of the JPEG encoding, must be in range of 0-100 where 100 is |
| 142 | * the highest quality |
| 143 | * @param exif pointer to the exif metadata. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 144 | * @return NO_ERROR if encoding succeeds, error code if error occurs. |
| 145 | */ |
| 146 | status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, |
| 147 | jr_uncompressed_ptr uncompressed_yuv_420_image, |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 148 | jpegr_transfer_function hdr_tf, |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 149 | jr_compressed_ptr dest, |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 150 | int quality, |
| Dichen Zhang | 95cbb9f | 2022-11-07 18:32:05 +0000 | [diff] [blame] | 151 | jr_exif_ptr exif); |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 152 | |
| 153 | /* |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 154 | * Compress JPEGR image from 10-bit HDR YUV, 8-bit SDR YUV and compressed 8-bit JPEG. |
| 155 | * |
| 156 | * This method requires HAL Hardware JPEG encoder. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 157 | * |
| 158 | * Generate recovery map from the HDR and SDR inputs, append the recovery map to the end of the |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 159 | * compressed JPEG. HDR and SDR inputs must be the same resolution and color space. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 160 | * @param uncompressed_p010_image uncompressed HDR image in P010 color format |
| 161 | * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format |
| 162 | * @param compressed_jpeg_image compressed 8-bit JPEG image |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 163 | * @param hdr_tf transfer function of the HDR image |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 164 | * @param dest destination of the compressed JPEGR image |
| 165 | * @return NO_ERROR if encoding succeeds, error code if error occurs. |
| 166 | */ |
| 167 | status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, |
| 168 | jr_uncompressed_ptr uncompressed_yuv_420_image, |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 169 | jr_compressed_ptr compressed_jpeg_image, |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 170 | jpegr_transfer_function hdr_tf, |
| Dichen Zhang | 95cbb9f | 2022-11-07 18:32:05 +0000 | [diff] [blame] | 171 | jr_compressed_ptr dest); |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 172 | |
| 173 | /* |
| 174 | * Compress JPEGR image from 10-bit HDR YUV and 8-bit SDR YUV. |
| 175 | * |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 176 | * This method requires HAL Hardware JPEG encoder. |
| 177 | * |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 178 | * Decode the compressed 8-bit JPEG image to YUV SDR, generate recovery map from the HDR input |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 179 | * and the decoded SDR result, append the recovery map to the end of the compressed JPEG. HDR |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 180 | * and SDR inputs must be the same resolution. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 181 | * @param uncompressed_p010_image uncompressed HDR image in P010 color format |
| 182 | * @param compressed_jpeg_image compressed 8-bit JPEG image |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 183 | * @param hdr_tf transfer function of the HDR image |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 184 | * @param dest destination of the compressed JPEGR image |
| 185 | * @return NO_ERROR if encoding succeeds, error code if error occurs. |
| 186 | */ |
| 187 | status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 188 | jr_compressed_ptr compressed_jpeg_image, |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 189 | jpegr_transfer_function hdr_tf, |
| Dichen Zhang | 95cbb9f | 2022-11-07 18:32:05 +0000 | [diff] [blame] | 190 | jr_compressed_ptr dest); |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * Decompress JPEGR image. |
| 194 | * |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 195 | * The output JPEGR image is in RGBA_1010102 data format if decoding to HDR. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 196 | * @param compressed_jpegr_image compressed JPEGR image |
| 197 | * @param dest destination of the uncompressed JPEGR image |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 198 | * @param exif destination of the decoded EXIF metadata. |
| 199 | * @param request_sdr flag that request SDR output. If set to true, decoder will only decode |
| 200 | * the primary image which is SDR. Setting of request_sdr and input source |
| 201 | * (HDR or SDR) can be found in the table below: |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 202 | * | input source | request_sdr | output of decoding | |
| 203 | * | HDR | true | SDR | |
| 204 | * | HDR | false | HDR | |
| 205 | * | SDR | true | SDR | |
| 206 | * | SDR | false | SDR | |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 207 | * @return NO_ERROR if decoding succeeds, error code if error occurs. |
| 208 | */ |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 209 | status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image, |
| Dichen Zhang | ffa3401 | 2022-11-03 23:21:13 +0000 | [diff] [blame] | 210 | jr_uncompressed_ptr dest, |
| Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame^] | 211 | jr_exif_ptr exif = nullptr, |
| 212 | bool request_sdr = false); |
| 213 | |
| 214 | /* |
| 215 | * Gets Info from JPEGR file without decoding it. |
| 216 | * |
| 217 | * The output is filled jpegr_info structure |
| 218 | * @param compressed_jpegr_image compressed JPEGR image |
| 219 | * @param jpegr_info pointer to output JPEGR info |
| 220 | * @return NO_ERROR if JPEGR parsing succeeds, error code otherwise |
| 221 | */ |
| 222 | status_t getJPEGRInfo(jr_compressed_ptr compressed_jpegr_image, |
| 223 | jr_info_ptr jpegr_info); |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 224 | private: |
| 225 | /* |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 226 | * This method is called in the decoding pipeline. It will decode the recovery map. |
| 227 | * |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 228 | * @param compressed_recovery_map compressed recovery map |
| 229 | * @param dest decoded recover map |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 230 | * @return NO_ERROR if decoding succeeds, error code if error occurs. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 231 | */ |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 232 | status_t decompressRecoveryMap(jr_compressed_ptr compressed_recovery_map, |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 233 | jr_uncompressed_ptr dest); |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * This method is called in the encoding pipeline. It will encode the recovery map. |
| 237 | * |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 238 | * @param uncompressed_recovery_map uncompressed recovery map |
| 239 | * @param dest encoded recover map |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 240 | * @return NO_ERROR if encoding succeeds, error code if error occurs. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 241 | */ |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 242 | status_t compressRecoveryMap(jr_uncompressed_ptr uncompressed_recovery_map, |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 243 | jr_compressed_ptr dest); |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * This method is called in the encoding pipeline. It will take the uncompressed 8-bit and |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 247 | * 10-bit yuv images as input, and calculate the uncompressed recovery map. The input images |
| 248 | * must be the same resolution. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 249 | * |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 250 | * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format |
| 251 | * @param uncompressed_p010_image uncompressed HDR image in P010 color format |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 252 | * @param dest recovery map; caller responsible for memory of data |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 253 | * @param metadata metadata provides the transfer function for the HDR |
| 254 | * image; range_scaling_factor and hdr10 FALL and CLL will |
| 255 | * be updated. |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 256 | * @return NO_ERROR if calculation succeeds, error code if error occurs. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 257 | */ |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 258 | status_t generateRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, |
| 259 | jr_uncompressed_ptr uncompressed_p010_image, |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 260 | jr_metadata_ptr metadata, |
| 261 | jr_uncompressed_ptr dest); |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 262 | |
| 263 | /* |
| 264 | * This method is called in the decoding pipeline. It will take the uncompressed (decoded) |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 265 | * 8-bit yuv image, the uncompressed (decoded) recovery map, and extracted JPEG/R metadata as |
| 266 | * input, and calculate the 10-bit recovered image. The recovered output image is the same |
| 267 | * color gamut as the SDR image, with the transfer function specified in the JPEG/R metadata, |
| 268 | * and is in RGBA1010102 data format. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 269 | * |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 270 | * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format |
| 271 | * @param uncompressed_recovery_map uncompressed recovery map |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 272 | * @param metadata JPEG/R metadata extracted from XMP. |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 273 | * @param dest reconstructed HDR image |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 274 | * @return NO_ERROR if calculation succeeds, error code if error occurs. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 275 | */ |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 276 | status_t applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image, |
| 277 | jr_uncompressed_ptr uncompressed_recovery_map, |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 278 | jr_metadata_ptr metadata, |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 279 | jr_uncompressed_ptr dest); |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 280 | |
| 281 | /* |
| Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame^] | 282 | * This methoud is called to separate primary image and recovery map image from JPEGR |
| 283 | * |
| 284 | * @param compressed_jpegr_image compressed JPEGR image |
| 285 | * @param primary_image destination of primary image |
| 286 | * @param recovery_map destination of compressed recovery map |
| 287 | * @return NO_ERROR if calculation succeeds, error code if error occurs. |
| 288 | */ |
| 289 | status_t extractPrimaryImageAndRecoveryMap(jr_compressed_ptr compressed_jpegr_image, |
| 290 | jr_compressed_ptr primary_image, |
| 291 | jr_compressed_ptr recovery_map); |
| 292 | /* |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 293 | * This method is called in the decoding pipeline. It will read XMP metadata to find the start |
| 294 | * position of the compressed recovery map, and will extract the compressed recovery map. |
| 295 | * |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 296 | * @param compressed_jpegr_image compressed JPEGR image |
| 297 | * @param dest destination of compressed recovery map |
| 298 | * @return NO_ERROR if calculation succeeds, error code if error occurs. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 299 | */ |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 300 | status_t extractRecoveryMap(jr_compressed_ptr compressed_jpegr_image, |
| Fyodor Kyslov | 1dcc442 | 2022-11-16 01:40:53 +0000 | [diff] [blame^] | 301 | jr_compressed_ptr dest); |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * This method is called in the encoding pipeline. It will take the standard 8-bit JPEG image |
| 305 | * and the compressed recovery map as input, and update the XMP metadata with the end of JPEG |
| 306 | * marker, and append the compressed gian map after the JPEG. |
| 307 | * |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 308 | * @param compressed_jpeg_image compressed 8-bit JPEG image |
| 309 | * @param compress_recovery_map compressed recover map |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 310 | * @param metadata JPEG/R metadata to encode in XMP of the jpeg |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 311 | * @param dest compressed JPEGR image |
| 312 | * @return NO_ERROR if calculation succeeds, error code if error occurs. |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 313 | */ |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 314 | status_t appendRecoveryMap(jr_compressed_ptr compressed_jpeg_image, |
| Dichen Zhang | 6947d53 | 2022-10-22 02:16:21 +0000 | [diff] [blame] | 315 | jr_compressed_ptr compressed_recovery_map, |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 316 | jr_metadata_ptr metadata, |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 317 | jr_compressed_ptr dest); |
| Dichen Zhang | 72fd2b1 | 2022-11-01 06:11:50 +0000 | [diff] [blame] | 318 | |
| 319 | /* |
| 320 | * This method generates XMP metadata. |
| 321 | * |
| 322 | * below is an example of the XMP metadata that this function generates where |
| 323 | * secondary_image_length = 1000 |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 324 | * range_scaling_factor = 1.25 |
| Dichen Zhang | 72fd2b1 | 2022-11-01 06:11:50 +0000 | [diff] [blame] | 325 | * |
| 326 | * <x:xmpmeta |
| 327 | * xmlns:x="adobe:ns:meta/" |
| 328 | * x:xmptk="Adobe XMP Core 5.1.2"> |
| 329 | * <rdf:RDF |
| 330 | * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
| 331 | * <rdf:Description |
| 332 | * xmlns:GContainer="http://ns.google.com/photos/1.0/container/"> |
| 333 | * <GContainer:Version>1</GContainer:Version> |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 334 | * <GContainer:RangeScalingFactor>1.25</GContainer:RangeScalingFactor> |
| Dichen Zhang | 72fd2b1 | 2022-11-01 06:11:50 +0000 | [diff] [blame] | 335 | * <GContainer:Directory> |
| 336 | * <rdf:Seq> |
| 337 | * <rdf:li> |
| 338 | * <GContainer:Item |
| 339 | * Item:Semantic="Primary" |
| 340 | * Item:Mime="image/jpeg"/> |
| 341 | * </rdf:li> |
| 342 | * <rdf:li> |
| 343 | * <GContainer:Item |
| 344 | * Item:Semantic="RecoveryMap" |
| 345 | * Item:Mime="image/jpeg" |
| 346 | * Item:Length="1000"/> |
| 347 | * </rdf:li> |
| 348 | * </rdf:Seq> |
| 349 | * </GContainer:Directory> |
| 350 | * </rdf:Description> |
| 351 | * </rdf:RDF> |
| 352 | * </x:xmpmeta> |
| 353 | * |
| 354 | * @param secondary_image_length length of secondary image |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 355 | * @param metadata JPEG/R metadata to encode as XMP |
| Dichen Zhang | 72fd2b1 | 2022-11-01 06:11:50 +0000 | [diff] [blame] | 356 | * @return XMP metadata in type of string |
| 357 | */ |
| Nick Deakin | 6bd9043 | 2022-11-20 16:26:37 -0500 | [diff] [blame] | 358 | std::string generateXmp(int secondary_image_length, jpegr_metadata& metadata); |
| Dichen Zhang | 85b3756 | 2022-10-11 11:08:28 -0700 | [diff] [blame] | 359 | }; |
| 360 | |
| Dichen Zhang | 596a756 | 2022-10-12 14:57:05 -0700 | [diff] [blame] | 361 | } // namespace android::recoverymap |
| Nick Deakin | f6bca5a | 2022-11-04 10:43:43 -0400 | [diff] [blame] | 362 | |
| 363 | #endif // ANDROID_JPEGRECOVERYMAP_RECOVERYMAP_H |