[KPhotoAlbum] Checking image file readability by MIME type, rather than file name
Robert L Krawitz
rlk at alum.mit.edu
Fri May 11 00:51:33 CEST 2007
From: "Jesper K. Pedersen" <blackie at blackie.dk>
Date: Thu, 10 May 2007 19:39:29 +0200
I wonder if KImageIO::typeForMime is expensive - afterall it needs to read
some of the file.
A solution might be to do something like:
return KImageIO::canRead(KImageIO::type(fileName)) ||
KImageIO::canRead(KImageIO::typeForMime(KImageIO::mimeType( fileName ))) ||
ImageManager::ImageDecoder::mightDecode( fileName );
Thus first checking using the file name, and if that fails trying using the
(presumeably) more expensive one.
I vote against this patch, on performance grounds. Example: the Canon
Digital Rebel produces thumbnail files (.thm, which are JPEGs) for
each raw image. As written, every time you scan for new images, it
will have to check each of these files. At present, it skips them
because the .thm suffix isn't known.
(For that matter, there's another problem with this -- it will read
the .thm files, see that they're actually JPEGs, and import them.
That's likely to be undesirable in its own right.)
Think about what happens if there are 50,000 files that need to be
checked each time someone wants to check for new images.
I'm not a big fan of using file suffixes for very much, but when
you're dealing with huge collections of files, you really don't want
to have to read each one of them -- even as little as one byte -- to
figure out what they are.
On Thursday 10 May 2007, Shawn Willden wrote:
| Bug 136955 has a patch attached that seems like a good idea to me. Can
| anyone think why it wouldn't? Personally, I think it's a bad idea to have
| misnamed files, but if it's possible to handle it gracefully, why not do
| Here's the text of the bug report:
| files named pict000.jpg or Akademy2005.png etc. are imported correctly,
| even if they are wrongly named and in reality both image/tiff, but
| Sol-2002.01.04 or Judy.image are not (both image/png).
| And the patch is at:
More information about the KPhotoAlbum