Skip to content

Commit

Permalink
Much speed. In directories with large numbers of png files, they were…
Browse files Browse the repository at this point in the history
… being inspected to see if they contained apng data. This inspection was really slow if there were hundreds of files. The new way simply defers this inspection (which needs to look at the file contents) until loading is performed. Inc Version to 1.0.24.
  • Loading branch information
bluescan committed Sep 5, 2021
1 parent d03ccd5 commit 0780b1a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Src/Crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void Viewer::ShowCropPopup(const tVector4& lrtb, const tVector2& uvmarg, const t
if (ImGui::Button("Cancel", tVector2(64, 0)))
CropMode = false;

ImGui::SameLine();
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - 64.0f);

if (ImGui::Button("Apply", tVector2(64, 0)))
Expand Down
2 changes: 1 addition & 1 deletion Src/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ FileDialog::DialogResult FileDialog::DoPopup()
// else if (Mode == DialogMode::OpenFile)
{
tList<tStringItem> foundFiles;
tSystem::tFindFiles(foundFiles, selDir);
tSystem::tFindFilesFast(foundFiles, selDir);
for (tStringItem* file = foundFiles.First(); file; file = file->Next())
{
//(*dir)[dir->Length()-1] = '\0'; // Remove slash.
Expand Down
39 changes: 13 additions & 26 deletions Src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ Image::Image(const tString& filename) :
FileSizeB(0),
LoadParams()
{
if ((Filetype == tSystem::tFileType::PNG) && Config.DetectAPNGInsidePNG && tImageAPNG::IsAnimatedPNG(Filename))
Filetype = tSystem::tFileType::APNG;

tMemset(&FileModTime, 0, sizeof(FileModTime));
ResetLoadParams();
tSystem::tFileInfo info;
Expand Down Expand Up @@ -106,9 +103,6 @@ bool Image::Load(const tString& filename)
Filename = filename;
Filetype = tGetFileType(Filename);

if ((Filetype == tSystem::tFileType::PNG) && Config.DetectAPNGInsidePNG && tImageAPNG::IsAnimatedPNG(Filename))
Filetype = tSystem::tFileType::APNG;

tSystem::tFileInfo info;
if (tSystem::tGetFileInfo(info, filename))
{
Expand Down Expand Up @@ -149,11 +143,23 @@ bool Image::Load()
if (Filetype == tFileType::Unknown)
return false;

// If the type is a png file, we may actually be dealing with an apng file inside.
// It is more efficient to only use the apng loader if we need to (even though it will
// handle non apng files). To this end, we modify the filetype used for loading if necessary.
// Note also that from the outside, we only determine the type from the extension. The
// IsAnimatedPNG call is quite expensive -- it needs to load part of the fileinto memory,
// not something we want to do before actually loading an image. If DetectAPNGInsidePNG is
// false, the PNG loader will always be used for .png files even if they have an apng inside.
// The designers of apng made the format backwards compatible with single-frame png loaders.
tSystem::tFileType loadingFiletype = Filetype;
if ((Filetype == tSystem::tFileType::PNG) && Config.DetectAPNGInsidePNG && tImageAPNG::IsAnimatedPNG(Filename))
loadingFiletype = tSystem::tFileType::APNG;

Info.SrcPixelFormat = tPixelFormat::Invalid;
bool success = false;
try
{
switch (Filetype)
switch (loadingFiletype)
{
case tSystem::tFileType::APNG:
{
Expand Down Expand Up @@ -777,25 +783,6 @@ void Image::SetFrameDuration(float duration, bool allFrames)
}


void Image::PrintInfo()
{
tPixelFormat format = tPixelFormat::Invalid;
if (Filetype == tSystem::tFileType::DDS)
{
if (DDSCubemap.IsValid())
format = DDSCubemap.GetSide(tCubemap::tSide::PosX)->GetPixelFormat();
else
format = DDSTexture2D.GetPixelFormat();
}
else
{
tPicture* picture = Pictures.First();
if (picture)
format = picture->IsOpaque() ? tPixelFormat::R8G8B8 : tPixelFormat::R8G8B8A8;
}
}


uint64 Image::Bind()
{
if (AltPictureEnabled && AltPicture.IsValid())
Expand Down
5 changes: 2 additions & 3 deletions Src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ class Image : public tLink<Image>
int FileSizeBytes = 0;
int MemSizeBytes = 0;
};
void PrintInfo();

bool IsAltMipmapsPictureAvail() const { return DDSTexture2D.IsValid() && AltPicture.IsValid(); }
bool IsAltCubemapPictureAvail() const { return DDSCubemap.IsValid() && AltPicture.IsValid(); }
Expand All @@ -135,7 +134,7 @@ class Image : public tLink<Image>

ImgInfo Info; // Info is only valid AFTER loading.
tString Filename; // Valid before load.
tSystem::tFileType Filetype; // Valid before load.
tSystem::tFileType Filetype; // Valid before load. Based on extension.
std::time_t FileModTime; // Valid before load.
uint64 FileSizeB; // Valid before load.

Expand Down Expand Up @@ -196,7 +195,7 @@ class Image : public tLink<Image>
};


// Implementation only below.
// Implementation below.


inline bool Image::TypeSupportsProperties() const
Expand Down
50 changes: 20 additions & 30 deletions Src/PropertyEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,25 @@ void Viewer::ShowPropertyEditorWindow(bool* popen)
ImGui::InputInt("Exposure", &CurrImage->LoadParams.HDR_Exposure); ImGui::SameLine();
ShowHelpMark("Exposure adjustment [-10, 10] if you reload this Radiance hdr file.");
tMath::tiClamp(CurrImage->LoadParams.HDR_Exposure, -10, 10);

ImGui::PopItemWidth();
if (ImGui::Button("Reset"))
CurrImage->ResetLoadParams();
ImGui::SameLine();

if (ImGui::Button("Reload"))
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 8);
ImGui::Separator();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 8);

if (ImGui::Button("Reset", tVector2(100, 0)))
{
CurrImage->ResetLoadParams();
CurrImage->Unload();
CurrImage->Load();
}
ImGui::SameLine();

if (ImGui::Button("Reload All"))
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - 100.0f);
if (ImGui::Button("Reload", tVector2(100, 0)))
{
tImage::tPicture::LoadParams params = CurrImage->LoadParams;
for (Image* img = Images.First(); img; img = img->Next())
{
if (img->Filetype != tSystem::tFileType::HDR)
continue;
img->Unload();
img->LoadParams = params;
img->Load();
}
CurrImage->Unload();
CurrImage->Load();
}

fileTypeSectionDisplayed = true;
Expand Down Expand Up @@ -111,30 +106,25 @@ void Viewer::ShowPropertyEditorWindow(bool* popen)
ImGui::InputFloat("Knee High", &CurrImage->LoadParams.EXR_KneeHigh, 0.01f, 0.1f, "%.3f"); ImGui::SameLine();
ShowHelpMark("Upper bound knee taper [3.5, 7.5] if you reload this exr file.");
tMath::tiClamp(CurrImage->LoadParams.EXR_KneeHigh, 3.5f, 7.5f);

ImGui::PopItemWidth();
if (ImGui::Button("Reset"))
CurrImage->ResetLoadParams();
ImGui::SameLine();

if (ImGui::Button("Reload"))
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 8);
ImGui::Separator();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 8);

if (ImGui::Button("Reset", tVector2(100, 0)))
{
CurrImage->ResetLoadParams();
CurrImage->Unload();
CurrImage->Load();
}
ImGui::SameLine();

if (ImGui::Button("Reload All"))
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - 100.0f);
if (ImGui::Button("Reload", tVector2(100, 0)))
{
tImage::tPicture::LoadParams params = CurrImage->LoadParams;
for (Image* img = Images.First(); img; img = img->Next())
{
if (img->Filetype != tSystem::tFileType::EXR)
continue;
img->Unload();
img->LoadParams = params;
img->Load();
}
CurrImage->Unload();
CurrImage->Load();
}

fileTypeSectionDisplayed = true;
Expand Down
5 changes: 3 additions & 2 deletions Src/TacentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ tString Viewer::FindImageFilesInCurrentFolder(tList<tStringItem>& foundFiles)
tPrintf("Finding image files in %s\n", imagesDir.Chars());
tSystem::tExtensions extensions;
Image::GetCanLoad(extensions);
tSystem::tFindFiles(foundFiles, imagesDir, extensions);
tSystem::tFindFilesFast(foundFiles, imagesDir, extensions);

return imagesDir;
}
Expand Down Expand Up @@ -450,6 +450,7 @@ void Viewer::LoadCurrImage()
(CurrImage->Filetype == tFileType::GIF) ||
(CurrImage->Filetype == tFileType::WEBP) ||
(CurrImage->Filetype == tFileType::APNG) ||
(CurrImage->Filetype == tFileType::PNG) || // PNGs that have APNGs inside (more than one frame), also autoplay.
(CurrImage->Filetype == tFileType::TIFF)
)
)
Expand Down Expand Up @@ -2463,7 +2464,7 @@ void Viewer::IconifyCallback(GLFWwindow* window, int iconified)
int Viewer::RemoveOldCacheFiles(const tString& cacheDir)
{
tList<tStringItem> cacheFiles;
tSystem::tFindFiles(cacheFiles, cacheDir, "bin");
tSystem::tFindFilesFast(cacheFiles, cacheDir, "bin");
int numFiles = cacheFiles.NumItems();
if (numFiles <= Config.MaxCacheFiles)
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Src/Version.cmake.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#define set(verStr) namespace ViewerVersion { extern int Major, Minor, Revision; struct Parser { Parser(const char*); }; static Parser parser(#verStr); }

set("VIEWER_VERSION" "1.0.23")
set("VIEWER_VERSION" "1.0.24")

#undef set

0 comments on commit 0780b1a

Please sign in to comment.