Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file imageBase.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196(*
* Copyright 2011 The Savonet Team
*
* This file is part of ocaml-mm.
*
* ocaml-mm is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ocaml-mm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ocaml-mm; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* As a special exception to the GNU Library General Public License, you may
* link, statically or dynamically, a "work that uses the Library" with a publicly
* distributed version of the Library to produce an executable file containing
* portions of the Library, and distribute that executable file under terms of
* your choice, without any of the additional requirements listed in clause 6
* of the GNU Library General Public License.
* By "a publicly distributed version of the Library", we mean either the unmodified
* Library as distributed by The Savonet Team, or a modified version of the Library that is
* distributed under the conditions defined in clause 3 of the GNU Library General
* Public License. This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU Library General Public License.
*
*)moduleList=structincludeListletreciter_rightf=function|x::l->iter_rightfl;fx|[]->()endmoduleData=structtypet=(int,Bigarray.int8_unsigned_elt,Bigarray.c_layout)Bigarray.Array1.t(* Creates an 16-bytes aligned plane. Returns (stride*plane). *)(* external create_rounded_plane : int -> int -> int * t = "caml_data_aligned_plane" *)letallocn=Bigarray.Array1.createBigarray.int8_unsignedBigarray.C_layoutn(** [round n k] rounds [n] to the nearest upper multiple of [k]. *)letroundkn=(n+(k-1))/k*k(** [aligned k n] allocates [n] bytes at a multiple of [k]. *)externalaligned:int->int->t="caml_data_aligned"(* Creates an 16-bytes aligned plane. Returns (stride*plane). *)letrounded_planewidthheight=letalign=16inletstride=round16widthinletdata=alignedalign(height*stride)in(stride,data)externalto_string:t->string="caml_data_to_string"externalto_bytes:t->bytes="caml_data_to_string"externalof_string:string->t="caml_data_of_string"letblit_allsrcdst=Bigarray.Array1.blitsrcdstexternalblit:t->int->t->int->int->unit="caml_data_blit_off"(* [@@noalloc] *)externalcopy:t->t="caml_data_copy"letsubbufofslen=Bigarray.Array1.subbufofslenletlengthimg=Bigarray.Array1.dimimgletsizeimg=lengthimgletget=Bigarray.Array1.getletfillbufx=Bigarray.Array1.fillbufxendmodulePixel=structtypergba=int*int*int*inttypergb=int*int*inttypeyuv=int*int*inttypeyuva=(int*int*int)*intexternalyuv_of_rgb:rgb->yuv="caml_yuv_of_rgb"externalrgb_of_yuv:yuv->rgb="caml_rgb_of_yuv"endmodulePoint=structtypet=int*intletmin(x,y)(x',y')=(minxx',minyy')letmax(x,y)(x',y')=(maxxx',maxyy')letlt(x,y)(x',y')=x<x'&&y<y'letle(x,y)(x',y')=x<=x'&&y<=y'letneg(x,y)=(-x,-y)endmoduleFraction=structtypet=int*intletmin(a,b)(a',b')=ifa*b'<a'*bthen(a,b)else(a',b')endmoduleDraw=struct(* Besenham algorithm. *)letlinep(sx,sy)(dx,dy)=letsteep=abs(dy-sy)>abs(dx-sx)inletsx,sy,dx,dy=ifsteepthen(sy,sx,dy,dx)else(sx,sy,dx,dy)inletsx,sy,dx,dy=ifsx>dxthen(dx,dy,sx,sy)else(sx,sy,dx,dy)inletdeltax=dx-sxinletdeltay=abs(dy-sy)inleterror=ref(deltax/2)inletystep=ifsy<dythen1else-1inletj=refsyinfori=sxtodx-1doifsteepthenp!jielsepi!j;error:=!error-deltay;if!error<0then(j:=!j+ystep;error:=!error+deltax)doneendmoduleMotion_multi=structtypevectors_data=(int,Bigarray.nativeint_elt,Bigarray.c_layout)Bigarray.Array1.ttypevectors={vectors:vectors_data;vectors_width:int;block_size:int;}externalmedian_denoise:int->vectors_data->unit="caml_rgb_motion_multi_median_denoise"letmedian_denoisev=median_denoisev.vectors_widthv.vectorsexternalmean:int->vectors_data->int*int="caml_rgb_motion_multi_mean"letmeanv=meanv.vectors_widthv.vectorsendmoduleRGB8=structmoduleColor=structtypet=int*int*intletof_intn=ifn>0xffffffthenraise(Invalid_argument"Not a color");((nlsr16)land0xff,(nlsr8)land0xff,nland0xff)endendmoduleGray8=struct(* TODO: stride ? *)typet={data:Data.t;width:int}letmakewd={data=d;width=w}(* Don't use create_rounded_plane here since there is not stride.. *)letcreatewh=makew(Bigarray.Array1.createBigarray.int8_unsignedBigarray.c_layout(w*h))moduleMotion=structexternalcompute:int->int->Data.t->Data.t->int*int="caml_mm_Gray8_motion_compute"letcomputebson=computebsn.widtho.datan.datamoduleMulti=structincludeMotion_multiexternalcompute:int->int->Data.t->Data.t->vectors_data="caml_mm_Gray8_motion_multi_compute"letcomputebson={vectors=computebsn.widtho.datan.data;vectors_width=n.width/bs;block_size=bs;}endendend