[Haskell] image writing library

Keith Wansbrough Keith.Wansbrough at cl.cam.ac.uk
Thu Aug 5 10:38:25 EDT 2004


> 
> Hi,
> 
> I would like to write an (Array (Int,Int) Int) to a file in some kind
> of image format.  I implemented (quick and very dirty) XBM output, but
> it would be nice to have some colors, and anyway, I can't seem to show
> the XBMs as grayscale.

Just write a "plain format" PPM by hand - if you want it in a
different format, just use the pnm tools to convert.

Format is:

P3
width height maxval
r g b r g b r g b r g b
r g b r g b r g b r g b
...



where all numbers are decimal, "P3" must be the first two chars, each
token must be separated by some whitespace (newline or space, doesn't
matter which or how many), and maxval is the maximum value of a
component (usually 15 or 255).

e.g.

       P3
       4 4
       15
        0  0  0    0  0  0    0  0  0   15  0 15
        0  0  0    0 15  7    0  0  0    0  0  0
        0  0  0    0  0  0    0 15  7    0  0  0
       15  0 15    0  0  0    0  0  0    0  0  0

Type "man 5 pnm" for more info.

Once you have the ppm file, do cjpeg to get jpeg, or ppmtoxpm,
ppmtobmp, or whatever else.

--KW 8-)

--KW 8-)



More information about the Haskell mailing list