Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Portable PNG exporter
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: malc <av1474@c...>
Subject: Re: [Caml-list] Portable PNG exporter
On Sat, 20 Sep 2008, Janne Hellsten wrote:

> Hi list,
> While working on a graphics related problem, I needed to save the
> contents of a Graphics framebuffer to a .png file.  Quick googling for
> "ocaml png" didn't bring up any results for libraries that would be
> easy to install via GODI.  I am aware of CamlImages but unfortunately
> I have never been successful at installing it due its heavy dependence
> on external libraries.  I also often work on Windows and installing
> external OCaml libraries on Windows is usually a major PITA (if
> possible at all).
> I decided to write a simple self-contained .png exporter that wouldn't
> depend on any external libraries (not even libpng or zlib).  I thought
> someone else might benefit from this piece of code and I thus made it
> freely available here:

Few things that hurt the eye:

Int32.of_string "[number]" is unnecessary, OCaml(not sure which version
this was introduced in though) can read various specific size ints

# 0n, 0l, 0L;;
- : nativeint * int32 * int64 = (0n, 0l, 0L)

Secondly `Printf.fprintf chnl "string"' looks rather expensive compared
to `output_string chnl "string"'.