Commit 49ca383f authored by Ell's avatar Ell

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.
parent a0a62656
......@@ -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 ||
......
......@@ -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)
......
......@@ -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);
......
......@@ -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);
......
......@@ -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,
......
......@@ -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"
......
......@@ -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"
......
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