[gimp] libgimpbase: new gimp_unit_get_accurate_digits() API function.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpbase: new gimp_unit_get_accurate_digits() API function.
- Date: Mon, 23 Jan 2017 20:05:45 +0000 (UTC)
commit 0c07ae3bbfce06f382f2b8ea3b2d53cf870f3a15
Author: Jehan <jehan girinstud io>
Date: Fri Jan 20 01:10:06 2017 +0100
libgimpbase: new gimp_unit_get_accurate_digits() API function.
libgimpbase/gimpbase.def | 1 +
libgimpbase/gimpunit.c | 31 +++++++++++++++++++++++++++++++
libgimpbase/gimpunit.h | 2 ++
3 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index c2abcff..526359e 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -174,6 +174,7 @@ EXPORTS
gimp_unit_get_number_of_built_in_units
gimp_unit_get_number_of_units
gimp_unit_get_plural
+ gimp_unit_get_scaled_digits
gimp_unit_get_singular
gimp_unit_get_symbol
gimp_unit_get_type
diff --git a/libgimpbase/gimpunit.c b/libgimpbase/gimpunit.c
index 8daa4dc..2b6ad57 100644
--- a/libgimpbase/gimpunit.c
+++ b/libgimpbase/gimpunit.c
@@ -21,6 +21,7 @@
#include "config.h"
+#include <math.h>
#include <string.h>
#include <glib-object.h>
@@ -256,6 +257,36 @@ gimp_unit_get_digits (GimpUnit unit)
}
/**
+ * gimp_unit_get_scaled_digits:
+ * @unit: The unit you want to know the digits.
+ * @resolution: the resolution in PPI.
+ *
+ * Returns the number of digits a @unit field should provide to get
+ * enough accuracy so that every pixel position shows a different
+ * value from neighboring pixels.
+ *
+ * Note: when needing digit accuracy to display a diagonal distance,
+ * the @resolution may not correspond to the image's horizontal or
+ * vertical resolution, but instead to the result of:
+ * `distance_in_pixel / distance_in_inch`.
+ *
+ * Returns: The suggested number of digits.
+ **/
+gint
+gimp_unit_get_scaled_digits (GimpUnit unit,
+ gdouble resolution)
+{
+ gint digits;
+
+ g_return_val_if_fail (_gimp_unit_vtable.unit_get_digits != NULL, 2);
+
+ digits = ceil (log10 (1.0 /
+ gimp_pixels_to_units (1.0, unit, resolution)));
+
+ return MAX (digits, gimp_unit_get_digits (unit));
+}
+
+/**
* gimp_unit_get_identifier:
* @unit: The unit you want to know the identifier of.
*
diff --git a/libgimpbase/gimpunit.h b/libgimpbase/gimpunit.h
index 2311a54..5f87b92 100644
--- a/libgimpbase/gimpunit.h
+++ b/libgimpbase/gimpunit.h
@@ -79,6 +79,8 @@ void gimp_unit_set_deletion_flag (GimpUnit unit,
gdouble gimp_unit_get_factor (GimpUnit unit);
gint gimp_unit_get_digits (GimpUnit unit);
+gint gimp_unit_get_scaled_digits (GimpUnit unit,
+ gdouble resolution);
const gchar * gimp_unit_get_identifier (GimpUnit unit);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]