My favorites | Sign in
Project Logo
                
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

(** Save a Targa (.tga) file to chnl. *)
let write_tga_chnl chnl pixels w h =
let header =
[0; 0; 2; 0; 0; 0; 0; 0; 0; 0; 0; 0;
w land 255; w lsr 8;
h land 255; h lsr 8; 32; 8] in
assert (List.length header = 18);
List.iter (fun e -> output_byte chnl e) header;
for y = 0 to h-1 do
for x = 0 to w-1 do
let c = pixels.(x+(h-1-y)*w) in (* h-1-y = Flip image *)
output_byte chnl (c land 255);
output_byte chnl ((c lsr 8) land 255);
output_byte chnl ((c lsr 16) land 255);
output_byte chnl 255;
done
done

(** Save a Targa (.tga) file to file `filename'. *)
let write_tga filename pixels w h =
let chnl = open_out_bin filename in
try
write_tga_chnl chnl pixels w h;
close_out chnl
with
_ ->
close_out chnl
Show details Hide details

Change log

r12 by jjhellst on Sep 20, 2008   Diff
Add Png module for saving PNG files
Go to: 
Project members, sign in to write a code review

Older revisions

r10 by jjhellst on Sep 20, 2008   Diff
Add an example that exports the
contents of Graphics framebuffer to a
Targa file
All revisions of this file

File info

Size: 793 bytes, 28 lines
Hosted by Google Code