-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prioritization among loaders? #144
Comments
@timholy any thoughts? |
I haven't worked on this package in ages, so I don't remember. You could check the implementation of |
So my OMETIFF loader is up and running over at https://github.com/tlnagy/OMETIFF.jl, but currently has its own It looks like this might be a little complicated. My reading of
This means that in my case, where I have identical magic bytes to already registered format, my loader would have lower priority than the default TIFF one. I think main way of solving this is to get rid of the uniqueness requirement and first sort on magic bytes and then on file name ( |
OK, now I have a couple of seconds to rub together and can actually look at code. Why can't you just list your OME-TIFF package above QuartzImageIO and ImageMagick in these lines? Just throw a Lines 85 to 104 in bf7756c
|
If the docs are inadequate on this point, a PR to fix them would be much appreciated! |
See more discussion in JuliaIO#144
I didn't realize that it would just try those loaders in order, #147 is my PR, but it needs to wait until a new version of OMETIFF.jl is merged into METADATA.jl |
I just scan the name of the stream quickly for |
Will FileIO try/suggest to install OMETIFF before trying ImageMagick if it can't find either? |
That's what I would expect, but imagemagick will most likely already be installed if the user opens almost any other image filetype first. This would only happen if the first image file the user opens happens to be TIFF. Not sure about a workaround. |
If it's not automatic and just a suggestion, can the suggestion message be customized? Maybe you could add "most users should skip this and try the next loader" to the message? |
How about this in # Handle OME-TIFFs, which are identical to normal TIFFs with the primary difference being the filename and embedded XML metadata
tiff_magic = (UInt8[0x4d,0x4d,0x00,0x2a], UInt8[0x4d,0x4d,0x00,0x2b], UInt8[0x49,0x49,0x2a,0x00],UInt8[0x49,0x49,0x2b,0x00])
function detecttiff(io)
seekstart(io)
magic = read(io, UInt8, 4)
# do any of the first 4 bytes match any of the 4 possible combinations of tiff magics
return any(map(x->all(magic .== x), tiff_magic))
end
# OME-TIFF
detect_ometiff(io) = detecttiff(io) && (endswith(io.name, ".ome.tif>") || endswith(io.name, ".ome.tiff>"))
add_format(format"OMETIFF", detect_ometiff, [".tif", ".tiff"], [:OMETIFF])
# normal TIFF
detect_noometiff(io) = detecttiff(io) && !(endswith(io.name, ".ome.tif>") || endswith(io.name, ".ome.tiff>"))
add_format(format"TIFF", detect_noometiff, [".tiff", ".tif"], [:QuartzImageIO, OSX], [:ImageMagick]) This should only install OMETIFF.jl if the user is actually opening an ome-tiff file. This basically just adds a filename check on top of the normal magic bytes check. |
The only test that is failing is the |
Making this change doesn't have much of an effect on the speed of loading a normal TIFF Master: julia> @benchmark load("/Users/tamasnagy/Downloads/129779/Figure_S5.tif")
WARNING: Compat.ASCIIString is deprecated, use String instead.
likely near no file:208
WARNING: Compat.UTF8String is deprecated, use String instead.
likely near no file:208
BenchmarkTools.Trial:
memory estimate: 14.68 MiB
allocs estimate: 276
--------------
minimum time: 39.933 ms (0.00% GC)
median time: 44.914 ms (4.94% GC)
mean time: 46.036 ms (5.88% GC)
maximum time: 133.672 ms (66.14% GC)
--------------
samples: 109
evals/sample: 1 This change: julia> @benchmark load("/Users/tamasnagy/Downloads/129779/Figure_S5.tif")
WARNING: Compat.ASCIIString is deprecated, use String instead.
likely near no file:208
WARNING: Compat.UTF8String is deprecated, use String instead.
likely near no file:208
BenchmarkTools.Trial:
memory estimate: 14.71 MiB
allocs estimate: 343
--------------
minimum time: 40.817 ms (0.00% GC)
median time: 45.740 ms (4.90% GC)
mean time: 47.232 ms (6.21% GC)
maximum time: 129.985 ms (65.44% GC)
--------------
samples: 106
evals/sample: 1 This is on 0.6 |
See my updates over at #147 |
Should this be closed? Or still relevant? |
I don't think this is relevant any more since we dispatch the correct TIFF package based on the name of the file + the TIFF magic bytes starting in #147 |
I'm writing a loader for uMicromanager OME-TIFF files. These have the standard TIFF magic bytes and TIFF ending and are picked up by the standard TIFF loader. I tried inserting my custom detection function either above or below the TIFF
add_format
call and I couldn't get it to work unless I commented out that line.Is there any way to assign priority for loaders?
The text was updated successfully, but these errors were encountered: