Commit 8918fd33 authored by Michael Natterer's avatar Michael Natterer 😴

pdb/libgimp: export gimp-image-new-with-precision

And switch on precision awareness of a plug-in in the core when
possible, instead of in the libgimp wrappers.
parent 3e4edc1a
......@@ -23,11 +23,14 @@
#include "pdb-types.h"
#include "core/gimp.h"
#include "core/gimpimage-convert.h"
#include "core/gimpimage.h"
#include "core/gimpitemstack.h"
#include "core/gimppalette.h"
#include "core/gimpparamspecs.h"
#include "plug-in/gimpplugin.h"
#include "plug-in/gimppluginmanager.h"
#include "gimppdb.h"
#include "gimppdberror.h"
......@@ -233,6 +236,9 @@ image_convert_precision_invoker (GimpProcedure *procedure,
if (success)
{
if (gimp->plug_in_manager->current_plug_in)
gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_is_not_precision (image, precision, error))
{
......
......@@ -64,6 +64,9 @@ drawable_get_format_invoker (GimpProcedure *procedure,
if (success)
{
if (gimp->plug_in_manager->current_plug_in)
gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
format = g_strdup (babl_get_name (gimp_drawable_get_format (drawable)));
}
......
......@@ -53,6 +53,8 @@
#include "core/gimpselection.h"
#include "core/gimptempbuf.h"
#include "core/gimpunit.h"
#include "plug-in/gimpplugin.h"
#include "plug-in/gimppluginmanager.h"
#include "vectors/gimpvectors.h"
#include "gimppdb.h"
......@@ -168,6 +170,52 @@ image_new_invoker (GimpProcedure *procedure,
return return_vals;
}
static GValueArray *
image_new_with_precision_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
GValueArray *return_vals;
gint32 width;
gint32 height;
gint32 type;
gint32 precision;
GimpImage *image = NULL;
width = g_value_get_int (&args->values[0]);
height = g_value_get_int (&args->values[1]);
type = g_value_get_enum (&args->values[2]);
precision = g_value_get_enum (&args->values[3]);
if (success)
{
if (gimp->plug_in_manager->current_plug_in)
gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
if (type != GIMP_INDEXED || precision == GIMP_PRECISION_U8)
{
image = gimp_create_image (gimp, width, height, type,
precision, FALSE);
if (! image)
success = FALSE;
}
else
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
gimp_value_set_image (&return_vals->values[1], image);
return return_vals;
}
static GValueArray *
image_duplicate_invoker (GimpProcedure *procedure,
Gimp *gimp,
......@@ -2883,6 +2931,55 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-new-with-precision
*/
procedure = gimp_procedure_new (image_new_with_precision_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-new-with-precision");
gimp_procedure_set_static_strings (procedure,
"gimp-image-new-with-precision",
"Creates a new image with the specified width, height, type and precision.",
"Creates a new image, undisplayed with the specified extents, type and precision. Indexed images can only be created at GIMP_PRECISION_U8 precision. See 'gimp-image-new' for further details.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2012",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("width",
"width",
"The width of the image",
1, GIMP_MAX_IMAGE_SIZE, 1,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("height",
"height",
"The height of the image",
1, GIMP_MAX_IMAGE_SIZE, 1,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("type",
"type",
"The type of image",
GIMP_TYPE_IMAGE_BASE_TYPE,
GIMP_RGB,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_enum ("precision",
"precision",
"The precision",
GIMP_TYPE_PRECISION,
GIMP_PRECISION_U8,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_image_id ("image",
"image",
"The ID of the newly created image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-duplicate
*/
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 671 procedures registered total */
/* 672 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -444,6 +444,7 @@ EXPORTS
gimp_image_merge_down
gimp_image_merge_visible_layers
gimp_image_new
gimp_image_new_with_precision
gimp_image_parasite_attach
gimp_image_parasite_detach
gimp_image_parasite_find
......
......@@ -744,8 +744,6 @@ gimp_drawable_get_format (gint32 drawable_ID)
if (format_str)
{
gimp_plugin_enable_precision ();
if (gimp_drawable_is_indexed (drawable_ID))
{
gint32 image_ID = gimp_item_get_image (drawable_ID);
......
......@@ -151,6 +151,51 @@ gimp_image_new (gint width,
return image_ID;
}
/**
* gimp_image_new_with_precision:
* @width: The width of the image.
* @height: The height of the image.
* @type: The type of image.
* @precision: The precision.
*
* Creates a new image with the specified width, height, type and
* precision.
*
* Creates a new image, undisplayed with the specified extents, type
* and precision. Indexed images can only be created at
* GIMP_PRECISION_U8 precision. See gimp_image_new() for further
* details.
*
* Returns: The ID of the newly created image.
*
* Since: GIMP 2.10
**/
gint32
gimp_image_new_with_precision (gint width,
gint height,
GimpImageBaseType type,
GimpPrecision precision)
{
GimpParam *return_vals;
gint nreturn_vals;
gint32 image_ID = -1;
return_vals = gimp_run_procedure ("gimp-image-new-with-precision",
&nreturn_vals,
GIMP_PDB_INT32, width,
GIMP_PDB_INT32, height,
GIMP_PDB_INT32, type,
GIMP_PDB_INT32, precision,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
image_ID = return_vals[1].data.d_image;
gimp_destroy_params (return_vals, nreturn_vals);
return image_ID;
}
/**
* gimp_image_duplicate:
* @image_ID: The image.
......
......@@ -37,6 +37,10 @@ gint* gimp_image_list (gint
gint32 gimp_image_new (gint width,
gint height,
GimpImageBaseType type);
gint32 gimp_image_new_with_precision (gint width,
gint height,
GimpImageBaseType type,
GimpPrecision precision);
gint32 gimp_image_duplicate (gint32 image_ID);
gboolean gimp_image_delete (gint32 image_ID);
GimpImageBaseType gimp_image_base_type (gint32 image_ID);
......
......@@ -240,6 +240,9 @@ HELP
%invoke = (
code => <<'CODE'
{
if (gimp->plug_in_manager->current_plug_in)
gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) &&
gimp_pdb_image_is_not_precision (image, precision, error))
{
......@@ -254,10 +257,13 @@ CODE
);
}
@headers = qw("core/gimpimage.h"
@headers = qw("core/gimp.h"
"core/gimpimage.h"
"core/gimpimage-convert.h"
"core/gimpitemstack.h"
"core/gimppalette.h"
"plug-in/gimpplugin.h"
"plug-in/gimppluginmanager.h"
"gimppdberror.h"
"gimppdb-utils.h"
"gimp-intl.h");
......
......@@ -283,6 +283,9 @@ sub drawable_get_format {
%invoke = (
code => <<'CODE'
{
if (gimp->plug_in_manager->current_plug_in)
gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
format = g_strdup (babl_get_name (gimp_drawable_get_format (drawable)));
}
CODE
......
......@@ -123,6 +123,53 @@ CODE
);
}
sub image_new_with_precision {
$blurb = 'Creates a new image with the specified width, height, type and precision.';
$help = <<'HELP';
Creates a new image, undisplayed with the specified extents, type
and precision. Indexed images can only be created at GIMP_PRECISION_U8
precision. See gimp_image_new() for further details.
HELP
&mitch_pdb_misc('2012', '2.10');
@inargs = (
{ name => 'width', type => '1 <= int32 <= GIMP_MAX_IMAGE_SIZE',
desc => 'The width of the image' },
{ name => 'height', type => '1 <= int32 <= GIMP_MAX_IMAGE_SIZE',
desc => 'The height of the image' },
{ name => 'type', type => 'enum GimpImageBaseType',
desc => 'The type of image' },
{ name => 'precision', type => 'enum GimpPrecision',
desc => 'The precision' }
);
@outargs = (
{ name => 'image', type => 'image',
desc => 'The ID of the newly created image' }
);
%invoke = (
code => <<'CODE'
{
if (gimp->plug_in_manager->current_plug_in)
gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);
if (type != GIMP_INDEXED || precision == GIMP_PRECISION_U8)
{
image = gimp_create_image (gimp, width, height, type,
precision, FALSE);
if (! image)
success = FALSE;
}
else
success = FALSE;
}
CODE
);
}
sub image_duplicate {
$blurb = 'Duplicate the specified image';
......@@ -2897,6 +2944,8 @@ CODE
"core/gimpprogress.h"
"core/gimptempbuf.h"
"core/gimpunit.h"
"plug-in/gimpplugin.h"
"plug-in/gimppluginmanager.h"
"gimppdbcontext.h"
"gimppdberror.h"
"gimppdb-utils.h"
......@@ -2904,7 +2953,8 @@ CODE
@procs = qw(image_is_valid
image_list
image_new image_duplicate image_delete
image_new image_new_with_precision
image_duplicate image_delete
image_base_type
image_width image_height
image_free_shadow
......@@ -2961,7 +3011,7 @@ CODE
# image_add_layer_mask and image_remove_layer_mask.
# If adding or removing functions, make sure the range below is
# updated correctly!
%exports = (app => [@procs], lib => [@procs[0..42,45..83]]);
%exports = (app => [@procs], lib => [@procs[0..43,46..84]]);
$desc = 'Image';
$doc_title = 'gimpimage';
......
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