1
(***********************************************************************)
5
(* Fran�ois Pessaux, projet Cristal, INRIA Rocquencourt *)
6
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
7
(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)
9
(* Copyright 1999-2004, *)
10
(* Institut National de Recherche en Informatique et en Automatique. *)
11
(* Distributed only by permission. *)
13
(***********************************************************************)
15
(* $Id: index16.ml,v 1.1 2006/11/28 15:43:28 rousse Exp $*)
20
let bytes_per_pixel = 2
22
int_of_char str.[pos ] * 256 +
23
int_of_char str.[pos + 1]
25
str.[pos ] <- char_of_int (t / 256);
26
str.[pos + 1] <- char_of_int (t mod 256)
28
let str = String.create bytes_per_pixel in
33
module RI = Genimage.MakeRawImage(E);;
35
type rawimage = RI.t;;
37
type t = { width : int;
40
mutable infos : Info.info list;
41
mutable colormap : Color.rgb Color.map;
42
mutable transparent : int };;
49
type mapelt = Color.rgb
50
let rawimage x = x.rawimage
51
let create_default width height rawimage =
55
colormap = { map = [||]; max = 65535 };
58
let create_duplicate src width height rawimage =
62
colormap = src.colormap;
63
transparent = src.transparent;
65
let colormap t = t.colormap
68
module IMAGE = Genimage.MakeIndexed(RI)(C);;
70
let create_with width height infos colormap transparent data =
73
rawimage = RI.create_with width height data;
75
transparent = transparent;
78
let rawimage = C.rawimage;;
79
let create = IMAGE.create;;
80
let make = IMAGE.make;;
81
let dump = IMAGE.dump;;
82
let unsafe_access = IMAGE.unsafe_access;;
83
let get_strip = IMAGE.get_strip;;
84
let set_strip = IMAGE.set_strip;;
85
let get_scanline = IMAGE.get_scanline;;
86
let set_scanline = IMAGE.set_scanline;;
87
let unsafe_get = IMAGE.unsafe_get;;
88
let unsafe_set = IMAGE.unsafe_set;;
91
let unsafe_get_color = IMAGE.unsafe_get_color;;
92
let get_color = IMAGE.get_color;;
93
let destroy = IMAGE.destroy;;
94
let copy = IMAGE.copy;;
96
let blit = IMAGE.blit;;
99
let unsafe_get_rgb = unsafe_get_color;;
100
let get_rgb = get_color;;
104
let to_rgb24 ?failsafe t =
105
let rgb24 = Rgb24.create t.width t.height in
106
let cmapsize = Array.length t.colormap.map in
107
begin match failsafe with
108
| Some failsafecolor ->
109
for y = 0 to t.height - 1 do
110
for x = 0 to t.width - 1 do
111
let idx = unsafe_get t x y in
113
if idx < 0 || idx >= cmapsize then failsafecolor
114
else t.colormap.map.(idx) in
115
Rgb24.unsafe_set rgb24 x y rgb
119
for y = 0 to t.height - 1 do
120
for x = 0 to t.width - 1 do
121
Rgb24.unsafe_set rgb24 x y (unsafe_get_color t x y)
127
let to_rgba32 ?failsafe t =
128
let rgba32 = Rgba32.create t.width t.height in
129
let cmapsize = Array.length t.colormap.map in
131
begin match failsafe with
132
| Some failsafecolor ->
133
for y = 0 to t.height - 1 do
134
for x = 0 to t.width - 1 do
136
let index = unsafe_get t x y in
137
if index < 0 || index >= cmapsize then failsafecolor
139
{ color = t.colormap.map.(index);
140
alpha = if index = t.transparent then 0 else 255; } in
141
Rgba32.unsafe_set rgba32 x y rgba
145
for y = 0 to t.height - 1 do
146
for x = 0 to t.width - 1 do
147
let index = unsafe_get t x y in
148
Rgba32.unsafe_set rgba32 x y
149
{ color = t.colormap.map.(index);
150
alpha = if index = t.transparent then 0 else 255 }