Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell-cafe] Haskell image libraries

11 views
Skip to first unread message

Max Rabkin

unread,
Nov 8, 2009, 9:35:10 AM11/8/09
to haskel...@haskell.org
Haskellers,

To add image support to fdo-notify, I need an image type. Looking
through Hackage, I didn't find any image library with the following
features:
* Load from a variety of formats (at least PNG and JPG, I'd say)
* Efficient per-pixel access, or a way to dump the image into a
ByteString as a bitmap (I need to serialise them into the protocol's
bitmap format)
Preferably, it should be possible to construct images programmatically too.

Is there really no such library? It would be nice to have something
like a Haskell equivalent of the Python Imaging Library, which is the
de facto standard image library in Python and supports just about
every type of operation on images you could ask for.

Regards,
Max
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Colin Paul Adams

unread,
Nov 8, 2009, 9:41:00 AM11/8/09
to Max Rabkin, haskel...@haskell.org
>>>>> "Max" == Max Rabkin <max.r...@gmail.com> writes:

Max> Haskellers, To add image support to fdo-notify, I need an
Max> image type. Looking through Hackage, I didn't find any image
Max> library with the following features: * Load from a variety of
Max> formats (at least PNG and JPG, I'd say) * Efficient per-pixel
Max> access, or a way to dump the image into a ByteString as a
Max> bitmap (I need to serialise them into the protocol's bitmap
Max> format) Preferably, it should be possible to construct images
Max> programmatically too.

Max> Is there really no such library? It would be nice to have
Max> something like a Haskell equivalent of the Python Imaging
Max> Library, which is the de facto standard image library in
Max> Python and supports just about every type of operation on
Max> images you could ask for.

I've found nothing either, having searched recently.
--
Colin Adams
Preston Lancashire

Jeremy Shaw

unread,
Nov 8, 2009, 9:56:24 AM11/8/09
to Max Rabkin, haskel...@haskell.org
There is a partial binding to libgd:

http://hackage.haskell.org/packages/archive/gd/3000.4.0/doc/html/Graphics-GD.html

http://www.libgd.org/Main_Page

But GD itself may not do what you want.

- jeremy

Andrew Coppin

unread,
Nov 8, 2009, 9:58:19 AM11/8/09
to haskel...@haskell.org
Max Rabkin wrote:
> Haskellers,
>
> To add image support to fdo-notify, I need an image type. Looking
> through Hackage, I didn't find any image library with the following
> features:
> * Load from a variety of formats (at least PNG and JPG, I'd say)
> * Efficient per-pixel access, or a way to dump the image into a
> ByteString as a bitmap (I need to serialise them into the protocol's
> bitmap format)
> Preferably, it should be possible to construct images programmatically too.
>
> Is there really no such library? It would be nice to have something
> like a Haskell equivalent of the Python Imaging Library, which is the
> de facto standard image library in Python and supports just about
> every type of operation on images you could ask for.
>
> Regards,
> Max
>

Try AC-EasyRaster-GTK. It's a thin layer over Gtk2hs that I wrote
precisely because it's so fiddly to do bitmapped graphics with Gtk2hs.
(Vector graphics is delightfully easy with Cairo, but bitmap graphics
requires manual bit-twiddling, and lots of simple but non-obvious API
calls.)

In particular, Easy Raster will trivially load and save PNG and JPEG
images, and provide pixel-level read/write functions (either with or
without bounds checks).

What I haven't implemented is access to the underlying pixel array.
There's a function ib_pixmap which will get you the GTK Pixmap object,
from which you can obtain the pixel array. But it's not an IOArray or
STArray or anything like that; it's some other datatype that implements
the MArray class, so it doesn't buy you much. You might as well just use
the pixel read/write functions from Easy Raster and manually iterate all
pixels...

(Another annoying quirk is that Gtk2hs doesn't provide a way to read or
write an image from a handle, only from a real file, so naturally Easy
Raster shares the same limitation.)

Colin Paul Adams

unread,
Nov 8, 2009, 10:16:54 AM11/8/09
to Jeremy Shaw, haskel...@haskell.org
>>>>> "Jeremy" == Jeremy Shaw <jer...@n-heptane.com> writes:

Jeremy> There is a partial binding to libgd:
Jeremy> http://hackage.haskell.org/packages/archive/gd/3000.4.0/doc/html/Graphics-GD.html

Jeremy> http://www.libgd.org/Main_Page

Jeremy> But GD itself may not do what you want.

I ended up using this myself, but it is an unsatisfactory compromise
(no support for TIFF - and many other formats, trashes EXIF
information). In my innocence I had imagined that GTK (the GIMP
ToolKit) would provide all the image manipulation facilities that the
GIMP offers. But no.


--
Colin Adams
Preston Lancashire

Stephan Friedrichs

unread,
Nov 8, 2009, 10:50:48 AM11/8/09
to Haskell Cafe
On Sun, 2009-11-08 at 16:34 +0200, Max Rabkin wrote:
> To add image support to fdo-notify, I need an image type. Looking
> through Hackage, I didn't find any image library with the following
> features:
> * Load from a variety of formats (at least PNG and JPG, I'd say)
> * Efficient per-pixel access, or a way to dump the image into a
> ByteString as a bitmap (I need to serialise them into the protocol's
> bitmap format)
> Preferably, it should be possible to construct images programmatically too.

What about the imlib bindings [1]? The only problem is, that imlib
doesn't provide a functional image type (you'll end up processing the
image in the IO monad), but it works quite well (I used it for my Piet
interpreter, which required basic image processing tasks like a
labelling algorithm).

HTH - Stephan

[1] http://hackage.haskell.org/package/Imlib

--
Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

- Dieter Nuhr

Andrew Coppin

unread,
Nov 8, 2009, 11:02:52 AM11/8/09
to haskel...@haskell.org
Max Rabkin wrote:
> On Sun, Nov 8, 2009 at 5:09 PM, Max Rabkin <max.r...@gmail.com> wrote:
>
>> On Sun, Nov 8, 2009 at 4:58 PM, Andrew Coppin
>> <andrew...@btinternet.com> wrote:
>>
>>> Try AC-EasyRaster-GTK.
>>>
>> Thanks, I'll give that a try
>>
>
> Having downloaded it, I must admit I was a bit put off by seeing things like
> init_system :: IO ()
> process_event :: IO ()
> wait_event :: IO ()
> main_loop :: IO ()
> in an image library.
>
> But it's the best we've got right now, so I've got a couple questions:
> is it safe to call init_system more than once? And what do I need the
> event-handling functions for, if anything?
>

If all you want to do is load/save images and do pixel I/O on them, you
can completely ignore process_event, wait_event, main_loop, etc. All you
need to do is make sure you call init_system at the start of your program.

(You see the ib_display function? If you want *that* to work properly,
you need to run the GTK event loop, which is what these event-related
functions are all about. If you're not trying to display the image on
screen, you can ignore all that.)

I should probably make the documentation clearer...

Henk-Jan van Tuyl

unread,
Nov 8, 2009, 5:17:12 PM11/8/09
to Max Rabkin, haskel...@haskell.org

wxHaskell contains functions to read and write images, for example
imageGetPixels [1] and imageCreateFromPixelArray [2]

Met vriendelijke groet,
Henk-Jan van Tuyl

[1]
http://hackage.haskell.org/packages/archive/wxcore/0.10.13.0/doc/html/Graphics-UI-WXCore-Image.html#v:imageGetPixels
[2]
http://hackage.haskell.org/packages/archive/wxcore/0.10.13.0/doc/html/Graphics-UI-WXCore-Image.html#v%3AimageCreateFromPixelArray


--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--


On Sun, 08 Nov 2009 15:34:26 +0100, Max Rabkin <max.r...@gmail.com>
wrote:

Pierre-Etienne Meunier

unread,
Nov 9, 2009, 5:24:52 AM11/9/09
to max.r...@gmail.com, haskel...@haskell.org
there is also a binding for libGD on hackage :

http://hackage.haskell.org/package/gd

And, of course, you can improve it, or write a binding to a more
complete library. Or, even better, write a mix between
http://www.libpng.org/pub/png/pngdocs.html
and
http://hackage.haskell.org/package/binary

0 new messages