Skip to content

Commit

Permalink
Removed chunk matching for recognizing file types as it slows down giv
Browse files Browse the repository at this point in the history
  • Loading branch information
dov committed Jan 10, 2023
1 parent b5f5adc commit b772f7e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 36 deletions.
6 changes: 5 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ make install
### cfitsio
- Using cmake toolchain
```
mkcd /space3/pub-repos/cfitsio-4.2.0/build_mingw64/
wget http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-4.2.0.tar.gz
tar xf cfitsio-4.2.0.tar.gz
cd cfitsio-4.2.0
mkdir build_mingw64
cd build_mingw64
cmake -DCMAKE_TOOLCHAIN_FILE=/home/dov/git/dov-env/cmake/mingw-w64-x86_64.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mingw64 ..
```
- This fails because of missing zlibrary
Expand Down
6 changes: 3 additions & 3 deletions libtool
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/sh
# Generated automatically by config.status (giv) 0.9.35
# Generated automatically by config.status (giv) 0.9.36
# Libtool was configured on host groovy:
# NOTE: Changes made to this file will be lost: look at ltmain.sh.

Expand Down Expand Up @@ -97,7 +97,7 @@ NM="/usr/bin/nm -B"
LN_S="ln -s"

# What is the maximum length of a command?
max_cmd_len=1572864
max_cmd_len=1879296

# Object file suffix (normally "o").
objext=o
Expand Down Expand Up @@ -291,7 +291,7 @@ hardcode_into_libs=yes
sys_lib_search_path_spec="/usr/lib/gcc/x86_64-redhat-linux/12 /usr/lib64 /lib64 /usr/lib /lib "

# Detected run-time system search path for libraries.
sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib /usr/lib64/R/lib /usr/lib/gtk-2.0/modules /usr/lib64/gtk-2.0/modules /usr/lib/gtk-3.0/modules /usr/lib64/gtk-3.0/modules /usr/lib64/alliance/lib /usr/lib64/iscsi /usr/lib64/llvm11/lib /usr/lib64/llvm13/lib /usr/local/lib /usr/local/lib64 /usr/lib64/octave/6.4.0 /usr/lib64/pipewire-0.3/jack/ /usr/lib64/qt5-qtwebengine-freeworld /usr/lib64/root /usr/lib64/tcl8.6 "
sys_lib_dlsearch_path_spec="/lib64 /usr/lib64 /lib /usr/lib /usr/lib64/R/lib /usr/lib/gtk-2.0/modules /usr/lib64/gtk-2.0/modules /usr/lib/gtk-3.0/modules /usr/lib64/gtk-3.0/modules /usr/lib64/alliance/lib /usr/lib64/iscsi /usr/lib64/llvm11/lib /usr/lib64/llvm13/lib /usr/local/lib /usr/local/lib64 /usr/i686-w64-mingw32/lib/ /usr/x86_64-w64-mingw32/lib/ /usr/lib64/octave/7.2.0 /usr/lib64/qt5-qtwebengine-freeworld /usr/lib64/root /usr/lib64/tcl8.6 "

# Explicit LT_SYS_LIBRARY_PATH set during ./configure time.
configure_time_lt_sys_library_path=""
Expand Down
13 changes: 11 additions & 2 deletions src/givplugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ gboolean giv_plugin_supported_file(const char *filename)
if (!giv_image_loaded_loaders)
rehash_loaders();

// Currently don't use chunk matching as it seriously slows
// down slow networks!!!
#if 0
// Read a chunk from the file
FILE *fh = fopen(filename, "rb");
if (!fh)
Expand All @@ -103,6 +106,7 @@ gboolean giv_plugin_supported_file(const char *filename)
chunk = g_new0(guchar, REQ_CHUNK_SIZE);
chunk_len = fread(chunk, 1, REQ_CHUNK_SIZE, fh);
fclose(fh);
#endif

GSList *ploaders = givimage_loaders;
while(ploaders) {
Expand All @@ -118,7 +122,8 @@ gboolean giv_plugin_supported_file(const char *filename)
}
ploaders = ploaders->next;
}
g_free(chunk);
if (chunk)
g_free(chunk);

return supported;
}
Expand All @@ -132,13 +137,18 @@ GivImage *giv_plugin_load_image(const char *filename,
if (!giv_image_loaded_loaders)
rehash_loaders();

#if 0
// Read a chunk from the file
FILE *fh = fopen(filename, "rb");
if (!fh)
return NULL;

chunk = g_new0(guchar, REQ_CHUNK_SIZE);
chunk_len = fread(chunk, 1, REQ_CHUNK_SIZE, fh);

fclose(fh);

#endif

GSList *ploaders = givimage_loaders;
while(ploaders) {
Expand Down Expand Up @@ -176,7 +186,6 @@ GivImage *giv_plugin_load_image(const char *filename,
}
ploaders = ploaders->next;
}
fclose(fh);
g_free(chunk);

return img;
Expand Down
7 changes: 5 additions & 2 deletions src/plugins/dicom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ extern "C" gboolean giv_plugin_supports_file(const char *filename,
guchar *start_chunk,
gint start_chunk_len)
{
gboolean is_dicom = g_ascii_strncasecmp ((gchar*)start_chunk+0x80,
"DICM",4) == 0;
gboolean is_dicom = false;

if (start_chunk && start_chunk_len >= 0x84)
is_dicom = g_ascii_strncasecmp ((gchar*)start_chunk+0x80,
"DICM",4) == 0;
if (!is_dicom)
is_dicom = g_ascii_strncasecmp((gchar*)filename+strlen(filename)-4,
".dcm",4)==0;
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/npy.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ gboolean giv_plugin_supports_file(const char *filename,
guchar *start_chunk,
gint start_chunk_len)
{
return g_strstr_len((const gchar*)start_chunk,
start_chunk_len,
"\223NUMPY") != NULL;
if (start_chunk)
return g_strstr_len((const gchar*)start_chunk,
start_chunk_len,
"\223NUMPY") != NULL;
else {
char *filename_down = g_utf8_strdown(filename,-1);
gboolean is_npy = g_str_has_suffix (filename_down, ".npy");
g_free(filename_down);
return is_npy;
}
}

GivImage *giv_plugin_load_file(const char *filename,
Expand Down
44 changes: 27 additions & 17 deletions src/plugins/ora.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,36 @@ extern "C" giv_plugin_support_t giv_plugin_get_support()
}

extern "C" gboolean giv_plugin_supports_file(const char *filename,
guchar *start_chunk,
gint start_chunk_len)
guchar *start_chunk,
gint start_chunk_len)
{
// An file is most probably an ora file if it is a zip file
// and it contains an image/openraster string.
static const gchar needle_ora[] = "image/openraster";
static const gchar needle_kra[] = "mimetypeapplication/x-krita";
return
// Is this a zip file?
my_memmem(start_chunk,start_chunk_len,
(const guchar*)"PK\003\004",4)!=NULL
// Does it contain a openraster or kra entry?
// Subtract one since the chunk data is not zero terminated
&& (my_memmem(start_chunk,
start_chunk_len,
(guchar*)needle_ora,sizeof(needle_ora)-1)!=NULL
|| my_memmem(start_chunk,
start_chunk_len,
(guchar*)needle_kra,sizeof(needle_kra)-1)!=NULL)
;
if (start_chunk and start_chunk_len > 4) {
static const gchar needle_ora[] = "image/openraster";
static const gchar needle_kra[] = "mimetypeapplication/x-krita";
return
// Is this a zip file?
my_memmem(start_chunk,start_chunk_len,
(const guchar*)"PK\003\004",4)!=NULL
// Does it contain a openraster or kra entry?
// Subtract one since the chunk data is not zero terminated
&& (my_memmem(start_chunk,
start_chunk_len,
(guchar*)needle_ora,sizeof(needle_ora)-1)!=NULL
|| my_memmem(start_chunk,
start_chunk_len,
(guchar*)needle_kra,sizeof(needle_kra)-1)!=NULL)
;
}
else
{
char *filename_down = g_utf8_strdown(filename,-1);
bool is_ora = (g_str_has_suffix (filename_down, ".kra")
|| g_str_has_suffix (filename_down, ".ora"));
g_free(filename_down);
return is_ora;
}
}

static int GetZipFile(zip *zh, const string&filename,
Expand Down
26 changes: 18 additions & 8 deletions src/plugins/tiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ gboolean giv_plugin_supports_file(const char *filename,
guchar *start_chunk,
gint start_chunk_len)
{
gboolean is_tiff = ((start_chunk[0] == 'M'
&& start_chunk[1] == 'M'
&& start_chunk[2] == 0
&& start_chunk[3] == '*')
|| (start_chunk[0] == 'I'
&& start_chunk[1] == 'I'
&& start_chunk[2] == '*'
&& start_chunk[3] == 0));
if (start_chunk)
{
gboolean is_tiff = ((start_chunk[0] == 'M'
&& start_chunk[1] == 'M'
&& start_chunk[2] == 0
&& start_chunk[3] == '*')
|| (start_chunk[0] == 'I'
&& start_chunk[1] == 'I'
&& start_chunk[2] == '*'
&& start_chunk[3] == 0));
return is_tiff;
}


char *filename_down = g_utf8_strdown(filename,-1);
gboolean is_tiff = g_str_has_suffix (filename_down, "tiff") || g_str_has_suffix (filename_down, "tif");
g_free(filename_down);

return is_tiff;
}

Expand Down

0 comments on commit b772f7e

Please sign in to comment.