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

#include <glib.h>
#include <float.h>
#include <math.h>
#include "xmpp-vala.h"
#include <stdlib.h>
#include <string.h>

#define XMPP_XEP_CONSISTENT_COLOR_KR 0.299
#define XMPP_XEP_CONSISTENT_COLOR_KG 0.587
#define XMPP_XEP_CONSISTENT_COLOR_KB 0.114
#define XMPP_XEP_CONSISTENT_COLOR_Y 0.732
#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

#define _g_checksum_free0(var) ((var == NULL) ? NULL : (var = (g_checksum_free (var), NULL)))

VALA_EXTERN guint8* xmpp_xep_consistent_color_rgbd_to_rgb (gdouble* rgbd,
                                               gint rgbd_length1,
                                               gint* result_length1);
VALA_EXTERN gfloat* xmpp_xep_consistent_color_rgbd_to_rgbf (gdouble* rgbd,
                                                gint rgbd_length1,
                                                gint* result_length1);
VALA_EXTERN gdouble* xmpp_xep_consistent_color_angle_to_rgbd (gdouble angle,
                                                  gint* result_length1);
VALA_EXTERN gdouble* hsluv_hsluv_to_rgb (gdouble* tuple,
                             gint tuple_length1,
                             gint* result_length1);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static guint8*
string_get_data (const gchar* self,
                 gint* result_length1)
{
	guint8* result;
	guint8* res = NULL;
	gint res_length1;
	gint _res_size_;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	g_return_val_if_fail (self != NULL, NULL);
	res = (guint8*) self;
	res_length1 = -1;
	_res_size_ = res_length1;
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	res_length1 = (gint) _tmp1_;
	_tmp2_ = res;
	_tmp2__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

gfloat
xmpp_xep_consistent_color_string_to_angle (const gchar* s)
{
	GChecksum* checksum = NULL;
	GChecksum* _tmp0_;
	guint8* _tmp1_;
	gint _tmp1__length1;
	gint _tmp2_ = 0;
	guint8* _tmp3_;
	gint _tmp3__length1;
	gsize len = 0UL;
	guint8* digest = NULL;
	guint8* _tmp4_;
	gint digest_length1;
	gint _digest_size_;
	guint16 output = 0U;
	gfloat result;
	g_return_val_if_fail (s != NULL, -1.0F);
	_tmp0_ = g_checksum_new (G_CHECKSUM_SHA1);
	checksum = _tmp0_;
	_tmp1_ = string_get_data (s, &_tmp2_);
	_tmp1__length1 = _tmp2_;
	_tmp3_ = _tmp1_;
	_tmp3__length1 = _tmp1__length1;
	g_checksum_update (checksum, _tmp3_, (gsize) -1);
	len = (gsize) 20;
	_tmp4_ = g_new0 (guint8, len);
	digest = _tmp4_;
	digest_length1 = len;
	_digest_size_ = digest_length1;
	g_checksum_get_digest (checksum, digest, &len);
	output = GUINT16_TO_LE ((guint16) (*((guint16*) digest)));
	result = (((gfloat) output) / 65536.0f) * 360.0f;
	digest = (g_free (digest), NULL);
	_g_checksum_free0 (checksum);
	return result;
}

guint8*
xmpp_xep_consistent_color_rgbd_to_rgb (gdouble* rgbd,
                                       gint rgbd_length1,
                                       gint* result_length1)
{
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	guint8* _tmp3_;
	guint8* _tmp4_;
	gint _tmp4__length1;
	guint8* result;
	_tmp0_ = rgbd[0];
	_tmp1_ = rgbd[1];
	_tmp2_ = rgbd[2];
	_tmp3_ = g_new0 (guint8, 3);
	_tmp3_[0] = (guint8) (_tmp0_ * 255.0);
	_tmp3_[1] = (guint8) (_tmp1_ * 255.0);
	_tmp3_[2] = (guint8) (_tmp2_ * 255.0);
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 3;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}

gfloat*
xmpp_xep_consistent_color_rgbd_to_rgbf (gdouble* rgbd,
                                        gint rgbd_length1,
                                        gint* result_length1)
{
	gdouble _tmp0_;
	gdouble _tmp1_;
	gdouble _tmp2_;
	gfloat* _tmp3_;
	gfloat* _tmp4_;
	gint _tmp4__length1;
	gfloat* result;
	_tmp0_ = rgbd[0];
	_tmp1_ = rgbd[1];
	_tmp2_ = rgbd[2];
	_tmp3_ = g_new0 (gfloat, 3);
	_tmp3_[0] = (gfloat) _tmp0_;
	_tmp3_[1] = (gfloat) _tmp1_;
	_tmp3_[2] = (gfloat) _tmp2_;
	_tmp4_ = _tmp3_;
	_tmp4__length1 = 3;
	if (result_length1) {
		*result_length1 = _tmp4__length1;
	}
	result = _tmp4_;
	return result;
}

gdouble*
xmpp_xep_consistent_color_angle_to_rgbd (gdouble angle,
                                         gint* result_length1)
{
	gdouble* _tmp0_;
	gdouble* _tmp1_;
	gint _tmp1__length1;
	gint _tmp2_ = 0;
	gdouble* _tmp3_;
	gdouble* _tmp4_;
	gint _tmp4__length1;
	gdouble* _tmp5_;
	gint _tmp5__length1;
	gdouble* result;
	_tmp0_ = g_new0 (gdouble, 3);
	_tmp0_[0] = angle;
	_tmp0_[1] = (gdouble) 100;
	_tmp0_[2] = (gdouble) 50;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = 3;
	_tmp3_ = hsluv_hsluv_to_rgb (_tmp1_, (gint) 3, &_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp4__length1 = _tmp2_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	_tmp5_ = _tmp4_;
	_tmp5__length1 = _tmp4__length1;
	if (result_length1) {
		*result_length1 = _tmp5__length1;
	}
	result = _tmp5_;
	return result;
}

gfloat*
xmpp_xep_consistent_color_string_to_rgbf (const gchar* s,
                                          gint* result_length1)
{
	gint _tmp0_ = 0;
	gdouble* _tmp1_;
	gdouble* _tmp2_;
	gint _tmp2__length1;
	gint _tmp3_ = 0;
	gfloat* _tmp4_;
	gfloat* _tmp5_;
	gint _tmp5__length1;
	gfloat* _tmp6_;
	gint _tmp6__length1;
	gfloat* result;
	g_return_val_if_fail (s != NULL, NULL);
	_tmp1_ = xmpp_xep_consistent_color_angle_to_rgbd ((gdouble) xmpp_xep_consistent_color_string_to_angle (s), &_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp0_;
	_tmp4_ = xmpp_xep_consistent_color_rgbd_to_rgbf (_tmp2_, (gint) _tmp0_, &_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp5__length1 = _tmp3_;
	_tmp2_ = (g_free (_tmp2_), NULL);
	_tmp6_ = _tmp5_;
	_tmp6__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	return result;
}

guint8*
xmpp_xep_consistent_color_string_to_rgb (const gchar* s,
                                         gint* result_length1)
{
	gint _tmp0_ = 0;
	gdouble* _tmp1_;
	gdouble* _tmp2_;
	gint _tmp2__length1;
	gint _tmp3_ = 0;
	guint8* _tmp4_;
	guint8* _tmp5_;
	gint _tmp5__length1;
	guint8* _tmp6_;
	gint _tmp6__length1;
	guint8* result;
	g_return_val_if_fail (s != NULL, NULL);
	_tmp1_ = xmpp_xep_consistent_color_angle_to_rgbd ((gdouble) xmpp_xep_consistent_color_string_to_angle (s), &_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp0_;
	_tmp4_ = xmpp_xep_consistent_color_rgbd_to_rgb (_tmp2_, (gint) _tmp0_, &_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp5__length1 = _tmp3_;
	_tmp2_ = (g_free (_tmp2_), NULL);
	_tmp6_ = _tmp5_;
	_tmp6__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	return result;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

