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

Commit e286f1c7 authored by Dichen Zhang's avatar Dichen Zhang
Browse files

JPEG/R: minor update for decoder.

Expose metadata for the decoder
Updata document
Rename "jpegr_metadata" to "jpegr_metadata_struct"

Bug: b/264715926
Test: jpegr_test

Change-Id: I6d97209453b2338996f5dc2aabfbdbe3e8a8c20c
parent e32fafd3
Loading
Loading
Loading
Loading
+35 −11
Original line number Diff line number Diff line
@@ -91,7 +91,10 @@ struct jpegr_exif_struct {
    int length;
};

struct jpegr_metadata {
/*
 * Holds information for recovery map related metadata.
 */
struct jpegr_metadata_struct {
  // JPEG/R version
  uint32_t version;
  // Max Content Boost for the map
@@ -103,12 +106,14 @@ struct jpegr_metadata {
typedef struct jpegr_uncompressed_struct* jr_uncompressed_ptr;
typedef struct jpegr_compressed_struct* jr_compressed_ptr;
typedef struct jpegr_exif_struct* jr_exif_ptr;
typedef struct jpegr_metadata* jr_metadata_ptr;
typedef struct jpegr_metadata_struct* jr_metadata_ptr;
typedef struct jpegr_info_struct* jr_info_ptr;

class JpegR {
public:
    /*
     * Experimental only
     *
     * Encode API-0
     * Compress JPEGR image from 10-bit HDR YUV.
     *
@@ -199,21 +204,40 @@ public:
     * Decode API
     * Decompress JPEGR image.
     *
     * The output JPEGR image is in RGBA_1010102 data format if decoding to HDR.
     * @param compressed_jpegr_image compressed JPEGR image
     * @param dest destination of the uncompressed JPEGR image
     * @param exif destination of the decoded EXIF metadata.
     * @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 recovery_map destination of the decoded recovery map.
     * @param compressed_jpegr_image compressed JPEGR image.
     * @param dest destination of the uncompressed JPEGR image.
     * @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}
     * @param output_format flag for setting output color format. Its value configures the output
                            color format. The default value is {@code JPEGR_OUTPUT_HDR_LINEAR}.
                            ----------------------------------------------------------------------
                            |   output_format          |    decoded color format to be written   |
                            ----------------------------------------------------------------------
                            |     JPEGR_OUTPUT_SDR     |                RGBA_8888                |
                            ----------------------------------------------------------------------
                            | JPEGR_OUTPUT_HDR_LINEAR  |        (default)RGBA_F16 linear         |
                            ----------------------------------------------------------------------
                            |   JPEGR_OUTPUT_HDR_PQ    |             RGBA_1010102 PQ             |
                            ----------------------------------------------------------------------
                            |   JPEGR_OUTPUT_HDR_HLG   |            RGBA_1010102 HLG             |
                            ----------------------------------------------------------------------
     * @param recovery_map destination of the decoded recovery map. The default value is NULL where
                           the decoder will do nothing about it. If configured not NULL the decoder
                           will write the decoded recovery_map data into this structure. The format
                           is defined in {@code jpegr_uncompressed_struct}.
     * @param metadata destination of the decoded metadata. The default value is NULL where the
                       decoder will do nothing about it. If configured not NULL the decoder will
                       write metadata into this structure. the format of metadata is defined in
                       {@code jpegr_metadata}.
     * @return NO_ERROR if decoding succeeds, error code if error occurs.
     */
    status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
                         jr_uncompressed_ptr dest,
                         jr_exif_ptr exif = nullptr,
                         jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR,
                         jr_uncompressed_ptr recovery_map = nullptr);
                         jr_uncompressed_ptr recovery_map = nullptr,
                         jr_metadata_ptr metadata = nullptr);

    /*
    * Gets Info from JPEGR file without decoding it.
+3 −3
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ static inline uint16_t EndianSwap16(uint16_t value) {
    #define Endian_SwapBE16(n) (n)
#endif

struct jpegr_metadata;
struct jpegr_metadata_struct;
/*
 * Mutable data structure. Holds information for metadata.
 */
@@ -87,7 +87,7 @@ status_t Write(jr_compressed_ptr destination, const void* source, size_t length,
 * @param metadata place to store HDR metadata values
 * @return true if metadata is successfully retrieved, false otherwise
*/
bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* metadata);
bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata_struct* metadata);

/*
 * This method generates XMP metadata for the primary image.
@@ -156,7 +156,7 @@ std::string generateXmpForPrimaryImage(int secondary_image_length);
 * @param metadata JPEG/R metadata to encode as XMP
 * @return XMP metadata in type of string
 */
 std::string generateXmpForSecondaryImage(jpegr_metadata& metadata);
 std::string generateXmpForSecondaryImage(jpegr_metadata_struct& metadata);
}  // namespace android::jpegrecoverymap

#endif //ANDROID_JPEGRECOVERYMAP_JPEGRUTILS_H
+20 −12
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
    return ERROR_JPEGR_INVALID_INPUT_TYPE;
  }

  jpegr_metadata metadata;
  jpegr_metadata_struct metadata;
  metadata.version = kJpegrVersion;

  jpegr_uncompressed_struct uncompressed_yuv_420_image;
@@ -176,7 +176,7 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
    return ERROR_JPEGR_INVALID_INPUT_TYPE;
  }

  jpegr_metadata metadata;
  jpegr_metadata_struct metadata;
  metadata.version = kJpegrVersion;

  jpegr_uncompressed_struct map;
@@ -235,7 +235,7 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
    return ERROR_JPEGR_INVALID_INPUT_TYPE;
  }

  jpegr_metadata metadata;
  jpegr_metadata_struct metadata;
  metadata.version = kJpegrVersion;

  jpegr_uncompressed_struct map;
@@ -288,7 +288,7 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
    return ERROR_JPEGR_RESOLUTION_MISMATCH;
  }

  jpegr_metadata metadata;
  jpegr_metadata_struct metadata;
  metadata.version = kJpegrVersion;

  jpegr_uncompressed_struct map;
@@ -332,7 +332,8 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
                            jr_uncompressed_ptr dest,
                            jr_exif_ptr exif,
                            jpegr_output_format output_format,
                            jr_uncompressed_ptr recovery_map) {
                            jr_uncompressed_ptr recovery_map,
                            jr_metadata_ptr metadata) {
  if (compressed_jpegr_image == nullptr || dest == nullptr) {
    return ERROR_JPEGR_INVALID_NULL_PTR;
  }
@@ -387,6 +388,18 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
    memcpy(recovery_map->data, recovery_map_decoder.getDecompressedImagePtr(), size);
  }

  jpegr_metadata_struct jr_metadata;
  if (!getMetadataFromXMP(static_cast<uint8_t*>(recovery_map_decoder.getXMPPtr()),
                          recovery_map_decoder.getXMPSize(), &jr_metadata)) {
    return ERROR_JPEGR_DECODE_ERROR;
  }

  if (metadata != nullptr) {
      metadata->version = jr_metadata.version;
      metadata->minContentBoost = jr_metadata.minContentBoost;
      metadata->maxContentBoost = jr_metadata.maxContentBoost;
  }

  if (output_format == JPEGR_OUTPUT_SDR) {
    return NO_ERROR;
  }
@@ -417,13 +430,8 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
  uncompressed_yuv_420_image.width = jpeg_decoder.getDecompressedImageWidth();
  uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight();

  jpegr_metadata metadata;
  if (!getMetadataFromXMP(static_cast<uint8_t*>(recovery_map_decoder.getXMPPtr()),
                          recovery_map_decoder.getXMPSize(), &metadata)) {
    return ERROR_JPEGR_DECODE_ERROR;
  }

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

+2 −2
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ const string kMapBaseRendition = Name(kRecoveryMapPrefix, "BaseRendition");
const string XMPXmlHandler::minContentBoostAttrName = kMapGainMapMin;
const string XMPXmlHandler::maxContentBoostAttrName = kMapGainMapMax;

bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata* metadata) {
bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata_struct* metadata) {
    string nameSpace = "http://ns.adobe.com/xap/1.0/\0";

    if (xmp_size < nameSpace.size()+2) {
@@ -327,7 +327,7 @@ string generateXmpForPrimaryImage(int secondary_image_length) {
  return ss.str();
}

string generateXmpForSecondaryImage(jpegr_metadata& metadata) {
string generateXmpForSecondaryImage(jpegr_metadata_struct& metadata) {
  const vector<string> kConDirSeq({kConDirectory, string("rdf:Seq")});
  const vector<string> kLiItem({string("rdf:li"), kConItem});

+3 −3
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ TEST_F(JpegRTest, build) {
}

TEST_F(JpegRTest, writeXmpThenRead) {
  jpegr_metadata metadata_expected;
  jpegr_metadata_struct metadata_expected;
  metadata_expected.maxContentBoost = 1.25;
  metadata_expected.minContentBoost = 0.75;
  const std::string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
@@ -189,7 +189,7 @@ TEST_F(JpegRTest, writeXmpThenRead) {
  xmpData.insert(xmpData.end(), reinterpret_cast<const uint8_t*>(xmp.c_str()),
                  reinterpret_cast<const uint8_t*>(xmp.c_str()) + xmp.size());

  jpegr_metadata metadata_read;
  jpegr_metadata_struct metadata_read;
  EXPECT_TRUE(getMetadataFromXMP(xmpData.data(), xmpData.size(), &metadata_read));
  ASSERT_EQ(metadata_expected.maxContentBoost, metadata_read.maxContentBoost);
  ASSERT_EQ(metadata_expected.minContentBoost, metadata_read.minContentBoost);
@@ -476,7 +476,7 @@ TEST_F(JpegRTest, ProfileRecoveryMapFuncs) {

  JpegRBenchmark benchmark;

  jpegr_metadata metadata = { .version = 1,
  jpegr_metadata_struct metadata = { .version = 1,
                              .maxContentBoost = 8.0f,
                              .minContentBoost = 1.0f / 8.0f };

Loading