Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
79 changes: 79 additions & 0 deletions src/JPEGView/JPEGProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,85 @@ void CJPEGProvider::NotifyNotUsed(CJPEGImage* pImage) {
if (pImage != NULL) delete pImage;
}

CJPEGImage* CJPEGProvider::RequestImage(EReadAheadDirection eDirection,
LPCTSTR strFileName, int nFrameIndex, const CProcessParams& processParams,
bool& bOutOfMemory, bool& bExceptionError) {
if (strFileName == NULL) {
bOutOfMemory = false;
bExceptionError = false;
return NULL;
}

// Search if we have the requested image already present or in progress
CImageRequest* pRequest = FindRequest(strFileName, nFrameIndex);
bool bDirectionChanged = eDirection != m_eOldDirection || eDirection == TOGGLE;
bool bRemoveAlsoActiveRequests = bDirectionChanged; // if direction changed, all read-ahead requests are wrongly guessed
bool bWasOutOfMemory = false;
m_eOldDirection = eDirection;

if (pRequest == NULL) {
// no request pending for this file, add to request queue and start async
pRequest = StartNewRequest(strFileName, nFrameIndex, processParams);
// wait with read ahead when direction changed - maybe user just wants to re-see last image
//if (!bDirectionChanged && eDirection != NONE) {
// // start parallel if more than one thread
// StartNewRequestBundle(pFileList, eDirection, processParams, m_nNumThread - 1, NULL);
//}
}

// wait for request if not yet ready
if (!pRequest->Ready) {
#ifdef DEBUG
::OutputDebugString(_T("Waiting for request: ")); ::OutputDebugString(pRequest->FileName); ::OutputDebugString(_T("\n"));
#endif
::WaitForSingleObject(pRequest->EventFinished, INFINITE);
GetLoadedImageFromWorkThread(pRequest);
}
else {
CJPEGImage* pImage = pRequest->Image;
if (pImage != NULL) {
// make sure the initial parameters are reset as when keep params was on before they are wrong
EProcessingFlags procFlags = processParams.ProcFlags;
pImage->RestoreInitialParameters(strFileName, processParams.ImageProcParams, procFlags,
processParams.RotationParams.Rotation, processParams.Zoom, processParams.Offsets,
CSize(processParams.TargetWidth, processParams.TargetHeight), processParams.MonitorSize);
}
#ifdef DEBUG
::OutputDebugString(_T("Found in cache: ")); ::OutputDebugString(pRequest->FileName); ::OutputDebugString(_T("\n"));
#endif
}

// set before removing unused images!
pRequest->InUse = true;
pRequest->AccessTimeStamp = m_nCurrentTimeStamp++;

if (pRequest->OutOfMemory) {
// The request could not be satisfied because the system is out of memory.
// Clear all memory and try again - maybe some readahead requests can be deleted
#ifdef DEBUG
::OutputDebugString(_T("Retrying request because out of memory: ")); ::OutputDebugString(pRequest->FileName); ::OutputDebugString(_T("\n"));
#endif
bWasOutOfMemory = true;
if (FreeAllPossibleMemory()) {
DeleteElement(pRequest);
pRequest = StartRequestAndWaitUntilReady(strFileName, nFrameIndex, processParams);
}
}

// cleanup stuff no longer used
RemoveUnusedImages(bRemoveAlsoActiveRequests);
ClearOldestInactiveRequest();

// check if we shall start new requests (don't start another request if we are short of memory!)
//if (m_requestList.size() < (unsigned int)m_nNumBuffers && !bDirectionChanged && !bWasOutOfMemory && eDirection != NONE) {
// StartNewRequestBundle(pFileList, eDirection, processParams, m_nNumThread, pRequest);
//}

bOutOfMemory = pRequest->OutOfMemory;
bExceptionError = pRequest->ExceptionError;
return pRequest->Image;
}

void CJPEGProvider::ClearAllRequests() {
std::list<CImageRequest*>::iterator iter;
for (iter = m_requestList.begin( ); iter != m_requestList.end( ); iter++ ) {
Expand Down
3 changes: 3 additions & 0 deletions src/JPEGView/JPEGProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class CJPEGProvider
// created automatically so that the next image will be ready immediately when requested in the future.
CJPEGImage* RequestImage(CFileList* pFileList, EReadAheadDirection eDirection, LPCTSTR strFileName, int nFrameIndex,
const CProcessParams & processParams, bool& bOutOfMemory, bool& bExceptionError);
CJPEGImage* CJPEGProvider::RequestImage(EReadAheadDirection eDirection,
LPCTSTR strFileName, int nFrameIndex, const CProcessParams& processParams,
bool& bOutOfMemory, bool& bExceptionError);

// Notifies that the specified image is no longer used and its memory can be freed.
// The CJPEGProvider class may decide to keep the image cached.
Expand Down
16 changes: 8 additions & 8 deletions src/JPEGView/JPEGView.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -152,7 +152,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\lazyhorse\Documents\github\wtl10\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
Expand All @@ -167,7 +167,7 @@
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(IntDir);C:\Users\lazyhorse\Documents\github\wtl10\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<AdditionalDependencies>legacy_stdio_definitions.lib;legacy_stdio_wide_specifiers.lib;Dbghelp.lib;gdiplus.lib;WICLoader.lib;turbojpeg-static.lib;libpng16.lib;zlib.lib;jxl_dec.lib;jxl_threads.lib;heif.lib;libwebp.lib;libwebpdemux.lib;avif.lib;lcms2.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down Expand Up @@ -256,7 +256,7 @@
</Midl>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>C:\Users\lazyhorse\Documents\github\wtl10\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;STRICT;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>false</StringPooling>
<ExceptionHandling>Async</ExceptionHandling>
Expand All @@ -276,7 +276,7 @@
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0409</Culture>
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(IntDir);C:\Users\lazyhorse\Documents\github\wtl10\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<AdditionalDependencies>legacy_stdio_definitions.lib;legacy_stdio_wide_specifiers.lib;gdiplus.lib;WICLoader.lib;turbojpeg-static.lib;libpng16.lib;zlib.lib;jxl_dec.lib;jxl_threads.lib;heif.lib;libwebp.lib;libwebpdemux.lib;avif.lib;lcms2.lib;%(AdditionalDependencies)</AdditionalDependencies>
Expand Down
Loading