Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file tiff.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139(***********************************************************************)(* *)(* 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: tiff.ml,v 1.2 2008/06/16 22:35:42 furuse Exp $ *)openImagesopenRgb24openUtilmodulePervasives=Stdlibtypecolormodel=RGB|CMYK|WHITEBLACK|BLACKWHITEtypein_handleexternalopen_in:string->int*int*float*colormodel*in_handle="open_tiff_file_for_read"externalread_scanline:in_handle->bytes->int->unit="read_tiff_scanline"externalclose_in:in_handle->unit="close_tiff_file"typeout_handleexternalopen_out:string->int->int->float->out_handle="open_tiff_file_for_write"externalwrite_scanline:out_handle->bytes->int->unit="write_tiff_scanline"externalclose_out:out_handle->unit="close_tiff_file"letloadnameopts=letprog=Images.load_progressoptsinletw,h,_dpi,colormodel,tif=open_innameinletimg,buf=matchcolormodelwith|RGB->letimg=Rgb24.createwhinRgb24img,Bytes.create(w*3)|CMYK->letimg=Cmyk32.createwhinCmyk32img,Bytes.create(w*4)|WHITEBLACK->letimg=Index8.createwhinimg.Index8.colormap.map<-[|{r=255;g=255;b=255};{r=0;g=0;b=0}|];Index8img,Bytes.create((w+7)/8)|BLACKWHITE->letimg=Index8.createwhinimg.Index8.colormap.map<-[|{r=0;g=0;b=0};{r=255;g=255;b=255}|];Index8img,Bytes.create((w+7)/8)inletset_scanline=matchcolormodel,imgwith|_,Rgb24img->funbufy->Rgb24.set_scanlineimgybuf|_,Cmyk32img->funbufy->Cmyk32.set_scanlineimgybuf|BLACKWHITE,Index8img|WHITEBLACK,Index8img->letbits=[|128;64;32;16;8;4;2;1|]infunbufy->forx=0tow-1doletc=xlsr3inletb=xland7inif(buf@%c)landArray.unsafe_getbitsb<>0thenIndex8.unsafe_setimgxy1done|_->assertfalseinfory=0toh-1doread_scanlinetifbufy;set_scanlinebufy;matchprogwith|Somep->p(float(y+1)/.floath)|None->()done;close_intif;imgletsavename_optsimage=matchimagewith|Rgb24bmp->letresolution=(* resolution in DPI *)matchImages.dpibmp.infoswith|Somer->r|None->200.0inletoc=open_outnamebmp.widthbmp.heightresolutioninfory=0tobmp.height-1dowrite_scanlineoc(Rgb24.get_scanlinebmpy)ydone;close_outoc|_->raiseWrong_image_typeletcheck_headerfilename=letlen=4inletic=open_in_binfilenameintryletstr=Bytes.createleninreally_inputicstr0len;Pervasives.close_inic;matchBytes.to_stringstrwith|"MM\000\042"->{header_width=-1;header_height=-1;header_infos=[Images.Info_BigEndian];}|"II\042\000"->{header_width=-1;header_height=-1;header_infos=[Images.Info_LittleEndian];}|_->raiseWrong_file_typewith|_->Pervasives.close_inic;raiseWrong_file_typelet()=add_methodsTiff{check_header=check_header;load=Someload;save=Somesave;load_sequence=None;save_sequence=None;}