Skip to content
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

ImageSharp "Does not support this kind of bitmap files" #735

Closed
4 tasks done
wc-matteo opened this issue Oct 11, 2018 · 6 comments · Fixed by #796
Closed
4 tasks done

ImageSharp "Does not support this kind of bitmap files" #735

wc-matteo opened this issue Oct 11, 2018 · 6 comments · Fixed by #796

Comments

@wc-matteo
Copy link

wc-matteo commented Oct 11, 2018

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

Trying to open a specific bitmap file created with Magick.NET fails with an exception. Other files created in the same way don't.

Selecting ImageMagick.MagickFormat.Bmp2 or ImageMagick.MagickFormat.Bmp3 resolves the issue. The issue is with ImageMagick.MagickFormat.Bmp specifically, which uses, according to the docs, version 4 of the format.

The image in question does open without issues in other Windows programs (Paint, Photos, Photoshop) and Dropbox.

Steps to Reproduce

Download the file.

Try to open it:

using (var image = Image.Load("bitmap.bmp"))
{}

generates

Exception has occurred: CLR/System.NotSupportedException
An unhandled exception of type 'System.NotSupportedException' occurred in SixLabors.ImageSharp.dll: 'Does not support this kind of bitmap files.'
   at SixLabors.ImageSharp.Formats.Bmp.BmpDecoderCore.Decode[TPixel](Stream stream)
   at SixLabors.ImageSharp.Image.Decode[TPixel](Stream stream, Configuration config)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](Configuration config, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, Stream stream, IImageFormat& format)
   at SixLabors.ImageSharp.Image.Load[TPixel](Configuration config, String path)

System Configuration

  • ImageSharp version: 1.0.0-beta0005
  • Environment (Operating system, version and so on): Windows 10 x64 1803
  • .NET Framework version: 4.7.2 / .NET Core 2.1.4
@JimBobSquarePants
Copy link
Member

@wc-matteo

Yeah, bitmap support covers the more common types so far. @dlemstra Is there code we can use as inspiration from ImageMagick?

@dlemstra
Copy link
Member

I think we should be able to add support for this. And the file coders/bmp.c could give some insight on how this is done in ImageMagick.

@JimBobSquarePants
Copy link
Member

That's good news! 🎉

@JimBobSquarePants
Copy link
Member

If we update the support listed in #320 we can fix this

@brianpopow
Copy link
Collaborator

@wc-matteo: would you mind sharing the image here again? The drop box link does not work anymore. Just attaching it to this ticket would be helpful to reproduce it.

@wc-matteo
Copy link
Author

@brianpopow fixed the link. Don't know what happened there.

brianpopow added a commit to brianpopow/ImageSharp that referenced this issue Dec 22, 2018
JimBobSquarePants pushed a commit that referenced this issue Jan 18, 2019
* decoding bitmaps with Bitfields masks

* added testcases for Bitfields bitmaps

* added parsing of the complete bitmap V4 header to get the color masks infos for the BITFIELDS compression

* writing now explicitly a Bitamp v3 header (40 bytes)

* added test image for issue #735

* fixed rescaling 5-bit / 6-bit to 0 - 255 range

* BitmapEncoder now writes BMP v4 header

* using MemoryMarshal.Cast to simplify parsing v4 header

* added testcases for bitmap v3, v4, v5

* Bitmap encoder writes again V3 header instead of V4. Additional fields for V4 are zero anyway.

* added parsing of special case for 56 bytes headers

* using the alpha mask in ReadRgb32BitFields() when its present

* added support for bitmasks greater then 8 bits per channel

* using MagickReferenceDecoder reference decoder for the test with 10 bits pixel masks

* changed bitmap constants to hex

* added enum for the bitmap info header type

* added support for 52 bytes header (same as 56 bytes without the alpha mask)

* clarified comment with difference between imagesharp and magick decoder for Rgba321010102

* BmpEncoder now writes a V4 info header and uses BITFIELDS compression

* workaround for issue that the decoder does not decode the alpha channel correctly: For V3 bitmaps, the alpha channel will be ignored during encoding

* Fix #732
antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this issue Nov 11, 2019
* decoding bitmaps with Bitfields masks

* added testcases for Bitfields bitmaps

* added parsing of the complete bitmap V4 header to get the color masks infos for the BITFIELDS compression

* writing now explicitly a Bitamp v3 header (40 bytes)

* added test image for issue SixLabors#735

* fixed rescaling 5-bit / 6-bit to 0 - 255 range

* BitmapEncoder now writes BMP v4 header

* using MemoryMarshal.Cast to simplify parsing v4 header

* added testcases for bitmap v3, v4, v5

* Bitmap encoder writes again V3 header instead of V4. Additional fields for V4 are zero anyway.

* added parsing of special case for 56 bytes headers

* using the alpha mask in ReadRgb32BitFields() when its present

* added support for bitmasks greater then 8 bits per channel

* using MagickReferenceDecoder reference decoder for the test with 10 bits pixel masks

* changed bitmap constants to hex

* added enum for the bitmap info header type

* added support for 52 bytes header (same as 56 bytes without the alpha mask)

* clarified comment with difference between imagesharp and magick decoder for Rgba321010102

* BmpEncoder now writes a V4 info header and uses BITFIELDS compression

* workaround for issue that the decoder does not decode the alpha channel correctly: For V3 bitmaps, the alpha channel will be ignored during encoding

* Fix SixLabors#732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants