X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=examples%2Fgif.ml;fp=examples%2Fgif.ml;h=050a9c8db384c57833a2cee85187779eccbfed0d;hb=8bfeff006a41bdd697a703efbfbb20c82bc65b6d;hp=0000000000000000000000000000000000000000;hpb=00f782f26fa89fa07dabb7155707b1415f50572b;p=ocaml-bitstring.git diff --git a/examples/gif.ml b/examples/gif.ml new file mode 100644 index 0000000..050a9c8 --- /dev/null +++ b/examples/gif.ml @@ -0,0 +1,33 @@ +(* GIF header parser. + * $Id$ + *) + +open Printf + +let () = + if Array.length Sys.argv <= 1 then + failwith "usage: gif input.gif"; + let filename = Sys.argv.(1) in + let bits = Bitmatch.bitstring_of_file filename in + + bitmatch bits with + | { ("GIF87a"|"GIF89a") : 6*8 : string; (* GIF magic. *) + width : 16 : littleendian; + height : 16 : littleendian; + colormap : 1; (* Has colormap? *) + colorbits : 3; (* Color res = colorbits+1 *) + sortflag : 1; + bps : 3; (* Bits/pixel = bps+1 *) + bg : 8; (* Background colour. *) + aspectratio : 8 } -> + printf "%s: GIF image:\n" filename; + printf " size %d %d\n" width height; + printf " has global colormap? %b\n" colormap; + printf " colorbits %d\n" (colorbits+1); + printf " global colormap is sorted? %b\n" sortflag; + printf " bits/pixel %d\n" (bps+1); + printf " background color index %d\n" bg; + printf " aspect ratio %d\n" aspectratio + + | { _ } -> + eprintf "%s: Not a GIF image\n" filename