solang-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Solang-devel] Problems in detecting content-types (and GdkPixbufLoader)


From: Debarshi Ray
Subject: [Solang-devel] Problems in detecting content-types (and GdkPixbufLoader)
Date: Mon, 7 Dec 2009 03:40:47 +0200

While playing with Solang over the weekend I discovered some
idiosyncrasies in the way Gio::content_type_guess figures out the
content-type of a file, which in turn affects how a Gdk::PixbufLoader
is selected to load a photo as a Gdk::Pixbuf. This is just an attempt
to document my findings.

+ If a filepath corresponding to an existing file is passed then
xdg_mime_get_mime_types_from_file_name is used to decipher the mime
type based on the file name itself.
+ If some data from the beginning of the file was also sent then it is
only consulted if an unique mime type could not be deciphered by the
above step.

So ContentTypeRepo::get_content_type needs to be fixed to send some
data from the beginning of the file to deal with files renamed to have
weird extensions. But even that is not going to enough if some one
renamed a .png to a .jpg because the above algorithm just looks at the
.jpg extension and assumes it to be image/jpeg and without looking at
the actual data which is something else.

To get around this GdkPixbuf tries to detect the content type by just
providing some data and no file name. This becomes problematic when
dealing with RAW images. Recent versions of libopenraw provide a
GdkPixbufLoader for RAW files. However GdkPixbuf detects some RAW
images as TIFF images even though the TIFF loader is unable to finally
load the RAW and errors out. In such cases it would have been good to
use the filename.

So, for the time being I propose to make the above modification to our
ContentTypeRepo::get_content_type and whereever there is a possibility
of encountering a RAW image explicitly select the GdkPixbufLoader
based on our detected content type instead of trusting GdkPixbuf to
select one for us. Even if we do not want to show a RAW, it is bad to
have the TIFF loader try to load it and throw an exception.

Here is a sample patch:
http://rishi.fedorapeople.org/0001-Improved-content-type-guessing-and-Gdk-PixbufLoader.patch

Happy hacking,
Debarshi
-- 
One reason that life is complex is that it has a real part and an
imaginary part.
    -- Andrew Koenig




reply via email to

[Prev in Thread] Current Thread [Next in Thread]