Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
pixel.ml1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76open Type type t = Pixel : (float, f32) Data.t -> t [@@unboxed] let empty n = let p = Data.create f32 n in Pixel p let length (Pixel p) = Data.length p let compare (Pixel a) (Pixel b) = Data.compare a b let equal (Pixel a) (Pixel b) = Data.equal a b let from_data data = let len = Data.length data in let (Pixel px) = empty len in let kind = Data.kind data in for i = 0 to len - 1 do px.{i} <- Kind.(to_float kind data.{i} |> normalize kind) done; Pixel px let to_data ~dest (Pixel px) = let len = Data.length dest in let kind = Data.kind dest in for i = 0 to min len (Data.length px) - 1 do dest.{i} <- Kind.(of_float kind (denormalize kind px.{i})) done let data (Pixel px) = px let rgb_to_xyz (Pixel px) = let (Pixel dest) = empty 3 in dest.{0} <- (0.4124564 *. px.{0}) +. (0.3575761 *. px.{1}) +. (0.1804375 *. px.{2}); dest.{1} <- (0.2126729 *. px.{0}) +. (0.7151522 *. px.{1}) +. (0.0721750 *. px.{2}); dest.{2} <- (0.0193339 *. px.{0}) +. (0.1191920 *. px.{1}) +. (0.9503041 *. px.{2}); Pixel dest let rgb_to_yuv (Pixel px) = let (Pixel dest) = empty 3 in dest.{0} <- (0.299 *. px.{0}) +. (0.587 *. px.{1}) +. (0.114 *. px.{2}); dest.{1} <- (-0.147 *. px.{0}) -. (0.289 *. px.{1}) +. (0.436 *. px.{2}); dest.{2} <- (0.615 *. px.{0}) -. (0.515 *. px.{1}) -. (0.100 *. px.{2}); Pixel dest let map_inplace f (Pixel px) = Data.map_inplace f px let map f (Pixel px) = let dest = Data.copy px in Data.map_inplace f dest; Pixel dest let map2_inplace f (Pixel a) (Pixel b) = Data.map2_inplace f a b let map2 f (Pixel a) (Pixel b) = let dest = Data.copy a in Data.map2_inplace f dest b; Pixel dest let convert_in_place from to_ px = map (fun x -> let x = Kind.normalize from x in Kind.denormalize to_ x) px let fold f (Pixel px) a = Data.fold f px a let fold2 f (Pixel px) (Pixel px') a = Data.fold2 f px px' a let pp fmt (Pixel px) = Format.fprintf fmt "Scalar(%f, %f, %f)" px.{0} px.{1} px.{2}