Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor animated image cache deletion #248

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 24 additions & 66 deletions src/JPEGView/ImageLoadThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,7 @@ CImageLoadThread::CImageLoadThread(void) : CWorkThread(true) {
}

CImageLoadThread::~CImageLoadThread(void) {
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
DeleteOtherCaches(IF_Unknown);
}

int CImageLoadThread::AsyncLoad(LPCTSTR strFileName, int nFrameIndex, const CProcessParams & processParams, HWND targetWnd, HANDLE eventFinished) {
Expand Down Expand Up @@ -290,44 +286,23 @@ void CImageLoadThread::ProcessRequest(CRequestBase& request) {
CRequest& rq = (CRequest&)request;
double dStartTime = Helpers::GetExactTickCount();
// Get image format and read the image
switch (GetImageFormat(rq.FileName)) {
EImageFormat nFormat = GetImageFormat(rq.FileName);
DeleteOtherCaches(nFormat);
switch (nFormat) {
case IF_JPEG :
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadJPEGRequest(&rq);
break;
case IF_WindowsBMP :
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadBMPRequest(&rq);
break;
case IF_TGA :
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadTGARequest(&rq);
break;
case IF_WEBP:
DeleteCachedGDIBitmap();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadWEBPRequest(&rq);
break;
#ifndef WINXP
case IF_PNG:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
if (CSettingsProvider::This().ForceGDIPlus()) {
DeleteCachedPngDecoder();
ProcessReadGDIPlusRequest(&rq);
Expand All @@ -336,66 +311,31 @@ void CImageLoadThread::ProcessRequest(CRequestBase& request) {
}
break;
case IF_JXL:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedAvifDecoder();
ProcessReadJXLRequest(&rq);
break;
case IF_AVIF:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
ProcessReadAVIFRequest(&rq);
break;
case IF_HEIF:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadHEIFRequest(&rq);
break;
case IF_PSD:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadPSDRequest(&rq);
break;
case IF_CameraRAW:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadRAWRequest(&rq);
break;
#endif
case IF_QOI:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadQOIRequest(&rq);
break;
case IF_WIC:
DeleteCachedGDIBitmap();
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadWICRequest(&rq);
break;
case IF_GIF:
case IF_TIFF:
default:
// try with GDI+
DeleteCachedWebpDecoder();
DeleteCachedPngDecoder();
DeleteCachedJxlDecoder();
DeleteCachedAvifDecoder();
ProcessReadGDIPlusRequest(&rq);
break;
}
Expand Down Expand Up @@ -436,6 +376,24 @@ static void LimitOffsets(CPoint& offsets, CSize clippingSize, const CSize & imag
offsets.y = max(-nMaxOffsetY, min(+nMaxOffsetY, offsets.y));
}

void CImageLoadThread::DeleteOtherCaches(EImageFormat nFormat) {
if (nFormat != IF_GIF) {
DeleteCachedGDIBitmap();
}
if (nFormat != IF_WEBP) {
DeleteCachedWebpDecoder();
}
if (nFormat != IF_PNG) {
DeleteCachedPngDecoder();
}
if (nFormat != IF_JXL) {
DeleteCachedJxlDecoder();
}
if (nFormat != IF_AVIF) {
DeleteCachedAvifDecoder();
}
}

void CImageLoadThread::DeleteCachedGDIBitmap() {
if (m_pLastBitmap != NULL) {
delete m_pLastBitmap;
Expand Down
1 change: 1 addition & 0 deletions src/JPEGView/ImageLoadThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class CImageLoadThread : public CWorkThread

virtual void ProcessRequest(CRequestBase& request);
virtual void AfterFinishProcess(CRequestBase& request);
void DeleteOtherCaches(EImageFormat nFormat);
void DeleteCachedGDIBitmap();
void DeleteCachedWebpDecoder();
void DeleteCachedPngDecoder();
Expand Down