Skip to content

Commit

Permalink
Fix failing 32-bit build by removing support for JXL and EXR
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Aug 25, 2024
1 parent 7a58468 commit 74aa8ec
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
4 changes: 3 additions & 1 deletion SKIV.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@
<ClCompile Include="src\imgui\imgui_impl_dx11.cpp" />
<ClCompile Include="src\imgui\imgui_impl_win32.cpp" />
<ClCompile Include="src\imgui\imgui_tables.cpp" />
<ClCompile Include="src\utility\DirectXTexEXR.cpp" />
<ClCompile Include="src\utility\DirectXTexEXR.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="src\utility\gamepad.cpp" />
<ClCompile Include="src\utility\image.cpp" />
<ClCompile Include="src\utility\registry.cpp" />
Expand Down
47 changes: 38 additions & 9 deletions src/tabs/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
#include <ImGuiNotify.hpp>

#include "DirectXTex.h"
#include <utility/DirectXTexEXR.h>
#include <wincodec.h>
#ifdef _M_X64
#include <utility/DirectXTexEXR.h>
#endif

#include <fonts/fa_621.h>
#include <fonts/fa_621b.h>
Expand Down Expand Up @@ -70,12 +72,14 @@
//#define STBI_ONLY_PIC
//#define STBI_ONLY_PNM

#ifdef _M_X64
#include <jxl/codestream_header.h>
#include <jxl/decode.h>
#include <jxl/decode_cxx.h>
#include <jxl/resizable_parallel_runner.h>
#include <jxl/resizable_parallel_runner_cxx.h>
#include <jxl/types.h>
#endif

#include <stb_image.h>
#include <html_coder.hpp>
Expand Down Expand Up @@ -129,11 +133,16 @@ const std::initializer_list<FileSignature> supported_formats =
FileSignature { L"image/gif", { L".gif" }, { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 } }, // GIF87a
FileSignature { L"image/gif", { L".gif" }, { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 } }, // GIF89a
FileSignature { L"image/vnd.radiance", { L".hdr" }, { 0x23, 0x3F, 0x52, 0x41, 0x44, 0x49, 0x41, 0x4E, 0x43, 0x45, 0x0A } }, // Radiance High Dynamic Range image file
#ifdef _M_X64
FileSignature { L"image/x-exr", { L".exr" }, { 0x76, 0x2F, 0x31, 0x01 } },
#endif
FileSignature { L"image/avif", { L".avif" }, { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66 }, // ftypavif

{ 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, // ?? ?? ?? ?? 66 74 79 70 61 76 69 66
#ifdef _M_X64
FileSignature { L"image/jxl", { L".jxl" }, { 0xFF, 0x0A } }, // Naked
FileSignature { L"image/jxl", { L".jxl" }, { 0x00, 0x00, 0x00, 0x0C, 0x4A, 0x58, 0x4C, 0x20, 0x0D, 0x0A, 0x87, 0x0A } }, // ISOBMFF-based container
#endif
FileSignature { L"image/vnd-ms.dds", { L".dds" }, { 0x44, 0x44, 0x53, 0x20 } },
//FileSignature { L"image/x-targa", { L".tga" }, { 0x00, } }, // TGA has no real unique header identifier, so just use the file extension on those
};
Expand All @@ -156,15 +165,18 @@ const std::initializer_list<FileSignature> supported_hdr_encode_formats =
FileSignature { L"image/png", { L".png" }, { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A } },
FileSignature { L"image/vnd.ms-photo", { L".jxr" }, { 0x49, 0x49, 0xBC } },
FileSignature { L"image/vnd.radiance", { L".hdr" }, { 0x23, 0x3F, 0x52, 0x41, 0x44, 0x49, 0x41, 0x4E, 0x43, 0x45, 0x0A } }, // Radiance High Dynamic Range image file
#ifdef _M_X64
FileSignature { L"image/x-exr", { L".exr" }, { 0x76, 0x2F, 0x31, 0x01 } },
FileSignature { L"image/jxl", { L".jxl" }, { 0xFF, 0x0A } },
#endif
//FileSignature { L"image/avif", { L".avif" }, { 0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66 }, // ftypavif
// { 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }, // ?? ?? ?? ?? 66 74 79 70 61 76 69 66
//FileSignature { L"image/vnd-ms.dds", { L".dds" }, { 0x44, 0x44, 0x53, 0x20 } },
};

bool isJXLDecoderAvailable (void)
{
#ifdef _M_X64
static HMODULE hModJXL = nullptr;
static HMODULE hModJXLCMS = nullptr;
static HMODULE hModJXLThreads = nullptr;
Expand Down Expand Up @@ -249,6 +261,9 @@ bool isJXLDecoderAvailable (void)
}

return supported;
#else
return false;
#endif
}

bool isExtensionSupported (const std::wstring extension)
Expand All @@ -257,11 +272,13 @@ bool isExtensionSupported (const std::wstring extension)
{
if (SKIF_Util_HasFileExtension (extension, type))
{
#ifdef _M_X64
// Support for JXL is optional
if (type.mime_type == L"image/jxl")
{
return isJXLDecoderAvailable ();
}
#endif

return true;
}
Expand Down Expand Up @@ -389,7 +406,7 @@ struct image_s {
std:: string folder_path_utf8 = { };
std::wstring path = { }; // Image path (full)
std:: string path_utf8 = { };
size_t size = 0;
uint64_t size = 0;
file_s ( ) { };
} file_info;

Expand Down Expand Up @@ -701,8 +718,10 @@ enum ImageDecoder {
ImageDecoder_WIC,
ImageDecoder_DDS,
ImageDecoder_stbi,
#ifdef _M_X64
ImageDecoder_JXL,
ImageDecoder_EXR,
#endif
ImageDecoder_HDR,
ImageDecoder_AVIF // TODO
};
Expand All @@ -713,10 +732,10 @@ class SK_AutoFile {
{
if (file_ != nullptr)
{
auto orig_pos = _ftelli64 (pFile);
_fseeki64 (pFile, 0, SEEK_END);
size_ = _ftelli64 (pFile);
_fseeki64 (pFile, orig_pos, SEEK_SET);
auto orig_pos = ftell (pFile);
fseek (pFile, 0, SEEK_END);
size_ = ftell (pFile);
fseek (pFile, orig_pos, SEEK_SET);
}
}

Expand All @@ -728,13 +747,13 @@ class SK_AutoFile {
}
}

long long getInitialSize (void) const {
size_t getInitialSize (void) const {
return size_;
}

private:
long long size_;
FILE* file_;
size_t size_;
FILE* file_;
};

class SKIV_ScopedThreadPriority_Viewer
Expand Down Expand Up @@ -998,9 +1017,13 @@ LoadLibraryTexture (image_s& image)
(type.mime_type == L"image/webp" ) ? ImageDecoder_WIC :
(type.mime_type == L"image/tiff" ) ? ImageDecoder_WIC :
(type.mime_type == L"image/avif" ) ? ImageDecoder_WIC :
#ifdef _M_X64
(type.mime_type == L"image/jxl" ) ? ImageDecoder_JXL :
#endif
(type.mime_type == L"image/vnd-ms.dds" ) ? ImageDecoder_DDS :
#ifdef _M_X64
(type.mime_type == L"image/x-exr" ) ? ImageDecoder_EXR :
#endif
ImageDecoder_WIC; // Not actually being used

// None of this is technically correct other than the .hdr case,
Expand Down Expand Up @@ -1034,8 +1057,10 @@ LoadLibraryTexture (image_s& image)
PLOG_DEBUG_IF(decoder == ImageDecoder_stbi) << "Using stbi decoder...";
PLOG_DEBUG_IF(decoder == ImageDecoder_WIC ) << "Using WIC decoder...";
PLOG_DEBUG_IF(decoder == ImageDecoder_DDS ) << "Using DDS decoder...";
#ifdef _M_X64
PLOG_DEBUG_IF(decoder == ImageDecoder_JXL ) << "Using JPEG-XL decoder...";
PLOG_DEBUG_IF(decoder == ImageDecoder_EXR ) << "Using OpenEXR decoder...";
#endif
PLOG_DEBUG_IF(decoder == ImageDecoder_HDR ) << "Using Radiance HDR decoder...";

if (decoder == ImageDecoder_None)
Expand Down Expand Up @@ -1357,6 +1382,7 @@ LoadLibraryTexture (image_s& image)
}
}

#ifdef _M_X64
if (decoder == ImageDecoder_EXR)
{
using namespace DirectX;
Expand Down Expand Up @@ -1386,6 +1412,7 @@ LoadLibraryTexture (image_s& image)
meta.dimension = DirectX::TEX_DIMENSION_TEXTURE2D;
}
}
#endif

if (decoder == ImageDecoder_HDR)
{
Expand Down Expand Up @@ -1421,6 +1448,7 @@ LoadLibraryTexture (image_s& image)
}
}

#ifdef _M_X64
if (decoder == ImageDecoder_JXL)
{
static HMODULE hModJXL;
Expand Down Expand Up @@ -1718,6 +1746,7 @@ LoadLibraryTexture (image_s& image)
if ( jxl_runner != nullptr)
jxlResizableParallelRunnerDestroy (nullptr);
}
#endif

// Push the existing texture to a stack to be released after the frame
// Do this regardless of whether we could actually load the new cover or not
Expand Down
4 changes: 4 additions & 0 deletions src/utility/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,7 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
wic_codec = GetWICCodec (WIC_CODEC_WMP);
}

#ifdef _M_X64
else if (StrStrIW (wszExtension, L"exr"))
{
using namespace DirectX;
Expand All @@ -2201,6 +2202,7 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
return S_OK;
}
}
#endif

else if (StrStrIW (wszExtension, L"hdr"))
{
Expand All @@ -2224,6 +2226,7 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
}
}

#ifdef _M_X64
else if (StrStrIW (wszExtension, L"jxl"))
{
extern bool isJXLDecoderAvailable (void);
Expand Down Expand Up @@ -2472,6 +2475,7 @@ SKIV_Image_SaveToDisk_HDR (const DirectX::Image& image, const wchar_t* wszFileNa
return
succeeded ? S_OK : E_FAIL;
}
#endif

else if (StrStrIW (wszExtension, L"avif"))
{
Expand Down

0 comments on commit 74aa8ec

Please sign in to comment.