/* image.c generated by valac 0.56.18, the Vala compiler
 * generated from image.vala, do not modify */

/*///////////////////////////////////////////////////////////////////////*/
/* Copyright 2011-2021 Simon Schneegans*/
/**/
/* Permission is hereby granted, free of charge, to any person obtaining*/
/* a copy of this software and associated documentation files (the*/
/* "Software"), to deal in the Software without restriction, including*/
/* without limitation the rights to use, copy, modify, merge, publish,*/
/* distribute, sublicense, and/or sell copies of the Software, and to*/
/* permit persons to whom the Software is furnished to do so, subject to*/
/* the following conditions:*/
/* */
/* The above copyright notice and this permission notice shall be*/
/* included in all copies or substantial portions of the Software.*/
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,*/
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF*/
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY*/
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,*/
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE*/
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
/*///////////////////////////////////////////////////////////////////////*/

#include <glib-object.h>
#include <cairo-gobject.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
#include <gee.h>
#include <gtk/gtk.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define GNOME_PIE_TYPE_IMAGE (gnome_pie_image_get_type ())
#define GNOME_PIE_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_IMAGE, GnomePieImage))
#define GNOME_PIE_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_IMAGE, GnomePieImageClass))
#define GNOME_PIE_IS_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_IMAGE))
#define GNOME_PIE_IS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_IMAGE))
#define GNOME_PIE_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_IMAGE, GnomePieImageClass))

typedef struct _GnomePieImage GnomePieImage;
typedef struct _GnomePieImageClass GnomePieImageClass;
typedef struct _GnomePieImagePrivate GnomePieImagePrivate;
enum  {
	GNOME_PIE_IMAGE_0_PROPERTY,
	GNOME_PIE_IMAGE_SURFACE_PROPERTY,
	GNOME_PIE_IMAGE_NUM_PROPERTIES
};
static GParamSpec* gnome_pie_image_properties[GNOME_PIE_IMAGE_NUM_PROPERTIES];
#define _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))

#define GNOME_PIE_TYPE_COLOR (gnome_pie_color_get_type ())
#define GNOME_PIE_COLOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_COLOR, GnomePieColor))
#define GNOME_PIE_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_COLOR, GnomePieColorClass))
#define GNOME_PIE_IS_COLOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_COLOR))
#define GNOME_PIE_IS_COLOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_COLOR))
#define GNOME_PIE_COLOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_COLOR, GnomePieColorClass))

typedef struct _GnomePieColor GnomePieColor;
typedef struct _GnomePieColorClass GnomePieColorClass;
#define _cairo_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_destroy (var), NULL)))

#define GNOME_PIE_TYPE_PIE_WINDOW (gnome_pie_pie_window_get_type ())
#define GNOME_PIE_PIE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_PIE_TYPE_PIE_WINDOW, GnomePiePieWindow))
#define GNOME_PIE_PIE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_PIE_TYPE_PIE_WINDOW, GnomePiePieWindowClass))
#define GNOME_PIE_IS_PIE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_PIE_TYPE_PIE_WINDOW))
#define GNOME_PIE_IS_PIE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_PIE_TYPE_PIE_WINDOW))
#define GNOME_PIE_PIE_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_PIE_TYPE_PIE_WINDOW, GnomePiePieWindowClass))

typedef struct _GnomePiePieWindow GnomePiePieWindow;
typedef struct _GnomePiePieWindowClass GnomePiePieWindowClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GnomePieImage {
	GObject parent_instance;
	GnomePieImagePrivate * priv;
};

struct _GnomePieImageClass {
	GObjectClass parent_class;
};

struct _GnomePieImagePrivate {
	cairo_surface_t* _surface;
};

static gint GnomePieImage_private_offset;
static gpointer gnome_pie_image_parent_class = NULL;

VALA_EXTERN GType gnome_pie_image_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieImage, g_object_unref)
VALA_EXTERN GType gnome_pie_color_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePieColor, g_object_unref)
VALA_EXTERN GnomePieImage* gnome_pie_image_new_empty (gint width,
                                          gint height,
                                          GnomePieColor* color);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct_empty (GType object_type,
                                                gint width,
                                                gint height,
                                                GnomePieColor* color);
VALA_EXTERN void gnome_pie_image_set_surface (GnomePieImage* self,
                                  cairo_surface_t* value);
VALA_EXTERN cairo_t* gnome_pie_image_context (GnomePieImage* self);
VALA_EXTERN gfloat gnome_pie_color_get_r (GnomePieColor* self);
VALA_EXTERN gfloat gnome_pie_color_get_g (GnomePieColor* self);
VALA_EXTERN gfloat gnome_pie_color_get_b (GnomePieColor* self);
VALA_EXTERN GnomePieImage* gnome_pie_image_new_from_file (const gchar* filename);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct_from_file (GType object_type,
                                                    const gchar* filename);
VALA_EXTERN void gnome_pie_image_load_file (GnomePieImage* self,
                                const gchar* filename);
VALA_EXTERN GnomePieImage* gnome_pie_image_new_from_file_at_size (const gchar* filename,
                                                      gint width,
                                                      gint height);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct_from_file_at_size (GType object_type,
                                                            const gchar* filename,
                                                            gint width,
                                                            gint height);
VALA_EXTERN void gnome_pie_image_load_file_at_size (GnomePieImage* self,
                                        const gchar* filename,
                                        gint width,
                                        gint height);
VALA_EXTERN GnomePieImage* gnome_pie_image_new_from_pixbuf (GdkPixbuf* pixbuf);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct_from_pixbuf (GType object_type,
                                                      GdkPixbuf* pixbuf);
VALA_EXTERN void gnome_pie_image_load_pixbuf (GnomePieImage* self,
                                  GdkPixbuf* pixbuf);
VALA_EXTERN GnomePieImage* gnome_pie_image_new_capture_screen (gint posx,
                                                   gint posy,
                                                   gint width,
                                                   gint height,
                                                   gboolean hide_pies);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct_capture_screen (GType object_type,
                                                         gint posx,
                                                         gint posy,
                                                         gint width,
                                                         gint height,
                                                         gboolean hide_pies);
VALA_EXTERN GType gnome_pie_pie_window_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GnomePiePieWindow, g_object_unref)
VALA_EXTERN GeeHashSet* gnome_pie_pie_manager_get_opened_windows (void);
VALA_EXTERN GnomePieImage* gnome_pie_pie_window_get_background (GnomePiePieWindow* self);
VALA_EXTERN void gnome_pie_image_paint_on (GnomePieImage* self,
                               cairo_t* ctx,
                               gdouble alpha);
VALA_EXTERN cairo_surface_t* gnome_pie_image_get_surface (GnomePieImage* self);
VALA_EXTERN gint gnome_pie_image_width (GnomePieImage* self);
VALA_EXTERN gint gnome_pie_image_height (GnomePieImage* self);
VALA_EXTERN GdkPixbuf* gnome_pie_image_to_pixbuf (GnomePieImage* self);
VALA_EXTERN GnomePieImage* gnome_pie_image_new (void);
VALA_EXTERN GnomePieImage* gnome_pie_image_construct (GType object_type);
static void gnome_pie_image_finalize (GObject * obj);
static GType gnome_pie_image_get_type_once (void);
static void _vala_gnome_pie_image_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec);
static void _vala_gnome_pie_image_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec);

static inline gpointer
gnome_pie_image_get_instance_private (GnomePieImage* self)
{
	return G_STRUCT_MEMBER_P (self, GnomePieImage_private_offset);
}

GnomePieImage*
gnome_pie_image_construct_empty (GType object_type,
                                 gint width,
                                 gint height,
                                 GnomePieColor* color)
{
	GnomePieImage * self = NULL;
	cairo_surface_t* _tmp0_;
	cairo_surface_t* _tmp1_;
	self = (GnomePieImage*) g_object_new (object_type, NULL);
	_tmp0_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	_tmp1_ = _tmp0_;
	gnome_pie_image_set_surface (self, _tmp1_);
	_cairo_surface_destroy0 (_tmp1_);
	if (color != NULL) {
		cairo_t* ctx = NULL;
		cairo_t* _tmp2_;
		cairo_t* _tmp3_;
		gfloat _tmp4_;
		gfloat _tmp5_;
		gfloat _tmp6_;
		gfloat _tmp7_;
		gfloat _tmp8_;
		gfloat _tmp9_;
		cairo_t* _tmp10_;
		_tmp2_ = gnome_pie_image_context (self);
		ctx = _tmp2_;
		_tmp3_ = ctx;
		_tmp4_ = gnome_pie_color_get_r (color);
		_tmp5_ = _tmp4_;
		_tmp6_ = gnome_pie_color_get_g (color);
		_tmp7_ = _tmp6_;
		_tmp8_ = gnome_pie_color_get_b (color);
		_tmp9_ = _tmp8_;
		cairo_set_source_rgb (_tmp3_, (gdouble) _tmp5_, (gdouble) _tmp7_, (gdouble) _tmp9_);
		_tmp10_ = ctx;
		cairo_paint (_tmp10_);
		_cairo_destroy0 (ctx);
	}
	return self;
}

GnomePieImage*
gnome_pie_image_new_empty (gint width,
                           gint height,
                           GnomePieColor* color)
{
	return gnome_pie_image_construct_empty (GNOME_PIE_TYPE_IMAGE, width, height, color);
}

GnomePieImage*
gnome_pie_image_construct_from_file (GType object_type,
                                     const gchar* filename)
{
	GnomePieImage * self = NULL;
	g_return_val_if_fail (filename != NULL, NULL);
	self = (GnomePieImage*) g_object_new (object_type, NULL);
	gnome_pie_image_load_file (self, filename);
	return self;
}

GnomePieImage*
gnome_pie_image_new_from_file (const gchar* filename)
{
	return gnome_pie_image_construct_from_file (GNOME_PIE_TYPE_IMAGE, filename);
}

GnomePieImage*
gnome_pie_image_construct_from_file_at_size (GType object_type,
                                             const gchar* filename,
                                             gint width,
                                             gint height)
{
	GnomePieImage * self = NULL;
	g_return_val_if_fail (filename != NULL, NULL);
	self = (GnomePieImage*) g_object_new (object_type, NULL);
	gnome_pie_image_load_file_at_size (self, filename, width, height);
	return self;
}

GnomePieImage*
gnome_pie_image_new_from_file_at_size (const gchar* filename,
                                       gint width,
                                       gint height)
{
	return gnome_pie_image_construct_from_file_at_size (GNOME_PIE_TYPE_IMAGE, filename, width, height);
}

GnomePieImage*
gnome_pie_image_construct_from_pixbuf (GType object_type,
                                       GdkPixbuf* pixbuf)
{
	GnomePieImage * self = NULL;
	g_return_val_if_fail (pixbuf != NULL, NULL);
	self = (GnomePieImage*) g_object_new (object_type, NULL);
	if (pixbuf != NULL) {
		gnome_pie_image_load_pixbuf (self, pixbuf);
	} else {
		cairo_surface_t* _tmp0_;
		cairo_surface_t* _tmp1_;
		_tmp0_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
		_tmp1_ = _tmp0_;
		gnome_pie_image_set_surface (self, _tmp1_);
		_cairo_surface_destroy0 (_tmp1_);
	}
	return self;
}

GnomePieImage*
gnome_pie_image_new_from_pixbuf (GdkPixbuf* pixbuf)
{
	return gnome_pie_image_construct_from_pixbuf (GNOME_PIE_TYPE_IMAGE, pixbuf);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

GnomePieImage*
gnome_pie_image_construct_capture_screen (GType object_type,
                                          gint posx,
                                          gint posy,
                                          gint width,
                                          gint height,
                                          gboolean hide_pies)
{
	GnomePieImage * self = NULL;
	GdkWindow* root = NULL;
	GdkWindow* _tmp0_;
	GdkWindow* _tmp1_;
	GdkPixbuf* pixbuf = NULL;
	GdkWindow* _tmp2_;
	GdkPixbuf* _tmp3_;
	GdkPixbuf* _tmp4_;
	self = (GnomePieImage*) g_object_new (object_type, NULL);
	_tmp0_ = gdk_get_default_root_window ();
	_tmp1_ = _g_object_ref0 (_tmp0_);
	root = _tmp1_;
	_tmp2_ = root;
	_tmp3_ = gdk_pixbuf_get_from_window (_tmp2_, posx, posy, width, height);
	pixbuf = _tmp3_;
	_tmp4_ = pixbuf;
	gnome_pie_image_load_pixbuf (self, _tmp4_);
	if (hide_pies) {
		{
			GeeIterator* _window_it = NULL;
			GeeHashSet* _tmp5_;
			GeeHashSet* _tmp6_;
			GeeIterator* _tmp7_;
			_tmp5_ = gnome_pie_pie_manager_get_opened_windows ();
			_tmp6_ = _tmp5_;
			_tmp7_ = gee_abstract_collection_iterator ((GeeAbstractCollection*) _tmp6_);
			_window_it = _tmp7_;
			while (TRUE) {
				GeeIterator* _tmp8_;
				GnomePiePieWindow* window = NULL;
				GeeIterator* _tmp9_;
				gpointer _tmp10_;
				GnomePiePieWindow* _tmp11_;
				GnomePieImage* _tmp12_;
				GnomePieImage* _tmp13_;
				_tmp8_ = _window_it;
				if (!gee_iterator_next (_tmp8_)) {
					break;
				}
				_tmp9_ = _window_it;
				_tmp10_ = gee_iterator_get (_tmp9_);
				window = (GnomePiePieWindow*) _tmp10_;
				_tmp11_ = window;
				_tmp12_ = gnome_pie_pie_window_get_background (_tmp11_);
				_tmp13_ = _tmp12_;
				if (_tmp13_ != NULL) {
					gint x = 0;
					gint y = 0;
					gint dx = 0;
					gint dy = 0;
					GnomePiePieWindow* _tmp14_;
					gint _tmp15_ = 0;
					gint _tmp16_ = 0;
					GnomePiePieWindow* _tmp17_;
					gint _tmp18_ = 0;
					gint _tmp19_ = 0;
					cairo_t* ctx = NULL;
					cairo_t* _tmp20_;
					cairo_t* _tmp21_;
					GnomePiePieWindow* _tmp22_;
					GnomePieImage* _tmp23_;
					GnomePieImage* _tmp24_;
					cairo_t* _tmp25_;
					x = 0;
					y = 0;
					dx = 0;
					dy = 0;
					_tmp14_ = window;
					gtk_window_get_position ((GtkWindow*) _tmp14_, &_tmp15_, &_tmp16_);
					x = _tmp15_;
					y = _tmp16_;
					_tmp17_ = window;
					gtk_window_get_size ((GtkWindow*) _tmp17_, &_tmp18_, &_tmp19_);
					dx = _tmp18_;
					dy = _tmp19_;
					_tmp20_ = gnome_pie_image_context (self);
					ctx = _tmp20_;
					_tmp21_ = ctx;
					cairo_translate (_tmp21_, (gdouble) ((gint) ((x - posx) + ((dx + 3) / 2))), (gdouble) ((gint) ((y - posy) + ((dy + 3) / 2))));
					_tmp22_ = window;
					_tmp23_ = gnome_pie_pie_window_get_background (_tmp22_);
					_tmp24_ = _tmp23_;
					_tmp25_ = ctx;
					gnome_pie_image_paint_on (_tmp24_, _tmp25_, 1.0);
					_cairo_destroy0 (ctx);
				}
				_g_object_unref0 (window);
			}
			_g_object_unref0 (_window_it);
		}
	}
	_g_object_unref0 (pixbuf);
	_g_object_unref0 (root);
	return self;
}

GnomePieImage*
gnome_pie_image_new_capture_screen (gint posx,
                                    gint posy,
                                    gint width,
                                    gint height,
                                    gboolean hide_pies)
{
	return gnome_pie_image_construct_capture_screen (GNOME_PIE_TYPE_IMAGE, posx, posy, width, height, hide_pies);
}

void
gnome_pie_image_load_file (GnomePieImage* self,
                           const gchar* filename)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (filename != NULL);
	{
		GdkPixbuf* pixbuf = NULL;
		GdkPixbuf* _tmp0_;
		_tmp0_ = gdk_pixbuf_new_from_file (filename, &_inner_error0_);
		pixbuf = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (pixbuf != NULL) {
			gnome_pie_image_load_pixbuf (self, pixbuf);
		} else {
			gchar* _tmp1_;
			gchar* _tmp2_;
			gchar* _tmp3_;
			gchar* _tmp4_;
			cairo_surface_t* _tmp5_;
			cairo_surface_t* _tmp6_;
			_tmp1_ = g_strconcat ("Failed to load ", filename, NULL);
			_tmp2_ = _tmp1_;
			_tmp3_ = g_strconcat (_tmp2_, "!", NULL);
			_tmp4_ = _tmp3_;
			g_warning ("image.vala:115: %s", _tmp4_);
			_g_free0 (_tmp4_);
			_g_free0 (_tmp2_);
			_tmp5_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
			_tmp6_ = _tmp5_;
			gnome_pie_image_set_surface (self, _tmp6_);
			_cairo_surface_destroy0 (_tmp6_);
		}
		_g_object_unref0 (pixbuf);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp7_;
		const gchar* _tmp8_;
		cairo_surface_t* _tmp9_;
		cairo_surface_t* _tmp10_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		g_message ("image.vala:119: Error loading image file: %s", _tmp8_);
		_tmp9_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
		_tmp10_ = _tmp9_;
		gnome_pie_image_set_surface (self, _tmp10_);
		_cairo_surface_destroy0 (_tmp10_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

void
gnome_pie_image_load_file_at_size (GnomePieImage* self,
                                   const gchar* filename,
                                   gint width,
                                   gint height)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (filename != NULL);
	{
		GdkPixbuf* pixbuf = NULL;
		GdkPixbuf* _tmp0_;
		_tmp0_ = gdk_pixbuf_new_from_file_at_size (filename, width, height, &_inner_error0_);
		pixbuf = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (pixbuf != NULL) {
			gnome_pie_image_load_pixbuf (self, pixbuf);
		} else {
			gchar* _tmp1_;
			gchar* _tmp2_;
			gchar* _tmp3_;
			gchar* _tmp4_;
			cairo_surface_t* _tmp5_;
			cairo_surface_t* _tmp6_;
			_tmp1_ = g_strconcat ("Failed to load ", filename, NULL);
			_tmp2_ = _tmp1_;
			_tmp3_ = g_strconcat (_tmp2_, "!", NULL);
			_tmp4_ = _tmp3_;
			g_warning ("image.vala:135: %s", _tmp4_);
			_g_free0 (_tmp4_);
			_g_free0 (_tmp2_);
			_tmp5_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
			_tmp6_ = _tmp5_;
			gnome_pie_image_set_surface (self, _tmp6_);
			_cairo_surface_destroy0 (_tmp6_);
		}
		_g_object_unref0 (pixbuf);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp7_;
		const gchar* _tmp8_;
		cairo_surface_t* _tmp9_;
		cairo_surface_t* _tmp10_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		g_message ("image.vala:140: Error loading image file: %s", _tmp8_);
		_tmp9_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
		_tmp10_ = _tmp9_;
		gnome_pie_image_set_surface (self, _tmp10_);
		_cairo_surface_destroy0 (_tmp10_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

void
gnome_pie_image_load_pixbuf (GnomePieImage* self,
                             GdkPixbuf* pixbuf)
{
	gint _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	cairo_surface_t* _tmp4_;
	cairo_surface_t* _tmp5_;
	cairo_t* ctx = NULL;
	cairo_t* _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (pixbuf != NULL);
	_tmp0_ = gdk_pixbuf_get_width (pixbuf);
	_tmp1_ = _tmp0_;
	_tmp2_ = gdk_pixbuf_get_height (pixbuf);
	_tmp3_ = _tmp2_;
	_tmp4_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, _tmp1_, _tmp3_);
	_tmp5_ = _tmp4_;
	gnome_pie_image_set_surface (self, _tmp5_);
	_cairo_surface_destroy0 (_tmp5_);
	_tmp6_ = gnome_pie_image_context (self);
	ctx = _tmp6_;
	gdk_cairo_set_source_pixbuf (ctx, pixbuf, 1.0, 1.0);
	cairo_paint (ctx);
	_cairo_destroy0 (ctx);
}

void
gnome_pie_image_paint_on (GnomePieImage* self,
                          cairo_t* ctx,
                          gdouble alpha)
{
	cairo_surface_t* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (ctx != NULL);
	_tmp0_ = self->priv->_surface;
	cairo_set_source_surface (ctx, _tmp0_, (gdouble) ((gint) (((-0.5) * gnome_pie_image_width (self)) - 1)), (gdouble) ((gint) (((-0.5) * gnome_pie_image_height (self)) - 1)));
	if (alpha >= 1.0) {
		cairo_paint (ctx);
	} else {
		cairo_paint_with_alpha (ctx, alpha);
	}
}

GdkPixbuf*
gnome_pie_image_to_pixbuf (GnomePieImage* self)
{
	gboolean _tmp0_ = FALSE;
	cairo_surface_t* _tmp1_;
	GdkPixbuf* pixbuf = NULL;
	cairo_surface_t* _tmp5_;
	guchar* _tmp6_;
	cairo_surface_t* _tmp7_;
	GdkPixbuf* _tmp8_;
	GdkPixbuf* _tmp9_;
	GdkPixbuf* _tmp10_;
	guint8* p = NULL;
	GdkPixbuf* _tmp11_;
	void* _tmp12_;
	void* _tmp13_;
	GdkPixbuf* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->_surface;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		cairo_surface_t* _tmp2_;
		guchar* _tmp3_;
		_tmp2_ = self->priv->_surface;
		_tmp3_ = cairo_image_surface_get_data (_tmp2_);
		_tmp0_ = _tmp3_ == NULL;
	}
	if (_tmp0_) {
		GdkPixbuf* _tmp4_;
		_tmp4_ = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1);
		result = _tmp4_;
		return result;
	}
	_tmp5_ = self->priv->_surface;
	_tmp6_ = cairo_image_surface_get_data (_tmp5_);
	_tmp7_ = self->priv->_surface;
	_tmp8_ = gdk_pixbuf_new_from_data (_tmp6_, GDK_COLORSPACE_RGB, TRUE, 8, gnome_pie_image_width (self), gnome_pie_image_height (self), cairo_image_surface_get_stride (_tmp7_), (GdkPixbufDestroyNotify) NULL, NULL);
	pixbuf = _tmp8_;
	_tmp9_ = pixbuf;
	_tmp10_ = gdk_pixbuf_copy (_tmp9_);
	_g_object_unref0 (pixbuf);
	pixbuf = _tmp10_;
	_tmp11_ = pixbuf;
	_tmp12_ = gdk_pixbuf_get_pixels (_tmp11_);
	_tmp13_ = _tmp12_;
	p = _tmp13_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp14_ = FALSE;
			_tmp14_ = TRUE;
			while (TRUE) {
				guint8 tmp = 0U;
				guint8* _tmp15_;
				guint8* _tmp16_;
				guint8* _tmp17_;
				guint8* _tmp18_;
				if (!_tmp14_) {
					i += 4;
				}
				_tmp14_ = FALSE;
				if (!(i < (((gnome_pie_image_width (self) * gnome_pie_image_height (self)) * 4) - 4))) {
					break;
				}
				_tmp15_ = p;
				tmp = *(_tmp15_ + i);
				_tmp16_ = p;
				_tmp17_ = p;
				*(_tmp16_ + i) = *((_tmp17_ + i) + 2);
				_tmp18_ = p;
				*((_tmp18_ + i) + 2) = tmp;
			}
		}
	}
	result = pixbuf;
	return result;
}

cairo_t*
gnome_pie_image_context (GnomePieImage* self)
{
	cairo_surface_t* _tmp0_;
	cairo_t* _tmp1_;
	cairo_t* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_surface;
	_tmp1_ = cairo_create (_tmp0_);
	result = _tmp1_;
	return result;
}

gint
gnome_pie_image_width (GnomePieImage* self)
{
	cairo_surface_t* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_surface;
	if (_tmp0_ != NULL) {
		cairo_surface_t* _tmp1_;
		_tmp1_ = self->priv->_surface;
		result = cairo_image_surface_get_width (_tmp1_);
		return result;
	}
	result = 0;
	return result;
}

gint
gnome_pie_image_height (GnomePieImage* self)
{
	cairo_surface_t* _tmp0_;
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->priv->_surface;
	if (_tmp0_ != NULL) {
		cairo_surface_t* _tmp1_;
		_tmp1_ = self->priv->_surface;
		result = cairo_image_surface_get_height (_tmp1_);
		return result;
	}
	result = 0;
	return result;
}

GnomePieImage*
gnome_pie_image_construct (GType object_type)
{
	GnomePieImage * self = NULL;
	self = (GnomePieImage*) g_object_new (object_type, NULL);
	return self;
}

GnomePieImage*
gnome_pie_image_new (void)
{
	return gnome_pie_image_construct (GNOME_PIE_TYPE_IMAGE);
}

cairo_surface_t*
gnome_pie_image_get_surface (GnomePieImage* self)
{
	cairo_surface_t* result;
	cairo_surface_t* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_surface;
	result = _tmp0_;
	return result;
}

static gpointer
_cairo_surface_reference0 (gpointer self)
{
	return self ? cairo_surface_reference (self) : NULL;
}

void
gnome_pie_image_set_surface (GnomePieImage* self,
                             cairo_surface_t* value)
{
	cairo_surface_t* old_value;
	g_return_if_fail (self != NULL);
	old_value = gnome_pie_image_get_surface (self);
	if (old_value != value) {
		cairo_surface_t* _tmp0_;
		_tmp0_ = _cairo_surface_reference0 (value);
		_cairo_surface_destroy0 (self->priv->_surface);
		self->priv->_surface = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gnome_pie_image_properties[GNOME_PIE_IMAGE_SURFACE_PROPERTY]);
	}
}

static void
gnome_pie_image_class_init (GnomePieImageClass * klass,
                            gpointer klass_data)
{
	gnome_pie_image_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GnomePieImage_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gnome_pie_image_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gnome_pie_image_set_property;
	G_OBJECT_CLASS (klass)->finalize = gnome_pie_image_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GNOME_PIE_IMAGE_SURFACE_PROPERTY, gnome_pie_image_properties[GNOME_PIE_IMAGE_SURFACE_PROPERTY] = g_param_spec_boxed ("surface", "surface", "surface", cairo_gobject_surface_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gnome_pie_image_instance_init (GnomePieImage * self,
                               gpointer klass)
{
	self->priv = gnome_pie_image_get_instance_private (self);
	self->priv->_surface = NULL;
}

static void
gnome_pie_image_finalize (GObject * obj)
{
	GnomePieImage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GNOME_PIE_TYPE_IMAGE, GnomePieImage);
	_cairo_surface_destroy0 (self->priv->_surface);
	G_OBJECT_CLASS (gnome_pie_image_parent_class)->finalize (obj);
}

static GType
gnome_pie_image_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GnomePieImageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gnome_pie_image_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GnomePieImage), 0, (GInstanceInitFunc) gnome_pie_image_instance_init, NULL };
	GType gnome_pie_image_type_id;
	gnome_pie_image_type_id = g_type_register_static (G_TYPE_OBJECT, "GnomePieImage", &g_define_type_info, 0);
	GnomePieImage_private_offset = g_type_add_instance_private (gnome_pie_image_type_id, sizeof (GnomePieImagePrivate));
	return gnome_pie_image_type_id;
}

GType
gnome_pie_image_get_type (void)
{
	static volatile gsize gnome_pie_image_type_id__once = 0;
	if (g_once_init_enter (&gnome_pie_image_type_id__once)) {
		GType gnome_pie_image_type_id;
		gnome_pie_image_type_id = gnome_pie_image_get_type_once ();
		g_once_init_leave (&gnome_pie_image_type_id__once, gnome_pie_image_type_id);
	}
	return gnome_pie_image_type_id__once;
}

static void
_vala_gnome_pie_image_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec)
{
	GnomePieImage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_PIE_TYPE_IMAGE, GnomePieImage);
	switch (property_id) {
		case GNOME_PIE_IMAGE_SURFACE_PROPERTY:
		g_value_set_boxed (value, gnome_pie_image_get_surface (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gnome_pie_image_set_property (GObject * object,
                                    guint property_id,
                                    const GValue * value,
                                    GParamSpec * pspec)
{
	GnomePieImage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GNOME_PIE_TYPE_IMAGE, GnomePieImage);
	switch (property_id) {
		case GNOME_PIE_IMAGE_SURFACE_PROPERTY:
		gnome_pie_image_set_surface (self, g_value_get_boxed (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

