123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141(***********************************************************************)(* *)(* 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: cmyk32.ml,v 1.4 2009/07/04 03:39:28 furuse Exp $*)(* CMYK 32 bit depth image format *)openUtilmoduleE=structopenColortypet=Color.cmykletbytes_per_pixel=4letgetstrpos={c=str@%pos;m=str@%pos+1;y=str@%pos+2;k=str@%pos+3;}letsetstrpost=str<<pos&char_of_intt.c;str<<pos+1&char_of_intt.m;str<<pos+2&char_of_intt.y;str<<pos+3&char_of_intt.kletmaket=letstr=Bytes.createbytes_per_pixelinsetstr0t;strendmoduleRI=Genimage.MakeRawImage(E)typerawimage=RI.ttypeelt=Color.cmyktypet={width:int;height:int;rawimage:RI.t;mutableinfos:Info.infolist;}moduleC=structtyperawimage=RI.ttypecontainer=tletrawimagex=x.rawimageletcreate_defaultwidthheightrawimage={width=width;height=height;rawimage=rawimage;infos=[];}letcreate_duplicatesrcwidthheightrawimage={width=width;height=height;rawimage=rawimage;infos=src.infos;}endmoduleIMAGE=Genimage.Make(RI)(C)letcreate_withwidthheightinfosdata={width=width;height=height;rawimage=RI.create_withwidthheightdata;infos=infos;}letcreate_with_scanlineswidthheightinfosdata={width=width;height=height;rawimage=RI.create_with_scanlineswidthheightdata;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.setletdestroy=IMAGE.destroyletcopy=IMAGE.copyletsub=IMAGE.subletblit=IMAGE.blitletmap=IMAGE.mapletblocks=IMAGE.blocksletdump_block=IMAGE.dump_blockopenColor(* image resize with smoothing *)letresizeprogimgnwnh=letnewimage=createnwnhinletxscale=floatnw/.floatimg.widthinletyscale=floatnh/.floatimg.heightinfory=0tonh-1doforx=0tonw-1doletstart_x=truncate(floatx/.xscale)andstart_y=truncate(floaty/.yscale)inletend_x=truncate((floatx+.0.99)/.xscale)andend_y=truncate((floaty+.0.99)/.yscale)inletsize=(end_x-start_x+1)*(end_y-start_y+1)inletsc=ref0andsm=ref0andsy=ref0andsk=ref0inforxx=start_xtoend_xdoforyy=start_ytoend_ydoletc=unsafe_getimgxxyyinsc:=!sc+c.c;sm:=!sm+c.m;sy:=!sy+c.y;sk:=!sk+c.k;donedone;unsafe_setnewimagexy{c=!sc/size;m=!sm/size;y=!sy/size;k=!sk/size;}done;matchprogwith|Somep->p(float(y+1)/.floatnh)|None->()done;newimage