Skip to content

Commit

Permalink
Exclude TIFF from thumbnailers (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk authored May 6, 2023
1 parent 0c1ee5d commit f7e5012
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 24 deletions.
1 change: 0 additions & 1 deletion application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ if(NOT F3D_MACOS_BUNDLE)
f3d_test(NAME TestThumbnailConfigFileVTU DATA dragon.vtu CONFIG thumbnail_build DEFAULT_LIGHTS)
f3d_test(NAME TestThumbnailConfigFileVTI DATA vase_4comp.vti CONFIG thumbnail_build DEFAULT_LIGHTS)
f3d_test(NAME TestThumbnailConfigFileSTL DATA suzanne.stl CONFIG thumbnail_build DEFAULT_LIGHTS)
f3d_test(NAME TestThumbnailConfigFileTIFF DATA logo.tif CONFIG thumbnail_build DEFAULT_LIGHTS)
f3d_test(NAME TestThumbnailConfigFilePLY DATA cube.ply CONFIG thumbnail_build DEFAULT_LIGHTS THRESHOLD 100)
endif()
endif()
Expand Down
22 changes: 17 additions & 5 deletions cmake/f3dPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ macro(f3d_plugin_init)
set(F3D_PLUGIN_INCLUDES_CODE "")
set(F3D_PLUGIN_REGISTER_CODE "")
set(F3D_PLUGIN_MIMETYPES "")
set(F3D_PLUGIN_MIMETYPES_THUMB "")
set(F3D_PLUGIN_CURRENT_READER_INDEX 0)
set(F3D_PLUGIN_JSON "{ \"readers\": [] }")
endmacro()
Expand All @@ -35,6 +36,7 @@ f3d_plugin_declare_reader(
[VTK_READER <class>]
[FORMAT_DESCRIPTION <string>]
[SCORE <integer>]
[EXCLUDE_FROM_THUMBNAILER]
[CUSTOM_CODE <file>]
EXTENSIONS <string>...
MIMETYPES <string>...)
Expand All @@ -49,14 +51,15 @@ The `NAME` argument is required. The arguments are as follows:
* `VTK_READER`: The VTK reader class to use.
* `FORMAT_DESCRIPTION`: The description of the format read by the reader.
* `SCORE`: The score of the reader (from 0 to 100). Default value is 50.
* `EXCLUDE_FROM_THUMBNAILER`: If specified, the reader will not be used for generating thumbnails.
* `CUSTOM_CODE`: A custom code file containing the implementation of ``applyCustomReader`` function.
* `EXTENSIONS`: (Required) The list of file extensions supported by the reader.
* `MIMETYPES`: (Required) The list of mimetypes supported by the reader.
#]==]

macro(f3d_plugin_declare_reader)
cmake_parse_arguments(F3D_READER "" "NAME;VTK_IMPORTER;VTK_READER;FORMAT_DESCRIPTION;SCORE;CUSTOM_CODE" "EXTENSIONS;MIMETYPES" ${ARGN})
cmake_parse_arguments(F3D_READER "EXCLUDE_FROM_THUMBNAILER" "NAME;VTK_IMPORTER;VTK_READER;FORMAT_DESCRIPTION;SCORE;CUSTOM_CODE" "EXTENSIONS;MIMETYPES" ${ARGN})

if(F3D_READER_CUSTOM_CODE)
set(F3D_READER_HAS_CUSTOM_CODE 1)
Expand Down Expand Up @@ -99,6 +102,15 @@ macro(f3d_plugin_declare_reader)
string(JSON F3D_READER_JSON
SET "${F3D_READER_JSON}" "mimetypes" "[${F3D_READER_MIMETYPES}]")

if (F3D_READER_EXCLUDE_FROM_THUMBNAILER)
string(JSON F3D_READER_JSON
SET "${F3D_READER_JSON}" "exclude_thumbnailer" "true")
else()
list(APPEND F3D_PLUGIN_MIMETYPES_THUMB ${F3D_READER_MIMETYPES})
string(JSON F3D_READER_JSON
SET "${F3D_READER_JSON}" "exclude_thumbnailer" "false")
endif()

string(JSON F3D_PLUGIN_JSON
SET "${F3D_PLUGIN_JSON}" "readers" ${F3D_PLUGIN_CURRENT_READER_INDEX} "${F3D_READER_JSON}")

Expand Down Expand Up @@ -297,14 +309,14 @@ macro(f3d_plugin_build)
if(F3D_PLUGIN_FREEDESKTOP)
configure_file(
"${_f3dPlugin_dir}/plugin.desktop.in"
"${CMAKE_CURRENT_BINARY_DIR}/f3d-plugin-${F3D_PLUGIN_NAME}.desktop")
"${CMAKE_BINARY_DIR}/share/applications/f3d-plugin-${F3D_PLUGIN_NAME}.desktop")
configure_file(
"${_f3dPlugin_dir}/plugin.thumbnailer.in"
"${CMAKE_CURRENT_BINARY_DIR}/f3d-plugin-${F3D_PLUGIN_NAME}.thumbnailer")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f3d-plugin-${F3D_PLUGIN_NAME}.desktop"
"${CMAKE_BINARY_DIR}/share/thumbnailers/f3d-plugin-${F3D_PLUGIN_NAME}.thumbnailer")
install(FILES "${CMAKE_BINARY_DIR}/share/applications/f3d-plugin-${F3D_PLUGIN_NAME}.desktop"
DESTINATION "share/applications"
COMPONENT plugin)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/f3d-plugin-${F3D_PLUGIN_NAME}.thumbnailer"
install(FILES "${CMAKE_BINARY_DIR}/share/thumbnailers/f3d-plugin-${F3D_PLUGIN_NAME}.thumbnailer"
DESTINATION "share/thumbnailers"
COMPONENT plugin)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/plugin.thumbnailer.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Type=X-Thumbnailer
Name=f3d Thumbnailer (${F3D_PLUGIN_NAME} plugin)
TryExec=f3d
Exec=f3d --config=thumbnail --load-plugins=${F3D_PLUGIN_NAME} --quiet --output=%o --resolution=%s,%s %i
MimeType=${F3D_PLUGIN_MIMETYPES}
MimeType=${F3D_PLUGIN_MIMETYPES_THUMB}
3 changes: 2 additions & 1 deletion doc/libf3d/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ f3d_plugin_declare_reader(
EXTENSIONS "myext" # set the extensions the reader can support
MIMETYPES "application/vnd.myext" # set the mimetypes the reader can support
VTK_READER ${vtk_classname} # set the name of the VTK class you have created
DESCRIPTION "Reader description"
DESCRIPTION "Reader description" # set the description of the reader
EXCLUDE_FROM_THUMBNAILER # add this flag if you don't want thumbnail generation for this reader
)
# More f3d_plugin_declare_reader calls are possible
Expand Down
4 changes: 4 additions & 0 deletions doc/user/DESKTOP_INTEGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ regsvr32 /u F3DShellExtension.dll
## MacOS

There is no support for thumbnails on MacOS, the .dmg binary release provides automatic file openings.

## Limitations

- TIFF files are excluded from the thumbnailer to avoid conflicts with other better 2D thumbnailers.
1 change: 1 addition & 0 deletions plugins/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ f3d_plugin_declare_reader(
MIMETYPES application/x-tgif
VTK_READER vtkTIFFReader
FORMAT_DESCRIPTION "TIFF"
EXCLUDE_FROM_THUMBNAILER
)

f3d_plugin_declare_reader(
Expand Down
5 changes: 0 additions & 5 deletions plugins/native/configs/thumbnail.d/10_native.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
{
"up": "+Z"
},
".*(tif|tiff)":
{
"up": "-Y",
"comp": "-2"
},
".*(ply)":
{
"comp": "-2",
Expand Down
3 changes: 0 additions & 3 deletions testing/baselines/TestThumbnailConfigFileTIFF.png

This file was deleted.

21 changes: 13 additions & 8 deletions winshellext/F3DShellExtension.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ void RunOnJSONExtensions(fs::path modulePath, F callback)
{
for (auto& r : readers.value())
{
auto exts = r.find("extensions");
auto excludeThumb = r.find("exclude_thumbnailer").value();

if (exts != r.end() && exts.value().is_array())
if (excludeThumb.is_boolean() && excludeThumb.get<bool>() == false)
{
for (auto& e : exts.value())
auto exts = r.find("extensions");

if (exts != r.end() && exts.value().is_array())
{
if (e.is_string())
for (auto& e : exts.value())
{
std::wstring ret = L".";
if (e.is_string())
{
std::wstring ret = L".";

std::wstring_convert<std::codecvt_utf8<wchar_t> > toUnicode;
ret += toUnicode.from_bytes(e.get<std::string>());
std::wstring_convert<std::codecvt_utf8<wchar_t> > toUnicode;
ret += toUnicode.from_bytes(e.get<std::string>());

callback(ret);
callback(ret);
}
}
}
}
Expand Down

0 comments on commit f7e5012

Please sign in to comment.