Skip to content

Commit

Permalink
HEIF Exif support
Browse files Browse the repository at this point in the history
  • Loading branch information
qbnu committed Jun 21, 2023
1 parent 0b2a7f0 commit 6fab641
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/JPEGView/HEIFWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void * HeifReader::ReadImage(int &width,
int &height,
int &nchannels,
int &frame_count,
void* &exif_chunk,
bool &outOfMemory,
int frame_index,
const void *buffer,
Expand All @@ -18,6 +19,7 @@ void * HeifReader::ReadImage(int &width,
nchannels = 4;

unsigned char* pPixelData = NULL;
exif_chunk = NULL;

heif::Context context;
context.read_from_memory_without_copy(buffer, sizebytes);
Expand Down Expand Up @@ -69,5 +71,17 @@ void * HeifReader::ReadImage(int &width,
}
ICCProfileTransform::DeleteTransform(transform);

std::vector<heif_item_id> exif_blocks = handle.get_list_of_metadata_block_IDs("Exif");

if (!exif_blocks.empty()) {
std::vector<uint8_t> exif = handle.get_metadata(exif_blocks[0]);
exif_chunk = exif.size() > 8 ? (uint8_t*)malloc(exif.size()) : NULL;
if (exif_chunk != NULL) {
memcpy(exif_chunk, exif.data(), exif.size());
*((unsigned short*)exif_chunk) = _byteswap_ushort(0xFFE1);
*((unsigned short*)exif_chunk + 1) = _byteswap_ushort(exif.size() - 2);
}
}

return (void*)pPixelData;
}
1 change: 1 addition & 0 deletions src/JPEGView/HEIFWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HeifReader
int &height, // height of the image loaded.
int &bpp, // BYTES (not bits) PER PIXEL.
int &frame_count, // number of top-level images
void* &exif_chunk, // Pointer to Exif data (must be freed by caller)
bool &outOfMemory, // set to true when no memory to read image
int frame_index, // index of requested frame
const void *buffer, // memory address containing heic compressed data.
Expand Down
6 changes: 4 additions & 2 deletions src/JPEGView/ImageLoadThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,14 +922,16 @@ void CImageLoadThread::ProcessReadHEIFRequest(CRequest* request) {
int nWidth, nHeight, nBPP, nFrameCount, nFrameTimeMs;
nFrameCount = 1;
nFrameTimeMs = 0;
uint8* pPixelData = (uint8*)HeifReader::ReadImage(nWidth, nHeight, nBPP, nFrameCount, request->OutOfMemory, request->FrameIndex, pBuffer, nFileSize);
void* pEXIFData;
uint8* pPixelData = (uint8*)HeifReader::ReadImage(nWidth, nHeight, nBPP, nFrameCount, pEXIFData, request->OutOfMemory, request->FrameIndex, pBuffer, nFileSize);
if (pPixelData != NULL) {
// Multiply alpha value into each AABBGGRR pixel
uint32* pImage32 = (uint32*)pPixelData;
for (int i = 0; i < nWidth * nHeight; i++)
*pImage32++ = WebpAlphaBlendBackground(*pImage32, CSettingsProvider::This().ColorTransparency());

request->Image = new CJPEGImage(nWidth, nHeight, pPixelData, NULL, nBPP, 0, IF_HEIF, false, request->FrameIndex, nFrameCount, nFrameTimeMs);
request->Image = new CJPEGImage(nWidth, nHeight, pPixelData, pEXIFData, nBPP, 0, IF_HEIF, false, request->FrameIndex, nFrameCount, nFrameTimeMs);
free(pEXIFData);
}
}
} catch(heif::Error he) {
Expand Down

0 comments on commit 6fab641

Please sign in to comment.