Commit 3e4edc1a authored by Michael Natterer's avatar Michael Natterer 😴

pdb/libgimp: export enum GimpPrecision and gimp-image-convert-precision

parent 2857c1c0
......@@ -328,7 +328,7 @@ typedef enum
GType gimp_precision_get_type (void) G_GNUC_CONST;
typedef enum /*< pdb-skip >*/
typedef enum
{
GIMP_PRECISION_U8, /*< desc="8-bit unsigned integer" >*/
GIMP_PRECISION_U16, /*< desc="16-bit unsigned integer" >*/
......
......@@ -129,8 +129,8 @@ image_convert_indexed_invoker (GimpProcedure *procedure,
{
GimpPalette *pal = NULL;
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_has_precision (image, GIMP_PRECISION_U8, error) &&
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8, error) &&
gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image))))
{
switch (palette_type)
......@@ -216,6 +216,38 @@ image_convert_set_dither_matrix_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GValueArray *
image_convert_precision_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpImage *image;
gint32 precision;
image = gimp_value_get_image (&args->values[0], gimp);
precision = g_value_get_enum (&args->values[1]);
if (success)
{
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_is_not_precision (image, precision, error))
{
gimp_image_convert_precision (image, precision, NULL);
}
else
{
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
void
register_convert_procs (GimpPDB *pdb)
{
......@@ -368,4 +400,34 @@ register_convert_procs (GimpPDB *pdb)
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-convert-precision
*/
procedure = gimp_procedure_new (image_convert_precision_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-convert-precision");
gimp_procedure_set_static_strings (procedure,
"gimp-image-convert-precision",
"Convert the image to the specified precision",
"This procedure converts the image to the specified precision. Note that indexed images cannot be converted and are always in GIMP_PRECISION_U8.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2012",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"The image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("precision",
"precision",
"The new precision",
GIMP_TYPE_PRECISION,
GIMP_PRECISION_U8,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
}
......@@ -618,7 +618,7 @@ gimp_pdb_image_is_not_base_type (GimpImage *image,
return TRUE;
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("Image '%s' (%d) is already of type '%s'"),
_("Image '%s' (%d) must not be of type '%s'"),
gimp_image_get_display_name (image),
gimp_image_get_ID (image),
gimp_pdb_enum_value_get_nick (GIMP_TYPE_IMAGE_BASE_TYPE, type));
......@@ -627,9 +627,9 @@ gimp_pdb_image_is_not_base_type (GimpImage *image,
}
gboolean
gimp_pdb_image_has_precision (GimpImage *image,
GimpPrecision precision,
GError **error)
gimp_pdb_image_is_precision (GimpImage *image,
GimpPrecision precision,
GError **error)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
......@@ -649,6 +649,26 @@ gimp_pdb_image_has_precision (GimpImage *image,
return FALSE;
}
gboolean
gimp_pdb_image_is_not_precision (GimpImage *image,
GimpPrecision precision,
GError **error)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (gimp_image_get_precision (image) != precision)
return TRUE;
g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
_("Image '%s' (%d) must not be of precision '%s'"),
gimp_image_get_display_name (image),
gimp_image_get_ID (image),
gimp_pdb_enum_value_get_nick (GIMP_TYPE_PRECISION, precision));
return FALSE;
}
GimpStroke *
gimp_pdb_get_vectors_stroke (GimpVectors *vectors,
gint stroke_ID,
......
......@@ -88,7 +88,10 @@ gboolean gimp_pdb_image_is_not_base_type (GimpImage *image,
GimpImageBaseType type,
GError **error);
gboolean gimp_pdb_image_has_precision (GimpImage *image,
gboolean gimp_pdb_image_is_precision (GimpImage *image,
GimpPrecision precision,
GError **error);
gboolean gimp_pdb_image_is_not_precision (GimpImage *image,
GimpPrecision precision,
GError **error);
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 670 procedures registered total */
/* 671 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -366,6 +366,7 @@ EXPORTS
gimp_image_clean_all
gimp_image_convert_grayscale
gimp_image_convert_indexed
gimp_image_convert_precision
gimp_image_convert_rgb
gimp_image_convert_set_dither_matrix
gimp_image_crop
......@@ -676,6 +677,7 @@ EXPORTS
gimp_plugin_precision_enabled
gimp_plugin_set_pdb_error_handler
gimp_posterize
gimp_precision_get_type
gimp_procedural_db_dump
gimp_procedural_db_get_data
gimp_procedural_db_get_data_size
......
......@@ -196,3 +196,39 @@ gimp_image_convert_set_dither_matrix (gint width,
return success;
}
/**
* gimp_image_convert_precision:
* @image_ID: The image.
* @precision: The new precision.
*
* Convert the image to the specified precision
*
* This procedure converts the image to the specified precision. Note
* that indexed images cannot be converted and are always in
* GIMP_PRECISION_U8.
*
* Returns: TRUE on success.
*
* Since: GIMP 2.10
**/
gboolean
gimp_image_convert_precision (gint32 image_ID,
GimpPrecision precision)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-image-convert-precision",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_INT32, precision,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
......@@ -45,6 +45,8 @@ gboolean gimp_image_convert_set_dither_matrix (gint width,
gint height,
gint matrix_length,
const guint8 *matrix);
gboolean gimp_image_convert_precision (gint32 image_ID,
GimpPrecision precision);
G_END_DECLS
......
......@@ -41,6 +41,7 @@ static const GimpGetTypeFunc get_type_funcs[] =
gimp_pdb_proc_type_get_type,
gimp_pdb_status_type_get_type,
gimp_paint_application_mode_get_type,
gimp_precision_get_type,
gimp_progress_command_get_type,
gimp_repeat_mode_get_type,
gimp_rotation_type_get_type,
......@@ -98,6 +99,7 @@ static const gchar * const type_names[] =
"GimpPDBProcType",
"GimpPDBStatusType",
"GimpPaintApplicationMode",
"GimpPrecision",
"GimpProgressCommand",
"GimpRepeatMode",
"GimpRotationType",
......
......@@ -258,6 +258,18 @@ typedef enum
} GimpOrientationType;
#define GIMP_TYPE_PRECISION (gimp_precision_get_type ())
GType gimp_precision_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_PRECISION_U8,
GIMP_PRECISION_U16,
GIMP_PRECISION_FLOAT
} GimpPrecision;
#define GIMP_TYPE_ROTATION_TYPE (gimp_rotation_type_get_type ())
GType gimp_rotation_type_get_type (void) G_GNUC_CONST;
......
......@@ -537,6 +537,15 @@ package Gimp::CodeGen::enums;
GIMP_ORIENTATION_VERTICAL => '1',
GIMP_ORIENTATION_UNKNOWN => '2' }
},
GimpPrecision =>
{ contig => 1,
header => 'core/core-enums.h',
symbols => [ qw(GIMP_PRECISION_U8 GIMP_PRECISION_U16
GIMP_PRECISION_FLOAT) ],
mapping => { GIMP_PRECISION_U8 => '0',
GIMP_PRECISION_U16 => '1',
GIMP_PRECISION_FLOAT => '2' }
},
GimpRotationType =>
{ contig => 1,
header => 'core/core-enums.h',
......
......@@ -130,8 +130,8 @@ HELP
{
GimpPalette *pal = NULL;
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_has_precision (image, GIMP_PRECISION_U8, error) &&
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8, error) &&
gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image))))
{
switch (palette_type)
......@@ -219,6 +219,41 @@ CODE
);
}
sub image_convert_precision {
$blurb = 'Convert the image to the specified precision';
$help = <<'HELP';
This procedure converts the image to the specified precision. Note
that indexed images cannot be converted and are always in
GIMP_PRECISION_U8.
HELP
&mitch_pdb_misc('2012', '2.10');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'precision', type => 'enum GimpPrecision',
desc => 'The new precision' }
);
%invoke = (
code => <<'CODE'
{
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_is_not_precision (image, precision, error))
{
gimp_image_convert_precision (image, precision, NULL);
}
else
{
success = FALSE;
}
}
CODE
);
}
@headers = qw("core/gimpimage.h"
"core/gimpimage-convert.h"
"core/gimpitemstack.h"
......@@ -230,7 +265,8 @@ CODE
@procs = qw(image_convert_rgb
image_convert_grayscale
image_convert_indexed
image_convert_set_dither_matrix);
image_convert_set_dither_matrix
image_convert_precision);
%exports = (app => [@procs], lib => [@procs]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment