Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file png.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(***********************************************************************)(* *)(* 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: png.ml,v 1.7 2009/07/04 03:39:28 furuse Exp $ *)openUtilopenImages(* do not change the ordering, since the tags are used in png*.c *)typepng_read_result=|PNG_RGB24ofbytesarray|PNG_RGBA32ofbytesarray|PNG_INDEX8ofbytesarray*rgbarray|PNG_INDEX16ofbytesarray*rgbarray|PNG_INDEX4ofbytesarray*rgbarrayexternalread_as_rgb24:string->int*int*bytesarray="read_png_file_as_rgb24"externalread:string->int*int*png_read_result="read_png_file"externalwrite_rgb:string->bytes->int->int->bool->unit="write_png_file_rgb"externalwrite_index:string->bytes->rgbarray->int->int->unit="write_png_file_index"letload_as_rgb24name_opts=letw,h,buf=read_as_rgb24nameinRgb24(Rgb24.create_with_scanlineswh[]buf)letloadname_opts=letw,h,res=readnameinmatchreswith|PNG_RGB24buf->Rgb24(Rgb24.create_with_scanlineswh[]buf)|PNG_RGBA32buf->Rgba32(Rgba32.create_with_scanlineswh[]buf)|PNG_INDEX8(buf,cmap)->Index8(Index8.create_with_scanlineswh[]{max=255;map=cmap;}(-1)buf)|PNG_INDEX16(buf,cmap)->Index16(Index16.create_with_scanlineswh[]{max=65535;map=cmap}(-1)buf)|PNG_INDEX4(buf,cmap)->letbuf'=Array.inith(fun_->Bytes.createw)infory=0toh-1doletb=buf'>@!yinforx=0tow-1dob<<x&char_of_int(letc=buf.(y)@%(x/2)inifxmod2=0thenclsr4elsecmod16)donedone;Index8(Index8.create_with_scanlineswh[]{max=16;map=cmap}(-1)buf')letsavename_optsimage=matchimagewith|Rgb24bmp->write_rgbname(Rgb24.dumpbmp)bmp.Rgb24.widthbmp.Rgb24.heightfalse|Rgba32bmp->write_rgbname(Rgba32.dumpbmp)bmp.Rgba32.widthbmp.Rgba32.heighttrue|Index8bmp->write_indexname(Index8.dumpbmp)bmp.Index8.colormap.mapbmp.Index8.widthbmp.Index8.height|Index16bmp->write_indexname(Index16.dumpbmp)bmp.Index16.colormap.mapbmp.Index16.widthbmp.Index16.height|Cmyk32_->failwith"Saving of CMYK not supported yet"letcheck_headerfilename=letlen=24inletic=open_in_binfilenameintryletstr=Bytes.createleninreally_inputicstr0len;close_inic;ifBytes.sub_stringstr13="PNG"thenbeginifBytes.sub_stringstr08<>"\137PNG\013\010\026\010"thenbegin{header_width=-1;header_height=-1;header_infos=[Info_Corrupted];}endelsebeginletbelongstr=(str@%0)lsl24+(str@%1)lsl16+(str@%2)lsl8+(str@%3)inletw=belong(Bytes.substr164)inleth=belong(Bytes.substr204)inletbdepth=Info_Depth(str@%12)inletinfos=tryletcolormodel=matchstr@%13with|0->Info_ColorModelGray|2->Info_ColorModelRGB|3->Info_ColorModelIndex|4->Info_ColorModelGrayA|6->Info_ColorModelRGBA|_->raiseNot_foundin[colormodel;bdepth]with|Not_found->[bdepth]in{header_width=w;header_height=h;header_infos=infos;}endendelseraiseWrong_file_typewith|_->close_inic;raiseWrong_file_typelet()=add_methodsPng{check_header=check_header;load=Someload;save=Somesave;load_sequence=None;save_sequence=None;}