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 ... endSample semantics and formats.
Raster data
type t= rasterThe 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 -> tv res first w_stride h_stride size sf bufis raster data with sample formatsfand 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_strideandh_stridecan be used to specify subspaces in the collection of samples, seesub.The function
scalar_stridescan be used to easily compute the linear buffer scalar index where a sample(x,y,z)starts.- raises Invalid_argument
if the elements of
sizeare not stricly positive, iffirstis negative, ifw_strideorh_strideare smaller than the index width or height or if the scalar type ofsfdoesn't match(Raster.buffer_scalar_type b).
val first : t -> intfirst ris the buffer scalar index where the first sample is stored.
val w_stride : t -> intw_stride ris 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 -> inth_stride ris 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.formatsample_format risr'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 -> intwi risr's index width in number of samples.
val hi : t -> inthi risr's index height in number of samples.
val di : t -> intd risr's index height in number of samples.
val w : ?meters:bool -> t -> floatw risr's index width.
val h : ?meters:bool -> t -> floath risr's index height.
val d : ?meters:bool -> t -> floatd risr's index depth.
val box1 : ?meters:bool -> ?mid:bool -> ?o:float -> t -> box1box1 meters mid o ris a box with originoand size(size1 meters r). Ifmidistrue(defaults tofalse),ospecifies the mid point of the box.odefaults to 0.
Functions
val dim : t -> intdim risr's index dimension from 1 to 3. Note that this is not derived from the case size given tovfor creatingr. It is derived from the size(w,h,d)as follows:(w,1,1)means 1,(w,h,1)withh > 1means 2,(w,h,d)withh,d > 1means 3.
val sub : [ `D1 of box1 | `D2 of box2 | `D3 of box3 ] -> t -> tsub regionis a raster corresponding to a subset of the index ofr. Bothrand 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
ris packed, if the origin is out of bounds or if new size is larger thanr's size.
val scalar_strides : t -> int * int * intscalar_strides ris(x_stride, y_stride, z_stride)wherex_strideis the number of buffer scalars from sample to sample.y_strideis the number of buffer scalars from line to line.z_strideis 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
ris packed.
Predicates and comparisons
Printers
val pp : Stdlib.Format.formatter -> t -> unitpp ppf tprints a textual represenation oftonppf. Doesn't print the buffer samples.