Revert "Update EXIF"
This reverts:
commit 0daf5f8e9073c54438d1045d6da70d9bbd7110a0,
commit Ie4c3632c03ac34867cb9e4f50fb782578ad8c8da,
commit I3d8c4a3fe3cff63f8b57277511aa801b9dd1b75d.
Reason for revert: POR has changed
bug: b/264715926
test: libjpegrecoverymap_test
Change-Id: I88d2c2c3cabb76bddf23622a695b01c21381b34a
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoder.h b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoder.h
index d0de48f..419b63d 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoder.h
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoder.h
@@ -47,7 +47,7 @@
*/
void* getDecompressedImagePtr();
/*
- * Returns the decompressed raw image buffer size. This mgit ethod must be called only after
+ * Returns the decompressed raw image buffer size. This method must be called only after
* calling decompressImage().
*/
size_t getDecompressedImageSize();
@@ -92,10 +92,6 @@
size_t* pWidth, size_t* pHeight,
std::vector<uint8_t>* iccData,
std::vector<uint8_t>* exifData);
- /*
- * Extracts EXIF package and updates the EXIF position / length without decoding the image.
- */
- bool extractEXIF(const void* image, int length);
private:
bool decode(const void* image, int length, bool decodeToRGBA);
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
index ae15d24..696be1b 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
@@ -321,13 +321,17 @@
jr_compressed_ptr dest);
/*
- * This method is called in the encoding pipeline. It will take the standard 8-bit JPEG image
- * and the compressed recovery map as input, and update the XMP metadata with the end of JPEG
- * marker, and append the compressed gian map after the JPEG.
+ * This method is called in the encoding pipeline. It will take the standard 8-bit JPEG image,
+ * the compressed recovery map and optionally the exif package as inputs, and generate the XMP
+ * metadata, and finally append everything in the order of:
+ * SOI, APP2(EXIF) (if EXIF is from outside), APP2(XMP), primary image, recovery map
+ * Note that EXIF package is only available for encoding API-0 and API-1. For encoding API-2 and
+ * API-3 this parameter is null, but the primary image in JPEG/R may still have EXIF as long as
+ * the input JPEG has EXIF.
*
* @param compressed_jpeg_image compressed 8-bit JPEG image
* @param compress_recovery_map compressed recover map
- * @param exif EXIF package
+ * @param (nullable) exif EXIF package
* @param metadata JPEG/R metadata to encode in XMP of the jpeg
* @param dest compressed JPEGR image
* @return NO_ERROR if calculation succeeds, error code if error occurs.
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymaputils.h b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymaputils.h
index 8b2672f..c36a363 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymaputils.h
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymaputils.h
@@ -45,7 +45,6 @@
* @return status of succeed or error code.
*/
status_t Write(jr_compressed_ptr destination, const void* source, size_t length, int &position);
-status_t Write(jr_exif_ptr destination, const void* source, size_t length, int &position);
/*
@@ -105,83 +104,6 @@
* @return XMP metadata in type of string
*/
std::string generateXmp(int secondary_image_length, jpegr_metadata& metadata);
-
-/*
- * Add J R entry to existing exif, or create a new one with J R entry if it's null.
- * EXIF syntax / change:
- * ori:
- * FF E1 - APP1
- * 01 FC - size of APP1 (to be calculated)
- * -----------------------------------------------------
- * 45 78 69 66 00 00 - Exif\0\0 "Exif header"
- * 49 49 2A 00 - TIFF Header
- * 08 00 00 00 - offset to the IFD (image file directory)
- * 06 00 - 6 entries
- * 00 01 - Width Tag
- * 03 00 - 'Short' type
- * 01 00 00 00 - 1 component
- * 00 05 00 00 - image with 0x500
- *--------------------------------------------------------------------------
- * new:
- * FF E1 - APP1
- * 02 08 - new size, equals to old size + EXIF_J_R_ENTRY_LENGTH (12)
- *-----------------------------------------------------
- * 45 78 69 66 00 00 - Exif\0\0 "Exif header"
- * 49 49 2A 00 - TIFF Header
- * 08 00 00 00 - offset to the IFD (image file directory)
- * 07 00 - +1 entry
- * 4A 52 Custom ('J''R') Tag
- * 07 00 - Unknown type
- * 01 00 00 00 - 1 component
- * 00 00 00 00 - empty data
- * 00 01 - Width Tag
- * 03 00 - 'Short' type
- * 01 00 00 00 - 1 component
- * 00 05 00 00 - image with 0x500
- */
-status_t updateExif(jr_exif_ptr exif, jr_exif_ptr dest);
-
-/*
- * Modify offsets in EXIF in place.
- *
- * Each tag has the following structure:
- *
- * 00 01 - Tag
- * 03 00 - data format
- * 01 00 00 00 - number of components
- * 00 05 00 00 - value
- *
- * The value means offset if
- * (1) num_of_components * bytes_per_component > 4 bytes, or
- * (2) tag == 0x8769 (ExifOffset).
- * In both cases, the method will add EXIF_J_R_ENTRY_LENGTH (12) to the offsets.
- */
-void updateExifOffsets(jr_exif_ptr exif, int pos, bool use_big_endian);
-void updateExifOffsets(jr_exif_ptr exif, int pos, int num_entry, bool use_big_endian);
-
-/*
- * Read data from the target position and target length in bytes;
- */
-int readValue(uint8_t* data, int pos, int length, bool use_big_endian);
-
-/*
- * Returns the length of data format in bytes
- *
- * ----------------------------------------------------------------------------------------------
- * | value | 1 | 2 | 3 | 4 |
- * | format | unsigned byte | ascii strings | unsigned short | unsigned long |
- * | bytes/component | 1 | 1 | 2 | 4 |
- * ----------------------------------------------------------------------------------------------
- * | value | 5 | 6 | 7 | 8 |
- * | format |unsigned rational| signed byte | undefined | signed short |
- * | bytes/component | 8 | 1 | 1 | 2 |
- * ----------------------------------------------------------------------------------------------
- * | value | 9 | 10 | 11 | 12 |
- * | format | signed long | signed rational | single float | double float |
- * | bytes/component | 4 | 8 | 4 | 8 |
- * ----------------------------------------------------------------------------------------------
- */
-int findFormatLengthInBytes(int data_format);
}
#endif //ANDROID_JPEGRECOVERYMAP_RECOVERYMAPUTILS_H
diff --git a/libs/jpegrecoverymap/jpegdecoder.cpp b/libs/jpegrecoverymap/jpegdecoder.cpp
index 6fbc6b0..1bf609a 100644
--- a/libs/jpegrecoverymap/jpegdecoder.cpp
+++ b/libs/jpegrecoverymap/jpegdecoder.cpp
@@ -248,60 +248,6 @@
return true;
}
-// TODO (Fyodor/Dichen): merge this method with getCompressedImageParameters() since they have
-// similar functionality. Yet Dichen is not familiar with who's calling
-// getCompressedImageParameters(), looks like it's used by some pending CLs.
-bool JpegDecoder::extractEXIF(const void* image, int length) {
- jpeg_decompress_struct cinfo;
- jpegr_source_mgr mgr(static_cast<const uint8_t*>(image), length);
- jpegrerror_mgr myerr;
-
- cinfo.err = jpeg_std_error(&myerr.pub);
- myerr.pub.error_exit = jpegrerror_exit;
-
- if (setjmp(myerr.setjmp_buffer)) {
- jpeg_destroy_decompress(&cinfo);
- return false;
- }
- jpeg_create_decompress(&cinfo);
-
- jpeg_save_markers(&cinfo, kAPP0Marker, 0xFFFF);
- jpeg_save_markers(&cinfo, kAPP1Marker, 0xFFFF);
- jpeg_save_markers(&cinfo, kAPP2Marker, 0xFFFF);
-
- cinfo.src = &mgr;
- jpeg_read_header(&cinfo, TRUE);
-
- bool exifAppears = false;
- size_t pos = 2; // position after SOI
- for (jpeg_marker_struct* marker = cinfo.marker_list;
- marker && !exifAppears;
- marker = marker->next) {
-
- pos += 4;
- pos += marker->original_length;
-
- if (marker->marker != kAPP1Marker) {
- continue;
- }
-
- const unsigned int len = marker->data_length;
- if (!exifAppears &&
- len > kExifIdCode.size() &&
- !strncmp(reinterpret_cast<const char*>(marker->data),
- kExifIdCode.c_str(),
- kExifIdCode.size())) {
- mEXIFBuffer.resize(len, 0);
- memcpy(static_cast<void*>(mEXIFBuffer.data()), marker->data, len);
- exifAppears = true;
- mExifPos = pos - marker->original_length;
- }
- }
-
- jpeg_destroy_decompress(&cinfo);
- return true;
-}
-
bool JpegDecoder::decompress(jpeg_decompress_struct* cinfo, const uint8_t* dest,
bool isSingleChannel) {
if (isSingleChannel) {
diff --git a/libs/jpegrecoverymap/recoverymap.cpp b/libs/jpegrecoverymap/recoverymap.cpp
index 22289de..30aa846 100644
--- a/libs/jpegrecoverymap/recoverymap.cpp
+++ b/libs/jpegrecoverymap/recoverymap.cpp
@@ -175,18 +175,7 @@
jpeg.data = jpeg_encoder.getCompressedImagePtr();
jpeg.length = jpeg_encoder.getCompressedImageSize();
- jpegr_exif_struct new_exif;
- if (exif == nullptr || exif->data == nullptr) {
- new_exif.length = PSEUDO_EXIF_PACKAGE_LENGTH;
- } else {
- new_exif.length = exif->length + EXIF_J_R_ENTRY_LENGTH;
- }
- new_exif.data = new uint8_t[new_exif.length];
- std::unique_ptr<uint8_t[]> new_exif_data;
- new_exif_data.reset(reinterpret_cast<uint8_t*>(new_exif.data));
- JPEGR_CHECK(updateExif(exif, &new_exif));
-
- JPEGR_CHECK(appendRecoveryMap(&jpeg, &compressed_map, &new_exif, &metadata, dest));
+ JPEGR_CHECK(appendRecoveryMap(&jpeg, &compressed_map, exif, &metadata, dest));
return NO_ERROR;
}
@@ -250,19 +239,7 @@
jpeg.data = jpeg_encoder.getCompressedImagePtr();
jpeg.length = jpeg_encoder.getCompressedImageSize();
- jpegr_exif_struct new_exif;
- if (exif == nullptr || exif->data == nullptr) {
- new_exif.length = PSEUDO_EXIF_PACKAGE_LENGTH;
- } else {
- new_exif.length = exif->length + EXIF_J_R_ENTRY_LENGTH;
- }
-
- new_exif.data = new uint8_t[new_exif.length];
- std::unique_ptr<uint8_t[]> new_exif_data;
- new_exif_data.reset(reinterpret_cast<uint8_t*>(new_exif.data));
- JPEGR_CHECK(updateExif(exif, &new_exif));
-
- JPEGR_CHECK(appendRecoveryMap(&jpeg, &compressed_map, &new_exif, &metadata, dest));
+ JPEGR_CHECK(appendRecoveryMap(&jpeg, &compressed_map, exif, &metadata, dest));
return NO_ERROR;
}
@@ -311,47 +288,7 @@
compressed_map.data = compressed_map_data.get();
JPEGR_CHECK(compressRecoveryMap(&map, &compressed_map));
- // Extract EXIF from JPEG without decoding.
- JpegDecoder jpeg_decoder;
- if (!jpeg_decoder.extractEXIF(compressed_jpeg_image->data, compressed_jpeg_image->length)) {
- return ERROR_JPEGR_DECODE_ERROR;
- }
-
- // Update exif.
- jpegr_exif_struct exif;
- exif.data = nullptr;
- exif.length = 0;
- jpegr_compressed_struct new_jpeg_image;
- new_jpeg_image.data = nullptr;
- new_jpeg_image.length = 0;
- if (jpeg_decoder.getEXIFPos() != 0) {
- copyJpegWithoutExif(&new_jpeg_image,
- compressed_jpeg_image,
- jpeg_decoder.getEXIFPos(),
- jpeg_decoder.getEXIFSize());
- exif.data = jpeg_decoder.getEXIFPtr();
- exif.length = jpeg_decoder.getEXIFSize();
- }
-
- jpegr_exif_struct new_exif;
- if (exif.data == nullptr) {
- new_exif.length = PSEUDO_EXIF_PACKAGE_LENGTH;
- } else {
- new_exif.length = exif.length + EXIF_J_R_ENTRY_LENGTH;
- }
-
- new_exif.data = new uint8_t[new_exif.length];
- std::unique_ptr<uint8_t[]> new_exif_data;
- new_exif_data.reset(reinterpret_cast<uint8_t*>(new_exif.data));
- JPEGR_CHECK(updateExif(&exif, &new_exif));
-
- JPEGR_CHECK(appendRecoveryMap(
- new_jpeg_image.data == nullptr ? compressed_jpeg_image : &new_jpeg_image,
- &compressed_map, &new_exif, &metadata, dest));
-
- if (new_jpeg_image.data != nullptr) {
- free(new_jpeg_image.data);
- }
+ JPEGR_CHECK(appendRecoveryMap(compressed_jpeg_image, &compressed_map, nullptr, &metadata, dest));
return NO_ERROR;
}
@@ -384,33 +321,6 @@
uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight();
uncompressed_yuv_420_image.colorGamut = compressed_jpeg_image->colorGamut;
- // Update exif.
- jpegr_exif_struct exif;
- exif.data = nullptr;
- exif.length = 0;
- jpegr_compressed_struct new_jpeg_image;
- new_jpeg_image.data = nullptr;
- new_jpeg_image.length = 0;
- if (jpeg_decoder.getEXIFPos() != 0) {
- copyJpegWithoutExif(&new_jpeg_image,
- compressed_jpeg_image,
- jpeg_decoder.getEXIFPos(),
- jpeg_decoder.getEXIFSize());
- exif.data = jpeg_decoder.getEXIFPtr();
- exif.length = jpeg_decoder.getEXIFSize();
- }
-
- jpegr_exif_struct new_exif;
- if (exif.data == nullptr) {
- new_exif.length = PSEUDO_EXIF_PACKAGE_LENGTH;
- } else {
- new_exif.length = exif.length + EXIF_J_R_ENTRY_LENGTH;
- }
- new_exif.data = new uint8_t[new_exif.length];
- std::unique_ptr<uint8_t[]> new_exif_data;
- new_exif_data.reset(reinterpret_cast<uint8_t*>(new_exif.data));
- JPEGR_CHECK(updateExif(&exif, &new_exif));
-
if (uncompressed_p010_image->width != uncompressed_yuv_420_image.width
|| uncompressed_p010_image->height != uncompressed_yuv_420_image.height) {
return ERROR_JPEGR_RESOLUTION_MISMATCH;
@@ -435,13 +345,7 @@
compressed_map.data = compressed_map_data.get();
JPEGR_CHECK(compressRecoveryMap(&map, &compressed_map));
- JPEGR_CHECK(appendRecoveryMap(
- new_jpeg_image.data == nullptr ? compressed_jpeg_image : &new_jpeg_image,
- &compressed_map, &new_exif, &metadata, dest));
-
- if (new_jpeg_image.data != nullptr) {
- free(new_jpeg_image.data);
- }
+ JPEGR_CHECK(appendRecoveryMap(compressed_jpeg_image, &compressed_map, nullptr, &metadata, dest));
return NO_ERROR;
}
@@ -967,15 +871,20 @@
// JPEG/R structure:
// SOI (ff d8)
+//
+// (Optional, only if EXIF package is from outside)
// APP1 (ff e1)
// 2 bytes of length (2 + length of exif package)
// EXIF package (this includes the first two bytes representing the package length)
-// APP1 (ff e1)
+//
+// (Required, XMP package) APP1 (ff e1)
// 2 bytes of length (2 + 29 + length of xmp package)
// name space ("http://ns.adobe.com/xap/1.0/\0")
// xmp
-// primary image (without the first two bytes (SOI) and without EXIF, may have other packages)
-// secondary image (the recovery map)
+//
+// (Required) primary image (without the first two bytes (SOI), may have other packages)
+//
+// (Required) secondary image (the recovery map)
//
// Metadata versions we are using:
// ECMA TR-98 for JFIF marker
@@ -989,7 +898,6 @@
jr_compressed_ptr dest) {
if (compressed_jpeg_image == nullptr
|| compressed_recovery_map == nullptr
- || exif == nullptr
|| metadata == nullptr
|| dest == nullptr) {
return ERROR_JPEGR_INVALID_NULL_PTR;
@@ -1002,7 +910,7 @@
JPEGR_CHECK(Write(dest, &photos_editing_formats::image_io::JpegMarker::kSOI, 1, pos));
// Write EXIF
- {
+ if (exif != nullptr) {
const int length = 2 + exif->length;
const uint8_t lengthH = ((length >> 8) & 0xff);
const uint8_t lengthL = (length & 0xff);
diff --git a/libs/jpegrecoverymap/recoverymaputils.cpp b/libs/jpegrecoverymap/recoverymaputils.cpp
index d5ad9a5..1617b8b 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 @@
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 @@
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