File: oColor.ml

package info (click to toggle)
camlimages 2.20-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,020 kB
  • ctags: 2,432
  • sloc: ml: 12,244; ansic: 2,402; makefile: 1,135; sh: 193
file content (62 lines) | stat: -rw-r--r-- 2,202 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
(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            Franois Pessaux, projet Cristal, INRIA Rocquencourt     *)
(*            Pierre Weis, projet Cristal, INRIA Rocquencourt          *)
(*            Jun Furuse, projet Cristal, INRIA Rocquencourt           *)
(*                                                                     *)
(*  Copyright 1999-2004,                                               *)
(*  Institut National de Recherche en Informatique et en Automatique.  *)
(*  Distributed only by permission.                                    *)
(*                                                                     *)
(***********************************************************************)

(* $Id: oColor.ml,v 1.7 2004/09/24 14:27:27 weis Exp $*)

(** Class interface for Color *)

open Color;;

module type COLORMAP = sig
  type t
  val size : t map -> int
  val find_exact : t map -> t -> int
  val add_color : t map -> t -> int
  val add_colors : t map -> t list -> int list
  val find_nearest : t map -> t -> int
end;;

class virtual ['a] map (cmap : 'a Color.map) = object
  val mapobj = cmap
  method colormap = mapobj
  
  method max = mapobj.max
  method map = mapobj.map
  
  method query_color x = if x < size cmap then cmap.map.(x) else raise Not_found
  
  method set_max max = mapobj.max <- max
  method set_map map = mapobj.map <- map
  
  method size = size mapobj
  method find_exact = find_exact mapobj
  method add_color = add_color mapobj
  method add_colors = add_colors mapobj
  method virtual find_nearest : 'a -> int
end;;

class rgbmap (cmap : rgb Color.map) = object
  inherit [rgb] map cmap
  method find_nearest = Rgb.find_nearest mapobj
end;;

class rgbamap (cmap : rgba Color.map) = object
  inherit [rgba] map cmap
  method find_nearest = Rgba.find_nearest mapobj
end;;

class cmykmap (cmap : cmyk Color.map) = object
  inherit [cmyk] map cmap
  method find_nearest = Cmyk.find_nearest mapobj
end;;