Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0823a7b8 authored by Dichen Zhang's avatar Dichen Zhang Committed by Automerger Merge Worker
Browse files

Merge "JPEG/R: Add display_boost parameter to decode API" into udc-dev am: 10b3da75

parents 00f01cf4 10b3da75
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -206,6 +206,7 @@ public:
     *
     *
     * @param compressed_jpegr_image compressed JPEGR image.
     * @param compressed_jpegr_image compressed JPEGR image.
     * @param dest destination of the uncompressed JPEGR image.
     * @param dest destination of the uncompressed JPEGR image.
     * @param max_display_boost (optional) the maximum available boost supported by a display
     * @param exif destination of the decoded EXIF metadata. The default value is NULL where the
     * @param exif destination of the decoded EXIF metadata. The default value is NULL where the
                   decoder will do nothing about it. If configured not NULL the decoder will write
                   decoder will do nothing about it. If configured not NULL the decoder will write
                   EXIF data into this structure. The format is defined in {@code jpegr_exif_struct}
                   EXIF data into this structure. The format is defined in {@code jpegr_exif_struct}
@@ -234,6 +235,7 @@ public:
     */
     */
    status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
    status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
                         jr_uncompressed_ptr dest,
                         jr_uncompressed_ptr dest,
                         float max_display_boost = -1.0f,
                         jr_exif_ptr exif = nullptr,
                         jr_exif_ptr exif = nullptr,
                         jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR,
                         jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR,
                         jr_uncompressed_ptr recovery_map = nullptr,
                         jr_uncompressed_ptr recovery_map = nullptr,
@@ -281,6 +283,7 @@ protected:
     * @param output_format flag for setting output color format. if set to
     * @param output_format flag for setting output color format. if set to
     *                      {@code JPEGR_OUTPUT_SDR}, decoder will only decode the primary image
     *                      {@code JPEGR_OUTPUT_SDR}, decoder will only decode the primary image
     *                      which is SDR. Default value is JPEGR_OUTPUT_HDR_LINEAR.
     *                      which is SDR. Default value is JPEGR_OUTPUT_HDR_LINEAR.
     * @param max_display_boost the maximum available boost supported by a display
     * @param dest reconstructed HDR image
     * @param dest reconstructed HDR image
     * @return NO_ERROR if calculation succeeds, error code if error occurs.
     * @return NO_ERROR if calculation succeeds, error code if error occurs.
     */
     */
@@ -288,6 +291,7 @@ protected:
                              jr_uncompressed_ptr uncompressed_recovery_map,
                              jr_uncompressed_ptr uncompressed_recovery_map,
                              jr_metadata_ptr metadata,
                              jr_metadata_ptr metadata,
                              jpegr_output_format output_format,
                              jpegr_output_format output_format,
                              float max_display_boost,
                              jr_uncompressed_ptr dest);
                              jr_uncompressed_ptr dest);


private:
private:
+11 −0
Original line number Original line Diff line number Diff line
@@ -135,6 +135,16 @@ struct RecoveryLUT {
    }
    }
  }
  }


  RecoveryLUT(jr_metadata_ptr metadata, float displayBoost) {
    float boostFactor = displayBoost > 0 ? displayBoost / metadata->maxContentBoost : 1.0f;
    for (int idx = 0; idx < kRecoveryFactorNumEntries; idx++) {
      float value = static_cast<float>(idx) / static_cast<float>(kRecoveryFactorNumEntries - 1);
      float logBoost = log2(metadata->minContentBoost) * (1.0f - value)
                     + log2(metadata->maxContentBoost) * value;
      mRecoveryTable[idx] = exp2(logBoost * boostFactor);
    }
  }

  ~RecoveryLUT() {
  ~RecoveryLUT() {
  }
  }


@@ -357,6 +367,7 @@ uint8_t encodeRecovery(float y_sdr, float y_hdr, jr_metadata_ptr metadata);
 * value, with the given hdr ratio, to the given sdr input in the range [0, 1].
 * value, with the given hdr ratio, to the given sdr input in the range [0, 1].
 */
 */
Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata);
Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata);
Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost);
Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT);
Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT);


/*
/*
+11 −6
Original line number Original line Diff line number Diff line
@@ -330,6 +330,7 @@ status_t JpegR::getJPEGRInfo(jr_compressed_ptr compressed_jpegr_image, jr_info_p
/* Decode API */
/* Decode API */
status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
                            jr_uncompressed_ptr dest,
                            jr_uncompressed_ptr dest,
                            float max_display_boost,
                            jr_exif_ptr exif,
                            jr_exif_ptr exif,
                            jpegr_output_format output_format,
                            jpegr_output_format output_format,
                            jr_uncompressed_ptr recovery_map,
                            jr_uncompressed_ptr recovery_map,
@@ -431,7 +432,7 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
  uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight();
  uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight();


  JPEGR_CHECK(applyRecoveryMap(&uncompressed_yuv_420_image, &map, &jr_metadata, output_format,
  JPEGR_CHECK(applyRecoveryMap(&uncompressed_yuv_420_image, &map, &jr_metadata, output_format,
                               dest));
                               max_display_boost, dest));
  return NO_ERROR;
  return NO_ERROR;
}
}


@@ -667,6 +668,7 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
                                 jr_uncompressed_ptr uncompressed_recovery_map,
                                 jr_uncompressed_ptr uncompressed_recovery_map,
                                 jr_metadata_ptr metadata,
                                 jr_metadata_ptr metadata,
                                 jpegr_output_format output_format,
                                 jpegr_output_format output_format,
                                 float max_display_boost,
                                 jr_uncompressed_ptr dest) {
                                 jr_uncompressed_ptr dest) {
  if (uncompressed_yuv_420_image == nullptr
  if (uncompressed_yuv_420_image == nullptr
   || uncompressed_recovery_map == nullptr
   || uncompressed_recovery_map == nullptr
@@ -678,13 +680,15 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
  dest->width = uncompressed_yuv_420_image->width;
  dest->width = uncompressed_yuv_420_image->width;
  dest->height = uncompressed_yuv_420_image->height;
  dest->height = uncompressed_yuv_420_image->height;
  ShepardsIDW idwTable(kMapDimensionScaleFactor);
  ShepardsIDW idwTable(kMapDimensionScaleFactor);
  RecoveryLUT recoveryLUT(metadata);
  float display_boost = max_display_boost > 0 ?
          std::min(max_display_boost, metadata->maxContentBoost)
          : metadata->maxContentBoost;
  RecoveryLUT recoveryLUT(metadata, display_boost);


  JobQueue jobQueue;
  JobQueue jobQueue;
  std::function<void()> applyRecMap = [uncompressed_yuv_420_image, uncompressed_recovery_map,
  std::function<void()> applyRecMap = [uncompressed_yuv_420_image, uncompressed_recovery_map,
                                       metadata, dest, &jobQueue, &idwTable, output_format,
                                       metadata, dest, &jobQueue, &idwTable, output_format,
                                       &recoveryLUT]() -> void {
                                       &recoveryLUT, display_boost]() -> void {
    const float hdr_ratio = metadata->maxContentBoost;
    size_t width = uncompressed_yuv_420_image->width;
    size_t width = uncompressed_yuv_420_image->width;
    size_t height = uncompressed_yuv_420_image->height;
    size_t height = uncompressed_yuv_420_image->height;


@@ -710,12 +714,13 @@ status_t JpegR::applyRecoveryMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
          } else {
          } else {
            recovery = sampleMap(uncompressed_recovery_map, map_scale_factor, x, y, idwTable);
            recovery = sampleMap(uncompressed_recovery_map, map_scale_factor, x, y, idwTable);
          }
          }

#if USE_APPLY_RECOVERY_LUT
#if USE_APPLY_RECOVERY_LUT
          Color rgb_hdr = applyRecoveryLUT(rgb_sdr, recovery, recoveryLUT);
          Color rgb_hdr = applyRecoveryLUT(rgb_sdr, recovery, recoveryLUT);
#else
#else
          Color rgb_hdr = applyRecovery(rgb_sdr, recovery, metadata);
          Color rgb_hdr = applyRecovery(rgb_sdr, recovery, metadata, display_boost);
#endif
#endif
          rgb_hdr = rgb_hdr / metadata->maxContentBoost;
          rgb_hdr = rgb_hdr / display_boost;
          size_t pixel_idx = x + y * width;
          size_t pixel_idx = x + y * width;


          switch (output_format) {
          switch (output_format) {
+7 −0
Original line number Original line Diff line number Diff line
@@ -463,6 +463,13 @@ Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata) {
  return e * recoveryFactor;
  return e * recoveryFactor;
}
}


Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata, float displayBoost) {
  float logBoost = log2(metadata->minContentBoost) * (1.0f - recovery)
                 + log2(metadata->maxContentBoost) * recovery;
  float recoveryFactor = exp2(logBoost * displayBoost / metadata->maxContentBoost);
  return e * recoveryFactor;
}

Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT) {
Color applyRecoveryLUT(Color e, float recovery, RecoveryLUT& recoveryLUT) {
  float recoveryFactor = recoveryLUT.getRecoveryFactor(recovery);
  float recoveryFactor = recoveryLUT.getRecoveryFactor(recovery);
  return e * recoveryFactor;
  return e * recoveryFactor;
+3 −2
Original line number Original line Diff line number Diff line
@@ -152,7 +152,8 @@ void JpegRBenchmark::BenchmarkApplyRecoveryMap(jr_uncompressed_ptr yuv420Image,


  timerStart(&applyRecMapTime);
  timerStart(&applyRecMapTime);
  for (auto i = 0; i < kProfileCount; i++) {
  for (auto i = 0; i < kProfileCount; i++) {
      ASSERT_EQ(OK, applyRecoveryMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG, dest));
      ASSERT_EQ(OK, applyRecoveryMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG,
                                     metadata->maxContentBoost /* displayBoost */, dest));
  }
  }
  timerStop(&applyRecMapTime);
  timerStop(&applyRecMapTime);


@@ -170,7 +171,7 @@ TEST_F(JpegRTest, build) {
  jpegRCodec.encodeJPEGR(nullptr, nullptr, nullptr, static_cast<jpegr_transfer_function>(0),
  jpegRCodec.encodeJPEGR(nullptr, nullptr, nullptr, static_cast<jpegr_transfer_function>(0),
                         nullptr);
                         nullptr);
  jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr);
  jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr);
  jpegRCodec.decodeJPEGR(nullptr, nullptr, nullptr);
  jpegRCodec.decodeJPEGR(nullptr, nullptr);
}
}


TEST_F(JpegRTest, writeXmpThenRead) {
TEST_F(JpegRTest, writeXmpThenRead) {
Loading