On Thu, Aug 05, 2004 at 02:07:02PM +0200, Ketil Malde wrote:
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.
I've searched around a bit, but the only stuff I could find was defunct references to GIF writer, Jeroen Fokker's JPEG stuff (which may still work, but I don't want JPEG compression), and the PPM support in Andrew Cooke's Pancito.
Ripping out the latter currently seems to be the best bet, not sure how closely tied it is to the rest of the code. So, before I start, does anybody know any other libraries or programs that could be used?
I once wrote a mini PPM read/write library for a markov-like-chains-in-images fun project. with the following basic API: type Image = Matrix Color withColor :: ((Int, Int, Int) -> (Int, Int, Int)) -> Color -> Color -- The Int-argument gives the maximum number for a color value: usually 255 readPPM :: String -> (Int, Image) showPPM :: Int -> Image -> String Though it's quite horribly slow it does work: Prelude PPM Matrix> (maxColor, img) <- readPPM `fmap` readFile "/tmp/foo.ppm" Prelude PPM Matrix> let img' = amap (withColor $ \(r,g,b) -> (r,g,b)) img Prelude PPM Matrix> writeFile "/tmp/bar.ppm" $ showPPM maxColor img' bar.ppm == foo.ppm afterwards. The Matrix module merely reexports some IArray instance. (DiffUArray, in my program) Happy hacking, Remi -- Nobody can be exactly like me. Even I have trouble doing it.