From 49ca383fa4571fab35d370d471d18694836e0e27 Mon Sep 17 00:00:00 2001 From: Ell Date: Fri, 6 Jul 2018 13:43:26 -0400 Subject: [PATCH] app, pdb: use gimp_babl_is_valid() in more places Use gimp_babl_is_valid(), added in the previous commit, to validate image-type/precision combinations in various functions. --- app/core/gimpimage-convert-indexed.c | 4 ++++ app/core/gimpimage-convert-precision.c | 4 ++-- app/core/gimpimage-convert-type.c | 3 +++ app/pdb/image-cmds.c | 3 ++- app/pdb/image-convert-cmds.c | 13 +++++++++---- pdb/groups/image.pdb | 3 ++- pdb/groups/image_convert.pdb | 15 ++++++++++----- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/core/gimpimage-convert-indexed.c b/app/core/gimpimage-convert-indexed.c index 4558ee4845..4221ee08d9 100644 --- a/app/core/gimpimage-convert-indexed.c +++ b/app/core/gimpimage-convert-indexed.c @@ -143,6 +143,7 @@ #include "core-types.h" +#include "gegl/gimp-babl.h" #include "gegl/gimp-gegl-utils.h" #include "gimp.h" @@ -767,6 +768,9 @@ gimp_image_convert_indexed (GimpImage *image, g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (gimp_image_get_base_type (image) != GIMP_INDEXED, FALSE); + g_return_val_if_fail (gimp_babl_is_valid (GIMP_INDEXED, + gimp_image_get_precision (image)), + FALSE); g_return_val_if_fail (custom_palette == NULL || GIMP_IS_PALETTE (custom_palette), FALSE); g_return_val_if_fail (custom_palette == NULL || diff --git a/app/core/gimpimage-convert-precision.c b/app/core/gimpimage-convert-precision.c index 21965b9f7a..e7bcfc9b3c 100644 --- a/app/core/gimpimage-convert-precision.c +++ b/app/core/gimpimage-convert-precision.c @@ -67,8 +67,8 @@ gimp_image_convert_precision (GimpImage *image, g_return_if_fail (GIMP_IS_IMAGE (image)); g_return_if_fail (precision != gimp_image_get_precision (image)); - g_return_if_fail (precision == GIMP_PRECISION_U8_GAMMA || - gimp_image_get_base_type (image) != GIMP_INDEXED); + g_return_if_fail (gimp_babl_is_valid (gimp_image_get_base_type (image), + precision)); g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); switch (precision) diff --git a/app/core/gimpimage-convert-type.c b/app/core/gimpimage-convert-type.c index 0483458eca..e72ff7754c 100644 --- a/app/core/gimpimage-convert-type.c +++ b/app/core/gimpimage-convert-type.c @@ -58,6 +58,9 @@ gimp_image_convert_type (GimpImage *image, g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE); g_return_val_if_fail (new_type != gimp_image_get_base_type (image), FALSE); g_return_val_if_fail (new_type != GIMP_INDEXED, FALSE); + g_return_val_if_fail (gimp_babl_is_valid (new_type, + gimp_image_get_precision (image)), + FALSE); g_return_val_if_fail (dest_profile == NULL || GIMP_IS_COLOR_PROFILE (dest_profile), FALSE); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE); diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index fa571dcdc0..daec5687dd 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -52,6 +52,7 @@ #include "core/gimpselection.h" #include "core/gimptempbuf.h" #include "file/file-utils.h" +#include "gegl/gimp-babl.h" #include "plug-in/gimpplugin-cleanup.h" #include "plug-in/gimpplugin.h" #include "plug-in/gimppluginmanager.h" @@ -196,7 +197,7 @@ image_new_with_precision_invoker (GimpProcedure *procedure, 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_GAMMA) + if (gimp_babl_is_valid (type, precision)) { image = gimp_create_image (gimp, width, height, type, precision, FALSE); diff --git a/app/pdb/image-convert-cmds.c b/app/pdb/image-convert-cmds.c index 58d4a92518..d36c69a372 100644 --- a/app/pdb/image-convert-cmds.c +++ b/app/pdb/image-convert-cmds.c @@ -35,6 +35,7 @@ #include "core/gimpitemstack.h" #include "core/gimppalette.h" #include "core/gimpparamspecs.h" +#include "gegl/gimp-babl.h" #include "plug-in/gimpplugin.h" #include "plug-in/gimppluginmanager.h" @@ -62,7 +63,8 @@ image_convert_rgb_invoker (GimpProcedure *procedure, if (success) { - if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error)) + if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error) && + gimp_babl_is_valid (GIMP_RGB, gimp_image_get_precision (image))) { success = gimp_image_convert_type (image, GIMP_RGB, NULL, NULL, error); } @@ -91,7 +93,8 @@ image_convert_grayscale_invoker (GimpProcedure *procedure, if (success) { - if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error)) + if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error) && + gimp_babl_is_valid (GIMP_GRAY, gimp_image_get_precision (image))) { success = gimp_image_convert_type (image, GIMP_GRAY, NULL, NULL, error); } @@ -134,8 +137,9 @@ image_convert_indexed_invoker (GimpProcedure *procedure, { GimpPalette *pal = NULL; - if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) && + if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) && gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8_GAMMA, error) && + gimp_babl_is_valid (GIMP_INDEXED, gimp_image_get_precision (image)) && gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image)))) { switch (palette_type) @@ -242,7 +246,8 @@ image_convert_precision_invoker (GimpProcedure *procedure, 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)) + gimp_pdb_image_is_not_precision (image, precision, error) && + gimp_babl_is_valid (gimp_image_get_base_type (image), precision)) { gimp_image_convert_precision (image, precision, GEGL_DITHER_NONE, diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index 6391c8649d..6958516e5b 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -161,7 +161,7 @@ HELP 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_GAMMA) + if (gimp_babl_is_valid (type, precision)) { image = gimp_create_image (gimp, width, height, type, precision, FALSE); @@ -2917,6 +2917,7 @@ CODE @headers = qw("libgimpmath/gimpmath.h" "libgimpbase/gimpbase.h" + "gegl/gimp-babl.h" "core/gimp.h" "core/gimpcontainer.h" "core/gimpimage-metadata.h" diff --git a/pdb/groups/image_convert.pdb b/pdb/groups/image_convert.pdb index e65dfa9d80..728631608b 100644 --- a/pdb/groups/image_convert.pdb +++ b/pdb/groups/image_convert.pdb @@ -35,7 +35,8 @@ HELP %invoke = ( code => <<'CODE' { - if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error)) + if (gimp_pdb_image_is_not_base_type (image, GIMP_RGB, error) && + gimp_babl_is_valid (GIMP_RGB, gimp_image_get_precision (image))) { success = gimp_image_convert_type (image, GIMP_RGB, NULL, NULL, error); } @@ -66,7 +67,8 @@ HELP %invoke = ( code => <<'CODE' { - if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error)) + if (gimp_pdb_image_is_not_base_type (image, GIMP_GRAY, error) && + gimp_babl_is_valid (GIMP_GRAY, gimp_image_get_precision (image))) { success = gimp_image_convert_type (image, GIMP_GRAY, NULL, NULL, error); } @@ -126,8 +128,9 @@ HELP { GimpPalette *pal = NULL; - if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) && + if (gimp_pdb_image_is_not_base_type (image, GIMP_INDEXED, error) && gimp_pdb_image_is_precision (image, GIMP_PRECISION_U8_GAMMA, error) && + gimp_babl_is_valid (GIMP_INDEXED, gimp_image_get_precision (image)) && gimp_item_stack_is_flat (GIMP_ITEM_STACK (gimp_image_get_layers (image)))) { switch (palette_type) @@ -240,7 +243,8 @@ HELP 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)) + gimp_pdb_image_is_not_precision (image, precision, error) && + gimp_babl_is_valid (gimp_image_get_base_type (image), precision)) { gimp_image_convert_precision (image, precision, GEGL_DITHER_NONE, @@ -257,7 +261,8 @@ CODE ); } -@headers = qw("core/gimp.h" +@headers = qw("gegl/gimp-babl.h" + "core/gimp.h" "core/gimpimage.h" "core/gimpimage-convert-indexed.h" "core/gimpimage-convert-precision.h"