[Haskell] image writing library

Ketil Malde ketil+haskell at ii.uib.no
Thu Aug 5 08:57:38 EDT 2004


I think wxWindows is something I'll eventually have to look into, but
it seems a bit heavy for my purposes at the moment.

I discovered that although XPM accepts values in the range 0x00..0xff,
it is still monochrome.  XGM (plain, that is, not raw) is
approximately the same format, but displays the way I wanted.  So I
ended up using:

    mkpgm :: Array (Int,Int) Int -> String
    mkpgm cm = header ++ "\n" ++ image
        where header = unwords ["P2",show width,show heigth,show maxval]
              image = unlines $ map show $ elems cm
              (width,heigth) = snd $ bounds cm
              maxval = maximum (elems cm)

Not *very* beautiful, but seems to do the job for my stuff.  I'll try
the PPM library if I need something a tad more fancy - like colors :-)

Thanks for the suggestions!

-ketil
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell mailing list