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

/*
 * Copyright 2015 Corentin Noël
 * Copyright 2025 elementary, Inc. <https://elementary.io>
 * SPDX-License-Identifier: GPL-3.0-or-later
 */

#include "gala.h"
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <cogl/cogl.h>
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <clutter/clutter.h>
#include <stdlib.h>
#include <string.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

enum  {
	GALA_IMAGE_0_PROPERTY,
	GALA_IMAGE_WIDTH_PROPERTY,
	GALA_IMAGE_HEIGHT_PROPERTY,
	GALA_IMAGE_PIXBUF_PROPERTY,
	GALA_IMAGE_NUM_PROPERTIES
};
static GParamSpec* gala_image_properties[GALA_IMAGE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _clutter_paint_node_unref0(var) ((var == NULL) ? NULL : (var = (clutter_paint_node_unref (var), NULL)))

struct _GalaImagePrivate {
	gint _width;
	gint _height;
	GdkPixbuf* _pixbuf;
	CoglTexture* texture;
};

static gint GalaImage_private_offset;
static gpointer gala_image_parent_class = NULL;
static ClutterContentInterface * gala_image_clutter_content_parent_iface = NULL;

static gboolean gala_image_real_get_preferred_size (ClutterContent* base,
                                             gfloat* width,
                                             gfloat* height);
static void gala_image_real_paint_content (ClutterContent* base,
                                    ClutterActor* actor,
                                    ClutterPaintNode* node,
                                    ClutterPaintContext* paint_context);
static void gala_image_real_invalidate (ClutterContent* base);
static void gala_image_real_invalidate_size (ClutterContent* base);
static void gala_image_finalize (GObject * obj);
static GType gala_image_get_type_once (void);
static void _vala_gala_image_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec);
static void _vala_gala_image_set_property (GObject * object,
                                    guint property_id,
                                    const GValue * value,
                                    GParamSpec * pspec);

static inline gpointer
gala_image_get_instance_private (GalaImage* self)
{
	return G_STRUCT_MEMBER_P (self, GalaImage_private_offset);
}

GalaImage*
gala_image_construct_from_pixbuf_with_size (GType object_type,
                                            gint width,
                                            gint height,
                                            GdkPixbuf* pixbuf)
{
	GalaImage * self = NULL;
	g_return_val_if_fail (pixbuf != NULL, NULL);
	self = (GalaImage*) g_object_new (object_type, "width", width, "height", height, "pixbuf", pixbuf, NULL);
	return self;
}

GalaImage*
gala_image_new_from_pixbuf_with_size (gint width,
                                      gint height,
                                      GdkPixbuf* pixbuf)
{
	return gala_image_construct_from_pixbuf_with_size (GALA_TYPE_IMAGE, width, height, pixbuf);
}

GalaImage*
gala_image_construct_from_pixbuf (GType object_type,
                                  GdkPixbuf* pixbuf)
{
	GalaImage * self = NULL;
	gint _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	g_return_val_if_fail (pixbuf != NULL, NULL);
	_tmp0_ = gdk_pixbuf_get_width (pixbuf);
	_tmp1_ = _tmp0_;
	_tmp2_ = gdk_pixbuf_get_height (pixbuf);
	_tmp3_ = _tmp2_;
	self = (GalaImage*) g_object_new (object_type, "width", _tmp1_, "height", _tmp3_, "pixbuf", pixbuf, NULL);
	return self;
}

GalaImage*
gala_image_new_from_pixbuf (GdkPixbuf* pixbuf)
{
	return gala_image_construct_from_pixbuf (GALA_TYPE_IMAGE, pixbuf);
}

static gboolean
gala_image_real_get_preferred_size (ClutterContent* base,
                                    gfloat* width,
                                    gfloat* height)
{
	GalaImage * self;
	gfloat _vala_width = 0.0F;
	gfloat _vala_height = 0.0F;
	CoglTexture* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean result;
	self = (GalaImage*) base;
	_tmp0_ = self->priv->texture;
	if (_tmp0_ == NULL) {
		_vala_width = (gfloat) 0;
		_vala_height = (gfloat) 0;
		result = FALSE;
		if (width) {
			*width = _vala_width;
		}
		if (height) {
			*height = _vala_height;
		}
		return result;
	}
	_tmp1_ = self->priv->_width;
	_vala_width = (gfloat) _tmp1_;
	_tmp2_ = self->priv->_height;
	_vala_height = (gfloat) _tmp2_;
	result = TRUE;
	if (width) {
		*width = _vala_width;
	}
	if (height) {
		*height = _vala_height;
	}
	return result;
}

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

static void
gala_image_real_paint_content (ClutterContent* base,
                               ClutterActor* actor,
                               ClutterPaintNode* node,
                               ClutterPaintContext* paint_context)
{
	GalaImage * self;
	gboolean _tmp0_ = FALSE;
	GdkPixbuf* _tmp1_;
	CoglTexture* _tmp25_;
	ClutterPaintNode* content_node = NULL;
	CoglTexture* _tmp26_;
	ClutterPaintNode* _tmp27_;
	ClutterPaintNode* _tmp28_;
	GError* _inner_error0_ = NULL;
	self = (GalaImage*) base;
	g_return_if_fail (actor != NULL);
	g_return_if_fail (node != NULL);
	g_return_if_fail (paint_context != NULL);
	_tmp1_ = self->priv->_pixbuf;
	if (_tmp1_ != NULL) {
		CoglTexture* _tmp2_;
		_tmp2_ = self->priv->texture;
		_tmp0_ = _tmp2_ == NULL;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		CoglContext* cogl_context = NULL;
		ClutterBackend* _tmp3_;
		CoglContext* _tmp4_;
		CoglContext* _tmp5_;
		CoglPixelFormat _tmp6_ = 0;
		GdkPixbuf* _tmp7_;
		CoglPixelFormat pixel_format = 0;
		_tmp3_ = clutter_get_default_backend ();
		_tmp4_ = clutter_backend_get_cogl_context (_tmp3_);
		_tmp5_ = _g_object_ref0 (_tmp4_);
		cogl_context = _tmp5_;
		_tmp7_ = self->priv->_pixbuf;
		if (gdk_pixbuf_get_has_alpha (_tmp7_)) {
			_tmp6_ = COGL_PIXEL_FORMAT_RGBA_8888;
		} else {
			_tmp6_ = COGL_PIXEL_FORMAT_RGB_888;
		}
		pixel_format = _tmp6_;
		{
			CoglTexture2D* _tmp8_ = NULL;
			CoglContext* _tmp9_;
			GdkPixbuf* _tmp10_;
			gint _tmp11_;
			gint _tmp12_;
			GdkPixbuf* _tmp13_;
			gint _tmp14_;
			gint _tmp15_;
			GdkPixbuf* _tmp16_;
			gint _tmp17_;
			gint _tmp18_;
			GdkPixbuf* _tmp19_;
			guint8* _tmp20_;
			CoglTexture2D* _tmp21_;
			CoglTexture2D* _tmp22_;
			_tmp9_ = cogl_context;
			_tmp10_ = self->priv->_pixbuf;
			_tmp11_ = gdk_pixbuf_get_width (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = self->priv->_pixbuf;
			_tmp14_ = gdk_pixbuf_get_height (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp16_ = self->priv->_pixbuf;
			_tmp17_ = gdk_pixbuf_get_rowstride (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = self->priv->_pixbuf;
			_tmp20_ = gdk_pixbuf_get_pixels (_tmp19_);
			_tmp21_ = (CoglTexture2D*) cogl_texture_2d_new_from_data (_tmp9_, _tmp12_, _tmp15_, pixel_format, _tmp18_, _tmp20_, &_inner_error0_);
			_tmp8_ = _tmp21_;
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			_tmp22_ = _tmp8_;
			_tmp8_ = NULL;
			_g_object_unref0 (self->priv->texture);
			self->priv->texture = (CoglTexture*) _tmp22_;
			_g_object_unref0 (_tmp8_);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError* e = NULL;
			GError* _tmp23_;
			const gchar* _tmp24_;
			e = _inner_error0_;
			_inner_error0_ = NULL;
			_tmp23_ = e;
			_tmp24_ = _tmp23_->message;
			g_critical ("Image.vala:77: %s", _tmp24_);
			_g_error_free0 (e);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (cogl_context);
			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;
		}
		_g_object_unref0 (cogl_context);
	}
	_tmp25_ = self->priv->texture;
	if (_tmp25_ == NULL) {
		return;
	}
	_tmp26_ = self->priv->texture;
	_tmp27_ = clutter_actor_create_texture_paint_node (actor, _tmp26_);
	content_node = _tmp27_;
	_tmp28_ = content_node;
	clutter_paint_node_add_child (node, _tmp28_);
	_clutter_paint_node_unref0 (content_node);
}

static void
gala_image_real_invalidate (ClutterContent* base)
{
	GalaImage * self;
	self = (GalaImage*) base;
}

static void
gala_image_real_invalidate_size (ClutterContent* base)
{
	GalaImage * self;
	self = (GalaImage*) base;
}

GalaImage*
gala_image_construct (GType object_type)
{
	GalaImage * self = NULL;
	self = (GalaImage*) g_object_new (object_type, NULL);
	return self;
}

GalaImage*
gala_image_new (void)
{
	return gala_image_construct (GALA_TYPE_IMAGE);
}

gint
gala_image_get_width (GalaImage* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_width;
	return result;
}

static void
gala_image_set_width (GalaImage* self,
                      gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_image_get_width (self);
	if (old_value != value) {
		self->priv->_width = value;
		g_object_notify_by_pspec ((GObject *) self, gala_image_properties[GALA_IMAGE_WIDTH_PROPERTY]);
	}
}

gint
gala_image_get_height (GalaImage* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = self->priv->_height;
	return result;
}

static void
gala_image_set_height (GalaImage* self,
                       gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_image_get_height (self);
	if (old_value != value) {
		self->priv->_height = value;
		g_object_notify_by_pspec ((GObject *) self, gala_image_properties[GALA_IMAGE_HEIGHT_PROPERTY]);
	}
}

GdkPixbuf*
gala_image_get_pixbuf (GalaImage* self)
{
	GdkPixbuf* result;
	GdkPixbuf* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_pixbuf;
	result = _tmp0_;
	return result;
}

static void
gala_image_set_pixbuf (GalaImage* self,
                       GdkPixbuf* value)
{
	GdkPixbuf* old_value;
	g_return_if_fail (self != NULL);
	old_value = gala_image_get_pixbuf (self);
	if (old_value != value) {
		GdkPixbuf* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_pixbuf);
		self->priv->_pixbuf = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gala_image_properties[GALA_IMAGE_PIXBUF_PROPERTY]);
	}
}

static void
gala_image_class_init (GalaImageClass * klass,
                       gpointer klass_data)
{
	gala_image_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GalaImage_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gala_image_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gala_image_set_property;
	G_OBJECT_CLASS (klass)->finalize = gala_image_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_IMAGE_WIDTH_PROPERTY, gala_image_properties[GALA_IMAGE_WIDTH_PROPERTY] = g_param_spec_int ("width", "width", "width", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_IMAGE_HEIGHT_PROPERTY, gala_image_properties[GALA_IMAGE_HEIGHT_PROPERTY] = g_param_spec_int ("height", "height", "height", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GALA_IMAGE_PIXBUF_PROPERTY, gala_image_properties[GALA_IMAGE_PIXBUF_PROPERTY] = g_param_spec_object ("pixbuf", "pixbuf", "pixbuf", gdk_pixbuf_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
gala_image_clutter_content_interface_init (ClutterContentInterface * iface,
                                           gpointer iface_data)
{
	gala_image_clutter_content_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_preferred_size = (gboolean (*) (ClutterContent*, gfloat*, gfloat*)) gala_image_real_get_preferred_size;
	iface->paint_content = (void (*) (ClutterContent*, ClutterActor*, ClutterPaintNode*, ClutterPaintContext*)) gala_image_real_paint_content;
	iface->invalidate = (void (*) (ClutterContent*)) gala_image_real_invalidate;
	iface->invalidate_size = (void (*) (ClutterContent*)) gala_image_real_invalidate_size;
}

static void
gala_image_instance_init (GalaImage * self,
                          gpointer klass)
{
	self->priv = gala_image_get_instance_private (self);
}

static void
gala_image_finalize (GObject * obj)
{
	GalaImage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GALA_TYPE_IMAGE, GalaImage);
	_g_object_unref0 (self->priv->_pixbuf);
	_g_object_unref0 (self->priv->texture);
	G_OBJECT_CLASS (gala_image_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
gala_image_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GalaImageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gala_image_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GalaImage), 0, (GInstanceInitFunc) gala_image_instance_init, NULL };
	static const GInterfaceInfo clutter_content_info = { (GInterfaceInitFunc) gala_image_clutter_content_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gala_image_type_id;
	gala_image_type_id = g_type_register_static (G_TYPE_OBJECT, "GalaImage", &g_define_type_info, 0);
	g_type_add_interface_static (gala_image_type_id, clutter_content_get_type (), &clutter_content_info);
	GalaImage_private_offset = g_type_add_instance_private (gala_image_type_id, sizeof (GalaImagePrivate));
	return gala_image_type_id;
}

GType
gala_image_get_type (void)
{
	static gsize gala_image_type_id__once = 0;
	if (g_once_init_enter (&gala_image_type_id__once)) {
		GType gala_image_type_id;
		gala_image_type_id = gala_image_get_type_once ();
		g_once_init_leave (&gala_image_type_id__once, gala_image_type_id);
	}
	return gala_image_type_id__once;
}

static void
_vala_gala_image_get_property (GObject * object,
                               guint property_id,
                               GValue * value,
                               GParamSpec * pspec)
{
	GalaImage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_IMAGE, GalaImage);
	switch (property_id) {
		case GALA_IMAGE_WIDTH_PROPERTY:
		g_value_set_int (value, gala_image_get_width (self));
		break;
		case GALA_IMAGE_HEIGHT_PROPERTY:
		g_value_set_int (value, gala_image_get_height (self));
		break;
		case GALA_IMAGE_PIXBUF_PROPERTY:
		g_value_set_object (value, gala_image_get_pixbuf (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gala_image_set_property (GObject * object,
                               guint property_id,
                               const GValue * value,
                               GParamSpec * pspec)
{
	GalaImage * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GALA_TYPE_IMAGE, GalaImage);
	switch (property_id) {
		case GALA_IMAGE_WIDTH_PROPERTY:
		gala_image_set_width (self, g_value_get_int (value));
		break;
		case GALA_IMAGE_HEIGHT_PROPERTY:
		gala_image_set_height (self, g_value_get_int (value));
		break;
		case GALA_IMAGE_PIXBUF_PROPERTY:
		gala_image_set_pixbuf (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

