libjpegrecoverymap: refactor of public APIs
1. Add color space enumerator and add this field to
jpegr_compressed/uncompressed_struct
2. Add EXIF structure and add this field to encode/decode methods.
3. Add request_sdr flag in the decode API.
4. Add quality parameter in the encode API.
5. Change in comments.
Bug: b/252835416
Test: build
Change-Id: Ic28041cd7ba2500dc9e8608aeb273fa79a8b2fd1
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
index 31f1872..d8647b6 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
@@ -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,6 +35,8 @@
int width;
// Height of the recovery map or image in pixels.
int height;
+ // Color space.
+ jpegr_color_space colorSpace;
};
/*
@@ -36,12 +45,25 @@
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;
int length;
};
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 @@
* @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 @@
* @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.
diff --git a/libs/jpegrecoverymap/recoverymap.cpp b/libs/jpegrecoverymap/recoverymap.cpp
index 67c23e9..7cedae9 100644
--- a/libs/jpegrecoverymap/recoverymap.cpp
+++ b/libs/jpegrecoverymap/recoverymap.cpp
@@ -20,13 +20,20 @@
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,
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,
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 @@
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;
}