123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456(***********************************************************************)(* *)(* Objective Caml *)(* *)(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1999-2004, *)(* Institut National de Recherche en Informatique et en Automatique. *)(* Distributed only by permission. *)(* *)(***********************************************************************)(* $Id: oImages.ml,v 1.5 2009/03/01 09:49:53 furuse Exp $ *)openImagesexceptionNon_supported_methodexceptionWrong_image_classtypeimage_class=|ClassRgb24|ClassIndex8|ClassIndex16|ClassRgba32|ClassCmyk32classtypeimgsize=objectmethodwidth:intmethodheight:intendclasstype['a]map=objectinheritimgsizemethodunsafe_get:int->int->'amethodunsafe_set:int->int->'a->unitmethodget:int->int->'amethodset:int->int->'a->unitmethodunsafe_access:int->int->bytes*intendclasstypeoimage=objectinheritimgsizemethodinfos:infolistmethodset_infos:infolist->unitmethodimage_class:image_classmethodimage:Images.tmethoddestroy:unitmethoddump:bytesmethodsave:string->formatoption->save_optionlist->unitmethodcoerce:oimagemethodblocks:int*intmethoddump_block:int->int->Bitmap.Block.tend(* Implementation *)classvirtualoimage_impl=object(self)methodvirtualimage_class:image_classmethodvirtualimage:Images.tmethodvirtualwidth:intmethodvirtualheight:intmethodvirtualinfos:infolistmethodvirtualset_infos:infolist->unitmethodvirtualdestroy:unitmethodvirtualdump:bytesmethodvirtualsave:string->formatoption->save_optionlist->unitmethodcoerce=(self:><image:_;image_class:_;width:_;height:_;infos:_;set_infos:_;destroy:_;dump:_;save:_;coerce:_;blocks:_;dump_block:_>)methodvirtualblocks:int*intmethodvirtualdump_block:int->int->Bitmap.Block.tendopenRgb24classtypergba32_class=objectinheritoimageinherit[Color.rgba]mapmethodsub:int->int->int->int->rgba32_classmethodblit:int->int->rgba32_class->int->int->int->int->unitmethodresize:(float->unit)option->int->int->rgba32_classmethodto_rgb24:rgb24_classendandrgb24_class=objectinheritoimageinherit[Color.rgb]mapmethodsub:int->int->int->int->rgb24_classmethodblit:int->int->rgb24_class->int->int->int->int->unitmethodresize:(float->unit)option->int->int->rgb24_classmethodto_rgba32:rgba32_classendclassrgba32_wrapperimg=objectinheritoimage_implmethodimage_class=ClassRgba32methodimage=Images.Rgba32imgmethodwidth=img.Rgba32.widthmethodheight=img.Rgba32.heightmethodinfos=img.Rgba32.infosmethoddump=Rgba32.dumpimgmethodset_infosinfos=img.Rgba32.infos<-infosmethodunsafe_access=Rgba32.unsafe_accessimgmethodunsafe_get=Rgba32.unsafe_getimgmethodunsafe_set=Rgba32.unsafe_setimgmethodget=Rgba32.getimgmethodset=Rgba32.setimgmethoddestroy=Rgba32.destroyimgmethodsubxywh=newrgba32_wrapper(Rgba32.subimgxywh)methodblitsxsy(dst:rgba32_class)=Images.blit(Rgba32img)sxsydst#imagemethodresizeprognwnh=newrgba32_wrapper(Rgba32.resizeprogimgnwnh)methodsavenameformatopts=Images.savenameformatopts(Rgba32img)methodto_rgb24=newrgb24_wrapper(Rgb24.of_rgba32img)methodblocks=Rgba32.blocksimgmethoddump_block=Rgba32.dump_blockimgendandrgb24_wrapperimg=objectinheritoimage_implmethodimage_class=ClassRgb24methodimage=Images.Rgb24imgmethodwidth=img.Rgb24.widthmethodheight=img.Rgb24.heightmethodinfos=img.Rgb24.infosmethoddump=dumpimgmethodset_infosinfos=img.Rgb24.infos<-infosmethodunsafe_access=unsafe_accessimgmethodunsafe_get=unsafe_getimgmethodunsafe_set=unsafe_setimgmethodget=getimgmethodset=setimgmethoddestroy=destroyimgmethodsubxywh=newrgb24_wrapper(subimgxywh)methodblitsxsy(dst:rgb24_class)=Images.blit(Rgb24img)sxsydst#imagemethodresizeprognwnh=newrgb24_wrapper(resizeprogimgnwnh)methodsavenameformatopts=Images.savenameformatopts(Rgb24img)methodto_rgba32=newrgba32_wrapper(Rgb24.to_rgba32img)methodblocks=Rgb24.blocksimgmethoddump_block=Rgb24.dump_blockimgendclassrgba32widthheight=objectinheritrgba32_wrapper(Rgba32.createwidthheight)endclassrgba32_filledwidthheightinit=objectinheritrgba32_wrapper(Rgba32.makewidthheightinit)endclassrgba32_withwidthheightdatabitmap=objectinheritrgba32_wrapper(Rgba32.create_withwidthheightdatabitmap)endclassrgb24widthheight=objectinheritrgb24_wrapper(createwidthheight)endclassrgb24_filledwidthheightinit=objectinheritrgb24_wrapper(makewidthheightinit)endclassrgb24_withwidthheightdatabitmap=objectinheritrgb24_wrapper(create_withwidthheightdatabitmap)endopenIndex8classtypeindex8_class=objectinheritoimageinherit[Index8.elt]mapinheritOColor.rgbmapmethodsub:int->int->int->int->index8_classmethodblit:int->int->index8_class->int->int->int->int->unitmethodget_color:int->int->Color.rgbmethodunsafe_get_color:int->int->Color.rgbmethodtransparent:Index8.eltmethodset_transparent:Index8.elt->unitmethodto_rgb24:rgb24_classmethodto_rgba32:rgba32_classendclassindex8_wrapperimg=object(self)inheritoimage_implinheritOColor.rgbmapimg.colormapmethodimage_class=ClassIndex8methodimage=Index8imgmethodwidth=img.widthmethodheight=img.heightmethodtransparent=img.transparentmethodinfos=img.infosmethoddump=dumpimgmethodset_transparentc=img.transparent<-cmethodset_infosinfos=img.infos<-infosmethodunsafe_access=unsafe_accessimgmethodunsafe_get=unsafe_getimgmethodunsafe_set=unsafe_setimgmethodget=getimgmethodset=setimgmethodget_colorxy=self#query_color(self#getxy)methodunsafe_get_colorxy=self#query_color(self#unsafe_getxy)methoddestroy=destroyimgmethodsubxywh=newindex8_wrapper(Index8.subimgxywh)methodblitsxsy(dst:index8_class)=Images.blit(Index8img)sxsydst#imagemethodsavenameformatopts=Images.savenameformatopts(Index8img)methodto_rgb24=newrgb24_wrapper(Index8.to_rgb24img)methodto_rgba32=newrgba32_wrapper(Index8.to_rgba32img)methodblocks=Index8.blocksimgmethoddump_block=Index8.dump_blockimgendclassindex8widthheight=objectinheritindex8_wrapper(createwidthheight)endclassindex8_filledwidthheightinit=objectinheritindex8_wrapper(makewidthheightinit)endclassindex8_withwidthheightinfoscmaptransbitmap=objectinheritindex8_wrapper(create_withwidthheightinfoscmaptransbitmap)endopenIndex16classtypeindex16_class=objectinheritoimageinherit[Index16.elt]mapinheritOColor.rgbmapmethodsub:int->int->int->int->index8_classmethodblit:int->int->index8_class->int->int->int->int->unitmethodget_color:int->int->Color.rgbmethodunsafe_get_color:int->int->Color.rgbmethodtransparent:Index16.eltmethodset_transparent:Index16.elt->unitmethodto_rgb24:rgb24_classmethodto_rgba32:rgba32_classendclassindex16_wrapperimg=object(self)inheritoimage_implinheritOColor.rgbmapimg.colormapmethodimage_class=ClassIndex16methodimage=Index16imgmethodwidth=img.widthmethodheight=img.heightmethodtransparent=img.transparentmethodinfos=img.infosmethoddump=dumpimgmethodset_transparentc=img.transparent<-cmethodset_infosinfos=img.infos<-infosmethodunsafe_access=unsafe_accessimgmethodunsafe_get=unsafe_getimgmethodunsafe_set=unsafe_setimgmethodget=getimgmethodset=setimgmethodget_colorxy=self#query_color(self#getxy)methodunsafe_get_colorxy=self#query_color(self#unsafe_getxy)methoddestroy=destroyimgmethodsubxywh=newindex16_wrapper(Index16.subimgxywh)methodblitsxsy(dst:index16_class)=Images.blit(Index16img)sxsydst#imagemethodto_rgb24=newrgb24_wrapper(Index16.to_rgb24img)methodto_rgba32=newrgba32_wrapper(Index16.to_rgba32img)methodsavenameformatopts=Images.savenameformatopts(Index16img)methodblocks=Index16.blocksimgmethoddump_block=Index16.dump_blockimgendclassindex16widthheight=objectinheritindex16_wrapper(createwidthheight)endclassindex16_filledwidthheightinit=objectinheritindex16_wrapper(makewidthheightinit)endclassindex16_withwidthheightinfoscmaptransbitmap=objectinheritindex16_wrapper(create_withwidthheightinfoscmaptransbitmap)endopenCmyk32classtypecmyk32_class=objectinheritoimageinherit[Color.cmyk]mapmethodsub:int->int->int->int->cmyk32_classmethodblit:int->int->cmyk32_class->int->int->int->int->unitmethodresize:(float->unit)option->int->int->cmyk32_classendclasscmyk32_wrapperimg=objectinheritoimage_implmethodimage_class=ClassCmyk32methodimage=Images.Cmyk32imgmethodwidth=img.widthmethodheight=img.heightmethodinfos=img.infosmethoddump=dumpimgmethodset_infosinfos=img.infos<-infosmethodunsafe_access=unsafe_accessimgmethodunsafe_get=unsafe_getimgmethodunsafe_set=unsafe_setimgmethodget=getimgmethodset=setimgmethoddestroy=destroyimgmethodsubxywh=newcmyk32_wrapper(subimgxywh)methodblitsxsy(dst:cmyk32_class)=Images.blit(Cmyk32img)sxsydst#imagemethodresizeprognwnh=newcmyk32_wrapper(resizeprogimgnwnh)methodsavenameformatopts=Images.savenameformatopts(Cmyk32img)methodblocks=Cmyk32.blocksimgmethoddump_block=Cmyk32.dump_blockimgendclasscmyk32widthheight=objectinheritcmyk32_wrapper(createwidthheight)endclasscmyk32_filledwidthheightinit=objectinheritcmyk32_wrapper(makewidthheightinit)endclasscmyk32_withwidthheightdatabitmap=objectinheritcmyk32_wrapper(create_withwidthheightdatabitmap)endtypetagged=|Rgb24ofrgb24_class|Index8ofindex8_class|Index16ofindex16_class|Rgba32ofrgba32_class|Cmyk32ofcmyk32_classletrgb24oimage=ifoimage#image_class=ClassRgb24then(Obj.magicoimage:rgb24_class)elseraiseWrong_image_classletindex8oimage=ifoimage#image_class=ClassIndex8then(Obj.magicoimage:index8_class)elseraiseWrong_image_classletindex16oimage=ifoimage#image_class=ClassIndex16then(Obj.magicoimage:index16_class)elseraiseWrong_image_classletrgba32oimage=ifoimage#image_class=ClassRgba32then(Obj.magicoimage:rgba32_class)elseraiseWrong_image_classletcmyk32oimage=ifoimage#image_class=ClassCmyk32then(Obj.magicoimage:cmyk32_class)elseraiseWrong_image_classlettagimg=matchimg#image_classwith|ClassRgb24->Rgb24(Obj.magicimg:rgb24_class)|ClassIndex8->Index8(Obj.magicimg:index8_class)|ClassIndex16->Index16(Obj.magicimg:index16_class)|ClassRgba32->Rgba32(Obj.magicimg:rgba32_class)|ClassCmyk32->Cmyk32(Obj.magicimg:cmyk32_class)letmake=function|Images.Index8img->(newindex8_wrapperimg)#coerce|Images.Rgb24img->(newrgb24_wrapperimg)#coerce|Images.Index16img->(newindex16_wrapperimg)#coerce|Images.Rgba32img->(newrgba32_wrapperimg)#coerce|Images.Cmyk32img->(newcmyk32_wrapperimg)#coerceletsubimgxywh=matchtagimgwith|Rgb24i->(i#subxywh)#coerce|Index8i->(i#subxywh)#coerce|Index16i->(i#subxywh)#coerce|Rgba32i->(i#subxywh)#coerce|Cmyk32i->(i#subxywh)#coerceletloadfilenameload_options=make(Images.loadfilenameload_options)