123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166(***********************************************************************)(* *)(* Objective Caml *)(* *)(* François Pessaux, projet Cristal, INRIA Rocquencourt *)(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1999-2004, *)(* Institut National de Recherche en Informatique et en Automatique. *)(* Distributed only by permission. *)(* *)(***********************************************************************)(* $Id: index8.ml,v 1.4 2009/07/04 03:39:28 furuse Exp $*)openUtilmoduleE=structtypet=intletbytes_per_pixel=1letget=(@%)letsetstrpost=str<<pos&char_of_inttletmaket=letstr=Bytes.createbytes_per_pixelinsetstr0t;strendmoduleRI=Genimage.MakeRawImage(E)typerawimage=RI.ttypeelt=inttypet={width:int;height:int;rawimage:RI.t;mutableinfos:Info.infolist;mutablecolormap:Color.rgbColor.map;mutabletransparent:int;}moduleC=structopenColortyperawimage=RI.ttypecontainer=ttypemapelt=Color.rgbletrawimagex=x.rawimageletcreate_defaultwidthheightrawimage={width=width;height=height;rawimage=rawimage;colormap={map=[||];max=255};transparent=(-1);infos=[]}letcreate_duplicatesrcwidthheightrawimage={width=width;height=height;rawimage=rawimage;colormap=src.colormap;transparent=src.transparent;infos=src.infos}letcolormapt=t.colormapendmoduleIMAGE=Genimage.MakeIndexed(RI)(C)letcreate_withwidthheightinfoscolormaptransparentdata={width=width;height=height;rawimage=RI.create_withwidthheightdata;colormap=colormap;transparent=transparent;infos=infos;}letcreate_with_scanlineswidthheightinfoscolormaptransparentdata={width=width;height=height;rawimage=RI.create_with_scanlineswidthheightdata;colormap=colormap;transparent=transparent;infos=infos;}letrawimage=C.rawimageletcreate=IMAGE.createletmake=IMAGE.makeletdump=IMAGE.dumpletunsafe_access=IMAGE.unsafe_accessletget_strip=IMAGE.get_stripletset_strip=IMAGE.set_stripletget_scanline=IMAGE.get_scanlineletset_scanline=IMAGE.set_scanlineletunsafe_get=IMAGE.unsafe_getletunsafe_set=IMAGE.unsafe_setletget=IMAGE.getletset=IMAGE.setletunsafe_get_color=IMAGE.unsafe_get_colorletget_color=IMAGE.get_colorletdestroy=IMAGE.destroyletcopy=IMAGE.copyletsub=IMAGE.subletblit=IMAGE.blitletmap=IMAGE.mapletblocks=IMAGE.blocksletdump_block=IMAGE.dump_blockletunsafe_get_rgb=unsafe_get_colorletget_rgb=get_coloropenColorletto_rgb24?failsafet=letrgb24=Rgb24.createt.widtht.heightinletcmapsize=Array.lengtht.colormap.mapinbeginmatchfailsafewith|Somefailsafecolor->fory=0tot.height-1doforx=0tot.width-1doletidx=unsafe_gettxyinletrgb=ifidx<0||idx>=cmapsizethenfailsafecolorelset.colormap.map.(idx)inRgb24.unsafe_setrgb24xyrgbdonedone|None->fory=0tot.height-1doforx=0tot.width-1doRgb24.unsafe_setrgb24xy(unsafe_get_colortxy)donedoneend;rgb24letto_rgba32?failsafet=letrgba32=Rgba32.createt.widtht.heightinletcmapsize=Array.lengtht.colormap.mapinbeginmatchfailsafewith|Somefailsafecolor->fory=0tot.height-1doforx=0tot.width-1doletrgba=letindex=unsafe_gettxyinifindex<0||index>=cmapsizethenfailsafecolorelse{color=t.colormap.map.(index);alpha=ifindex=t.transparentthen0else255}inRgba32.unsafe_setrgba32xyrgbadonedone|None->fory=0tot.height-1doforx=0tot.width-1doletindex=unsafe_gettxyinRgba32.unsafe_setrgba32xy{color=t.colormap.map.(index);alpha=ifindex=t.transparentthen0else255}donedoneend;rgba32