diff options
Diffstat (limited to 'libs/jpegrecoverymap/recoverymaputils.cpp')
| -rw-r--r-- | libs/jpegrecoverymap/recoverymaputils.cpp | 191 |
1 files changed, 1 insertions, 190 deletions
diff --git a/libs/jpegrecoverymap/recoverymaputils.cpp b/libs/jpegrecoverymap/recoverymaputils.cpp index d5ad9a51c4..1617b8b97a 100644 --- a/libs/jpegrecoverymap/recoverymaputils.cpp +++ b/libs/jpegrecoverymap/recoverymaputils.cpp @@ -22,8 +22,6 @@ #include <image_io/xml/xml_handler.h> #include <image_io/xml/xml_rule.h> -#include <utils/Log.h> - using namespace photos_editing_formats::image_io; using namespace std; @@ -55,12 +53,6 @@ status_t Write(jr_compressed_ptr destination, const void* source, size_t length, return NO_ERROR; } -status_t Write(jr_exif_ptr destination, const void* source, size_t length, int &position) { - memcpy((uint8_t*)destination->data + sizeof(uint8_t) * position, source, length); - position += length; - return NO_ERROR; -} - // Extremely simple XML Handler - just searches for interesting elements class XMPXmlHandler : public XmlHandler { public: @@ -344,185 +336,4 @@ string generateXmp(int secondary_image_length, jpegr_metadata& metadata) { return ss.str(); } -/* - * Helper function - * Add J R entry to existing exif, or create a new one with J R entry if it's null. - */ -status_t updateExif(jr_exif_ptr exif, jr_exif_ptr dest) { - if (exif == nullptr || exif->data == nullptr) { - uint8_t data[PSEUDO_EXIF_PACKAGE_LENGTH] = { - 0x45, 0x78, 0x69, 0x66, 0x00, 0x00, - 0x49, 0x49, 0x2A, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x01, 0x00, - 0x4A, 0x52, - 0x07, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - int pos = 0; - Write(dest, data, PSEUDO_EXIF_PACKAGE_LENGTH, pos); - return NO_ERROR; - } - - int num_entry = 0; - uint8_t num_entry_low = 0; - uint8_t num_entry_high = 0; - bool use_big_endian = false; - if (reinterpret_cast<uint16_t*>(exif->data)[3] == 0x4949) { - num_entry_low = reinterpret_cast<uint8_t*>(exif->data)[14]; - num_entry_high = reinterpret_cast<uint8_t*>(exif->data)[15]; - } else if (reinterpret_cast<uint16_t*>(exif->data)[3] == 0x4d4d) { - use_big_endian = true; - num_entry_high = reinterpret_cast<uint8_t*>(exif->data)[14]; - num_entry_low = reinterpret_cast<uint8_t*>(exif->data)[15]; - } else { - return ERROR_JPEGR_METADATA_ERROR; - } - num_entry = (num_entry_high << 8) | num_entry_low; - num_entry += 1; - num_entry_low = num_entry & 0xff; - num_entry_high = (num_entry >> 8) & 0xff; - - int pos = 0; - Write(dest, (uint8_t*)exif->data, 14, pos); - - if (use_big_endian) { - Write(dest, &num_entry_high, 1, pos); - Write(dest, &num_entry_low, 1, pos); - uint8_t data[EXIF_J_R_ENTRY_LENGTH] = { - 0x4A, 0x52, - 0x00, 0x07, - 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x00}; - Write(dest, data, EXIF_J_R_ENTRY_LENGTH, pos); - } else { - Write(dest, &num_entry_low, 1, pos); - Write(dest, &num_entry_high, 1, pos); - uint8_t data[EXIF_J_R_ENTRY_LENGTH] = { - 0x4A, 0x52, - 0x07, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; - Write(dest, data, EXIF_J_R_ENTRY_LENGTH, pos); - } - - Write(dest, (uint8_t*)exif->data + 16, exif->length - 16, pos); - - updateExifOffsets(dest, - 28, // start from the second tag, skip the "JR" tag - num_entry - 1, - use_big_endian); - - return NO_ERROR; -} - -/* - * Helper function - * Modify offsets in EXIF in place. - */ -void updateExifOffsets(jr_exif_ptr exif, int pos, bool use_big_endian) { - int num_entry = readValue(reinterpret_cast<uint8_t*>(exif->data), pos, 2, use_big_endian); - updateExifOffsets(exif, pos + 2, num_entry, use_big_endian); -} - -void updateExifOffsets(jr_exif_ptr exif, int pos, int num_entry, bool use_big_endian) { - for (int i = 0; i < num_entry; pos += EXIF_J_R_ENTRY_LENGTH, i++) { - int tag = readValue(reinterpret_cast<uint8_t*>(exif->data), pos, 2, use_big_endian); - bool need_to_update_offset = false; - if (tag == 0x8769) { - need_to_update_offset = true; - int sub_ifd_offset = - readValue(reinterpret_cast<uint8_t*>(exif->data), pos + 8, 4, use_big_endian) - + 6 // "Exif\0\0"; - + EXIF_J_R_ENTRY_LENGTH; - updateExifOffsets(exif, sub_ifd_offset, use_big_endian); - } else { - int data_format = - readValue(reinterpret_cast<uint8_t*>(exif->data), pos + 2, 2, use_big_endian); - int num_of_components = - readValue(reinterpret_cast<uint8_t*>(exif->data), pos + 4, 4, use_big_endian); - int data_length = findFormatLengthInBytes(data_format) * num_of_components; - if (data_length > 4) { - need_to_update_offset = true; - } - } - - if (!need_to_update_offset) { - continue; - } - - int offset = readValue(reinterpret_cast<uint8_t*>(exif->data), pos + 8, 4, use_big_endian); - - offset += EXIF_J_R_ENTRY_LENGTH; - - if (use_big_endian) { - reinterpret_cast<uint8_t*>(exif->data)[pos + 11] = offset & 0xff; - reinterpret_cast<uint8_t*>(exif->data)[pos + 10] = (offset >> 8) & 0xff; - reinterpret_cast<uint8_t*>(exif->data)[pos + 9] = (offset >> 16) & 0xff; - reinterpret_cast<uint8_t*>(exif->data)[pos + 8] = (offset >> 24) & 0xff; - } else { - reinterpret_cast<uint8_t*>(exif->data)[pos + 8] = offset & 0xff; - reinterpret_cast<uint8_t*>(exif->data)[pos + 9] = (offset >> 8) & 0xff; - reinterpret_cast<uint8_t*>(exif->data)[pos + 10] = (offset >> 16) & 0xff; - reinterpret_cast<uint8_t*>(exif->data)[pos + 11] = (offset >> 24) & 0xff; - } - } -} - -/* - * Read data from the target position and target length in bytes; - */ -int readValue(uint8_t* data, int pos, int length, bool use_big_endian) { - if (length == 2) { - if (use_big_endian) { - return (data[pos] << 8) | data[pos + 1]; - } else { - return (data[pos + 1] << 8) | data[pos]; - } - } else if (length == 4) { - if (use_big_endian) { - return (data[pos] << 24) | (data[pos + 1] << 16) | (data[pos + 2] << 8) | data[pos + 3]; - } else { - return (data[pos + 3] << 24) | (data[pos + 2] << 16) | (data[pos + 1] << 8) | data[pos]; - } - } else { - // Not support for now. - ALOGE("Error in readValue(): pos=%d, length=%d", pos, length); - return -1; - } -} - -/* - * Helper function - * Returns the length of data format in bytes - */ -int findFormatLengthInBytes(int data_format) { - switch (data_format) { - case 1: // unsigned byte - case 2: // ascii strings - case 6: // signed byte - case 7: // undefined - return 1; - - case 3: // unsigned short - case 8: // signed short - return 2; - - case 4: // unsigned long - case 9: // signed long - case 11: // single float - return 4; - - case 5: // unsigned rational - case 10: // signed rational - case 12: // double float - return 8; - - default: - // should not hit here - ALOGE("Error in findFormatLengthInBytes(): data_format=%d", data_format); - return -1; - } -} - -} // namespace android::recoverymap
\ No newline at end of file +} // namespace android::recoverymap |