Module Gg.Raster
Raster data.
WARNING. This interface is subject to change in the future.
Raster data organizes data samples of any dimension in discrete 1D, 2D (images) or 3D space.
A sample has a semantics that defines its dimension and the meaning of its components. For example a 4D sample could represent a linear sRGBA sample. Samples are stored in a linear buffer of scalars of a given type. A sample can use one scalar per component, can be packed in a single scalar or may have no direct obvious relationship to buffer scalars (compressed data). The sample format defines the semantics and scalar storage of a sample.
A raster data value is a collection of samples indexed by width, height and depth (i.e. x, y, z) stored in a buffer. It defines the sample data, the extents of the index and the sample format. The optional resolution in samples per meters of a raster data can specify its physical dimension.
Spatial convention. If the sample index has to be interpreted spatially. It must be interpreted relative to the origin of a right-handed coordinate system. This means that the first sample, indexed by (0,0,0)
is the bottom-left backmost sample (bottom-left sample for a 2D image).
Index sizes. Index sizes are specified using size types which are made of floats as it is more pratical in most scenarios. These floats should however be integral floats. The function v
, Sample.scalar_count
and sub
ensure this by applying Float.round
to these values. This means that the raster size functions when called with meters = false
will always return sizes that are integral floats that you can convert to integers safely without having to think about rounding issues. Note also that index sizes are always strictly positive.
Sample semantics and formats
module Sample : sig ... end
Sample semantics and formats.
Raster data
type t
= raster
The type for raster data.
val v : ?res:v3 -> ?first:int -> ?w_stride:int -> ?h_stride:int -> [ `D1 of float | `D2 of size2 | `D3 of size3 ] -> Sample.format -> buffer -> t
v res first w_stride h_stride size sf buf
is raster data with sample formatsf
and bufferb
.size
, specify the index extents. height and depth if unspecified default to1
. All extents must be strictly positive.first
, buffer scalar index where the data of the first sample is stored.w_stride
, number of samples (not buffer scalars) to skip to go from the first sample of a line to the first sample of the next line. Defaults to the index width.h_stride
, number of lines to skip to go from the first line of a plane to the first line of the next plane. Defaults to the index height.res
, is an optional sample resolution specification in samples per meters.
For certain sample formats
first
,w_stride
andh_stride
can be used to specify subspaces in the collection of samples, seesub
.The function
scalar_strides
can be used to easily compute the linear buffer scalar index where a sample(x,y,z)
starts.- raises Invalid_argument
if the elements of
size
are not stricly positive, iffirst
is negative, ifw_stride
orh_stride
are smaller than the index width or height or if the scalar type ofsf
doesn't match(Raster.buffer_scalar_type b)
.
val first : t -> int
first r
is the buffer scalar index where the first sample is stored.
val w_stride : t -> int
w_stride r
is the number of samples to skip to go from the first sample of a line to the first sample of the next line.
val h_stride : t -> int
h_stride r
is the number of lines to skip to go from the first line of a plane to the first line of the next plane.
val sample_format : t -> Sample.format
sample_format r
isr
's sample format.
Raster sizes and boxes
In these functions have an optional meter
argument that defaults to false
. If false
the result is in integral number of samples. If true
the result is in meters according to the rasters' resolution. If the raster has no resolution, Raster.res_default
is used in all dimensions.
val wi : t -> int
wi r
isr
's index width in number of samples.
val hi : t -> int
hi r
isr
's index height in number of samples.
val di : t -> int
d r
isr
's index height in number of samples.
val w : ?meters:bool -> t -> float
w r
isr
's index width.
val h : ?meters:bool -> t -> float
h r
isr
's index height.
val d : ?meters:bool -> t -> float
d r
isr
's index depth.
val box1 : ?meters:bool -> ?mid:bool -> ?o:float -> t -> box1
box1 meters mid o r
is a box with origino
and size(size1 meters r)
. Ifmid
istrue
(defaults tofalse
),o
specifies the mid point of the box.o
defaults to 0.
Functions
val dim : t -> int
dim r
isr
's index dimension from 1 to 3. Note that this is not derived from the case size given tov
for creatingr
. It is derived from the size(w,h,d)
as follows:(w,1,1)
means 1,(w,h,1)
withh > 1
means 2,(w,h,d)
withh,d > 1
means 3.
val sub : [ `D1 of box1 | `D2 of box2 | `D3 of box3 ] -> t -> t
sub region
is a raster corresponding to a subset of the index ofr
. Bothr
and the resulting raster share the same buffer. The integral origin of the box defines the new sample origin of the raster data and its integral size the new size of the index.If the dimension of the box is smaller than the raster the result is in the first line (
y = 0
) and/or layer (z = 0
) of the rasterr
.- raises Invalid_argument,
if the sample format of
r
is packed, if the origin is out of bounds or if new size is larger thanr
's size.
val scalar_strides : t -> int * int * int
scalar_strides r
is(x_stride, y_stride, z_stride)
wherex_stride
is the number of buffer scalars from sample to sample.y_stride
is the number of buffer scalars from line to line.z_stride
is the number of buffer scalars from plane to plane.
The buffer index where the sample
(x,y,z)
starts is given by:(Raster.first r) + z * z_stride + y * y_stride + x * x_stride
- raises Invalid_argument
if the sample format of
r
is packed.
Predicates and comparisons
Printers
val pp : Stdlib.Format.formatter -> t -> unit
pp ppf t
prints a textual represenation oft
onppf
. Doesn't print the buffer samples.