libgimpbase: add utility functions to convert between pixels and units

This commit is contained in:
Michael Natterer 2010-02-21 16:45:01 +01:00
parent 41a277f040
commit 52041715a9
3 changed files with 50 additions and 0 deletions

View File

@ -80,6 +80,7 @@ EXPORTS
gimp_pdb_proc_type_get_type
gimp_pdb_status_type_get_type
gimp_personal_rc_file
gimp_pixels_to_units
gimp_pixpipe_params_build
gimp_pixpipe_params_init
gimp_pixpipe_params_parse
@ -117,6 +118,7 @@ EXPORTS
gimp_unit_get_type
gimp_unit_new
gimp_unit_set_deletion_flag
gimp_units_to_pixels
gimp_user_directory
gimp_user_directory_get_type
gimp_utf8_strtrim

View File

@ -459,3 +459,44 @@ gimp_param_spec_unit (const gchar *name,
return G_PARAM_SPEC (pspec);
}
/**
* gimp_pixels_to_units:
* @pixels: value in pixels
* @unit: unit to convert to
* @resolution: respoution in DPI
*
* Returns: %pixels converted to units.
*
* Since: GIMP 2.8
**/
gdouble
gimp_pixels_to_units (gdouble pixels,
GimpUnit unit,
gdouble resolution)
{
if (unit == GIMP_UNIT_PIXEL)
return pixels;
return pixels * gimp_unit_get_factor (unit) / resolution;
}
/**
* gimp_inits_to_pixels:
* @value: value in units
* @unit: unit of %value
* @resolution: respoution in DPI
*
* Returns: %value converted to pixels.
*
* Since: GIMP 2.8
**/
gdouble
gimp_units_to_pixels (gdouble value,
GimpUnit unit,
gdouble resolution)
{
if (unit == GIMP_UNIT_PIXEL)
return value;
return value * resolution / gimp_unit_get_factor (unit);
}

View File

@ -81,6 +81,13 @@ const gchar * gimp_unit_get_abbreviation (GimpUnit unit);
const gchar * gimp_unit_get_singular (GimpUnit unit);
const gchar * gimp_unit_get_plural (GimpUnit unit);
gdouble gimp_pixels_to_units (gdouble pixels,
GimpUnit unit,
gdouble resolution);
gdouble gimp_units_to_pixels (gdouble units,
GimpUnit unit,
gdouble resolution);
G_END_DECLS