Alexander Foremny | 28 Jun 2012 13:34
Picon
Gravatar

Data.Bitmap, readBitmap exception

Hello,

I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
following sample GHCi session fails for me.

> Prelude Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO (Bitmap Word8)
> *** Exception: Data/Bitmap/Internal.hs:(63,17)-(67,15): Non-exhaustive patterns in case

I downloaded the sources of bitmap-0.2 from Hackage and modified the
relevant function by appending the last line.

> decodeCType :: CInt -> PixelComponentType
> decodeCType k = case k of
>   1 -> PctWord8
>   2 -> PctWord16
>   3 -> PctWord32
>   4 -> PctFloat
>   _ -> error $ "decodeCType: unexpected integer (" ++ show k ++ ")"

With this modification the same GHCi session given above results in
the following error.

> Prelude Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO (Bitmap Word8)
> *** Exception: decodeCType: unexpected integer (7077888)

I don't have any idea where 7077888 comes from. Am I doing something
wrong? Is my bitmap corrupted in some way? The number 7077888 has no
apparent significance except that it is a perfect cube [3]. So I guess
this is not a problem with endianness.

(Continue reading)

Brandon Allbery | 28 Jun 2012 14:03
Picon
Gravatar

Re: Data.Bitmap, readBitmap exception

On Thu, Jun 28, 2012 at 7:34 AM, Alexander Foremny <alexanderforemny <at> gmail.com> wrote:
I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
following sample GHCi session fails for me.

For what it's worth, my system doesn't recognize your bitmap as a valid image file.

--
brandon s allbery                                      allbery.b <at> gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Krzysztof Skrzętnicki | 28 Jun 2012 14:10
Picon

Re: Data.Bitmap, readBitmap exception

That bitmap must be pretty weird. 'file' command reports 'data', so headers must be off. Image viewer OTOH does handle the file.

Best regards,
Krzysztof Skrzętnicki

On Thu, Jun 28, 2012 at 2:03 PM, Brandon Allbery <allbery.b <at> gmail.com> wrote:
On Thu, Jun 28, 2012 at 7:34 AM, Alexander Foremny <alexanderforemny <at> gmail.com> wrote:
I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
following sample GHCi session fails for me.

For what it's worth, my system doesn't recognize your bitmap as a valid image file.

--
brandon s allbery                                      allbery.b <at> gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Alexander Foremny | 28 Jun 2012 14:13
Picon
Gravatar

Re: Data.Bitmap, readBitmap exception

For what it's worth I created that Bitmap file with Gimp and exported
to 32 bit R G B A bitmap. I'll try another bitmap file later and
report back.

2012/6/28 Krzysztof Skrzętnicki <gtener <at> gmail.com>:
> That bitmap must be pretty weird. 'file' command reports 'data', so headers
> must be off. Image viewer OTOH does handle the file.
>
> Best regards,
> Krzysztof Skrzętnicki
>
> On Thu, Jun 28, 2012 at 2:03 PM, Brandon Allbery <allbery.b <at> gmail.com>
> wrote:
>>
>> On Thu, Jun 28, 2012 at 7:34 AM, Alexander Foremny
>> <alexanderforemny <at> gmail.com> wrote:
>>>
>>> I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
>>> following sample GHCi session fails for me.
>>
>>
>> For what it's worth, my system doesn't recognize your bitmap as a valid
>> image file.
>>
>> --
>> brandon s allbery                                      allbery.b <at> gmail.com
>> wandering unix systems administrator (available)     (412) 475-9364 vm/sms
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe <at> haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Alexander Foremny | 28 Jun 2012 17:47
Picon
Gravatar

Re: Data.Bitmap, readBitmap exception

I tested a similar GHCi session as the ones above with a Bitmap file I
found in the wild and I encountered the same results for Bitmap Word8,
Bitmap Word16 and other exceptions for Bitmap Word32, Bitmap Float.

> readBitmap "chef.bmp" :: IO (Bitmap Word32)
> *** Exception: mallocForeignPtrBytes: size must be >= 0

However, there is still the possibility that this Bitmap might be
corrupted either. Just thought I'd report this.

Regards,
Alexander Foremny

2012/6/28 Alexander Foremny <alexanderforemny <at> gmail.com>:
> For what it's worth I created that Bitmap file with Gimp and exported
> to 32 bit R G B A bitmap. I'll try another bitmap file later and
> report back.
>
> 2012/6/28 Krzysztof Skrzętnicki <gtener <at> gmail.com>:
>> That bitmap must be pretty weird. 'file' command reports 'data', so headers
>> must be off. Image viewer OTOH does handle the file.
>>
>> Best regards,
>> Krzysztof Skrzętnicki
>>
>> On Thu, Jun 28, 2012 at 2:03 PM, Brandon Allbery <allbery.b <at> gmail.com>
>> wrote:
>>>
>>> On Thu, Jun 28, 2012 at 7:34 AM, Alexander Foremny
>>> <alexanderforemny <at> gmail.com> wrote:
>>>>
>>>> I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
>>>> following sample GHCi session fails for me.
>>>
>>>
>>> For what it's worth, my system doesn't recognize your bitmap as a valid
>>> image file.
>>>
>>> --
>>> brandon s allbery                                      allbery.b <at> gmail.com
>>> wandering unix systems administrator (available)     (412) 475-9364 vm/sms
>>>
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe <at> haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Balazs Komuves | 29 Jun 2012 21:41
Picon

Re: Data.Bitmap, readBitmap exception


Hello,

Author of Data.Bitmap here. The issue is caused by the fact that Data.Bitmap does *not* support
bmp files at all. This should be clear from the documentation. The functions you tried to used use
their own file format, which a really very simple format; they are only added for simple experimentation.
(again, this is explicit in the docs). The same documentation points to the stb-image [1] package,
 which supports loading of some common formats (png, jpg, bmp).

In general, I suggest that with package-specific question, unless it is a widely used package,
mail the maintainer directly; you have better chance to get an answer that way.

Regards,
Balazs

[1] http://hackage.haskell.org/package/stb-image

Hello,

I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
following sample GHCi session fails for me.

> Prelude Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO (Bitmap Word8)
> *** Exception: Data/Bitmap/Internal.hs:(63,17)-(67,15): Non-exhaustive patterns in case

I downloaded the sources of bitmap-0.2 from Hackage and modified the
relevant function by appending the last line.

> decodeCType :: CInt -> PixelComponentType
> decodeCType k = case k of
>   1 -> PctWord8
>   2 -> PctWord16
>   3 -> PctWord32
>   4 -> PctFloat
>   _ -> error $ "decodeCType: unexpected integer (" ++ show k ++ ")"

With this modification the same GHCi session given above results in
the following error.

> Prelude Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO (Bitmap Word8)
> *** Exception: decodeCType: unexpected integer (7077888)

I don't have any idea where 7077888 comes from. Am I doing something
wrong? Is my bitmap corrupted in some way? The number 7077888 has no
apparent significance except that it is a perfect cube [3]. So I guess
this is not a problem with endianness.

In fact as far as I can tell `decodeCType` is only called on
`(PixelComponent t => c_type t)` and `c_type t` only yields integer
values in the (inclusive) range of 1 to 4. That is if I am not missing
some orphaned instance.

Could anyone please enlighten me what is happening and if I am doing
something wrong?

In case this is relevant: I am using bitmap-0.2 from Hackage with GHC
7.4.1 on a 3.2.20 kernel i686 architecture Linux.

Regards,
Alexander Foremny

[1] http://hackage.haskell.org/package/bitmap
[2] https://www.dropbox.com/s/pyutvni9vx6f6mo/b.bmp
[3] http://www.wolframalpha.com/input/?i=7077888

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Alexander Foremny | 2 Jul 2012 20:33
Picon
Gravatar

Re: Data.Bitmap, readBitmap exception

Hello Balazs,

thank you for the explanation. It is clear to me now and obvious from
the description. I haven't had a detailed understanding of the BMP
format and interpreted pixel rectangles as BMP files which they are
clearly not. I then thought stb-image was necessary for compressed
image formats like PNG and but not for BMP.

Thanks you for the clarification. I'll try the maintainer the next
time directly, but above all else I'll be more thorough reading the
documentation.

Regards
Alexander Foremny

2012/6/29 Balazs Komuves <bkomuves <at> gmail.com>:
>
> Hello,
>
> Author of Data.Bitmap here. The issue is caused by the fact that Data.Bitmap
> does *not* support
> bmp files at all. This should be clear from the documentation. The functions
> you tried to used use
> their own file format, which a really very simple format; they are only
> added for simple experimentation.
> (again, this is explicit in the docs). The same documentation points to the
> stb-image [1] package,
>  which supports loading of some common formats (png, jpg, bmp).
>
> In general, I suggest that with package-specific question, unless it is a
> widely used package,
> mail the maintainer directly; you have better chance to get an answer that
> way.
>
> Regards,
> Balazs
>
> [1] http://hackage.haskell.org/package/stb-image
>
>> Hello,
>>
>>
>> I am using bitmap-0.2 [1] to load a Bitmap file [2]. However, the
>> following sample GHCi session fails for me.
>>
>> > Prelude Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO
>> > (Bitmap Word8)
>> > *** Exception: Data/Bitmap/Internal.hs:(63,17)-(67,15): Non-exhaustive
>> > patterns in case
>>
>> I downloaded the sources of bitmap-0.2 from Hackage and modified the
>> relevant function by appending the last line.
>>
>> > decodeCType :: CInt -> PixelComponentType
>> > decodeCType k = case k of
>> >   1 -> PctWord8
>> >   2 -> PctWord16
>> >   3 -> PctWord32
>> >   4 -> PctFloat
>> >   _ -> error $ "decodeCType: unexpected integer (" ++ show k ++ ")"
>>
>> With this modification the same GHCi session given above results in
>> the following error.
>>
>> > Prelude Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO
>> > (Bitmap Word8)
>> > *** Exception: decodeCType: unexpected integer (7077888)
>>
>> I don't have any idea where 7077888 comes from. Am I doing something
>> wrong? Is my bitmap corrupted in some way? The number 7077888 has no
>> apparent significance except that it is a perfect cube [3]. So I guess
>> this is not a problem with endianness.
>>
>> In fact as far as I can tell `decodeCType` is only called on
>> `(PixelComponent t => c_type t)` and `c_type t` only yields integer
>> values in the (inclusive) range of 1 to 4. That is if I am not missing
>> some orphaned instance.
>>
>> Could anyone please enlighten me what is happening and if I am doing
>> something wrong?
>>
>> In case this is relevant: I am using bitmap-0.2 from Hackage with GHC
>> 7.4.1 on a 3.2.20 kernel i686 architecture Linux.
>>
>> Regards,
>> Alexander Foremny
>>
>> [1] http://hackage.haskell.org/package/bitmap
>> [2] https://www.dropbox.com/s/pyutvni9vx6f6mo/b.bmp
>> [3] http://www.wolframalpha.com/input/?i=7077888
>
>

Gmane