type 'a result = ('a, [ `Msg of string ]) Base.Result.t

Image representation

type 'kind buffer = ('a, 'b, Bigarray.c_layout) Bigarray.Array1.t constraint 'kind = ('a, 'b) Bigarray.kind

buffer simply is an alias to a bigarray with c_layout. The buffer type serves two purposes:

  • representing input files,
  • representing the raw pixels of an image.

Two kind of pixel buffers are manipulated:

  • int8 for images with 8-bit channels
  • float32 for images with floating point channels
type float32 = (float, Bigarray.float32_elt) Bigarray.kind
type 'kind t = private {
  1. width : int;
  2. height : int;
  3. channels : int;
  4. offset : int;
  5. stride : int;
  6. data : 'kind buffer;

A record describing an image. The buffer contains channels * width * height items, in this order:

  • channels are interleaved
  • each pixel is made of channels items
  • each line is made of width pixels
  • image is made of height lines

Creating image

val image : width:int -> height:int -> channels:int -> ?offset:int -> ?stride:int -> 'kind buffer -> 'kind t result

Image accessors

val width : _ t -> int
val height : _ t -> int
val channels : _ t -> int
val data : 'kind t -> 'kind buffer

Image decoding

val load : ?channels:int -> string -> int8 t result

Load an 8-bit per channel image from a filename. If channels is specified, it has to be between 1 and 4 and the decoded image will be processed to have the requested number of channels.

val loadf : ?channels:int -> string -> float32 t result

Load a floating point channel image from a filename. See load for channels parameter.

val decode : ?channels:int -> _ buffer -> int8 t result

Decode an 8-bit per channel image from a buffer. See load for channels parameter.

val decodef : ?channels:int -> _ buffer -> float32 t result

Decode a floating point channel image from a buffer. See load for channels parameter.

Low-level interface

Functions are similar to the above one, except memory is not managed by OCaml GC. It has to be released explicitly with free_unmanaged function.

You get slightly faster load times, more deterministic memory use and more responsibility. Use at your own risk!

val load_unmanaged : ?channels:int -> string -> int8 t result
val loadf_unmanaged : ?channels:int -> string -> float32 t result
val decode_unmanaged : ?channels:int -> _ buffer -> int8 t result
val decodef_unmanaged : ?channels:int -> _ buffer -> float32 t result
val free_unmanaged : _ t -> unit

Image filtering

val mipmap : int8 t -> int8 t -> unit

Generate one level of mipmap: downsample image half in each dimension. In mipmap imgin imgout:

  • imgout.channels must be imgin.channels
  • imgout.width must be imgin.width / 2
  • imgout.height must be imgin.height / 2
  • imgout.data will be filled with downsampled imgin.data
val mipmapf : float32 t -> float32 t -> unit

Downsample floating point images. See mipmap.

val vflip : int8 t -> unit

Flip the image vertically

val vflipf : float32 t -> unit

Flip the image vertically

val expblur : int8 t -> radius:float -> unit

Blur the image