123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176(***********************************************************************)(* *)(* 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: genimage.ml,v 1.6 2009/07/04 03:39:28 furuse Exp $ *)openColoropenImage_intfmoduleMakeRawImage(E:ENCODE)=structmoduleBitmap=Bitmap.Make(E)moduleEncode=Etypeelt=E.ttypebitmap=Bitmap.ttypet={width:int;height:int;bitmap:bitmap;}letwidtht=t.widthletheightt=t.heightletdumpt=Bitmap.dumpt.bitmapletcreate_withwidthheightinit_buffer={width=width;height=height;bitmap=Bitmap.create_withwidthheightinit_buffer;}letcreate_with_scanlineswidthheightinit_scanlines={width=width;height=height;bitmap=Bitmap.create_with_scanlineswidthheightinit_scanlines;}letcreatewidthheight={width=width;height=height;bitmap=Bitmap.createwidthheightNone;}letmakewidthheightinit={width=width;height=height;bitmap=Bitmap.createwidthheight(Some(E.makeinit));}letunsafe_accesstxy=Bitmap.accesst.bitmapxyletget_stript=Bitmap.get_stript.bitmapletset_stript=Bitmap.set_stript.bitmapletget_scanlinet=Bitmap.get_scanlinet.bitmapletget_scanline_ptrt=Bitmap.get_scanline_ptrt.bitmapletset_scanlinet=Bitmap.set_scanlinet.bitmapletunsafe_gettxy=letstr,pos=Bitmap.accesst.bitmapxyinE.getstrposletunsafe_settxyc=letstr,pos=Bitmap.accesst.bitmapxyinE.setstrposcletgettxy=Region.checkt.widtht.heightxy;unsafe_gettxyletsettxyc=Region.checkt.widtht.heightxy;unsafe_settxycletdestroyt=Bitmap.destroyt.bitmapletcopysrc={srcwithbitmap=Bitmap.copysrc.bitmap}letsubsrcxywh={width=w;height=h;bitmap=Bitmap.subsrc.bitmapxywh;}letblitsrcsxsydstdxdywh=Bitmap.blitsrc.bitmapsxsydst.bitmapdxdywhletmapfsrcsxsydstdxdywh=fory=0toh-1doforx=0tow-1dolets=unsafe_getsrc(sx+x)(sy+y)inletdx'=dx+xanddy'=dy+yinletd=unsafe_getdstdx'dy'inunsafe_setdstdx'dy'(fsd)donedoneletblocksimg=Bitmap.blocksimg.bitmapletdump_blockimg=Bitmap.dump_blockimg.bitmapendmoduleMake(RI:RAWIMAGE)(CON:CONTAINERwithtyperawimage=RI.t)=structtypet=CON.containertypeelt=RI.eltletdumpt=RI.dump(CON.rawimaget)letcreatewidthheight=CON.create_defaultwidthheight(RI.createwidthheight)letmakewidthheightc=CON.create_defaultwidthheight(RI.makewidthheightc)letunsafe_accesst=RI.unsafe_access(CON.rawimaget)letget_stript=RI.get_strip(CON.rawimaget)letset_stript=RI.set_strip(CON.rawimaget)letget_scanlinet=RI.get_scanline(CON.rawimaget)letget_scanline_ptrt=RI.get_scanline_ptr(CON.rawimaget)letset_scanlinet=RI.set_scanline(CON.rawimaget)letunsafe_gett=RI.unsafe_get(CON.rawimaget)letunsafe_sett=RI.unsafe_set(CON.rawimaget)letgett=RI.get(CON.rawimaget)letsett=RI.set(CON.rawimaget)letdestroyt=RI.destroy(CON.rawimaget)letcopyt=lett'=CON.rawimagetinCON.create_duplicatet(RI.widtht')(RI.heightt')(RI.copyt')letsubtxywh=lett'=CON.rawimagetinCON.create_duplicatetwh(RI.subt'xywh)letblitsrcsxsydstdxdywh=RI.blit(CON.rawimagesrc)sxsy(CON.rawimagedst)dxdywhletmapfsrcsxsydstdxdywh=RI.mapf(CON.rawimagesrc)sxsy(CON.rawimagedst)dxdywhletblocksimg=RI.blocks(CON.rawimageimg)letdump_blockimg=RI.dump_block(CON.rawimageimg)endmoduleMakeIndexed(RI:RAWIMAGEwithtypeelt=int)(CON:CONTAINER_INDEXEDwithtyperawimage=RI.t)=structincludeMake(RI)(CON)typemapelt=CON.mapeltletunsafe_get_colort=letcolormap=CON.colormaptinfunxy->colormap.map.(unsafe_gettxy)letget_colort=letcolormap=CON.colormaptinfunxy->leti=gettxyinifi<0||i>=Array.lengthcolormap.mapthenraiseNot_found;colormap.map.(i)end