123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247(**************************************************************************)(* Lablgtk *)(* *)(* This program is free software; you can redistribute it *)(* and/or modify it under the terms of the GNU Library General *)(* Public License as published by the Free Software Foundation *)(* version 2, with the exception described in file COPYING which *)(* comes with the library. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Library General Public License for more details. *)(* *)(* You should have received a copy of the GNU Library General *)(* Public License along with this program; if not, write to the *)(* Free Software Foundation, Inc., 59 Temple Place, Suite 330, *)(* Boston, MA 02111-1307 USA *)(* *)(* *)(**************************************************************************)(* $Id$ *)openGauxopenGobjectopenGdktypepixbuf=[`pixbuf]objtypecolorspace=[`RGB]typealpha_mode=[`BILEVEL|`FULL]typeinterpolation=[`NEAREST|`TILES|`BILINEAR|`HYPER]typegdkpixbuferror=|ERROR_CORRUPT_IMAGE|ERROR_INSUFFICIENT_MEMORY|ERROR_BAD_OPTION|ERROR_UNKNOWN_TYPE|ERROR_UNSUPPORTED_OPERATION|ERROR_FAILEDexceptionGdkPixbufErrorofgdkpixbuferror*stringexternal_init:unit->unit="ml_gdkpixbuf_init"let()=_init();Callback.register_exception"gdk_pixbuf_error"(GdkPixbufError(ERROR_CORRUPT_IMAGE,""))externalset_marshal_use_rle:bool->unit="ml_gdk_pixbuf_set_marshal_use_rle"(* Accessors *)externalget_n_channels:pixbuf->int="ml_gdk_pixbuf_get_n_channels"externalget_has_alpha:pixbuf->bool="ml_gdk_pixbuf_get_has_alpha"externalget_bits_per_sample:pixbuf->int="ml_gdk_pixbuf_get_bits_per_sample"externalget_width:pixbuf->int="ml_gdk_pixbuf_get_width"externalget_height:pixbuf->int="ml_gdk_pixbuf_get_height"externalget_rowstride:pixbuf->int="ml_gdk_pixbuf_get_rowstride"external_get_pixels:pixbuf->Obj.t*int="ml_gdk_pixbuf_get_pixels"letget_pixelspixbuf=letobj,pos=_get_pixelspixbufinletget_length(_,pixbuf)=get_rowstridepixbuf*get_heightpixbuf+posinletr=Gpointer.unsafe_create_region~path:[|0|]~get_length(obj,pixbuf)inGpointer.sub~posr(* Constructors *)external_create:colorspace:colorspace->has_alpha:bool->bits:int->width:int->height:int->pixbuf="ml_gdk_pixbuf_new"letcreate~width~height?(bits=8)?(colorspace=`RGB)?(has_alpha=false)()=_create~colorspace~has_alpha~bits~width~heightletcasto:pixbuf=Gobject.try_casto"GdkPixbuf"externalcopy:pixbuf->pixbuf="ml_gdk_pixbuf_copy"externalsubpixbuf:pixbuf->src_x:int->src_y:int->width:int->height:int->pixbuf="ml_gdk_pixbuf_new_subpixbuf"externalfrom_file:string->pixbuf="ml_gdk_pixbuf_new_from_file"externalget_file_info:string->string*int*int="ml_gdk_pixbuf_get_file_info"externalfrom_file_at_size:string->width:int->height:int->pixbuf="ml_gdk_pixbuf_new_from_file_at_size"externalfrom_xpm_data:stringarray->pixbuf="ml_gdk_pixbuf_new_from_xpm_data"external_from_data:Gpointer.region->has_alpha:bool->bits:int->width:int->height:int->rowstride:int->pixbuf="ml_gdk_pixbuf_new_from_data_bc""ml_gdk_pixbuf_new_from_data"letfrom_data~width~height?(bits=8)?rowstride?(has_alpha=false)data=letnc=ifhas_alphathen4else3inletrowstride=matchrowstridewithNone->width*nc|Somer->rinifbits<>8||rowstride<width*nc||width<=0||height<=0||Gpointer.lengthdata<rowstride*(height-1)+width*nctheninvalid_arg"GdkPixbuf.from_data";_from_datadata~has_alpha~bits~width~height~rowstride(* GtkPixbuf removed in gtk3
external _get_from_drawable :
pixbuf -> [>`drawable] obj -> colormap -> src_x:int -> src_y:int ->
dest_x:int -> dest_y:int -> width:int -> height:int -> unit
= "ml_gdk_pixbuf_get_from_drawable_bc" "ml_gdk_pixbuf_get_from_drawable"
let get_from_drawable ~dest ?(dest_x=0) ?(dest_y=0) ?width ?height
?(src_x=0) ?(src_y=0) ?(colormap=Gdk.Rgb.get_cmap()) src =
let dw, dh = Gdk.Drawable.get_size src in
let mw = min (dw - src_x) (get_width dest - dest_x)
and mh = min (dh - src_y) (get_height dest - dest_y) in
let width = default mw ~opt:width and height = default mh ~opt:height in
if src_x < 0 || src_y < 0 || dest_x < 0 || dest_y < 0
|| width <= 0 || height <= 0 || width > mw || height > mh
then invalid_arg "GdkPixbuf.get_from_drawable";
_get_from_drawable dest src colormap ~src_x ~src_y ~dest_x ~dest_y
~width ~height
(* Render *)
external _render_alpha :
src:pixbuf -> bitmap -> src_x:int -> src_y:int ->
dest_x:int -> dest_y:int -> width:int -> height:int -> threshold:int -> unit
= "ml_gdk_pixbuf_render_threshold_alpha_bc"
"ml_gdk_pixbuf_render_threshold_alpha"
let render_alpha bm ?(dest_x=0) ?(dest_y=0) ?width ?height ?(threshold=128)
?(src_x=0) ?(src_y=0) src =
let width = may_default get_width src ~opt:width
and height = may_default get_height src ~opt:height in
_render_alpha ~src bm ~src_x ~src_y ~dest_x ~dest_y ~width ~height ~threshold
external _draw_pixbuf :
src:pixbuf -> [>`drawable] obj -> gc -> src_x:int -> src_y:int ->
dest_x:int -> dest_y:int -> width:int -> height:int ->
dither:Tags.rgb_dither -> x_dither:int -> y_dither:int -> unit
= "ml_gdk_pixbuf_render_to_drawable_bc"
"ml_gdk_pixbuf_render_to_drawable"
let draw_pixbuf dw gc ?(dest_x=0) ?(dest_y=0)
?width ?height ?(dither=`NONE) ?(x_dither=0) ?(y_dither=0)
?(src_x=0) ?(src_y=0) src =
let width = may_default get_width src ~opt:width
and height = may_default get_height src ~opt:height in
_draw_pixbuf dw gc ~src ~src_x ~src_y ~dest_x ~dest_y ~width ~height
~dither ~x_dither ~y_dither
let render_to_drawable dw ?(gc=Gdk.GC.create dw) =
draw_pixbuf dw gc
external _render_to_drawable_alpha :
src:pixbuf -> [>`drawable] obj -> src_x:int -> src_y:int ->
dest_x:int -> dest_y:int -> width:int -> height:int ->
alpha:alpha_mode -> threshold:int ->
dither:Tags.rgb_dither -> x_dither:int -> y_dither:int -> unit
= "ml_gdk_pixbuf_render_to_drawable_alpha_bc"
"ml_gdk_pixbuf_render_to_drawable_alpha"
let render_to_drawable_alpha dw ?(dest_x=0) ?(dest_y=0) ?width ?height
?(alpha=`FULL) ?(threshold=128)
?(dither=`NONE) ?(x_dither=0) ?(y_dither=0) ?(src_x=0) ?(src_y=0) src =
let width = may_default get_width src ~opt:width
and height = may_default get_height src ~opt:height in
_render_to_drawable_alpha ~src dw ~src_x ~src_y ~dest_x ~dest_y ~width
~height ~dither ~x_dither ~y_dither ~alpha ~threshold
external _create_pixmap : pixbuf -> threshold:int -> pixmap * bitmap option
= "ml_gdk_pixbuf_render_pixmap_and_mask"
let create_pixmap ?(threshold=128) pb = _create_pixmap pb ~threshold
*)(* Transform *)external_add_alpha:pixbuf->subst:bool->r:int->g:int->b:int->pixbuf="ml_gdk_pixbuf_add_alpha"letadd_alpha?transparentpb=matchtransparentwithNone->_add_alphapb~subst:false~r:0~g:0~b:0|Some(r,g,b)->_add_alphapb~subst:true~r~g~bexternalfill:pixbuf->int32->unit="ml_gdk_pixbuf_fill"external_saturate_and_pixelate:pixbuf->dest:pixbuf->saturation:float->pixelate:bool->unit="ml_gdk_pixbuf_saturate_and_pixelate"letsaturate_and_pixelate~dest~saturation~pixelatesrc=_saturate_and_pixelatesrc~dest~saturation~pixelateexternal_copy_area:src:pixbuf->src_x:int->src_y:int->width:int->height:int->dest:pixbuf->dest_x:int->dest_y:int->unit="ml_gdk_pixbuf_copy_area_bc""ml_gdk_pixbuf_copy_area"letcopy_area~dest?(dest_x=0)?(dest_y=0)?width?height?(src_x=0)?(src_y=0)src=letmw=min(get_widthsrc-src_x)(get_widthdest-dest_x)andmh=min(get_heightsrc-src_y)(get_heightdest-dest_y)inletwidth=matchwidthwithSomew->w|None->mwandheight=matchheightwithSomeh->h|None->mhinifsrc_x<0||src_y<0||dest_x<0||dest_y<0||width<=0||height<=0||width>mw||height>mhtheninvalid_arg"GdkPixbuf.copy_area";_copy_area~src~src_x~src_y~width~height~dest~dest_x~dest_yletget_sizeszsc~ssrc~sdest~dest~ofs=matchsz,scwithNone,None->(sdest-dest,(floatdest+.ofs)/.floatssrc)|None,Somesc->(truncate(floatssrc*.sc-.ofs),sc)|Somesz,None->(sz,(floatsz+.ofs)/.floatssrc)|Somesz,Somesc->(sz,sc)external_scale:src:pixbuf->dest:pixbuf->dest_x:int->dest_y:int->width:int->height:int->ofs_x:float->ofs_y:float->scale_x:float->scale_y:float->interp:interpolation->unit="ml_gdk_pixbuf_scale_bc""ml_gdk_pixbuf_scale"letscale~dest?(dest_x=0)?(dest_y=0)?width?height?(ofs_x=0.)?(ofs_y=0.)?scale_x?scale_y?(interp=`BILINEAR)src=letwidth,scale_x=get_sizewidthscale_x~ssrc:(get_widthsrc)~sdest:(get_widthdest)~dest:dest_x~ofs:ofs_xandheight,scale_y=get_sizeheightscale_y~ssrc:(get_heightsrc)~sdest:(get_heightdest)~dest:dest_y~ofs:ofs_yin_scale~src~dest~dest_x~dest_y~width~height~ofs_x~ofs_y~scale_x~scale_y~interpexternal_composite:src:pixbuf->dest:pixbuf->dest_x:int->dest_y:int->width:int->height:int->ofs_x:float->ofs_y:float->scale_x:float->scale_y:float->interp:interpolation->alpha:int->unit="ml_gdk_pixbuf_composite_bc""ml_gdk_pixbuf_composite"letcomposite~dest~alpha?(dest_x=0)?(dest_y=0)?width?height?(ofs_x=0.)?(ofs_y=0.)?scale_x?scale_y?(interp=`BILINEAR)src=letwidth,scale_x=get_sizewidthscale_x~ssrc:(get_widthsrc)~sdest:(get_widthdest)~dest:dest_x~ofs:ofs_xandheight,scale_y=get_sizeheightscale_y~ssrc:(get_heightsrc)~sdest:(get_heightdest)~dest:dest_y~ofs:ofs_yin_composite~src~dest~dest_x~dest_y~width~height~ofs_x~ofs_y~scale_x~scale_y~interp~alpha(* Saving *)externalsave:filename:string->typ:string->?options:(string*string)list->pixbuf->unit="ml_gdk_pixbuf_save"externalsave_to_callback:pixbuf->typ:string->?options:(string*string)list->(string->unit)->unit="ml_gdk_pixbuf_save_to_callback"letsave_to_bufferpb~typ?optionsbuffer=save_to_callbackpb~typ?options(Buffer.add_stringbuffer)