Skip to content

Commit

Permalink
AVIF Exif data support
Browse files Browse the repository at this point in the history
  • Loading branch information
qbnu committed Jun 21, 2023
1 parent 2ce3887 commit e1852b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/JPEGView/AVIFWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void* AvifReader::ReadImage(int& width,
int frame_index,
int& frame_count,
int& frame_time,
void*& exif_chunk,
bool& outOfMemory,
const void* buffer,
int sizebytes)
Expand All @@ -30,6 +31,7 @@ void* AvifReader::ReadImage(int& width,
width = height = 0;
nchannels = 4;
has_animation = false;
exif_chunk = NULL;

avifResult result;
int nthreads = 256; // sets maximum number of active threads allowed for libavif, default is 1
Expand Down Expand Up @@ -93,9 +95,22 @@ void* AvifReader::ReadImage(int& width,
if (cache.transform == NULL)
cache.transform = ICCProfileTransform::CreateTransform(icc.data, icc.size, ICCProfileTransform::FORMAT_BGRA);
ICCProfileTransform::DoTransform(cache.transform, cache.rgb.pixels, cache.rgb.pixels, width, height);

avifRWData exif = cache.decoder->image->exif;
if (exif.size > 8 && exif.size < 65528 && exif.data != NULL) {
exif_chunk = malloc(exif.size + 10);
if (exif_chunk != NULL) {
memcpy(exif_chunk, "\xFF\xE1\0\0Exif\0\0", 10);
*((unsigned short*)exif_chunk + 1) = _byteswap_ushort(exif.size + 8);
memcpy((uint8_t*)exif_chunk + 10, exif.data, exif.size);
}
}

void* pPixelData = cache.rgb.pixels;
if (!has_animation)
DeleteCache();
return cache.rgb.pixels;

return pPixelData;
}

void AvifReader::DeleteCache() {
Expand Down
1 change: 1 addition & 0 deletions src/JPEGView/AVIFWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AvifReader
int frame_index, // index of frame
int& frame_count, // number of frames
int& frame_time, // frame duration in milliseconds
void*& exif_chunk, // Pointer to Exif data (must be freed by caller)
bool& outOfMemory, // set to true when no memory to read image
const void* buffer, // memory address containing jxl compressed data.
int sizebytes); // size of jxl 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 @@ -860,8 +860,9 @@ void CImageLoadThread::ProcessReadAVIFRequest(CRequest* request) {
if (bUseCachedDecoder || (::ReadFile(hFile, pBuffer, nFileSize, (LPDWORD)&nNumBytesRead, NULL) && nNumBytesRead == nFileSize)) {
int nWidth, nHeight, nBPP, nFrameCount, nFrameTimeMs;
bool bHasAnimation;
void* pEXIFData;
uint8* pPixelData = (uint8*)AvifReader::ReadImage(nWidth, nHeight, nBPP, bHasAnimation, request->FrameIndex,
nFrameCount, nFrameTimeMs, request->OutOfMemory, pBuffer, nFileSize);
nFrameCount, nFrameTimeMs, pEXIFData, request->OutOfMemory, pBuffer, nFileSize);
if (pPixelData != NULL) {
if (bHasAnimation)
m_sLastAvifFileName = sFileName;
Expand All @@ -870,7 +871,8 @@ void CImageLoadThread::ProcessReadAVIFRequest(CRequest* request) {
for (int i = 0; i < nWidth * nHeight; i++)
*pImage32++ = WebpAlphaBlendBackground(*pImage32, CSettingsProvider::This().ColorTransparency());

request->Image = new CJPEGImage(nWidth, nHeight, pPixelData, NULL, 4, 0, IF_AVIF, bHasAnimation, request->FrameIndex, nFrameCount, nFrameTimeMs);
request->Image = new CJPEGImage(nWidth, nHeight, pPixelData, pEXIFData, 4, 0, IF_AVIF, bHasAnimation, request->FrameIndex, nFrameCount, nFrameTimeMs);
free(pEXIFData);
bSuccess = true;
} else {
DeleteCachedAvifDecoder();
Expand Down

0 comments on commit e1852b2

Please sign in to comment.