Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file xvthumb.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174(***********************************************************************)(* *)(* 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: xvthumb.ml,v 1.1 2007/01/18 10:29:58 rousse Exp $ *)(* XV thumbnail loader/saver *)openImages(********************************************************************** load *)letread_idic=letbuf=Bytes.create7intryreally_inputicbuf07;ifBytes.to_stringbuf="P7 332\n"then()elsebeginprerr_endline"wrong header id";raiseWrong_image_typeendwith|_->prerr_endline"wrong header id";raiseWrong_image_typeletread_headeric=read_idic;letinfo=refNoneintrywhiletruedoletstr=input_lineicinifstr="#END_OF_COMMENTS"thenraiseExit;tryletpref="#IMGINFO:"inletpref_len=String.lengthprefinifString.substr0pref_len=prefthenbegininfo:=Some(String.substrpref_len(String.lengthstr-pref_len))end;with|_->()done;raiseExitwith|Exit->letinfo=match!infowithSomeinfo->info|None->raiseWrong_image_typeintryletstr=input_lineicinlettokens=List.mapint_of_string(Mstring.split_str(function' '->true|_->false)str)inmatchtokenswith[w;h;cols]whencols<=255->info,w,h|_->prerr_endline("GEOM get failed: "^str);raiseWrong_image_typewith|_->raiseWrong_image_typeletcmap_332()={max=256;map=Array.init256(funx->{r=(255*((xland(7lsl5))lsr5))/7;g=(255*((xland(7lsl2))lsr2))/7;b=(255*((xland(3lsl0))lsr0))/3})}letload_bodyicwh=letlength=w*hinletstr=Bytes.createlengthintryreally_inputicstr0length;Index8.create_withwh[](cmap_332())(-1)strwith|_->prerr_endline"short";raiseWrong_image_typeletloadname=letic=open_in_binnameinletinfo,w,h=read_headericinletimg=load_bodyicwhinclose_inic;info,img(********************************************************************** save *)openIndex8letwrite_idoc=output_stringoc"P7 332\n"letwrite_headerocinfowidthheight=write_idoc;output_stringoc"#XVVERSION:Version 3.10a (created the camlimages library)\n";output_stringoc"#IMGINFO:";output_stringocinfo;output_charoc'\n';output_stringoc"#END_OF_COMMENTS\n";output_stringoc(string_of_intwidth);output_charoc' ';output_stringoc(string_of_intheight);output_stringoc" 255\n"letconvert_332rgb=(* no dithering !!! *)(rgb.r/32)lsl5+(rgb.g/32)lsl2+rgb.b/64letsave_bodyocimg=fory=0toimg.height-1doforx=0toimg.width-1dooutput_byteoc(convert_332(unsafe_get_rgbimgxy))donedoneletsavenameinfoimg=letoc=open_outnameinwrite_headerocinfoimg.widthimg.height;save_bodyocimg;close_outocletcreateimg=letw,h=Images.sizeimginletnw,nh=letscale_w=80.0/.floatwandscale_h=60.0/.floathinifscale_w>1.0&&scale_h>1.0thenw,helsebeginifscale_w<scale_hthenbegin80,truncate(floath*.scale_w)endelsebegintruncate(floatw*.scale_h),60endendinletresized24=matchimgwith|Rgb24t->Rgb24.resizeNonetnwnh|Index8t->letrgb24=Index8.to_rgb24tinletresized=Rgb24.resizeNonergb24nwnhinRgb24.destroyrgb24;resized|Index16t->letrgb24=Index16.to_rgb24tinletresized=Rgb24.resizeNonergb24nwnhinRgb24.destroyrgb24;resized|Rgba32_|Cmyk32_->failwith"RGBA and CMYK not supported"inletthumb=Index8.create_withnwnh[](cmap_332())(-1)(Bytes.create(nw*nh))infory=0tonh-1doforx=0tonw-1doIndex8.unsafe_setthumbxy(convert_332(Rgb24.unsafe_getresized24xy))donedone;Rgb24.destroyresized24;thumb