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

Commit 8ecd08e7 authored by Dichen Zhang's avatar Dichen Zhang Committed by Android (Google) Code Review
Browse files

Merge "libjpegrecoverymap: refactor of public APIs"

parents 369cbd15 ffa34015
Loading
Loading
Loading
Loading
+59 −5
Original line number Diff line number Diff line
@@ -18,6 +18,13 @@

namespace android::recoverymap {

typedef enum {
  JPEGR_COLORSPACE_UNSPECIFIED,
  JPEGR_COLORSPACE_BT709,
  JPEGR_COLORSPACE_P3,
  JPEGR_COLORSPACE_BT2100,
} jpegr_color_space;

/*
 * Holds information for uncompressed image or recovery map.
 */
@@ -28,12 +35,26 @@ struct jpegr_uncompressed_struct {
    int width;
    // Height of the recovery map or image in pixels.
    int height;
    // Color space.
    jpegr_color_space colorSpace;
};

/*
 * Holds information for compressed image or recovery map.
 */
struct jpegr_compressed_struct {
    // Pointer to the data location.
    void* data;
    // Data length.
    int length;
    // Color space.
    jpegr_color_space colorSpace;
};

/*
 * Holds information for EXIF metadata.
 */
struct jpegr_exif_struct {
    // Pointer to the data location.
    void* data;
    // Data length;
@@ -42,6 +63,7 @@ struct jpegr_compressed_struct {

typedef struct jpegr_uncompressed_struct* jr_uncompressed_ptr;
typedef struct jpegr_compressed_struct* jr_compressed_ptr;
typedef struct jpegr_exif_struct* jr_exif_ptr;

class RecoveryMap {
public:
@@ -53,14 +75,24 @@ public:
     * @param uncompressed_p010_image uncompressed HDR image in P010 color format
     * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format
     * @param dest destination of the compressed JPEGR image
     * @param quality target quality of the JPEG encoding, must be in range of 0-100 where 100 is
     *                the highest quality
     * @param exif pointer to the exif metadata.
     * @param hdr_ratio HDR ratio. If not configured, this value will be calculated by the JPEG/R
     *                  encoder.
     * @return NO_ERROR if encoding succeeds, error code if error occurs.
     */
    status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
                         jr_uncompressed_ptr uncompressed_yuv_420_image,
                         void* dest);
                         void* dest,
                         int quality,
                         jr_exif_ptr exif,
                         float hdr_ratio = 0.0f);

    /*
     * Compress JPEGR image from 10-bit HDR YUV and 8-bit SDR YUV.
     * Compress JPEGR image from 10-bit HDR YUV, 8-bit SDR YUV and compressed 8-bit JPEG.
     *
     * This method requires HAL Hardware JPEG encoder.
     *
     * Generate recovery map from the HDR and SDR inputs, append the recovery map to the end of the
     * compressed JPEG.
@@ -68,35 +100,57 @@ public:
     * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format
     * @param compressed_jpeg_image compressed 8-bit JPEG image
     * @param dest destination of the compressed JPEGR image
     * @param hdr_ratio HDR ratio. If not configured, this value will be calculated by the JPEG/R
     *                  encoder.
     * @return NO_ERROR if encoding succeeds, error code if error occurs.
     */
    status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
                         jr_uncompressed_ptr uncompressed_yuv_420_image,
                         void* compressed_jpeg_image,
                         void* dest);
                         void* dest,
                         float hdr_ratio = 0.0f);

    /*
     * Compress JPEGR image from 10-bit HDR YUV and 8-bit SDR YUV.
     *
     * This method requires HAL Hardware JPEG encoder.
     *
     * Decode the compressed 8-bit JPEG image to YUV SDR, generate recovery map from the HDR input
     * and the decoded SDR result, append the recovery map to the end of the compressed JPEG.
     * @param uncompressed_p010_image uncompressed HDR image in P010 color format
     * @param compressed_jpeg_image compressed 8-bit JPEG image
     * @param dest destination of the compressed JPEGR image
     * @param hdr_ratio HDR ratio. If not configured, this value will be calculated by the JPEG/R
     *                  encoder.
     * @return NO_ERROR if encoding succeeds, error code if error occurs.
     */
    status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
                         void* compressed_jpeg_image,
                         void* dest);
                         void* dest,
                         float hdr_ratio = 0.0f);

    /*
     * Decompress JPEGR image.
     *
     * @param compressed_jpegr_image compressed JPEGR image
     * @param dest destination of the uncompressed JPEGR image
     * @param exif destination of the decoded EXIF metadata. Default value is nullptr where EXIF
     *             metadata will not be decoded.
     * @param request_sdr flag that request SDR output, default to false (request HDR output). If
     *                    set to true, decoder will only decode the primary image which is SDR.
     *                    Setting of request_sdr and input source (HDR or SDR) can be found in
     *                    the table below:
     *                    |  input source  |  request_sdr  |  output of decoding  |
     *                    |       HDR      |     true      |          SDR         |
     *                    |       HDR      |     false     |          HDR         |
     *                    |       SDR      |     true      |          SDR         |
     *                    |       SDR      |     false     |          SDR         |
     * @return NO_ERROR if decoding succeeds, error code if error occurs.
     */
    status_t decodeJPEGR(void* compressed_jpegr_image, jr_uncompressed_ptr dest);
    status_t decodeJPEGR(void* compressed_jpegr_image,
                         jr_uncompressed_ptr dest,
                         jr_exif_ptr exif = nullptr,
                         bool request_sdr = false);
private:
    /*
     * This method is called in the decoding pipeline. It will decode the recovery map.
+16 −4
Original line number Diff line number Diff line
@@ -20,13 +20,20 @@ namespace android::recoverymap {

status_t RecoveryMap::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
                                  jr_uncompressed_ptr uncompressed_yuv_420_image,
                                  void* dest) {
                                  void* dest,
                                  int quality,
                                  jr_exif_ptr /* exif */,
                                  float /* hdr_ratio */) {
  if (uncompressed_p010_image == nullptr
   || uncompressed_yuv_420_image == nullptr
   || dest == nullptr) {
    return ERROR_JPEGR_INVALID_NULL_PTR;
  }

  if (quality < 0 || quality > 100) {
    return ERROR_JPEGR_INVALID_INPUT_TYPE;
  }

  // TBD
  return NO_ERROR;
}
@@ -34,7 +41,8 @@ status_t RecoveryMap::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
status_t RecoveryMap::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
                                  jr_uncompressed_ptr uncompressed_yuv_420_image,
                                  void* compressed_jpeg_image,
                                  void* dest) {
                                  void* dest,
                                  float /* hdr_ratio */) {

  if (uncompressed_p010_image == nullptr
   || uncompressed_yuv_420_image == nullptr
@@ -49,7 +57,8 @@ status_t RecoveryMap::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,

status_t RecoveryMap::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
                                  void* compressed_jpeg_image,
                                  void* dest) {
                                  void* dest,
                                  float /* hdr_ratio */) {
  if (uncompressed_p010_image == nullptr
   || compressed_jpeg_image == nullptr
   || dest == nullptr) {
@@ -60,7 +69,10 @@ status_t RecoveryMap::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
  return NO_ERROR;
}

status_t RecoveryMap::decodeJPEGR(void* compressed_jpegr_image, jr_uncompressed_ptr dest) {
status_t RecoveryMap::decodeJPEGR(void* compressed_jpegr_image,
                                  jr_uncompressed_ptr dest,
                                  jr_exif_ptr /* exif */,
                                  bool /* request_sdr */) {
  if (compressed_jpegr_image == nullptr || dest == nullptr) {
    return ERROR_JPEGR_INVALID_NULL_PTR;
  }