File: gif.ml

package info (click to toggle)
ocaml-bitstring 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 908 kB
  • sloc: ml: 3,817; ansic: 136; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 = Bitstring.bitstring_of_file filename in

  match%bitstring 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