123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869(***********************************************************************)(* *)(* 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: xpm.ml,v 1.2 2008/06/16 22:35:42 furuse Exp $ *)openImagesopenColoropenUtilexternalread:string->int*int*stringarray*intarray="read_xpm_file"letloadfile_opts=letw,h,cmap,imap=readfileinletcmap,transparent=colormap_parsecmapin(* if the colors <= 256 then we create index8,
otherwise create index16 *)ifArray.lengthcmap<=256thenbeginletbuf=Bytes.create(w*h)infori=0tow*h-1dobuf<<i&char_of_intimap.(i)done;Index8(Index8.create_withwh[]{map=cmap;max=256-1;}transparentbuf)endelsebeginletbuf=Bytes.create(w*h*2)infori=0tow*h-1dolet(&)=(@@)inbuf<<i*2&char_of_int(imap.(i)/256);buf<<i*2+1&char_of_int(imap.(i)mod256)done;Index16(Index16.create_withwh[]{map=cmap;max=256*256-1;}transparentbuf)endletcheck_headerfilename=letlen=9inletic=open_in_binfilenameintryletstr=Bytes.createleninreally_inputicstr0len;close_inic;ifBytes.to_stringstr="/* XPM */"then{header_width=-1;header_height=-1;header_infos=[];}elseraiseWrong_file_typewith|_->raiseWrong_file_typelet()=add_methodsXpm{check_header=check_header;load=Someload;save=None;load_sequence=None;save_sequence=None;}