1 (* $Id: glPix.ml,v 1.10 2005-10-14 13:35:32 garrigue Exp $ *)
5 type ('a
,'b
) t
= { format
: 'a
; width
: int ; height
:int ; raw
: 'b
Raw.t
}
7 let create k ~format ~width ~height
=
8 let size = format_size format
* width
* height
in
9 let len = match k
with `bitmap
-> (size-1)/8+1 | #
Gl.real_kind
-> size in
10 let raw = Raw.create k ~
len in
11 { format
= format
; width
= width
; height
= height
; raw = raw }
13 let of_raw raw ~format ~width ~height
=
14 let size = format_size format
* width
* height
15 and len = Raw.length
raw in
17 match Raw.kind
raw with `bitmap
-> len * 8 | #
Gl.real_kind
-> len in
18 if size > len then invalid_arg
"GlPix.of_raw";
19 { format
= format
; width
= width
; height
= height
; raw = raw }
21 let to_raw img
= img
.raw
22 let format img
= img
.format
23 let width img
= img
.width
24 let height img
= img
.height
28 match Raw.kind img
.raw with `bitmap
-> (img
.width-1)/8+1
29 | #
Gl.real_kind
-> img
.width
31 let stride = format_size img
.format in
32 let line = stride * width in
33 fun ~x ~y
-> x
* stride + y
* line
36 width:int -> height:int -> orig
:point2
-> move
:point2
->
37 [`bitmap
] Raw.t
-> unit
39 type bitmap
= ([`color_index
], [`bitmap
]) t
40 let bitmap (img
: bitmap) =
41 bitmap ~
width:img
.width ~
height:img
.height img
.raw
44 x
:int -> y
:int -> width:int -> height:int ->
45 buffer
:[`color
|`depth
|`stencil
] -> unit
49 width:int -> height:int -> format:[< format] -> [< Gl.kind
] Raw.t
-> unit
52 draw img
.raw ~
width:img
.width ~
height:img
.height ~
format:img
.format
55 [`i_to_i
|`i_to_r
|`i_to_g
|`i_to_b
|`i_to_a
56 |`s_to_s
|`r_to_r
|`g_to_g
|`b_to_b
|`a_to_a
]
57 external map
: map
-> [`
float] Raw.t
-> unit
61 `pack_swap_bytes
of bool
62 | `pack_lsb_first
of bool
63 | `pack_row_length
of int
64 | `pack_skip_pixels
of int
65 | `pack_skip_rows
of int
66 | `pack_alignment
of int
67 | `unpack_swap_bytes
of bool
68 | `unpack_lsb_first
of bool
69 | `unpack_row_length
of int
70 | `unpack_skip_pixels
of int
71 | `unpack_skip_rows
of int
72 | `unpack_alignment
of int
74 external store
: store_param
-> unit = "ml_glPixelStorei"
76 type transfer_param
= [
78 | `map_stencil
of bool
80 | `index_offset
of int
83 | `green_scale
of float
84 | `green_bias
of float
85 | `blue_scale
of float
87 | `alpha_scale
of float
88 | `alpha_bias
of float
89 | `depth_scale
of float
90 | `depth_bias
of float
92 external transfer
: transfer_param
-> unit = "ml_glPixelTransfer"
94 external zoom
: x
:float -> y
:float -> unit = "ml_glPixelZoom"
97 x
:float -> y
:float -> ?z
:float -> ?w
:float -> unit -> unit
101 x
:int -> y
:int -> width:int -> height:int ->
102 format:[< format] -> [< Gl.kind
] Raw.t
-> unit
103 = "ml_glReadPixels_bc" "ml_glReadPixels"
104 let read ~x ~y ~
width ~
height ~
format ~kind
=
105 let raw = Raw.create kind ~
len:(width * height * format_size
format) in
106 read ~x ~y ~
width ~
height ~
format raw;
107 { raw = raw; width = width; height = height; format = format }