2003-08-28 10:40:14 +00:00
// Pixbuf.custom - Gdk Pixbuf class customizations
2003-02-19 06:00:27 +00:00
//
2003-08-28 10:40:14 +00:00
// Authors:
// Vladimir Vukicevic <vladimir@pobox.com>
// Miguel de Icaza <miguel@ximian.com>
2004-02-12 17:31:37 +00:00
// Mike Kestner <mkestner@ximian.com>
2003-08-28 10:40:14 +00:00
// Duncan Mak <duncan@ximian.com>
// Gonzalo Paniagua Javier <gonzalo@ximian.com>
// Martin Willemoes Hansen <mwh@sysrq.dk>
2003-02-19 06:00:27 +00:00
//
2003-08-28 10:40:14 +00:00
// (C) 2002 Vladimir Vukicevic
// (C) 2003 Ximian, Inc. (Miguel de Icaza)
// (C) 2003 Ximian, Inc. (Duncan Mak)
// (C) 2003 Ximian, Inc. (Gonzalo Paniagua Javier)
// (C) 2003 Martin Willemoes Hansen
2004-02-12 17:31:37 +00:00
// (C) 2004 Novell, Inc.
2003-02-19 06:00:27 +00:00
//
2003-08-28 10:40:14 +00:00
// This code is inserted after the automatically generated code.
2003-02-19 06:00:27 +00:00
2003-11-18 19:10:36 +00:00
[DllImport("libgobject-2.0-0.dll")]
static extern void g_object_ref (IntPtr handle);
private void LoadFromStream (System.IO.Stream input)
2002-11-10 10:09:05 +00:00
{
PixbufLoader loader = new PixbufLoader ();
byte [] buffer = new byte [8192];
int n;
2003-11-17 07:38:40 +00:00
2002-11-10 10:09:05 +00:00
while ((n = input.Read (buffer, 0, 8192)) != 0)
loader.Write (buffer, (uint) n);
2003-11-17 07:38:40 +00:00
loader.Close ();
2003-11-18 19:10:36 +00:00
Raw = loader.PixbufHandle;
if (Raw == IntPtr.Zero)
throw new ArgumentException ("Unable to load pixbuf from stream");
g_object_ref (Raw);
2002-11-10 10:09:05 +00:00
}
2003-11-18 19:10:36 +00:00
public Pixbuf (System.IO.Stream stream)
{
LoadFromStream (stream);
}
public Pixbuf (System.Reflection.Assembly assembly, string resource)
2002-11-10 10:09:05 +00:00
{
2003-11-17 18:54:07 +00:00
if (assembly == null)
2003-11-18 19:10:36 +00:00
assembly = System.Reflection.Assembly.GetCallingAssembly ();
2003-11-17 19:01:12 +00:00
if (resource == null)
throw new ArgumentNullException ("resource");
2003-11-17 18:54:07 +00:00
2003-11-17 07:38:40 +00:00
System.IO.Stream s = assembly.GetManifestResourceStream (resource);
if (s == null)
2003-11-18 19:10:36 +00:00
throw new ArgumentException ("resource must be a valid resource name of 'assembly'.");
LoadFromStream (s);
2002-11-10 10:09:05 +00:00
}
2003-11-17 07:38:40 +00:00
2003-11-18 19:10:36 +00:00
static public Pixbuf LoadFromResource (string resource)
2002-11-10 10:09:05 +00:00
{
2003-11-17 19:01:12 +00:00
if (resource == null)
throw new ArgumentNullException ("resource");
2003-11-18 19:10:36 +00:00
return new Pixbuf (System.Reflection.Assembly.GetCallingAssembly (), resource);
2002-11-10 10:09:05 +00:00
}
2002-09-17 05:29:54 +00:00
2002-11-10 10:09:05 +00:00
2003-08-30 00:26:38 +00:00
[DllImport("libgdk_pixbuf-2.0-0.dll")]
2002-11-10 10:09:05 +00:00
static extern IntPtr gdk_pixbuf_scale_simple(IntPtr raw, int dest_width, int dest_height, int interp_type);
2002-09-17 05:29:54 +00:00
2002-11-10 10:09:05 +00:00
public Gdk.Pixbuf ScaleSimple(int dest_width, int dest_height, Gdk.InterpType interp_type) {
IntPtr raw_ret = gdk_pixbuf_scale_simple(Handle, dest_width, dest_height, (int) interp_type);
2003-07-23 17:19:21 +00:00
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret, true);
2002-11-10 10:09:05 +00:00
return ret;
}
2002-09-17 05:29:54 +00:00
2003-08-30 00:26:38 +00:00
[DllImport("libgdk_pixbuf-2.0-0.dll")]
2002-11-10 10:09:05 +00:00
static extern IntPtr gdk_pixbuf_composite_color_simple(IntPtr raw, int dest_width, int dest_height, int interp_type, int overall_alpha, int check_size, uint color1, uint color2);
2002-09-17 05:29:54 +00:00
2002-11-10 10:09:05 +00:00
public Gdk.Pixbuf CompositeColorSimple(int dest_width, int dest_height, Gdk.InterpType interp_type, int overall_alpha, int check_size, uint color1, uint color2) {
IntPtr raw_ret = gdk_pixbuf_composite_color_simple(Handle, dest_width, dest_height, (int) interp_type, overall_alpha, check_size, color1, color2);
2003-07-23 17:19:21 +00:00
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret, true);
2002-11-10 10:09:05 +00:00
return ret;
}
2002-09-17 05:29:54 +00:00
2003-08-30 00:26:38 +00:00
[DllImport("libgdk_pixbuf-2.0-0.dll")]
2002-11-10 10:09:05 +00:00
static extern IntPtr gdk_pixbuf_add_alpha(IntPtr raw, bool substitute_color, byte r, byte g, byte b);
public Gdk.Pixbuf AddAlpha(bool substitute_color, byte r, byte g, byte b) {
IntPtr raw_ret = gdk_pixbuf_add_alpha(Handle, substitute_color, r, g, b);
2003-07-23 17:19:21 +00:00
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret, true);
2002-11-10 10:09:05 +00:00
return ret;
}
2003-02-19 06:00:27 +00:00
2003-11-29 21:55:28 +00:00
// overload to default the colorspace
2003-02-19 06:00:27 +00:00
public Pixbuf(byte [] data, bool has_alpha, int bits_per_sample, int width, int height, int rowstride, Gdk.PixbufDestroyNotify destroy_fn)
{
GdkSharp.PixbufDestroyNotifyWrapper destroy_fn_wrapper = null;
2003-04-06 09:21:15 +00:00
destroy_fn_wrapper = new GdkSharp.PixbufDestroyNotifyWrapper (destroy_fn, this);
2003-02-19 06:00:27 +00:00
Raw = gdk_pixbuf_new_from_data(data, (int) Gdk.Colorspace.Rgb, has_alpha, bits_per_sample, width, height, rowstride, destroy_fn_wrapper.NativeDelegate, IntPtr.Zero);
}
public unsafe Pixbuf(byte[] data, bool copy_pixels)
{
IntPtr error = IntPtr.Zero;
Raw = gdk_pixbuf_new_from_inline(data.Length, data, copy_pixels, out error);
if (error != IntPtr.Zero) throw new GLib.GException (error);
}
2003-11-30 03:07:41 +00:00
[DllImport("libgdk_pixbuf-2.0-0.dll")]
2003-02-19 06:00:27 +00:00
static extern unsafe IntPtr gdk_pixbuf_new_from_inline(int len, IntPtr data, bool copy_pixels, out IntPtr error);
2003-11-30 01:00:56 +00:00
2003-02-19 06:00:27 +00:00
public unsafe Pixbuf(int data_length, void *data, bool copy_pixels)
{
IntPtr error = IntPtr.Zero;
Raw = gdk_pixbuf_new_from_inline(data_length, (IntPtr) data, copy_pixels, out error);
if (error != IntPtr.Zero) throw new GLib.GException (error);
}
//
// ICloneable interface
//
public object Clone ()
{
return Copy ();
}
//
// These are factory versions of a couple of existing methods, but simplify
// the process by reducing the number of steps required. Here a single
// operation will create the Pixbuf instead of two
//
public Gdk.Pixbuf CreateFromDrawable (Gdk.Drawable src, Gdk.Colormap cmap, int src_x, int src_y, int dest_x, int dest_y, int width, int height) {
IntPtr raw_ret = gdk_pixbuf_get_from_drawable((IntPtr) 0, src.Handle, cmap.Handle, src_x, src_y, dest_x, dest_y, width, height);
return new Pixbuf (raw_ret);
}
//
// Add an overload that takes System.Drawing.Color arguments instead of uint32 values for colors
//
public void CompositeColor(Gdk.Pixbuf dest, int dest_x, int dest_y, int dest_width, int dest_height,
double offset_x, double offset_y, double scale_x, double scale_y,
Gdk.InterpType interp_type, int overall_alpha, int check_x, int check_y,
int check_size, System.Drawing.Color color1, System.Drawing.Color color2)
{
gdk_pixbuf_composite_color(Handle, dest.Handle, dest_x, dest_y, dest_width, dest_height, offset_x,
offset_y, scale_x, scale_y, (int) interp_type, overall_alpha, check_x, check_y, check_size,
(uint) color1.ToArgb (), (uint) color2.ToArgb ());
}
public Gdk.Pixbuf CompositeColorSimple(int dest_width, int dest_height, Gdk.InterpType interp_type, int overall_alpha, int check_size, System.Drawing.Color color1, System.Drawing.Color color2) {
return CompositeColorSimple (dest_width, dest_height, interp_type, overall_alpha, check_size, (uint) color1.ToArgb (), (uint) color2.ToArgb ());
}
2003-03-14 03:04:15 +00:00
//
// the 'Pixels' property
//
[DllImport("libgdk_pixbuf-2.0-0.dll")]
static extern unsafe byte* gdk_pixbuf_get_pixels(IntPtr raw);
public unsafe byte* Pixels {
get {
byte *ret = gdk_pixbuf_get_pixels (Handle);
return ret;
}
}
2004-02-12 17:31:37 +00:00
[DllImport("libgdk_pixbuf-2.0-0.dll")]
static extern IntPtr gdk_pixbuf_get_formats();
public static PixbufFormat[] Formats {
get {
IntPtr list_ptr = gdk_pixbuf_get_formats ();
if (list_ptr == IntPtr.Zero)
return new PixbufFormat [0];
GLib.SList list = new GLib.SList (list_ptr, typeof (PixbufFormat));
PixbufFormat[] result = new PixbufFormat [list.Count];
for (int i = 0; i < list.Count; i++)
result [i] = (PixbufFormat) list [i];
return result;
}
}