app: use GEGL to extract an image's component into a channel

Add gimp_image_get_component_format() for that purpose.
This commit is contained in:
Michael Natterer 2012-03-16 13:47:38 +01:00
parent a898491b3f
commit 5d1474c17e
6 changed files with 53 additions and 17 deletions

View file

@ -1695,36 +1695,36 @@ gimp_channel_new_from_component (GimpImage *image,
{
GimpProjection *projection;
GimpChannel *channel;
TileManager *proj_tiles;
PixelRegion src;
PixelRegion dest;
GeglBuffer *src_buffer;
TileManager *dest_tiles;
GeglBuffer *dest_buffer;
gint width;
gint height;
gint pixel;
const Babl *format;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
pixel = gimp_image_get_component_index (image, type);
format = gimp_image_get_component_format (image, type);
g_return_val_if_fail (pixel != -1, NULL);
g_return_val_if_fail (format != NULL, NULL);
projection = gimp_image_get_projection (image);
gimp_pickable_flush (GIMP_PICKABLE (projection));
proj_tiles = gimp_pickable_get_tiles (GIMP_PICKABLE (projection));
width = tile_manager_width (proj_tiles);
height = tile_manager_height (proj_tiles);
src_buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (projection));
width = gegl_buffer_get_width (src_buffer);
height = gegl_buffer_get_height (src_buffer);
channel = gimp_channel_new (image, width, height, name, color);
pixel_region_init (&src, proj_tiles,
0, 0, width, height, FALSE);
pixel_region_init (&dest,
gimp_drawable_get_tiles (GIMP_DRAWABLE (channel)),
0, 0, width, height, TRUE);
dest_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (channel));
dest_buffer = gimp_tile_manager_create_buffer_with_format (dest_tiles,
format, TRUE);
copy_component (&src, &dest, pixel);
gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
g_object_unref (dest_buffer);
return channel;
}

View file

@ -1974,6 +1974,25 @@ gimp_image_mask_changed (GimpImage *image)
/* image components */
const Babl *
gimp_image_get_component_format (const GimpImage *image,
GimpChannelType channel)
{
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
switch (channel)
{
case GIMP_RED_CHANNEL: return babl_format ("R u8");
case GIMP_GREEN_CHANNEL: return babl_format ("G u8");
case GIMP_BLUE_CHANNEL: return babl_format ("B u8");
case GIMP_GRAY_CHANNEL: return babl_format ("Y u8");
case GIMP_INDEXED_CHANNEL: return babl_format ("Y u8");
case GIMP_ALPHA_CHANNEL: return babl_format ("A u8");
}
return NULL;
}
gint
gimp_image_get_component_index (const GimpImage *image,
GimpChannelType channel)

View file

@ -237,6 +237,8 @@ void gimp_image_mask_changed (GimpImage *image);
/* image components */
const Babl * gimp_image_get_component_format (const GimpImage *image,
GimpChannelType channel);
gint gimp_image_get_component_index (const GimpImage *image,
GimpChannelType channel);

View file

@ -93,6 +93,21 @@ gimp_gegl_init (Gimp *gimp)
G_CALLBACK (gimp_gegl_notify_tile_cache_size),
NULL);
babl_format_new ("name", "R u8",
babl_model ("RGBA"),
babl_type ("u8"),
babl_component ("R"),
NULL);
babl_format_new ("name", "G u8",
babl_model ("RGBA"),
babl_type ("u8"),
babl_component ("G"),
NULL);
babl_format_new ("name", "B u8",
babl_model ("RGBA"),
babl_type ("u8"),
babl_component ("B"),
NULL);
babl_format_new ("name", "A u8",
babl_model ("RGBA"),
babl_type ("u8"),

View file

@ -106,7 +106,7 @@ channel_new_from_component_invoker (GimpProcedure *procedure,
if (success)
{
if (gimp_image_get_component_index (image, component) != -1)
if (gimp_image_get_component_format (image, component) != NULL)
channel = gimp_channel_new_from_component (image,
component, name, NULL);

View file

@ -161,7 +161,7 @@ HELP
%invoke = (
code => <<'CODE'
{
if (gimp_image_get_component_index (image, component) != -1)
if (gimp_image_get_component_format (image, component) != NULL)
channel = gimp_channel_new_from_component (image,
component, name, NULL);