Skip to content

BUG: BMP can't be read without proper extension#1407

Merged
thewtex merged 1 commit intoInsightSoftwareConsortium:masterfrom
Nekto89:bmpimageio_check_extension
Nov 9, 2019
Merged

BUG: BMP can't be read without proper extension#1407
thewtex merged 1 commit intoInsightSoftwareConsortium:masterfrom
Nekto89:bmpimageio_check_extension

Conversation

@Nekto89
Copy link
Copy Markdown
Contributor

@Nekto89 Nekto89 commented Nov 9, 2019

This change allows reading BMP files that have wrong extension.

PR Checklist

@dzenanz dzenanz requested a review from YannLePoul November 9, 2019 16:53
Copy link
Copy Markdown
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nekto89 well done - thanks!

@thewtex thewtex merged commit 3ac8203 into InsightSoftwareConsortium:master Nov 9, 2019
@YannLePoul
Copy link
Copy Markdown
Contributor

YannLePoul commented Nov 9, 2019

First question is is it a feature or a bug. For bmp, it has been implemented on purpose this way.

But I guess the real problem here is that the behavior is not consistent across all imageIO.
extensionFound comes from the HasSupportedReadExtension function. This function seems to be called in the CanReadFile method of BMPImageIO, JPEGImageIO, JPEG2000ImageIO, MINCImageIO, MRCImageIO, NrrdImageIO, StimulateImageIO, but not for other IO, like TiffImageIo...

@YannLePoul
Copy link
Copy Markdown
Contributor

Merged too fast ?

I would be in favor of a consistent behavior for all ImageIO to test whether they can read the file or not not based on the file extension.

if (!extensionFound)
{
itkDebugMacro(<< "The filename extension is not recognized");
return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same behavior is found for BMPImageIO, JPEGImageIO, JPEG2000ImageIO, MINCImageIO, MRCImageIO, NrrdImageIO, StimulateImageIO, but not for other IO, like TiffImageIo...

@thewtex
Copy link
Copy Markdown
Member

thewtex commented Nov 9, 2019

Some file formats or the reader implementations only can check whether they can read a given file based on the file extension.

Other readers can perform more advanced checks, e.g. looking at the first "magic" bytes that identify a file format in its header. These readers can correctly identify a file without a filename, with the wrong filename, or without a filename extension. In DICOM, for example, it is common to not have a filename extension.

So, we should not limit all readers to require an extension. But, if we can improve the BMP reader to go beyond extension checking, patches for that would be welcome :-).

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Nov 9, 2019

BMP reader already looks for magic BM, it is just that it was also looking for .bmp extension before this PR.

@blowekamp
Copy link
Copy Markdown
Member

We could cautiously allow ImageIOs to open the file to check if it can read the file. The way the IO factory works is that for every ImageIO it is constructed and then "CanRead" is called to determine if it's the correct one to use. If every ImageIO open the file, checks, and closes the file it will slow down this process ( consider network or remote files ).

There have been recent improvements for the ImageIOs to report the extensions it can read. To pursue this feature further I'd recommend making the IO Factory construction two passes:

  • Check the extension of the file is supported for each IO, if found then use that ImageIO.
  • Then check the CanRead method which may open the file.

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Nov 10, 2019

Sounds logical, but is it a non-trivial amount of work. Can you create an issue to track the implementation? Are you willing to undertake it?

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Nov 10, 2019

@Nekto89 I guess this patch introduced a new warning on one of the nightly build machines:
https://open.cdash.org/viewBuildError.php?type=1&buildid=6201669

@Nekto89
Copy link
Copy Markdown
Contributor Author

Nekto89 commented Nov 12, 2019

@Nekto89 I guess this patch introduced a new warning on one of the nightly build machines:
https://open.cdash.org/viewBuildError.php?type=1&buildid=6201669

This is probably caused by older Xcode that warns on perfectly normal C++ code (same with std::array). Do you want me to add additional braces here?

@dzenanz
Copy link
Copy Markdown
Member

dzenanz commented Nov 12, 2019

It would be good.

hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this pull request May 6, 2026
…geio_check_extension

BUG: BMP can't be read without proper extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants