Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file imageGeneric.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230(*
* 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.
*
*)moduleRGBA32=ImageRGBA32moduleYUV420=ImageYUV420exceptionNot_implementedmodulePixel=structtypergb_format=|RGB24(* 24 bit RGB. Each color is an uint8_t. Color order is RGBRGB *)|BGR24(* 24 bit BGR. Each color is an uint8_t. Color order is BGRBGR *)|RGB32(* 32 bit RGB. Each color is an uint8_t. Color order is RGBXRGBX, where X is unused *)|BGR32(* 32 bit BGR. Each color is an uint8_t. Color order is BGRXBGRX, where X is unused *)|RGBA32(* 32 bit RGBA. Each color is an uint8_t. Color order is RGBARGBA *)typeyuv_format=|YUV422(* Planar YCbCr 4:2:2. Each component is an uint8_t *)|YUV444(* Planar YCbCr 4:4:4. Each component is an uint8_t *)|YUV411(* Planar YCbCr 4:1:1. Each component is an uint8_t *)|YUV410(* Planar YCbCr 4:1:0. Each component is an uint8_t *)|YUVJ420(* Planar YCbCr 4:2:0. Each component is an uint8_t,
* luma and chroma values are full range (0x00 .. 0xff) *)|YUVJ422(* Planar YCbCr 4:2:2. Each component is an uint8_t,
* luma and chroma values are full range (0x00 .. 0xff) *)|YUVJ444(* Planar YCbCr 4:4:4. Each component is an uint8_t, luma and
* chroma values are full range (0x00 .. 0xff) *)typeformat=RGBofrgb_format|YUVofyuv_formatletsize=function|RGBx->(matchxwithRGB24|BGR24->3|RGB32|BGR32|RGBA32->4)|YUV_->raiseNot_implementedletstring_of_format=function|RGBx->(matchxwith|RGB24->"RGB24"|BGR24->"BGR24"|RGB32->"RGB32"|BGR32->"BGR32"|RGBA32->"RGBA32")|YUVx->(matchxwith|YUV422->"YUV422"|YUV444->"YUV444"|YUV411->"YUV411"|YUV410->"YUV410"|YUVJ420->"YUVJ420"|YUVJ422->"YUVJ422"|YUVJ444->"YUVJ444")endtypedata=(int,Bigarray.int8_unsigned_elt,Bigarray.c_layout)Bigarray.Array1.ttypergb={rgb_pixel:Pixel.rgb_format;rgb_data:data;rgb_stride:int}typeyuv={yuv_pixel:Pixel.yuv_format;y:data;y_stride:int;u:data;v:data;uv_stride:int;}typet_data=RGBofrgb|YUVofyuvtypet={data:t_data;width:int;height:int}letrgb_dataimg=matchimg.datawith|RGBrgb->(rgb.rgb_data,rgb.rgb_stride)|_->assertfalseletyuv_dataimg=matchimg.datawith|YUVyuv->((yuv.y,yuv.y_stride),(yuv.u,yuv.v,yuv.uv_stride))|_->assertfalseletwidthimg=img.widthletheightimg=img.heightletpixel_formatimg=matchimg.datawith|RGBrgb->Pixel.RGBrgb.rgb_pixel|YUVyuv->Pixel.YUVyuv.yuv_pixelletmake_rgbpix?stridewidthheightdata=letstride=matchstridewithSomes->s|None->width*Pixel.size(Pixel.RGBpix)inletrgb_data={rgb_pixel=pix;rgb_data=data;rgb_stride=stride}in{data=RGBrgb_data;width;height}letof_RGBA32img=letrgb_data={rgb_pixel=Pixel.RGBA32;rgb_data=img.RGBA32.data;rgb_stride=img.RGBA32.stride;}in{data=RGBrgb_data;width=img.RGBA32.width;height=img.RGBA32.height}letto_RGBA32img=letrgb_data=matchimg.datawithRGBd->d|_->assertfalseinassert(rgb_data.rgb_pixel=Pixel.RGBA32);{RGBA32.data=rgb_data.rgb_data;width=img.width;height=img.height;stride=rgb_data.rgb_stride;}letof_YUV420img=letyuv_data={yuv_pixel=Pixel.YUVJ420;y=img.YUV420.y;y_stride=img.YUV420.y_stride;u=img.YUV420.u;v=img.YUV420.v;uv_stride=img.YUV420.uv_stride;}in{data=YUVyuv_data;width=img.YUV420.width;height=img.YUV420.height}letto_YUV420img=letyuv=matchimg.datawithYUVyuv->yuv|_->assertfalseinassert(yuv.yuv_pixel=Pixel.YUVJ420);YUV420.makeimg.widthimg.heightyuv.yyuv.y_strideyuv.uyuv.vyuv.uv_strideexternalrgba32_to_bgr32:data->int->data->int->int*int->unit="caml_RGBA32_to_BGR32"externalrgb24_to_rgba32:data->int->data->int->int*int->unit="caml_RGB24_to_RGBA32"externalrgb32_to_rgba32:data->int->data->int->int*int->unit="caml_RGB32_to_RGBA32"letblankimg=matchimg.datawith|RGBrgb->(matchrgb.rgb_pixelwith|Pixel.RGBA32->RGBA32.blank(to_RGBA32img)|_->failwith"Not implemented")|YUVyuv->(matchyuv.yuv_pixelwith|Pixel.YUVJ420->YUV420.blank(to_YUV420img)|_->failwith"Not implemented")letconvert?(proportional=true)?scale_kindsrcdst=match(src.data,dst.data)with|RGBs,RGBdwhens.rgb_pixel=Pixel.RGBA32&&d.rgb_pixel=Pixel.RGBA32->letsrc=to_RGBA32srcinletdst=to_RGBA32dstinRGBA32.Scale.onto?kind:scale_kind~proportionalsrcdst|YUVs,RGBdwhens.yuv_pixel=Pixel.YUVJ420&&d.rgb_pixel=Pixel.RGBA32->letsrc=to_YUV420srcinletsrc=YUV420.to_RGBA32srcinletdst=to_RGBA32dstinRGBA32.Scale.onto?kind:scale_kind~proportionalsrcdst|RGBs,YUVdwhens.rgb_pixel=Pixel.RGBA32&&d.yuv_pixel=Pixel.YUVJ420->letsrc=to_RGBA32srcinletsrc=YUV420.of_RGBA32srcinletdst=to_YUV420dstinYUV420.scale~proportionalsrcdst|RGBs,RGBdwhens.rgb_pixel=Pixel.RGBA32&&d.rgb_pixel=Pixel.BGR32->ifsrc.width=dst.width&&src.height=dst.heightthenrgba32_to_bgr32s.rgb_datas.rgb_strided.rgb_datad.rgb_stride(src.width,src.height)elseraiseNot_implemented|RGBs,RGBdwhens.rgb_pixel=Pixel.RGB24&&d.rgb_pixel=Pixel.RGBA32->ifsrc.width=dst.width&&src.height=dst.heightthenrgb24_to_rgba32s.rgb_datas.rgb_strided.rgb_datad.rgb_stride(src.width,src.height)elseraiseNot_implemented|RGBs,RGBdwhens.rgb_pixel=Pixel.RGB32&&d.rgb_pixel=Pixel.RGBA32->ifsrc.width=dst.width&&src.height=dst.heightthenrgb32_to_rgba32s.rgb_datas.rgb_strided.rgb_datad.rgb_stride(src.width,src.height)elseraiseNot_implemented|_->raiseNot_implemented