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 Diff line number Diff line
@@ -206,6 +206,7 @@ public:
     *
     * @param compressed_jpegr_image compressed 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
                   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}
@@ -234,6 +235,7 @@ public:
     */
    status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
                         jr_uncompressed_ptr dest,
                         float max_display_boost = -1.0f,
                         jr_exif_ptr exif = nullptr,
                         jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR,
                         jr_uncompressed_ptr recovery_map = nullptr,
@@ -281,6 +283,7 @@ protected:
     * @param output_format flag for setting output color format. if set to
     *                      {@code JPEGR_OUTPUT_SDR}, decoder will only decode the primary image
     *                      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
     * @return NO_ERROR if calculation succeeds, error code if error occurs.
     */
@@ -288,6 +291,7 @@ protected:
                              jr_uncompressed_ptr uncompressed_recovery_map,
                              jr_metadata_ptr metadata,
                              jpegr_output_format output_format,
                              float max_display_boost,
                              jr_uncompressed_ptr dest);

private:
+11 −0
Original line number 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() {
  }

@@ -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].
 */
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);

/*
+11 −6
Original line number Diff line number Diff line
@@ -330,6 +330,7 @@ status_t JpegR::getJPEGRInfo(jr_compressed_ptr compressed_jpegr_image, jr_info_p
/* Decode API */
status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
                            jr_uncompressed_ptr dest,
                            float max_display_boost,
                            jr_exif_ptr exif,
                            jpegr_output_format output_format,
                            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();

  JPEGR_CHECK(applyRecoveryMap(&uncompressed_yuv_420_image, &map, &jr_metadata, output_format,
                               dest));
                               max_display_boost, dest));
  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_metadata_ptr metadata,
                                 jpegr_output_format output_format,
                                 float max_display_boost,
                                 jr_uncompressed_ptr dest) {
  if (uncompressed_yuv_420_image == 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->height = uncompressed_yuv_420_image->height;
  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;
  std::function<void()> applyRecMap = [uncompressed_yuv_420_image, uncompressed_recovery_map,
                                       metadata, dest, &jobQueue, &idwTable, output_format,
                                       &recoveryLUT]() -> void {
    const float hdr_ratio = metadata->maxContentBoost;
                                       &recoveryLUT, display_boost]() -> void {
    size_t width = uncompressed_yuv_420_image->width;
    size_t height = uncompressed_yuv_420_image->height;

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

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

          switch (output_format) {
+7 −0
Original line number Diff line number Diff line
@@ -463,6 +463,13 @@ Color applyRecovery(Color e, float recovery, jr_metadata_ptr metadata) {
  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) {
  float recoveryFactor = recoveryLUT.getRecoveryFactor(recovery);
  return e * recoveryFactor;
+3 −2
Original line number Diff line number Diff line
@@ -152,7 +152,8 @@ void JpegRBenchmark::BenchmarkApplyRecoveryMap(jr_uncompressed_ptr yuv420Image,

  timerStart(&applyRecMapTime);
  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);

@@ -170,7 +171,7 @@ TEST_F(JpegRTest, build) {
  jpegRCodec.encodeJPEGR(nullptr, 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) {
Loading