[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: Re: [Haskell-cafe] Data.Bitmap, readBitmap exception
From: Balazs Komuves <bkomuves () gmail ! com>
Date: 2012-06-29 19:41:27
Message-ID: CAHZd2pn-eJs9R+TN+AA2ESnO8YvKPodjf=9GF4Az9-HLb=Lp5A () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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
>
[Attachment #5 (text/html)]
<br>Hello,<br><br>Author of Data.Bitmap here. The issue is caused by the fact that \
Data.Bitmap does *not* support<br>bmp files at all. This should be clear from the \
documentation. The functions you tried to used use <br>their own file format, which a \
really very simple format; they are only added for simple experimentation. <br> \
(again, this is explicit in the docs). The same documentation points to the stb-image \
[1] package,<br> which supports loading of some common formats (png, jpg, \
bmp).<br><br>In general, I suggest that with package-specific question, unless it is \
a widely used package,<br> mail the maintainer directly; you have better chance to \
get an answer that way.<br><br>Regards,<br>Balazs<br><br>[1] <a \
href="http://hackage.haskell.org/package/stb-image">http://hackage.haskell.org/package/stb-image</a><br>
<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex" class="gmail_quote">Hello,<br><br>I am using \
bitmap-0.2 [1] to load a Bitmap file [2]. However, the<br>following sample GHCi \
session fails for me.<br> <br>> Prelude Data.Bitmap Data.Bitmap.Pure.File> \
readBitmap "b.bmp" :: IO (Bitmap Word8)<br>> *** Exception: \
Data/Bitmap/Internal.hs:(63,17)-(67,15): Non-exhaustive patterns in case<br><br>I \
downloaded the sources of bitmap-0.2 from Hackage and modified the<br> relevant \
function by appending the last line.<br><br>> decodeCType :: CInt -> \
PixelComponentType<br>> decodeCType k = case k of<br>> 1 -> \
PctWord8<br>> 2 -> PctWord16<br>> 3 -> PctWord32<br> > 4 \
-> PctFloat<br>> _ -> error $ "decodeCType: unexpected integer \
(" ++ show k ++ ")"<br><br>With this modification the same GHCi \
session given above results in<br>the following error.<br> <br>> Prelude \
Data.Bitmap Data.Bitmap.Pure.File> readBitmap "b.bmp" :: IO (Bitmap \
Word8)<br>> *** Exception: decodeCType: unexpected integer (7077888)<br><br>I \
don't have any idea where 7077888 comes from. Am I doing something<br> wrong? Is \
my bitmap corrupted in some way? The number 7077888 has no<br>apparent significance \
except that it is a perfect cube [3]. So I guess<br>this is not a problem with \
endianness.<br><br>In fact as far as I can tell `decodeCType` is only called on<br> \
`(PixelComponent t => c_type t)` and `c_type t` only yields integer<br>values in \
the (inclusive) range of 1 to 4. That is if I am not missing<br>some orphaned \
instance.<br><br>Could anyone please enlighten me what is happening and if I am \
doing<br> something wrong?<br><br>In case this is relevant: I am using bitmap-0.2 \
from Hackage with GHC<br>7.4.1 on a 3.2.20 kernel i686 architecture \
Linux.<br><br>Regards,<br>Alexander Foremny<br><br>[1] <a \
href="http://hackage.haskell.org/package/bitmap">http://hackage.haskell.org/package/bitmap</a><br>
[2] <a href="https://www.dropbox.com/s/pyutvni9vx6f6mo/b.bmp">https://www.dropbox.com/s/pyutvni9vx6f6mo/b.bmp</a><br>[3] \
<a href="http://www.wolframalpha.com/input/?i=7077888">http://www.wolframalpha.com/input/?i=7077888</a><br>
</blockquote><br>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic