package ocaml-canvas
Library
Module
Module type
Parameter
Class
Class type
Image data manipulation functions
val create : (int * int) -> t
create size
creates an empty image data of the given size
.
Exceptions:
Exception.Not_initialized
ifBackend.init
was not calledInvalid_argument
if either component ofsize
is outside the range 1-32767
val createFromPNG : string -> t React.event
createFromPNG filename
creates an image data with the contents of PNG file filename
. The returned event will be triggered once the image is loaded.
Exceptions:
Exception.Not_initialized
ifBackend.init
was not calledException.Read_png_failed
if the PNG file could not be read
val getSize : t -> int * int
getSize id
returns the size of image data id
sub c ~pos ~size
returns a copy of the pixel data at position pos
of size size
in image data id
. Any pixel outside the image bounds is considered to be transparent black.
Exceptions:
Invalid_argument
if either component ofsize
is outside the range 1-32767
blit ~dst ~dpos ~src ~spos ~size
copies the area specified by spos
and size
from image data src
to image data dst
at position dpos
. If the given position and size yield an inconsistent area, this has no effect.
Exceptions:
Invalid_argument
if either component ofsize
is outside the range 1-32767
getPixel id pos
returns the color of the pixel at position pos
in image data id
. If pos
is outside the image bounds, returns the transparent black color.
putPixel id pos c
sets the color of the pixel at position pos
in image data id
to color c
. If pos
is outside the image bounds, this has no effect.
importPNG id ~pos filename
loads the file filename
into image data id
at position pos
. Any pixel that falls outside the image bounds is ignored. The returned event will be triggered once the image is loaded.
Exceptions:
Exception.Not_initialized
ifBackend.init
was not calledException.Read_png_failed
if the PNG file could not be read
val exportPNG : t -> string -> unit
exportPNG id filename
saves the contents of image data id
to a file with name filename
Exceptions:
Exception.Not_initialized
ifBackend.init
was not calledException.Write_png_failed
if the PNG file could not be written
type t_repr =
(int, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout)
Stdlib.Bigarray.Array3.t
Image data's internal representation is a big array of dimension 3 (height, width, component), with the components in BGRA order
of_bigarray ba
reinterprets a big array ba
as an image data. The big array must be of dimension 3 (height, width, component), with the components in BGRA order. The underlying memory will be shared between the image data and the big array.
Exceptions:
Invalid_argument
if the first or second dimension ofba
is outside the range 1-32767, or if the third dimension ofba
is not 4