1*89a0ef05SAndroid Build Coastguard Worker /* 2*89a0ef05SAndroid Build Coastguard Worker * Copyright 2022 The Android Open Source Project 3*89a0ef05SAndroid Build Coastguard Worker * 4*89a0ef05SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*89a0ef05SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*89a0ef05SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*89a0ef05SAndroid Build Coastguard Worker * 8*89a0ef05SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*89a0ef05SAndroid Build Coastguard Worker * 10*89a0ef05SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*89a0ef05SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*89a0ef05SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*89a0ef05SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*89a0ef05SAndroid Build Coastguard Worker * limitations under the License. 15*89a0ef05SAndroid Build Coastguard Worker */ 16*89a0ef05SAndroid Build Coastguard Worker 17*89a0ef05SAndroid Build Coastguard Worker #ifndef ULTRAHDR_JPEGR_H 18*89a0ef05SAndroid Build Coastguard Worker #define ULTRAHDR_JPEGR_H 19*89a0ef05SAndroid Build Coastguard Worker 20*89a0ef05SAndroid Build Coastguard Worker #include <array> 21*89a0ef05SAndroid Build Coastguard Worker #include <cfloat> 22*89a0ef05SAndroid Build Coastguard Worker 23*89a0ef05SAndroid Build Coastguard Worker #include "ultrahdr_api.h" 24*89a0ef05SAndroid Build Coastguard Worker #include "ultrahdr/ultrahdr.h" 25*89a0ef05SAndroid Build Coastguard Worker #include "ultrahdr/ultrahdrcommon.h" 26*89a0ef05SAndroid Build Coastguard Worker #include "ultrahdr/jpegdecoderhelper.h" 27*89a0ef05SAndroid Build Coastguard Worker #include "ultrahdr/jpegencoderhelper.h" 28*89a0ef05SAndroid Build Coastguard Worker 29*89a0ef05SAndroid Build Coastguard Worker namespace ultrahdr { 30*89a0ef05SAndroid Build Coastguard Worker 31*89a0ef05SAndroid Build Coastguard Worker // Default configurations 32*89a0ef05SAndroid Build Coastguard Worker // gainmap image downscale factor 33*89a0ef05SAndroid Build Coastguard Worker static const int kMapDimensionScaleFactorDefault = 1; 34*89a0ef05SAndroid Build Coastguard Worker static const int kMapDimensionScaleFactorAndroidDefault = 4; 35*89a0ef05SAndroid Build Coastguard Worker 36*89a0ef05SAndroid Build Coastguard Worker // JPEG compress quality (0 ~ 100) for base image 37*89a0ef05SAndroid Build Coastguard Worker static const int kBaseCompressQualityDefault = 95; 38*89a0ef05SAndroid Build Coastguard Worker 39*89a0ef05SAndroid Build Coastguard Worker // JPEG compress quality (0 ~ 100) for gain map 40*89a0ef05SAndroid Build Coastguard Worker static const int kMapCompressQualityDefault = 95; 41*89a0ef05SAndroid Build Coastguard Worker static const int kMapCompressQualityAndroidDefault = 85; 42*89a0ef05SAndroid Build Coastguard Worker 43*89a0ef05SAndroid Build Coastguard Worker // Gain map calculation 44*89a0ef05SAndroid Build Coastguard Worker static const bool kUseMultiChannelGainMapDefault = true; 45*89a0ef05SAndroid Build Coastguard Worker static const bool kUseMultiChannelGainMapAndroidDefault = false; 46*89a0ef05SAndroid Build Coastguard Worker 47*89a0ef05SAndroid Build Coastguard Worker // encoding preset 48*89a0ef05SAndroid Build Coastguard Worker static const uhdr_enc_preset_t kEncSpeedPresetDefault = UHDR_USAGE_BEST_QUALITY; 49*89a0ef05SAndroid Build Coastguard Worker static const uhdr_enc_preset_t kEncSpeedPresetAndroidDefault = UHDR_USAGE_REALTIME; 50*89a0ef05SAndroid Build Coastguard Worker 51*89a0ef05SAndroid Build Coastguard Worker // Default gamma value for gain map 52*89a0ef05SAndroid Build Coastguard Worker static const float kGainMapGammaDefault = 1.0f; 53*89a0ef05SAndroid Build Coastguard Worker 54*89a0ef05SAndroid Build Coastguard Worker // The current JPEGR version that we encode to 55*89a0ef05SAndroid Build Coastguard Worker static const char* const kJpegrVersion = "1.0"; 56*89a0ef05SAndroid Build Coastguard Worker 57*89a0ef05SAndroid Build Coastguard Worker /* 58*89a0ef05SAndroid Build Coastguard Worker * Holds information of jpeg image 59*89a0ef05SAndroid Build Coastguard Worker */ 60*89a0ef05SAndroid Build Coastguard Worker struct jpeg_info_struct { 61*89a0ef05SAndroid Build Coastguard Worker std::vector<uint8_t> imgData = std::vector<uint8_t>(0); 62*89a0ef05SAndroid Build Coastguard Worker std::vector<uint8_t> iccData = std::vector<uint8_t>(0); 63*89a0ef05SAndroid Build Coastguard Worker std::vector<uint8_t> exifData = std::vector<uint8_t>(0); 64*89a0ef05SAndroid Build Coastguard Worker std::vector<uint8_t> xmpData = std::vector<uint8_t>(0); 65*89a0ef05SAndroid Build Coastguard Worker std::vector<uint8_t> isoData = std::vector<uint8_t>(0); 66*89a0ef05SAndroid Build Coastguard Worker unsigned int width; 67*89a0ef05SAndroid Build Coastguard Worker unsigned int height; 68*89a0ef05SAndroid Build Coastguard Worker unsigned int numComponents; 69*89a0ef05SAndroid Build Coastguard Worker }; 70*89a0ef05SAndroid Build Coastguard Worker 71*89a0ef05SAndroid Build Coastguard Worker /* 72*89a0ef05SAndroid Build Coastguard Worker * Holds information of jpegr image 73*89a0ef05SAndroid Build Coastguard Worker */ 74*89a0ef05SAndroid Build Coastguard Worker struct jpegr_info_struct { 75*89a0ef05SAndroid Build Coastguard Worker unsigned int width; // copy of primary image width (for easier access) 76*89a0ef05SAndroid Build Coastguard Worker unsigned int height; // copy of primary image height (for easier access) 77*89a0ef05SAndroid Build Coastguard Worker jpeg_info_struct* primaryImgInfo = nullptr; 78*89a0ef05SAndroid Build Coastguard Worker jpeg_info_struct* gainmapImgInfo = nullptr; 79*89a0ef05SAndroid Build Coastguard Worker }; 80*89a0ef05SAndroid Build Coastguard Worker 81*89a0ef05SAndroid Build Coastguard Worker typedef struct jpeg_info_struct* j_info_ptr; 82*89a0ef05SAndroid Build Coastguard Worker typedef struct jpegr_info_struct* jr_info_ptr; 83*89a0ef05SAndroid Build Coastguard Worker 84*89a0ef05SAndroid Build Coastguard Worker class JpegR { 85*89a0ef05SAndroid Build Coastguard Worker public: 86*89a0ef05SAndroid Build Coastguard Worker JpegR(void* uhdrGLESCtxt = nullptr, 87*89a0ef05SAndroid Build Coastguard Worker int mapDimensionScaleFactor = kMapDimensionScaleFactorAndroidDefault, 88*89a0ef05SAndroid Build Coastguard Worker int mapCompressQuality = kMapCompressQualityAndroidDefault, 89*89a0ef05SAndroid Build Coastguard Worker bool useMultiChannelGainMap = kUseMultiChannelGainMapAndroidDefault, 90*89a0ef05SAndroid Build Coastguard Worker float gamma = kGainMapGammaDefault, 91*89a0ef05SAndroid Build Coastguard Worker uhdr_enc_preset_t preset = kEncSpeedPresetAndroidDefault, float minContentBoost = FLT_MIN, 92*89a0ef05SAndroid Build Coastguard Worker float maxContentBoost = FLT_MAX, float targetDispPeakBrightness = -1.0f); 93*89a0ef05SAndroid Build Coastguard Worker 94*89a0ef05SAndroid Build Coastguard Worker /*!\brief Encode API-0. 95*89a0ef05SAndroid Build Coastguard Worker * 96*89a0ef05SAndroid Build Coastguard Worker * Create ultrahdr jpeg image from raw hdr intent. 97*89a0ef05SAndroid Build Coastguard Worker * 98*89a0ef05SAndroid Build Coastguard Worker * Experimental only. 99*89a0ef05SAndroid Build Coastguard Worker * 100*89a0ef05SAndroid Build Coastguard Worker * Input hdr image is tonemapped to sdr image. A gainmap coefficient is computed between hdr and 101*89a0ef05SAndroid Build Coastguard Worker * sdr intent. sdr intent and gain map coefficient are compressed using jpeg encoding. compressed 102*89a0ef05SAndroid Build Coastguard Worker * gainmap is appended at the end of compressed sdr image. 103*89a0ef05SAndroid Build Coastguard Worker * 104*89a0ef05SAndroid Build Coastguard Worker * \param[in] hdr_intent hdr intent raw input image descriptor 105*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store compressed ultrahdr image 106*89a0ef05SAndroid Build Coastguard Worker * \param[in] quality quality factor for sdr intent jpeg compression 107*89a0ef05SAndroid Build Coastguard Worker * \param[in] exif optional exif metadata that needs to be inserted in 108*89a0ef05SAndroid Build Coastguard Worker * compressed output 109*89a0ef05SAndroid Build Coastguard Worker * 110*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 111*89a0ef05SAndroid Build Coastguard Worker */ 112*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t encodeJPEGR(uhdr_raw_image_t* hdr_intent, uhdr_compressed_image_t* dest, 113*89a0ef05SAndroid Build Coastguard Worker int quality, uhdr_mem_block_t* exif); 114*89a0ef05SAndroid Build Coastguard Worker 115*89a0ef05SAndroid Build Coastguard Worker /*!\brief Encode API-1. 116*89a0ef05SAndroid Build Coastguard Worker * 117*89a0ef05SAndroid Build Coastguard Worker * Create ultrahdr jpeg image from raw hdr intent and raw sdr intent. 118*89a0ef05SAndroid Build Coastguard Worker * 119*89a0ef05SAndroid Build Coastguard Worker * A gainmap coefficient is computed between hdr and sdr intent. sdr intent and gain map 120*89a0ef05SAndroid Build Coastguard Worker * coefficient are compressed using jpeg encoding. compressed gainmap is appended at the end of 121*89a0ef05SAndroid Build Coastguard Worker * compressed sdr image. 122*89a0ef05SAndroid Build Coastguard Worker * NOTE: Color transfer of sdr intent is expected to be sRGB. 123*89a0ef05SAndroid Build Coastguard Worker * 124*89a0ef05SAndroid Build Coastguard Worker * \param[in] hdr_intent hdr intent raw input image descriptor 125*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent sdr intent raw input image descriptor 126*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store compressed ultrahdr image 127*89a0ef05SAndroid Build Coastguard Worker * \param[in] quality quality factor for sdr intent jpeg compression 128*89a0ef05SAndroid Build Coastguard Worker * \param[in] exif optional exif metadata that needs to be inserted in 129*89a0ef05SAndroid Build Coastguard Worker * compressed output 130*89a0ef05SAndroid Build Coastguard Worker * 131*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 132*89a0ef05SAndroid Build Coastguard Worker */ 133*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t encodeJPEGR(uhdr_raw_image_t* hdr_intent, uhdr_raw_image_t* sdr_intent, 134*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* dest, int quality, uhdr_mem_block_t* exif); 135*89a0ef05SAndroid Build Coastguard Worker 136*89a0ef05SAndroid Build Coastguard Worker /*!\brief Encode API-2. 137*89a0ef05SAndroid Build Coastguard Worker * 138*89a0ef05SAndroid Build Coastguard Worker * Create ultrahdr jpeg image from raw hdr intent, raw sdr intent and compressed sdr intent. 139*89a0ef05SAndroid Build Coastguard Worker * 140*89a0ef05SAndroid Build Coastguard Worker * A gainmap coefficient is computed between hdr and sdr intent. gain map coefficient is 141*89a0ef05SAndroid Build Coastguard Worker * compressed using jpeg encoding. compressed gainmap is appended at the end of compressed sdr 142*89a0ef05SAndroid Build Coastguard Worker * intent. ICC profile is added if one isn't present in the sdr intent JPEG image. 143*89a0ef05SAndroid Build Coastguard Worker * NOTE: Color transfer of sdr intent is expected to be sRGB. 144*89a0ef05SAndroid Build Coastguard Worker * NOTE: sdr intent raw and compressed inputs are expected to be related via compress/decompress 145*89a0ef05SAndroid Build Coastguard Worker * operations. 146*89a0ef05SAndroid Build Coastguard Worker * 147*89a0ef05SAndroid Build Coastguard Worker * \param[in] hdr_intent hdr intent raw input image descriptor 148*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent sdr intent raw input image descriptor 149*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent_compressed sdr intent compressed input image descriptor 150*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store compressed ultrahdr 151*89a0ef05SAndroid Build Coastguard Worker * image 152*89a0ef05SAndroid Build Coastguard Worker * 153*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 154*89a0ef05SAndroid Build Coastguard Worker */ 155*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t encodeJPEGR(uhdr_raw_image_t* hdr_intent, uhdr_raw_image_t* sdr_intent, 156*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* sdr_intent_compressed, 157*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* dest); 158*89a0ef05SAndroid Build Coastguard Worker 159*89a0ef05SAndroid Build Coastguard Worker /*!\brief Encode API-3. 160*89a0ef05SAndroid Build Coastguard Worker * 161*89a0ef05SAndroid Build Coastguard Worker * Create ultrahdr jpeg image from raw hdr intent and compressed sdr intent. 162*89a0ef05SAndroid Build Coastguard Worker * 163*89a0ef05SAndroid Build Coastguard Worker * The sdr intent is decoded and a gainmap coefficient is computed between hdr and sdr intent. 164*89a0ef05SAndroid Build Coastguard Worker * gain map coefficient is compressed using jpeg encoding. compressed gainmap is appended at the 165*89a0ef05SAndroid Build Coastguard Worker * end of compressed sdr image. ICC profile is added if one isn't present in the sdr intent JPEG 166*89a0ef05SAndroid Build Coastguard Worker * image. 167*89a0ef05SAndroid Build Coastguard Worker * NOTE: Color transfer of sdr intent is expected to be sRGB. 168*89a0ef05SAndroid Build Coastguard Worker * 169*89a0ef05SAndroid Build Coastguard Worker * \param[in] hdr_intent hdr intent raw input image descriptor 170*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent_compressed sdr intent compressed input image descriptor 171*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store compressed ultrahdr 172*89a0ef05SAndroid Build Coastguard Worker * image 173*89a0ef05SAndroid Build Coastguard Worker * 174*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 175*89a0ef05SAndroid Build Coastguard Worker */ 176*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t encodeJPEGR(uhdr_raw_image_t* hdr_intent, 177*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* sdr_intent_compressed, 178*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* dest); 179*89a0ef05SAndroid Build Coastguard Worker 180*89a0ef05SAndroid Build Coastguard Worker /*!\brief Encode API-4. 181*89a0ef05SAndroid Build Coastguard Worker * 182*89a0ef05SAndroid Build Coastguard Worker * Create ultrahdr jpeg image from compressed sdr image and compressed gainmap image 183*89a0ef05SAndroid Build Coastguard Worker * 184*89a0ef05SAndroid Build Coastguard Worker * compressed gainmap image is added at the end of compressed sdr image. ICC profile is added if 185*89a0ef05SAndroid Build Coastguard Worker * one isn't present in the sdr intent compressed image. 186*89a0ef05SAndroid Build Coastguard Worker * 187*89a0ef05SAndroid Build Coastguard Worker * \param[in] base_img_compressed sdr intent compressed input image descriptor 188*89a0ef05SAndroid Build Coastguard Worker * \param[in] gainmap_img_compressed gainmap compressed image descriptor 189*89a0ef05SAndroid Build Coastguard Worker * \param[in] metadata gainmap metadata descriptor 190*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store compressed ultrahdr 191*89a0ef05SAndroid Build Coastguard Worker * image 192*89a0ef05SAndroid Build Coastguard Worker * 193*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 194*89a0ef05SAndroid Build Coastguard Worker */ 195*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t encodeJPEGR(uhdr_compressed_image_t* base_img_compressed, 196*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* gainmap_img_compressed, 197*89a0ef05SAndroid Build Coastguard Worker uhdr_gainmap_metadata_ext_t* metadata, 198*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* dest); 199*89a0ef05SAndroid Build Coastguard Worker 200*89a0ef05SAndroid Build Coastguard Worker /*!\brief Decode API. 201*89a0ef05SAndroid Build Coastguard Worker * 202*89a0ef05SAndroid Build Coastguard Worker * Decompress ultrahdr jpeg image. 203*89a0ef05SAndroid Build Coastguard Worker * 204*89a0ef05SAndroid Build Coastguard Worker * NOTE: This method requires that the ultrahdr input image contains an ICC profile with primaries 205*89a0ef05SAndroid Build Coastguard Worker * that match those of a color gamut that this library is aware of; Bt.709, Display-P3, or 206*89a0ef05SAndroid Build Coastguard Worker * Bt.2100. It also assumes the base image color transfer characteristics are sRGB. 207*89a0ef05SAndroid Build Coastguard Worker * 208*89a0ef05SAndroid Build Coastguard Worker * \param[in] uhdr_compressed_img compressed ultrahdr image descriptor 209*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store decoded output 210*89a0ef05SAndroid Build Coastguard Worker * \param[in] max_display_boost (optional) the maximum available boost supported by a 211*89a0ef05SAndroid Build Coastguard Worker * display, the value must be greater than or equal 212*89a0ef05SAndroid Build Coastguard Worker * to 1.0 213*89a0ef05SAndroid Build Coastguard Worker * \param[in] output_ct (optional) output color transfer 214*89a0ef05SAndroid Build Coastguard Worker * \param[in] output_format (optional) output pixel format 215*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] gainmap_img (optional) output image descriptor to store decoded 216*89a0ef05SAndroid Build Coastguard Worker * gainmap image 217*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] gainmap_metadata (optional) descriptor to store gainmap metadata 218*89a0ef05SAndroid Build Coastguard Worker * 219*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 220*89a0ef05SAndroid Build Coastguard Worker * 221*89a0ef05SAndroid Build Coastguard Worker * NOTE: This method only supports single gain map metadata values for fields that allow 222*89a0ef05SAndroid Build Coastguard Worker * multi-channel metadata values. 223*89a0ef05SAndroid Build Coastguard Worker * 224*89a0ef05SAndroid Build Coastguard Worker * NOTE: Not all combinations of output color transfer and output pixel format are supported. 225*89a0ef05SAndroid Build Coastguard Worker * Refer below table for supported combinations. 226*89a0ef05SAndroid Build Coastguard Worker * ---------------------------------------------------------------------- 227*89a0ef05SAndroid Build Coastguard Worker * | color transfer | color format | 228*89a0ef05SAndroid Build Coastguard Worker * ---------------------------------------------------------------------- 229*89a0ef05SAndroid Build Coastguard Worker * | SDR | 32bppRGBA8888 | 230*89a0ef05SAndroid Build Coastguard Worker * ---------------------------------------------------------------------- 231*89a0ef05SAndroid Build Coastguard Worker * | HDR_LINEAR | 64bppRGBAHalfFloat | 232*89a0ef05SAndroid Build Coastguard Worker * ---------------------------------------------------------------------- 233*89a0ef05SAndroid Build Coastguard Worker * | HDR_PQ | 32bppRGBA1010102 | 234*89a0ef05SAndroid Build Coastguard Worker * ---------------------------------------------------------------------- 235*89a0ef05SAndroid Build Coastguard Worker * | HDR_HLG | 32bppRGBA1010102 | 236*89a0ef05SAndroid Build Coastguard Worker * ---------------------------------------------------------------------- 237*89a0ef05SAndroid Build Coastguard Worker */ 238*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t decodeJPEGR(uhdr_compressed_image_t* uhdr_compressed_img, 239*89a0ef05SAndroid Build Coastguard Worker uhdr_raw_image_t* dest, float max_display_boost = FLT_MAX, 240*89a0ef05SAndroid Build Coastguard Worker uhdr_color_transfer_t output_ct = UHDR_CT_LINEAR, 241*89a0ef05SAndroid Build Coastguard Worker uhdr_img_fmt_t output_format = UHDR_IMG_FMT_64bppRGBAHalfFloat, 242*89a0ef05SAndroid Build Coastguard Worker uhdr_raw_image_t* gainmap_img = nullptr, 243*89a0ef05SAndroid Build Coastguard Worker uhdr_gainmap_metadata_t* gainmap_metadata = nullptr); 244*89a0ef05SAndroid Build Coastguard Worker 245*89a0ef05SAndroid Build Coastguard Worker /*!\brief This function parses the bitstream and returns information that is useful for actual 246*89a0ef05SAndroid Build Coastguard Worker * decoding. This does not decode the image. That is handled by decodeJPEGR 247*89a0ef05SAndroid Build Coastguard Worker * 248*89a0ef05SAndroid Build Coastguard Worker * \param[in] uhdr_compressed_img compressed ultrahdr image descriptor 249*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] uhdr_image_info image info descriptor 250*89a0ef05SAndroid Build Coastguard Worker * 251*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 252*89a0ef05SAndroid Build Coastguard Worker */ 253*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t getJPEGRInfo(uhdr_compressed_image_t* uhdr_compressed_img, 254*89a0ef05SAndroid Build Coastguard Worker jr_info_ptr uhdr_image_info); 255*89a0ef05SAndroid Build Coastguard Worker 256*89a0ef05SAndroid Build Coastguard Worker /*!\brief set gain map dimension scale factor 257*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 258*89a0ef05SAndroid Build Coastguard Worker * 259*89a0ef05SAndroid Build Coastguard Worker * \param[in] mapDimensionScaleFactor scale factor 260*89a0ef05SAndroid Build Coastguard Worker * 261*89a0ef05SAndroid Build Coastguard Worker * \return none 262*89a0ef05SAndroid Build Coastguard Worker */ setMapDimensionScaleFactor(int mapDimensionScaleFactor)263*89a0ef05SAndroid Build Coastguard Worker void setMapDimensionScaleFactor(int mapDimensionScaleFactor) { 264*89a0ef05SAndroid Build Coastguard Worker this->mMapDimensionScaleFactor = mapDimensionScaleFactor; 265*89a0ef05SAndroid Build Coastguard Worker } 266*89a0ef05SAndroid Build Coastguard Worker 267*89a0ef05SAndroid Build Coastguard Worker /*!\brief get gain map dimension scale factor 268*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 269*89a0ef05SAndroid Build Coastguard Worker * 270*89a0ef05SAndroid Build Coastguard Worker * \return mapDimensionScaleFactor 271*89a0ef05SAndroid Build Coastguard Worker */ getMapDimensionScaleFactor()272*89a0ef05SAndroid Build Coastguard Worker int getMapDimensionScaleFactor() { return this->mMapDimensionScaleFactor; } 273*89a0ef05SAndroid Build Coastguard Worker 274*89a0ef05SAndroid Build Coastguard Worker /*!\brief set gain map compression quality factor 275*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 276*89a0ef05SAndroid Build Coastguard Worker * 277*89a0ef05SAndroid Build Coastguard Worker * \param[in] mapCompressQuality quality factor for gain map image compression 278*89a0ef05SAndroid Build Coastguard Worker * 279*89a0ef05SAndroid Build Coastguard Worker * \return none 280*89a0ef05SAndroid Build Coastguard Worker */ setMapCompressQuality(int mapCompressQuality)281*89a0ef05SAndroid Build Coastguard Worker void setMapCompressQuality(int mapCompressQuality) { 282*89a0ef05SAndroid Build Coastguard Worker this->mMapCompressQuality = mapCompressQuality; 283*89a0ef05SAndroid Build Coastguard Worker } 284*89a0ef05SAndroid Build Coastguard Worker 285*89a0ef05SAndroid Build Coastguard Worker /*!\brief get gain map quality factor 286*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 287*89a0ef05SAndroid Build Coastguard Worker * 288*89a0ef05SAndroid Build Coastguard Worker * \return quality factor 289*89a0ef05SAndroid Build Coastguard Worker */ getMapCompressQuality()290*89a0ef05SAndroid Build Coastguard Worker int getMapCompressQuality() { return this->mMapCompressQuality; } 291*89a0ef05SAndroid Build Coastguard Worker 292*89a0ef05SAndroid Build Coastguard Worker /*!\brief set gain map gamma 293*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 294*89a0ef05SAndroid Build Coastguard Worker * 295*89a0ef05SAndroid Build Coastguard Worker * \param[in] gamma gamma parameter that is used for gain map calculation 296*89a0ef05SAndroid Build Coastguard Worker * 297*89a0ef05SAndroid Build Coastguard Worker * \return none 298*89a0ef05SAndroid Build Coastguard Worker */ setGainMapGamma(float gamma)299*89a0ef05SAndroid Build Coastguard Worker void setGainMapGamma(float gamma) { this->mGamma = gamma; } 300*89a0ef05SAndroid Build Coastguard Worker 301*89a0ef05SAndroid Build Coastguard Worker /*!\brief get gain map gamma 302*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 303*89a0ef05SAndroid Build Coastguard Worker * 304*89a0ef05SAndroid Build Coastguard Worker * \return gamma parameter 305*89a0ef05SAndroid Build Coastguard Worker */ getGainMapGamma()306*89a0ef05SAndroid Build Coastguard Worker float getGainMapGamma() { return this->mGamma; } 307*89a0ef05SAndroid Build Coastguard Worker 308*89a0ef05SAndroid Build Coastguard Worker /*!\brief enable / disable multi channel gain map 309*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 310*89a0ef05SAndroid Build Coastguard Worker * 311*89a0ef05SAndroid Build Coastguard Worker * \param[in] useMultiChannelGainMap enable / disable multi channel gain map 312*89a0ef05SAndroid Build Coastguard Worker * 313*89a0ef05SAndroid Build Coastguard Worker * \return none 314*89a0ef05SAndroid Build Coastguard Worker */ setUseMultiChannelGainMap(bool useMultiChannelGainMap)315*89a0ef05SAndroid Build Coastguard Worker void setUseMultiChannelGainMap(bool useMultiChannelGainMap) { 316*89a0ef05SAndroid Build Coastguard Worker this->mUseMultiChannelGainMap = useMultiChannelGainMap; 317*89a0ef05SAndroid Build Coastguard Worker } 318*89a0ef05SAndroid Build Coastguard Worker 319*89a0ef05SAndroid Build Coastguard Worker /*!\brief check if multi channel gain map is enabled 320*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 321*89a0ef05SAndroid Build Coastguard Worker * 322*89a0ef05SAndroid Build Coastguard Worker * \return true if multi channel gain map is enabled, false otherwise 323*89a0ef05SAndroid Build Coastguard Worker */ isUsingMultiChannelGainMap()324*89a0ef05SAndroid Build Coastguard Worker bool isUsingMultiChannelGainMap() { return this->mUseMultiChannelGainMap; } 325*89a0ef05SAndroid Build Coastguard Worker 326*89a0ef05SAndroid Build Coastguard Worker /*!\brief set gain map min and max content boost 327*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 328*89a0ef05SAndroid Build Coastguard Worker * 329*89a0ef05SAndroid Build Coastguard Worker * \param[in] minBoost gain map min content boost 330*89a0ef05SAndroid Build Coastguard Worker * \param[in] maxBoost gain map max content boost 331*89a0ef05SAndroid Build Coastguard Worker * 332*89a0ef05SAndroid Build Coastguard Worker * \return none 333*89a0ef05SAndroid Build Coastguard Worker */ setGainMapMinMaxContentBoost(float minBoost,float maxBoost)334*89a0ef05SAndroid Build Coastguard Worker void setGainMapMinMaxContentBoost(float minBoost, float maxBoost) { 335*89a0ef05SAndroid Build Coastguard Worker this->mMinContentBoost = minBoost; 336*89a0ef05SAndroid Build Coastguard Worker this->mMaxContentBoost = maxBoost; 337*89a0ef05SAndroid Build Coastguard Worker } 338*89a0ef05SAndroid Build Coastguard Worker 339*89a0ef05SAndroid Build Coastguard Worker /*!\brief get gain map min max content boost 340*89a0ef05SAndroid Build Coastguard Worker * NOTE: Applicable only in encoding scenario 341*89a0ef05SAndroid Build Coastguard Worker * 342*89a0ef05SAndroid Build Coastguard Worker * \param[out] minBoost gain map min content boost 343*89a0ef05SAndroid Build Coastguard Worker * \param[out] maxBoost gain map max content boost 344*89a0ef05SAndroid Build Coastguard Worker * 345*89a0ef05SAndroid Build Coastguard Worker * \return none 346*89a0ef05SAndroid Build Coastguard Worker */ getGainMapMinMaxContentBoost(float & minBoost,float & maxBoost)347*89a0ef05SAndroid Build Coastguard Worker void getGainMapMinMaxContentBoost(float& minBoost, float& maxBoost) { 348*89a0ef05SAndroid Build Coastguard Worker minBoost = this->mMinContentBoost; 349*89a0ef05SAndroid Build Coastguard Worker maxBoost = this->mMaxContentBoost; 350*89a0ef05SAndroid Build Coastguard Worker } 351*89a0ef05SAndroid Build Coastguard Worker 352*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of Encode API-0. 353*89a0ef05SAndroid Build Coastguard Worker * 354*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its alias 355*89a0ef05SAndroid Build Coastguard Worker */ 356*89a0ef05SAndroid Build Coastguard Worker status_t encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, ultrahdr_transfer_function hdr_tf, 357*89a0ef05SAndroid Build Coastguard Worker jr_compressed_ptr dest, int quality, jr_exif_ptr exif); 358*89a0ef05SAndroid Build Coastguard Worker 359*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of Encode API-1. 360*89a0ef05SAndroid Build Coastguard Worker * 361*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its actual 362*89a0ef05SAndroid Build Coastguard Worker */ 363*89a0ef05SAndroid Build Coastguard Worker status_t encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, jr_uncompressed_ptr yuv420_image_ptr, 364*89a0ef05SAndroid Build Coastguard Worker ultrahdr_transfer_function hdr_tf, jr_compressed_ptr dest, int quality, 365*89a0ef05SAndroid Build Coastguard Worker jr_exif_ptr exif); 366*89a0ef05SAndroid Build Coastguard Worker 367*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of Encode API-2. 368*89a0ef05SAndroid Build Coastguard Worker * 369*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its actual 370*89a0ef05SAndroid Build Coastguard Worker */ 371*89a0ef05SAndroid Build Coastguard Worker status_t encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, jr_uncompressed_ptr yuv420_image_ptr, 372*89a0ef05SAndroid Build Coastguard Worker jr_compressed_ptr yuv420jpg_image_ptr, ultrahdr_transfer_function hdr_tf, 373*89a0ef05SAndroid Build Coastguard Worker jr_compressed_ptr dest); 374*89a0ef05SAndroid Build Coastguard Worker 375*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of Encode API-3. 376*89a0ef05SAndroid Build Coastguard Worker * 377*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its actual 378*89a0ef05SAndroid Build Coastguard Worker */ 379*89a0ef05SAndroid Build Coastguard Worker status_t encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, jr_compressed_ptr yuv420jpg_image_ptr, 380*89a0ef05SAndroid Build Coastguard Worker ultrahdr_transfer_function hdr_tf, jr_compressed_ptr dest); 381*89a0ef05SAndroid Build Coastguard Worker 382*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of Encode API-4. 383*89a0ef05SAndroid Build Coastguard Worker * 384*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its actual 385*89a0ef05SAndroid Build Coastguard Worker */ 386*89a0ef05SAndroid Build Coastguard Worker status_t encodeJPEGR(jr_compressed_ptr yuv420jpg_image_ptr, 387*89a0ef05SAndroid Build Coastguard Worker jr_compressed_ptr gainmapjpg_image_ptr, ultrahdr_metadata_ptr metadata, 388*89a0ef05SAndroid Build Coastguard Worker jr_compressed_ptr dest); 389*89a0ef05SAndroid Build Coastguard Worker 390*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of Decode API 391*89a0ef05SAndroid Build Coastguard Worker * 392*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its actual 393*89a0ef05SAndroid Build Coastguard Worker */ 394*89a0ef05SAndroid Build Coastguard Worker status_t decodeJPEGR(jr_compressed_ptr jpegr_image_ptr, jr_uncompressed_ptr dest, 395*89a0ef05SAndroid Build Coastguard Worker float max_display_boost = FLT_MAX, jr_exif_ptr exif = nullptr, 396*89a0ef05SAndroid Build Coastguard Worker ultrahdr_output_format output_format = ULTRAHDR_OUTPUT_HDR_LINEAR, 397*89a0ef05SAndroid Build Coastguard Worker jr_uncompressed_ptr gainmap_image_ptr = nullptr, 398*89a0ef05SAndroid Build Coastguard Worker ultrahdr_metadata_ptr metadata = nullptr); 399*89a0ef05SAndroid Build Coastguard Worker 400*89a0ef05SAndroid Build Coastguard Worker /* \brief Alias of getJPEGRInfo 401*89a0ef05SAndroid Build Coastguard Worker * 402*89a0ef05SAndroid Build Coastguard Worker * \deprecated This function is deprecated. Use its actual 403*89a0ef05SAndroid Build Coastguard Worker */ 404*89a0ef05SAndroid Build Coastguard Worker status_t getJPEGRInfo(jr_compressed_ptr jpegr_image_ptr, jr_info_ptr jpegr_image_info_ptr); 405*89a0ef05SAndroid Build Coastguard Worker 406*89a0ef05SAndroid Build Coastguard Worker /*!\brief This function receives iso block and / or xmp block and parses gainmap metadata and fill 407*89a0ef05SAndroid Build Coastguard Worker * the output descriptor. If both iso block and xmp block are available, then iso block is 408*89a0ef05SAndroid Build Coastguard Worker * preferred over xmp. 409*89a0ef05SAndroid Build Coastguard Worker * 410*89a0ef05SAndroid Build Coastguard Worker * \param[in] iso_data iso memory block 411*89a0ef05SAndroid Build Coastguard Worker * \param[in] iso_size iso block size 412*89a0ef05SAndroid Build Coastguard Worker * \param[in] xmp_data xmp memory block 413*89a0ef05SAndroid Build Coastguard Worker * \param[in] xmp_size xmp block size 414*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] gainmap_metadata gainmap metadata descriptor 415*89a0ef05SAndroid Build Coastguard Worker * 416*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 417*89a0ef05SAndroid Build Coastguard Worker */ 418*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t parseGainMapMetadata(uint8_t* iso_data, size_t iso_size, uint8_t* xmp_data, 419*89a0ef05SAndroid Build Coastguard Worker size_t xmp_size, 420*89a0ef05SAndroid Build Coastguard Worker uhdr_gainmap_metadata_ext_t* uhdr_metadata); 421*89a0ef05SAndroid Build Coastguard Worker 422*89a0ef05SAndroid Build Coastguard Worker /*!\brief This method is used to tone map a hdr image 423*89a0ef05SAndroid Build Coastguard Worker * 424*89a0ef05SAndroid Build Coastguard Worker * \param[in] hdr_intent hdr image descriptor 425*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] sdr_intent sdr image descriptor 426*89a0ef05SAndroid Build Coastguard Worker * 427*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 428*89a0ef05SAndroid Build Coastguard Worker */ 429*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t toneMap(uhdr_raw_image_t* hdr_intent, uhdr_raw_image_t* sdr_intent); 430*89a0ef05SAndroid Build Coastguard Worker 431*89a0ef05SAndroid Build Coastguard Worker /*!\brief This method takes hdr intent and sdr intent and computes gainmap coefficient. 432*89a0ef05SAndroid Build Coastguard Worker * 433*89a0ef05SAndroid Build Coastguard Worker * This method is called in the encoding pipeline. It takes uncompressed 8-bit and 10-bit yuv 434*89a0ef05SAndroid Build Coastguard Worker * images as input and calculates gainmap. 435*89a0ef05SAndroid Build Coastguard Worker * 436*89a0ef05SAndroid Build Coastguard Worker * NOTE: The input images must be the same resolution. 437*89a0ef05SAndroid Build Coastguard Worker * NOTE: The SDR input is assumed to use the sRGB transfer function. 438*89a0ef05SAndroid Build Coastguard Worker * 439*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent sdr intent raw input image descriptor 440*89a0ef05SAndroid Build Coastguard Worker * \param[in] hdr_intent hdr intent raw input image descriptor 441*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] gainmap_metadata gainmap metadata descriptor 442*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] gainmap_img gainmap image descriptor 443*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_is_601 (optional) if sdr_is_601 is true, then use BT.601 444*89a0ef05SAndroid Build Coastguard Worker * gamut to represent sdr intent regardless of the value 445*89a0ef05SAndroid Build Coastguard Worker * present in the sdr intent image descriptor 446*89a0ef05SAndroid Build Coastguard Worker * \param[in] use_luminance (optional) used for single channel gainmap. If 447*89a0ef05SAndroid Build Coastguard Worker * use_luminance is true, gainmap calculation is based 448*89a0ef05SAndroid Build Coastguard Worker * on the pixel's luminance which is a weighted 449*89a0ef05SAndroid Build Coastguard Worker * combination of r, g, b channels; otherwise, gainmap 450*89a0ef05SAndroid Build Coastguard Worker * calculation is based of the maximun value of r, g, b 451*89a0ef05SAndroid Build Coastguard Worker * channels. 452*89a0ef05SAndroid Build Coastguard Worker * 453*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 454*89a0ef05SAndroid Build Coastguard Worker */ 455*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t generateGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_image_t* hdr_intent, 456*89a0ef05SAndroid Build Coastguard Worker uhdr_gainmap_metadata_ext_t* gainmap_metadata, 457*89a0ef05SAndroid Build Coastguard Worker std::unique_ptr<uhdr_raw_image_ext_t>& gainmap_img, 458*89a0ef05SAndroid Build Coastguard Worker bool sdr_is_601 = false, bool use_luminance = true); 459*89a0ef05SAndroid Build Coastguard Worker 460*89a0ef05SAndroid Build Coastguard Worker protected: 461*89a0ef05SAndroid Build Coastguard Worker /*!\brief This method takes sdr intent, gainmap image and gainmap metadata and computes hdr 462*89a0ef05SAndroid Build Coastguard Worker * intent. This method is called in the decoding pipeline. The output hdr intent image will have 463*89a0ef05SAndroid Build Coastguard Worker * same color gamut as sdr intent. 464*89a0ef05SAndroid Build Coastguard Worker * 465*89a0ef05SAndroid Build Coastguard Worker * NOTE: The SDR input is assumed to use the sRGB transfer function. 466*89a0ef05SAndroid Build Coastguard Worker * 467*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent sdr intent raw input image descriptor 468*89a0ef05SAndroid Build Coastguard Worker * \param[in] gainmap_img gainmap image descriptor 469*89a0ef05SAndroid Build Coastguard Worker * \param[in] gainmap_metadata gainmap metadata descriptor 470*89a0ef05SAndroid Build Coastguard Worker * \param[in] output_ct output color transfer 471*89a0ef05SAndroid Build Coastguard Worker * \param[in] output_format output pixel format 472*89a0ef05SAndroid Build Coastguard Worker * \param[in] max_display_boost the maximum available boost supported by a 473*89a0ef05SAndroid Build Coastguard Worker * display, the value must be greater than or equal 474*89a0ef05SAndroid Build Coastguard Worker * to 1.0 475*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store output 476*89a0ef05SAndroid Build Coastguard Worker * 477*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 478*89a0ef05SAndroid Build Coastguard Worker */ 479*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t applyGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_image_t* gainmap_img, 480*89a0ef05SAndroid Build Coastguard Worker uhdr_gainmap_metadata_ext_t* gainmap_metadata, 481*89a0ef05SAndroid Build Coastguard Worker uhdr_color_transfer_t output_ct, uhdr_img_fmt_t output_format, 482*89a0ef05SAndroid Build Coastguard Worker float max_display_boost, uhdr_raw_image_t* dest); 483*89a0ef05SAndroid Build Coastguard Worker 484*89a0ef05SAndroid Build Coastguard Worker private: 485*89a0ef05SAndroid Build Coastguard Worker /*!\brief compress gainmap image 486*89a0ef05SAndroid Build Coastguard Worker * 487*89a0ef05SAndroid Build Coastguard Worker * \param[in] gainmap_img gainmap image descriptor 488*89a0ef05SAndroid Build Coastguard Worker * \param[in] jpeg_enc_obj jpeg encoder object handle 489*89a0ef05SAndroid Build Coastguard Worker * 490*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 491*89a0ef05SAndroid Build Coastguard Worker */ 492*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t compressGainMap(uhdr_raw_image_t* gainmap_img, JpegEncoderHelper* jpeg_enc_obj); 493*89a0ef05SAndroid Build Coastguard Worker 494*89a0ef05SAndroid Build Coastguard Worker /*!\brief This method is called to separate base image and gain map image from compressed 495*89a0ef05SAndroid Build Coastguard Worker * ultrahdr image 496*89a0ef05SAndroid Build Coastguard Worker * 497*89a0ef05SAndroid Build Coastguard Worker * \param[in] jpegr_image compressed ultrahdr image descriptor 498*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] primary_image sdr image descriptor 499*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] gainmap_image gainmap image descriptor 500*89a0ef05SAndroid Build Coastguard Worker * 501*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 502*89a0ef05SAndroid Build Coastguard Worker */ 503*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t extractPrimaryImageAndGainMap(uhdr_compressed_image_t* jpegr_image, 504*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* primary_image, 505*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* gainmap_image); 506*89a0ef05SAndroid Build Coastguard Worker 507*89a0ef05SAndroid Build Coastguard Worker /*!\brief This function parses the bitstream and returns metadata that is useful for actual 508*89a0ef05SAndroid Build Coastguard Worker * decoding. This does not decode the image. That is handled by decompressImage(). 509*89a0ef05SAndroid Build Coastguard Worker * 510*89a0ef05SAndroid Build Coastguard Worker * \param[in] jpeg_image compressed jpeg image descriptor 511*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] image_info image info descriptor 512*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] img_width (optional) image width 513*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] img_height (optional) image height 514*89a0ef05SAndroid Build Coastguard Worker * 515*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 516*89a0ef05SAndroid Build Coastguard Worker */ 517*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t parseJpegInfo(uhdr_compressed_image_t* jpeg_image, j_info_ptr image_info, 518*89a0ef05SAndroid Build Coastguard Worker unsigned int* img_width = nullptr, 519*89a0ef05SAndroid Build Coastguard Worker unsigned int* img_height = nullptr); 520*89a0ef05SAndroid Build Coastguard Worker 521*89a0ef05SAndroid Build Coastguard Worker /*!\brief This method takes compressed sdr intent, compressed gainmap coefficient, gainmap 522*89a0ef05SAndroid Build Coastguard Worker * metadata and creates a ultrahdr image. This is done by first generating XMP packet from gainmap 523*89a0ef05SAndroid Build Coastguard Worker * metadata, then appending in the order, 524*89a0ef05SAndroid Build Coastguard Worker * SOI, APP2 (Exif is present), APP2 (XMP), base image, gain map image. 525*89a0ef05SAndroid Build Coastguard Worker * 526*89a0ef05SAndroid Build Coastguard Worker * NOTE: In the final output, EXIF package will appear if ONLY ONE of the following conditions is 527*89a0ef05SAndroid Build Coastguard Worker * fulfilled: 528*89a0ef05SAndroid Build Coastguard Worker * (1) EXIF package is available from outside input. I.e. pExif != nullptr. 529*89a0ef05SAndroid Build Coastguard Worker * (2) Compressed sdr intent has EXIF. 530*89a0ef05SAndroid Build Coastguard Worker * If both conditions are fulfilled, this method will return error indicating that it is unable to 531*89a0ef05SAndroid Build Coastguard Worker * choose which exif to be placed in the bitstream. 532*89a0ef05SAndroid Build Coastguard Worker * 533*89a0ef05SAndroid Build Coastguard Worker * \param[in] sdr_intent_compressed sdr intent image descriptor 534*89a0ef05SAndroid Build Coastguard Worker * \param[in] gainmap_compressed gainmap intent input image descriptor 535*89a0ef05SAndroid Build Coastguard Worker * \param[in] pExif exif block to be placed in the bitstream 536*89a0ef05SAndroid Build Coastguard Worker * \param[in] pIcc pointer to icc segment that needs to be added to the 537*89a0ef05SAndroid Build Coastguard Worker * compressed image 538*89a0ef05SAndroid Build Coastguard Worker * \param[in] icc_size size of icc segment 539*89a0ef05SAndroid Build Coastguard Worker * \param[in] metadata gainmap metadata descriptor 540*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] dest output image descriptor to store compressed ultrahdr 541*89a0ef05SAndroid Build Coastguard Worker * image 542*89a0ef05SAndroid Build Coastguard Worker * 543*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 544*89a0ef05SAndroid Build Coastguard Worker */ 545*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t appendGainMap(uhdr_compressed_image_t* sdr_intent_compressed, 546*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* gainmap_compressed, 547*89a0ef05SAndroid Build Coastguard Worker uhdr_mem_block_t* pExif, void* pIcc, size_t icc_size, 548*89a0ef05SAndroid Build Coastguard Worker uhdr_gainmap_metadata_ext_t* metadata, 549*89a0ef05SAndroid Build Coastguard Worker uhdr_compressed_image_t* dest); 550*89a0ef05SAndroid Build Coastguard Worker 551*89a0ef05SAndroid Build Coastguard Worker /*!\brief This method is used to convert a raw image from one gamut space to another gamut space 552*89a0ef05SAndroid Build Coastguard Worker * in-place. 553*89a0ef05SAndroid Build Coastguard Worker * 554*89a0ef05SAndroid Build Coastguard Worker * \param[in, out] image raw image descriptor 555*89a0ef05SAndroid Build Coastguard Worker * \param[in] src_encoding input gamut space 556*89a0ef05SAndroid Build Coastguard Worker * \param[in] dst_encoding destination gamut space 557*89a0ef05SAndroid Build Coastguard Worker * 558*89a0ef05SAndroid Build Coastguard Worker * \return uhdr_error_info_t #UHDR_CODEC_OK if operation succeeds, uhdr_codec_err_t otherwise. 559*89a0ef05SAndroid Build Coastguard Worker */ 560*89a0ef05SAndroid Build Coastguard Worker uhdr_error_info_t convertYuv(uhdr_raw_image_t* image, uhdr_color_gamut_t src_encoding, 561*89a0ef05SAndroid Build Coastguard Worker uhdr_color_gamut_t dst_encoding); 562*89a0ef05SAndroid Build Coastguard Worker 563*89a0ef05SAndroid Build Coastguard Worker /* 564*89a0ef05SAndroid Build Coastguard Worker * This method will check the validity of the input arguments. 565*89a0ef05SAndroid Build Coastguard Worker * 566*89a0ef05SAndroid Build Coastguard Worker * @param p010_image_ptr uncompressed HDR image in P010 color format 567*89a0ef05SAndroid Build Coastguard Worker * @param yuv420_image_ptr pointer to uncompressed SDR image struct. HDR image is expected to 568*89a0ef05SAndroid Build Coastguard Worker * be in 420p color format 569*89a0ef05SAndroid Build Coastguard Worker * @param hdr_tf transfer function of the HDR image 570*89a0ef05SAndroid Build Coastguard Worker * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength} 571*89a0ef05SAndroid Build Coastguard Worker * represents the maximum available size of the desitination buffer, and it must be 572*89a0ef05SAndroid Build Coastguard Worker * set before calling this method. If the encoded JPEGR size exceeds 573*89a0ef05SAndroid Build Coastguard Worker * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}. 574*89a0ef05SAndroid Build Coastguard Worker * @return NO_ERROR if the input args are valid, error code is not valid. 575*89a0ef05SAndroid Build Coastguard Worker */ 576*89a0ef05SAndroid Build Coastguard Worker status_t areInputArgumentsValid(jr_uncompressed_ptr p010_image_ptr, 577*89a0ef05SAndroid Build Coastguard Worker jr_uncompressed_ptr yuv420_image_ptr, 578*89a0ef05SAndroid Build Coastguard Worker ultrahdr_transfer_function hdr_tf, jr_compressed_ptr dest_ptr); 579*89a0ef05SAndroid Build Coastguard Worker 580*89a0ef05SAndroid Build Coastguard Worker /* 581*89a0ef05SAndroid Build Coastguard Worker * This method will check the validity of the input arguments. 582*89a0ef05SAndroid Build Coastguard Worker * 583*89a0ef05SAndroid Build Coastguard Worker * @param p010_image_ptr uncompressed HDR image in P010 color format 584*89a0ef05SAndroid Build Coastguard Worker * @param yuv420_image_ptr pointer to uncompressed SDR image struct. HDR image is expected to 585*89a0ef05SAndroid Build Coastguard Worker * be in 420p color format 586*89a0ef05SAndroid Build Coastguard Worker * @param hdr_tf transfer function of the HDR image 587*89a0ef05SAndroid Build Coastguard Worker * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength} 588*89a0ef05SAndroid Build Coastguard Worker * represents the maximum available size of the destination buffer, and it must be 589*89a0ef05SAndroid Build Coastguard Worker * set before calling this method. If the encoded JPEGR size exceeds 590*89a0ef05SAndroid Build Coastguard Worker * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}. 591*89a0ef05SAndroid Build Coastguard Worker * @param quality target quality of the JPEG encoding, must be in range of 0-100 where 100 is 592*89a0ef05SAndroid Build Coastguard Worker * the highest quality 593*89a0ef05SAndroid Build Coastguard Worker * @return NO_ERROR if the input args are valid, error code is not valid. 594*89a0ef05SAndroid Build Coastguard Worker */ 595*89a0ef05SAndroid Build Coastguard Worker status_t areInputArgumentsValid(jr_uncompressed_ptr p010_image_ptr, 596*89a0ef05SAndroid Build Coastguard Worker jr_uncompressed_ptr yuv420_image_ptr, 597*89a0ef05SAndroid Build Coastguard Worker ultrahdr_transfer_function hdr_tf, jr_compressed_ptr dest, 598*89a0ef05SAndroid Build Coastguard Worker int quality); 599*89a0ef05SAndroid Build Coastguard Worker 600*89a0ef05SAndroid Build Coastguard Worker // Configurations 601*89a0ef05SAndroid Build Coastguard Worker void* mUhdrGLESCtxt; // opengl es context 602*89a0ef05SAndroid Build Coastguard Worker int mMapDimensionScaleFactor; // gain map scale factor 603*89a0ef05SAndroid Build Coastguard Worker int mMapCompressQuality; // gain map quality factor 604*89a0ef05SAndroid Build Coastguard Worker bool mUseMultiChannelGainMap; // enable multichannel gain map 605*89a0ef05SAndroid Build Coastguard Worker float mGamma; // gain map gamma parameter 606*89a0ef05SAndroid Build Coastguard Worker uhdr_enc_preset_t mEncPreset; // encoding speed preset 607*89a0ef05SAndroid Build Coastguard Worker float mMinContentBoost; // min content boost recommendation 608*89a0ef05SAndroid Build Coastguard Worker float mMaxContentBoost; // max content boost recommendation 609*89a0ef05SAndroid Build Coastguard Worker float mTargetDispPeakBrightness; // target display max luminance in nits 610*89a0ef05SAndroid Build Coastguard Worker }; 611*89a0ef05SAndroid Build Coastguard Worker 612*89a0ef05SAndroid Build Coastguard Worker /* 613*89a0ef05SAndroid Build Coastguard Worker * Holds tonemapping results of a pixel 614*89a0ef05SAndroid Build Coastguard Worker */ 615*89a0ef05SAndroid Build Coastguard Worker struct GlobalTonemapOutputs { 616*89a0ef05SAndroid Build Coastguard Worker std::array<float, 3> rgb_out; 617*89a0ef05SAndroid Build Coastguard Worker float y_hdr; 618*89a0ef05SAndroid Build Coastguard Worker float y_sdr; 619*89a0ef05SAndroid Build Coastguard Worker }; 620*89a0ef05SAndroid Build Coastguard Worker 621*89a0ef05SAndroid Build Coastguard Worker /*!\brief Applies a global tone mapping, based on Chrome's HLG/PQ rendering implemented at 622*89a0ef05SAndroid Build Coastguard Worker * https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/color_transform.cc;l=1197-1252;drc=ac505aff1d29ec3bfcf317cb77d5e196a3664e92 623*89a0ef05SAndroid Build Coastguard Worker * 624*89a0ef05SAndroid Build Coastguard Worker * \param[in] rgb_in hdr intent pixel in array format. 625*89a0ef05SAndroid Build Coastguard Worker * \param[in] headroom ratio between hdr and sdr peak luminances. Must be greater 626*89a0ef05SAndroid Build Coastguard Worker * than 1. If the input is normalized, then this is used to 627*89a0ef05SAndroid Build Coastguard Worker * stretch it linearly from [0.0..1.0] to [0.0..headroom] 628*89a0ef05SAndroid Build Coastguard Worker * \param[in] is_normalized marker to differentiate, if the input is normalized. 629*89a0ef05SAndroid Build Coastguard Worker * 630*89a0ef05SAndroid Build Coastguard Worker * \return tonemapped pixel in the normalized range [0.0..1.0] 631*89a0ef05SAndroid Build Coastguard Worker */ 632*89a0ef05SAndroid Build Coastguard Worker GlobalTonemapOutputs globalTonemap(const std::array<float, 3>& rgb_in, float headroom, 633*89a0ef05SAndroid Build Coastguard Worker bool is_normalized); 634*89a0ef05SAndroid Build Coastguard Worker 635*89a0ef05SAndroid Build Coastguard Worker } // namespace ultrahdr 636*89a0ef05SAndroid Build Coastguard Worker 637*89a0ef05SAndroid Build Coastguard Worker #endif // ULTRAHDR_JPEGR_H 638