summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dichen Zhang <dichenzhang@google.com> 2023-02-25 00:12:44 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-02-25 00:12:44 +0000
commitb833f58c30ac3186df64950a0962bae17ec8621d (patch)
treeaa8a9e8467d967efe670ebd80bb13cc010dac240
parente319cc6b2f3422df09a47efc77ae015313e4694d (diff)
parent15345ea885bde901532635068621a2dbae8f66fa (diff)
Merge "jpegr mpf: fix bug" into udc-dev
-rw-r--r--libs/jpegrecoverymap/jpegr.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/libs/jpegrecoverymap/jpegr.cpp b/libs/jpegrecoverymap/jpegr.cpp
index 09a4315480..c22020a903 100644
--- a/libs/jpegrecoverymap/jpegr.cpp
+++ b/libs/jpegrecoverymap/jpegr.cpp
@@ -824,11 +824,24 @@ status_t JpegR::appendRecoveryMap(jr_compressed_ptr compressed_jpeg_image,
return ERROR_JPEGR_INVALID_NULL_PTR;
}
- int pos = 0;
+ const string nameSpace = "http://ns.adobe.com/xap/1.0/";
+ const int nameSpaceLength = nameSpace.size() + 1; // need to count the null terminator
- const string xmp_primary = generateXmpForPrimaryImage(compressed_recovery_map->length);
+ // calculate secondary image length first, because the length will be written into the primary
+ // image xmp
const string xmp_secondary = generateXmpForSecondaryImage(*metadata);
+ const int xmp_secondary_length = 2 /* 2 bytes representing the length of the package */
+ + nameSpaceLength /* 29 bytes length of name space including \0 */
+ + xmp_secondary.size(); /* length of xmp packet */
+ const int secondary_image_size = 2 /* 2 bytes length of APP1 sign */
+ + xmp_secondary_length
+ + compressed_recovery_map->length;
+ // primary image
+ const string xmp_primary = generateXmpForPrimaryImage(secondary_image_size);
+ // same as primary
+ const int xmp_primary_length = 2 + nameSpaceLength + xmp_primary.size();
+ int pos = 0;
// Begin primary image
// Write SOI
JPEGR_CHECK(Write(dest, &photos_editing_formats::image_io::JpegMarker::kStart, 1, pos));
@@ -848,12 +861,7 @@ status_t JpegR::appendRecoveryMap(jr_compressed_ptr compressed_jpeg_image,
// Prepare and write XMP
{
- const string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
- const int nameSpaceLength = nameSpace.size() + 1; // need to count the null terminator
- // 2 bytes: representing the length of the package
- // 29 bytes: length of name space "http://ns.adobe.com/xap/1.0/\0",
- // x bytes: length of xmp packet
- const int length = 2 + nameSpaceLength + xmp_primary.size();
+ const int length = xmp_primary_length;
const uint8_t lengthH = ((length >> 8) & 0xff);
const uint8_t lengthL = (length & 0xff);
JPEGR_CHECK(Write(dest, &photos_editing_formats::image_io::JpegMarker::kStart, 1, pos));
@@ -870,12 +878,15 @@ status_t JpegR::appendRecoveryMap(jr_compressed_ptr compressed_jpeg_image,
const uint8_t lengthH = ((length >> 8) & 0xff);
const uint8_t lengthL = (length & 0xff);
int primary_image_size = pos + length + compressed_jpeg_image->length;
- int secondary_image_offset = primary_image_size;
- int secondary_image_size = xmp_secondary.size() + compressed_recovery_map->length;
- sp<DataStruct> mpf = generateMpf(0, /* primary_image_offset */
- primary_image_size,
- secondary_image_offset,
- secondary_image_size);
+ // between APP2 + package size + signature
+ // ff e2 00 58 4d 50 46 00
+ // 2 + 2 + 4 = 8 (bytes)
+ // and ff d8 sign of the secondary image
+ int secondary_image_offset = primary_image_size - pos - 8;
+ sp<DataStruct> mpf = generateMpf(primary_image_size,
+ 0, /* primary_image_offset */
+ secondary_image_size,
+ secondary_image_offset);
JPEGR_CHECK(Write(dest, &photos_editing_formats::image_io::JpegMarker::kStart, 1, pos));
JPEGR_CHECK(Write(dest, &photos_editing_formats::image_io::JpegMarker::kAPP2, 1, pos));
JPEGR_CHECK(Write(dest, &lengthH, 1, pos));
@@ -895,12 +906,7 @@ status_t JpegR::appendRecoveryMap(jr_compressed_ptr compressed_jpeg_image,
// Prepare and write XMP
{
- const string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
- const int nameSpaceLength = nameSpace.size() + 1; // need to count the null terminator
- // 2 bytes: representing the length of the package
- // 29 bytes: length of name space "http://ns.adobe.com/xap/1.0/\0",
- // x bytes: length of xmp packet
- const int length = 2 + nameSpaceLength + xmp_secondary.size();
+ const int length = xmp_secondary_length;
const uint8_t lengthH = ((length >> 8) & 0xff);
const uint8_t lengthL = (length & 0xff);
JPEGR_CHECK(Write(dest, &photos_editing_formats::image_io::JpegMarker::kStart, 1, pos));