Example #1
0
/**
 * huey_ctx_get_device:
 *
 * Since: 0.1.29
 **/
GUsbDevice *
huey_ctx_get_device (HueyCtx *ctx)
{
	HueyCtxPrivate *priv = GET_PRIVATE (ctx);
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return priv->device;
}
Example #2
0
/**
 * huey_ctx_get_unlock_string:
 *
 * Since: 0.1.29
 **/
const gchar *
huey_ctx_get_unlock_string (HueyCtx *ctx)
{
	HueyCtxPrivate *priv = GET_PRIVATE (ctx);
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return priv->unlock_string;
}
Example #3
0
/**
 * huey_ctx_get_dark_offset:
 *
 * Since: 0.1.29
 **/
const CdVec3 *
huey_ctx_get_dark_offset (HueyCtx *ctx)
{
	HueyCtxPrivate *priv = GET_PRIVATE (ctx);
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return &priv->dark_offset;
}
Example #4
0
/**
 * huey_ctx_get_calibration_value:
 *
 * Since: 0.1.29
 **/
gfloat
huey_ctx_get_calibration_value (HueyCtx *ctx)
{
	HueyCtxPrivate *priv = GET_PRIVATE (ctx);
	g_return_val_if_fail (HUEY_IS_CTX (ctx), -1);
	return priv->calibration_value;
}
Example #5
0
/**
 * huey_ctx_get_calibration_crt:
 *
 * Since: 0.1.29
 **/
const CdMat3x3 *
huey_ctx_get_calibration_crt (HueyCtx *ctx)
{
	HueyCtxPrivate *priv = GET_PRIVATE (ctx);
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return &priv->calibration_crt;
}
Example #6
0
/**
 * huey_ctx_set_device:
 *
 * Since: 0.1.29
 **/
void
huey_ctx_set_device (HueyCtx *ctx, GUsbDevice *device)
{
	HueyCtxPrivate *priv = GET_PRIVATE (ctx);
	g_return_if_fail (HUEY_IS_CTX (ctx));
	priv->device = g_object_ref (device);
}
Example #7
0
/**
 * huey_ctx_finalize:
 **/
static void
huey_ctx_finalize (GObject *object)
{
	HueyCtx *ctx = HUEY_CTX (object);

	g_return_if_fail (HUEY_IS_CTX (object));

	g_free (ctx->priv->unlock_string);

	G_OBJECT_CLASS (huey_ctx_parent_class)->finalize (object);
}
Example #8
0
/**
 * huey_ctx_setup:
 *
 * Since: 0.1.29
 **/
gboolean
huey_ctx_setup (HueyCtx *ctx, GError **error)
{
	gboolean ret;
	HueyCtxPrivate *priv = ctx->priv;

	g_return_val_if_fail (HUEY_IS_CTX (ctx), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	/* get matrix */
	cd_mat33_clear (&priv->calibration_lcd);
	ret = huey_device_read_register_matrix (priv->device,
						HUEY_EEPROM_ADDR_CALIBRATION_DATA_LCD,
						&priv->calibration_lcd,
						error);
	if (!ret)
		goto out;
	g_debug ("device calibration LCD: %s",
		 cd_mat33_to_string (&priv->calibration_lcd));

	/* get another matrix, although this one is different... */
	cd_mat33_clear (&priv->calibration_crt);
	ret = huey_device_read_register_matrix (priv->device,
						HUEY_EEPROM_ADDR_CALIBRATION_DATA_CRT,
						&priv->calibration_crt,
						error);
	if (!ret)
		goto out;
	g_debug ("device calibration CRT: %s",
		 cd_mat33_to_string (&priv->calibration_crt));

	/* this number is different on all three hueys */
	ret = huey_device_read_register_float (priv->device,
					       HUEY_EEPROM_ADDR_AMBIENT_CALIB_VALUE,
					       &priv->calibration_value,
					       error);
	if (!ret)
		goto out;

	/* this vector changes between sensor 1 and 3 */
	ret = huey_device_read_register_vector (priv->device,
						HUEY_EEPROM_ADDR_DARK_OFFSET,
						&priv->dark_offset,
						error);
	if (!ret)
		goto out;
out:
	return ret;
}
Example #9
0
/**
 * huey_ctx_get_device:
 *
 * Since: 0.1.29
 **/
GUsbDevice *
huey_ctx_get_device (HueyCtx *ctx)
{
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return ctx->priv->device;
}
Example #10
0
/**
 * huey_ctx_take_sample:
 *
 * Since: 0.1.29
 **/
CdColorXYZ *
huey_ctx_take_sample (HueyCtx *ctx, CdSensorCap cap, GError **error)
{
	CdColorRGB values;
	CdColorXYZ color_result;
	CdColorXYZ *result = NULL;
	CdMat3x3 *device_calibration;
	CdVec3 *temp;
	gboolean ret = FALSE;
	HueyCtxDeviceRaw color_native;
	HueyCtxMultiplier multiplier;

	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	g_return_val_if_fail (error == NULL || *error == NULL, NULL);

	/* no hardware support */
	if (cap == CD_SENSOR_CAP_PROJECTOR) {
		g_set_error_literal (error,
				     HUEY_CTX_ERROR,
				     HUEY_CTX_ERROR_NO_SUPPORT,
				     "Huey cannot measure in projector mode");
		goto out;
	}

	/* set this to one value for a quick approximate value */
	multiplier.R = 1;
	multiplier.G = 1;
	multiplier.B = 1;
	ret = huey_ctx_sample_for_threshold (ctx,
					     &multiplier,
					     &color_native,
					     error);
	if (!ret)
		goto out;
	g_debug ("initial values: red=%i, green=%i, blue=%i",
		 color_native.R, color_native.G, color_native.B);

	/* try to fill the 16 bit register for accuracy */
	multiplier.R = HUEY_POLL_FREQUENCY / color_native.R;
	multiplier.G = HUEY_POLL_FREQUENCY / color_native.G;
	multiplier.B = HUEY_POLL_FREQUENCY / color_native.B;

	/* don't allow a value of zero */
	if (multiplier.R == 0)
		multiplier.R = 1;
	if (multiplier.G == 0)
		multiplier.G = 1;
	if (multiplier.B == 0)
		multiplier.B = 1;
	g_debug ("using multiplier factor: red=%i, green=%i, blue=%i",
		 multiplier.R, multiplier.G, multiplier.B);
	ret = huey_ctx_sample_for_threshold (ctx,
					     &multiplier,
					     &color_native,
					     error);
	if (!ret)
		goto out;
	g_debug ("raw values: red=%i, green=%i, blue=%i",
		 color_native.R, color_native.G, color_native.B);

	/* get DeviceRGB values */
	values.R = (gdouble) multiplier.R * 0.5f * HUEY_POLL_FREQUENCY / ((gdouble) color_native.R);
	values.G = (gdouble) multiplier.G * 0.5f * HUEY_POLL_FREQUENCY / ((gdouble) color_native.G);
	values.B = (gdouble) multiplier.B * 0.5f * HUEY_POLL_FREQUENCY / ((gdouble) color_native.B);
	g_debug ("scaled values: red=%0.6lf, green=%0.6lf, blue=%0.6lf",
		 values.R, values.G, values.B);

	/* remove dark offset */
	temp = (CdVec3*) &values;
	cd_vec3_subtract (temp,
			  &ctx->priv->dark_offset,
			  temp);

	g_debug ("dark offset values: red=%0.6lf, green=%0.6lf, blue=%0.6lf",
		 values.R, values.G, values.B);

	/* negative values don't make sense (device needs recalibration) */
	if (values.R < 0.0f)
		values.R = 0.0f;
	if (values.G < 0.0f)
		values.G = 0.0f;
	if (values.B < 0.0f)
		values.B = 0.0f;

	/* we use different calibration matrices for each output type */
	switch (cap) {
	case CD_SENSOR_CAP_CRT:
	case CD_SENSOR_CAP_PLASMA:
		g_debug ("using CRT calibration matrix");
		device_calibration = &ctx->priv->calibration_crt;
		break;
	default:
		g_debug ("using LCD calibration matrix");
		device_calibration = &ctx->priv->calibration_lcd;
		break;
	}

	/* convert from device RGB to XYZ */
	huey_ctx_convert_device_RGB_to_XYZ (&values,
					    &color_result,
					    device_calibration,
					    HUEY_XYZ_POST_MULTIPLY_FACTOR);
	g_debug ("finished values: red=%0.6lf, green=%0.6lf, blue=%0.6lf",
		 color_result.X, color_result.Y, color_result.Z);

	/* save result */
	result = cd_color_xyz_dup (&color_result);
out:
	return result;
}
Example #11
0
/**
 * huey_ctx_get_unlock_string:
 *
 * Since: 0.1.29
 **/
const gchar *
huey_ctx_get_unlock_string (HueyCtx *ctx)
{
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return ctx->priv->unlock_string;
}
Example #12
0
/**
 * huey_ctx_get_dark_offset:
 *
 * Since: 0.1.29
 **/
const CdVec3 *
huey_ctx_get_dark_offset (HueyCtx *ctx)
{
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return &ctx->priv->dark_offset;
}
Example #13
0
/**
 * huey_ctx_get_calibration_value:
 *
 * Since: 0.1.29
 **/
gfloat
huey_ctx_get_calibration_value (HueyCtx *ctx)
{
	g_return_val_if_fail (HUEY_IS_CTX (ctx), -1);
	return ctx->priv->calibration_value;
}
Example #14
0
/**
 * huey_ctx_get_calibration_crt:
 *
 * Since: 0.1.29
 **/
const CdMat3x3 *
huey_ctx_get_calibration_crt (HueyCtx *ctx)
{
	g_return_val_if_fail (HUEY_IS_CTX (ctx), NULL);
	return &ctx->priv->calibration_crt;
}
Example #15
0
/**
 * huey_ctx_set_device:
 *
 * Since: 0.1.29
 **/
void
huey_ctx_set_device (HueyCtx *ctx, GUsbDevice *device)
{
	g_return_if_fail (HUEY_IS_CTX (ctx));
	ctx->priv->device = g_object_ref (device);
}