GNOME Bugzilla – Bug 326411
Imagefile should use file magic to load images
Last modified: 2009-08-11 10:56:40 UTC
right now ImageFile uses just the filename to pick the loader, it should use the files magic numbers.
Are you aware of an implementation of file(1) in C# ?
gnome-vfs has the needed function, and I'll make certain the shared-mime-info database has valied magic for all the formats we load. It really just needs to be hooked up.
In the meantime, I've started a implementation of this. It's a very short number of lines. It's working now, just need some time to be integrated with f-spot. Once it is ready, I'll send it to you and it's yours to decide...
Created attachment 67178 [details] [review] Use the file magic to choose the loader This code replace the extension based loader. For now, it only detect png, gif and jpg. If there is any interest, I can easily extend the table to support the other formats. Comments are welcome.
Created attachment 67180 [details] [review] use the mimetype to choose a loader This patch has exactly the same functionality as the previous. It uses the mime type provided by the GnomeVfs instead of reading the file magic. I guess Larry will prefer this one. (Same comment: for now, only for jpg, gif, png, but I can extend the table)
I'm planning to extend the patch 67180 to support the whole list of files F-spot handle. But I don't have the mime type (as reported by nautilus > properties) for the following files: .svg .gif .cr2 .nef .pef .raw .tiff .tif .orf .srf .dng .crw .ppm .mrw .raf .x3f I can probably find out some of them, but I know nothing at all about nef, pef, raw, orf, srf, dng, mrw, raf, x3f please comment to this bug if you had some...
Nautilus reports .nef as image/tiff
I think you will run into problems as .dng is also reported as image/tiff most raw files seems to be reported as image/tiff
Created attachment 68674 [details] [review] ImageFile.cs patch which uses both mime info and extensions My dirty patch which first checks for a legal mime type and then uses the extension to associate it with the right image loader. Based on Stephane Delcroix patch. Seems to work (I mostly reused the old code). The mime types are still not complete...
Zaxmy (comment #8), I'm aware of this, and still don't know exactly how to solve it (but there is a way, I'm sure of that). Zaxmy again (comment #9 and patch), good try, but your patch is simply useless. You 're checking the mime type and then return the type only defined by the extension... Zaxmy again and again (comment #7), thanks for the mime type of the nef file.
(In reply to comment #10) > Zaxmy again (comment #9 and patch), good try, but your patch is simply useless. > You 're checking the mime type and then return the type only defined by the > extension... I think useless is a bit of over statement, it's more useful than your orginal patch ;-) I looked up how libgnomevfs does it, they have a own implementation of file... gthumb relies on gdk-pixbuf's ability to detect the right file format when displaying images, they just check that it is a mime type containing the magic "image" word.
Gnome-vfs uses the freedesktop spec for shared mime info. I have a patch for shared-mime-info that has magic for most of the raw types here, I sent it upstream a while ago but it died after a little discussion. Things like .nef and .cr2 are in fact tiff files in that they are aranged using the same ifd concept with some extensions/modifications. The ImageFile tiff loader can be cleaned up and made generic enough to deal with all the variants without too much trouble.
Sounds like the best solution.
interesting related bug: https://bugs.freedesktop.org/show_bug.cgi?id=8170 I'm currently testing it...
ok, it works ! I copied the attachment as /usr/share/mime/packages/raw.xml, updated the mime infos with update-mime-database /usr/share/mime, and the raw files are detected correctly (tested with nautilus) Apparently, there's still a problem with .cr2. Can f-spot install its own mime xml file or wait for the inclusion of that in shared-mime-info ?
*** Bug 491193 has been marked as a duplicate of this bug. ***
Any news on this bug, after Stephane's "ok it works !" comment in comment #15 It's been over one year with a workable solution or?
no, no news. the "official" mime db still doesn't recognize all the raw formats :(
*** Bug 564817 has been marked as a duplicate of this bug. ***
Should be fixed: commit a41352f10074d4acc7b1e7eafe5a1484ee70bed4 Author: Gabriel Burt <gabriel.burt@gmail.com> Date: Mon Aug 10 16:55:04 2009 -0700 Support loading files with no extensions