From b420a7738ce5d309eaddda4d54bc6b7f7f643fbe Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Thu, 30 Oct 2025 01:16:25 +0000 Subject: [PATCH] app, pdb: fix gimp_drawable_get_sub_thumbnail() on high-bit depth drawable. Resolves #13598 Applies the same logic designed by Jehan in f78a0629 to the gimp_drawable_get_sub_thumbnail function. This allows GimpZoomPreview and GimpDrawablePreview in older plug-ins to show correct previews for images that are larger than 8-bit. --- app/pdb/drawable-cmds.c | 41 ++++++++++++++++++++++++++++++----- pdb/groups/drawable.pdb | 47 ++++++++++++++++++++++++++++++++++------- 2 files changed, 75 insertions(+), 13 deletions(-) diff --git a/app/pdb/drawable-cmds.c b/app/pdb/drawable-cmds.c index a702feba1a..ded88a68c7 100644 --- a/app/pdb/drawable-cmds.c +++ b/app/pdb/drawable-cmds.c @@ -1094,11 +1094,42 @@ drawable_sub_thumbnail_invoker (GimpProcedure *procedure, if (buf) { - width = gimp_temp_buf_get_width (buf); - height = gimp_temp_buf_get_height (buf); - bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (buf)); - thumbnail_data = g_bytes_new (gimp_temp_buf_get_data (buf), - gimp_temp_buf_get_data_size (buf)); + const Babl *format = gimp_temp_buf_get_format (buf); + const Babl *rgb_format = babl_format ("R'G'B' u8"); + const Babl *rgba_format = babl_format ("R'G'B'A u8"); + const Babl *fish = NULL; + + if (babl_format_has_alpha (format) && format != rgba_format) + { + fish = babl_fish (format, rgba_format); + format = rgba_format; + } + else if (! babl_format_has_alpha (format) && format != rgb_format) + { + fish = babl_fish (format, rgb_format); + format = rgb_format; + } + + width = gimp_temp_buf_get_width (buf); + height = gimp_temp_buf_get_height (buf); + bpp = babl_format_get_bytes_per_pixel (format); + if (fish) + { + guchar *data; + gint data_size = bpp * width * height; + + data = g_malloc (data_size); + babl_process (fish, gimp_temp_buf_get_data (buf), data, + width * height); + + thumbnail_data = g_bytes_new (data, data_size); + g_free (data); + } + else + { + thumbnail_data = g_bytes_new (gimp_temp_buf_get_data (buf), + gimp_temp_buf_get_data_size (buf)); + } gimp_temp_buf_unref (buf); } diff --git a/pdb/groups/drawable.pdb b/pdb/groups/drawable.pdb index f71921d6fd..8464fb4767 100644 --- a/pdb/groups/drawable.pdb +++ b/pdb/groups/drawable.pdb @@ -1074,9 +1074,9 @@ HELP desc => 'The previews height' }, { name => 'bpp', type => 'int32', desc => 'The previews bpp' }, - { name => 'thumbnail_data', type => 'bytes', - desc => 'The thumbnail data' } - ); + { name => 'thumbnail_data', type => 'bytes', + desc => 'The thumbnail data' } + ); %invoke = ( headers => [ qw("core/gimpdrawable-preview.h") ], @@ -1100,11 +1100,42 @@ HELP if (buf) { - width = gimp_temp_buf_get_width (buf); - height = gimp_temp_buf_get_height (buf); - bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (buf)); - thumbnail_data = g_bytes_new (gimp_temp_buf_get_data (buf), - gimp_temp_buf_get_data_size (buf)); + const Babl *format = gimp_temp_buf_get_format (buf); + const Babl *rgb_format = babl_format ("R'G'B' u8"); + const Babl *rgba_format = babl_format ("R'G'B'A u8"); + const Babl *fish = NULL; + + if (babl_format_has_alpha (format) && format != rgba_format) + { + fish = babl_fish (format, rgba_format); + format = rgba_format; + } + else if (! babl_format_has_alpha (format) && format != rgb_format) + { + fish = babl_fish (format, rgb_format); + format = rgb_format; + } + + width = gimp_temp_buf_get_width (buf); + height = gimp_temp_buf_get_height (buf); + bpp = babl_format_get_bytes_per_pixel (format); + if (fish) + { + guchar *data; + gint data_size = bpp * width * height; + + data = g_malloc (data_size); + babl_process (fish, gimp_temp_buf_get_data (buf), data, + width * height); + + thumbnail_data = g_bytes_new (data, data_size); + g_free (data); + } + else + { + thumbnail_data = g_bytes_new (gimp_temp_buf_get_data (buf), + gimp_temp_buf_get_data_size (buf)); + } gimp_temp_buf_unref (buf); }