File: thumbnails.ml

package info (click to toggle)
advi 1.6.0-6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 17,416 kB
  • ctags: 2,825
  • sloc: ml: 12,261; sh: 1,500; ansic: 935; makefile: 738; perl: 57; tcl: 10
file content (70 lines) | stat: -rw-r--r-- 2,718 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(***********************************************************************)
(*                                                                     *)
(*                             Active-DVI                              *)
(*                                                                     *)
(*                   Projet Cristal, INRIA Rocquencourt                *)
(*                                                                     *)
(*  Copyright 2002 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the GNU Lesser General Public License.          *)
(*                                                                     *)
(*  Jun Furuse, Didier Rmy and Pierre Weis.                           *)
(*  Contributions by Roberto Di Cosmo, Didier Le Botlan,               *)
(*  Xavier Leroy, and Alan Schmitt.                                    *)
(*                                                                     *)
(*  Based on Mldvi by Alexandre Miquel.                                *)
(***********************************************************************)

(* $Id: thumbnails.ml,v 1.8 2004/09/15 16:37:55 weis Exp $ *)

(* Screen shot. *)
open Images;;

let save_gr_image fname x y nw nh =
  let screen_w = Graphics.size_x () and screen_h = Graphics.size_y () in
  let img = Graphic_image.get_image x y screen_w screen_h in
  let cimg =
    if nw = screen_w && nh = screen_h then img else
    Rgb24.resize None img nw nh in
  Images.save fname None [] (Rgb24 cimg)
;;

let thumbnails =
 Options.flag false "-thumbnails"
 "  create thumbnails for your slides\
 \n\t and write them into cachedir,\
 \n\t (the default is to skip thumbnails construction).";;

let thumbnails_size_w = ref 24;;
let thumbnails_size_h = ref 32;;
let set_thumbnails_size s =
  let g = Ageometry.parse s in
  thumbnails_size_w := g.Ageometry.width;
  thumbnails_size_h := g.Ageometry.height;;

Options.add
 "-thumbnails-size"
 (Arg.String set_thumbnails_size)
 "<geom>: set the thumbnails geometry size to <geom>,\
 \n\t (the default geometry is \"24x32\").";;

let save n =
  if !thumbnails then
    let jpegfname =
      Filename.concat (Userfile.get_advi_cache_dir ())
        (Printf.sprintf "shot%d.jpg" n) in
    let bbfname =
      Filename.concat (Userfile.get_advi_cache_dir ())
        (Printf.sprintf "shot%d.bb" n) in
    save_gr_image jpegfname 0 0 !thumbnails_size_w !thumbnails_size_h;
    let bboc = open_out bbfname in
    let s =
      Printf.sprintf "%%%%BoundingBox: 0 0 %d %d\n"
        !thumbnails_size_w !thumbnails_size_h in
    output_string bboc s;
    flush bboc;
    close_out bboc;;