+ location)))
+
+#?(pkg-exists-p "gtk+-2.0" :atleast-version "2.14.0")
+(progn
+ (defbinding %pixbuf-new-from-stream () pointer
+ gio:input-stream-designator
+ (nil (or null gio:cancellable))
+ (nil (or null gerror) :out))
+
+ (defbinding %pixbuf-new-from-stream-at-scale () pointer
+ gio:input-stream-designator
+ (width int)
+ (height int)
+ (preserve-aspect-ratio boolean)
+ (nil (or null gio:cancellable))
+ (nil (or null gerror) :out))
+
+ (defun %load-from-stream (stream width height preserve-aspect-p)
+ (multiple-value-bind (location gerror)
+ (cond
+ ((or width height)
+ (%pixbuf-new-from-stream-at-scale stream
+ (or width -1) (or height -1) preserve-aspect-p))
+ (t (%pixbuf-new-from-stream stream)))
+ (if gerror
+ (signal-gerror gerror)
+ location))))
+
+(defmethod allocate-foreign ((pixbuf pixbuf) &key source (bits-per-sample 8)
+ (colorspace :rgb) (has-alpha t) width height
+ (preserve-aspect-ratio t) destroy stride)
+ (cond
+ ((not source)
+ (%pixbuf-new colorspace has-alpha bits-per-sample width height))
+ ((typep source 'pointer)
+ ;; TODO: destory
+ (%pixbuf-new-from-data source colorspace has-alpha bits-per-sample width height (or stride (* width (if has-alpha 4 3)))))
+ ((and (vectorp source) (stringp (aref source 0)))
+ (%pixbuf-new-from-xpm-data source))
+ ((typep source 'vector)
+
+ )
+ ((or (pathnamep source) (stringp source))
+ #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0")
+ (unless preserve-aspect-ratio
+ (warn ":preserve-aspect-ratio not supported with this version of Gtk"))
+ (%pixbuf-load source width height preserve-aspect-ratio))
+ #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.14.0")
+ ((typep source 'gio:input-stream-designator)
+ (%load-from-stream source width height preserve-aspect-ratio))
+ ((call-next-method))))
+
+
+(defbinding (pixbuf-subpixbuf "gdk_pixbuf_new_subpixbuf") ()
+ (or null (referenced pixbuf))
+ pixbuf (src-x int) (src-y int) (width int) (height int))
+
+(defbinding pixbuf-copy () (or null (referenced pixbuf))
+ pixbuf)
+
+
+(defbinding pixbuf-get-option () (copy-of string)
+ (pixbuf pixbuf)
+ (key string))
+
+(defun pixbuf-load (filename &key width height size (preserve-aspect-ratio t))
+ (make-instance 'pixbuf :source filename
+ :width (or size width) :height (or size height)
+ :preserve-aspect-ratio preserve-aspect-ratio))