added gimp_channel_new_from_component() which creates a new GimpChannel

2003-03-12  Sven Neumann  <sven@gimp.org>

	* app/core/gimpchannel.[ch]: added gimp_channel_new_from_component()
	which creates a new GimpChannel from an image's color component.

	* app/gui/channels-commands.[ch]: added
	channels_duplicate_component_cmd_callback().

	* app/paint-funcs/paint-funcs-generic.h
	* app/paint-funcs/paint-funcs.[ch]: added code to extract a color
	component from a PixelRegion (untested!).

	* plug-ins/common/checkerboard.c: cosmetics.
This commit is contained in:
Sven Neumann 2003-03-11 23:54:49 +00:00 committed by Sven Neumann
parent 833a02bdeb
commit 3c30a90bdb
13 changed files with 297 additions and 71 deletions

View File

@ -1,3 +1,17 @@
2003-03-12 Sven Neumann <sven@gimp.org>
* app/core/gimpchannel.[ch]: added gimp_channel_new_from_component()
which creates a new GimpChannel from an image's color component.
* app/gui/channels-commands.[ch]: added
channels_duplicate_component_cmd_callback().
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.[ch]: added code to extract a color
component from a PixelRegion (untested!).
* plug-ins/common/checkerboard.c: cosmetics.
2003-03-11 Michael Natterer <mitch@gimp.org> 2003-03-11 Michael Natterer <mitch@gimp.org>
* app/core/gimpimagefile.c (gimp_imagefile_create_thumbnail), * app/core/gimpimagefile.c (gimp_imagefile_create_thumbnail),

View File

@ -541,6 +541,25 @@ channels_edit_channel_query (GimpChannel *channel)
gtk_widget_show (options->query_box); gtk_widget_show (options->query_box);
} }
void
channels_duplicate_component_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *channel;
GimpRGB color;
return_if_no_image (gimage, data);
gimp_rgba_set (&color, 0, 0, 0, 0.5);
/* FIXME: hardcoded component */
channel = gimp_channel_new_from_component (gimage, GIMP_RED_CHANNEL,
"Component Copy",
&color);
gimp_image_add_channel (gimage, channel, -1);
gimp_image_flush (gimage);
}
/* private functions */ /* private functions */

View File

@ -46,5 +46,8 @@ void channels_new_channel_query (GimpImage *gimage,
gboolean interactive); gboolean interactive);
void channels_edit_channel_query (GimpChannel *channel); void channels_edit_channel_query (GimpChannel *channel);
void channels_duplicate_component_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __CHANNELS_COMMANDS_H__ */ #endif /* __CHANNELS_COMMANDS_H__ */

View File

@ -39,6 +39,7 @@
#include "paint-funcs/paint-funcs.h" #include "paint-funcs/paint-funcs.h"
#include "gimpimage.h" #include "gimpimage.h"
#include "gimpimage-projection.h"
#include "gimpimage-undo-push.h" #include "gimpimage-undo-push.h"
#include "gimpchannel.h" #include "gimpchannel.h"
#include "gimplayer.h" #include "gimplayer.h"
@ -272,6 +273,58 @@ gimp_channel_new (GimpImage *gimage,
return channel; return channel;
} }
GimpChannel *
gimp_channel_new_from_component (GimpImage *gimage,
GimpChannelType type,
const gchar *name,
const GimpRGB *color)
{
GimpChannel *channel;
TileManager *projection;
PixelRegion src;
PixelRegion dest;
gint width;
gint height;
gint pixel = -1;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (color != NULL, NULL);
switch (type)
{
case GIMP_RED_CHANNEL: pixel = RED_PIX; break;
case GIMP_GREEN_CHANNEL: pixel = GREEN_PIX; break;
case GIMP_BLUE_CHANNEL: pixel = BLUE_PIX; break;
case GIMP_GRAY_CHANNEL: pixel = GRAY_PIX; break;
case GIMP_INDEXED_CHANNEL: pixel = INDEXED_PIX; break;
case GIMP_ALPHA_CHANNEL:
switch (gimp_image_base_type (gimage))
{
case GIMP_RGB: pixel = ALPHA_PIX; break;
case GIMP_GRAY: pixel = ALPHA_G_PIX; break;
case GIMP_INDEXED: pixel = ALPHA_I_PIX; break;
}
break;
}
g_return_val_if_fail (pixel != -1, NULL);
projection = gimp_image_projection (gimage);
width = tile_manager_width (projection);
height = tile_manager_height (projection);
channel = gimp_channel_new (gimage, width, height, name, color);
pixel_region_init (&src, projection,
0, 0, width, height, FALSE);
pixel_region_init (&dest, GIMP_DRAWABLE (channel)->tiles,
0, 0, width, height, TRUE);
copy_component (&src, &dest, pixel);
return channel;
}
void void
gimp_channel_set_color (GimpChannel *channel, gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color) const GimpRGB *color)

View File

@ -70,36 +70,41 @@ struct _GimpChannelClass
/* function declarations */ /* function declarations */
GType gimp_channel_get_type (void) G_GNUC_CONST; GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage, GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width, gint width,
gint height, gint height,
const gchar *name, const gchar *name,
const GimpRGB *color); const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel); GimpChannel * gimp_channel_new_from_component (GimpImage *gimage,
void gimp_channel_set_opacity (GimpChannel *channel, GimpChannelType type,
gdouble opacity); const gchar *name,
const GimpRGB *color);
void gimp_channel_get_color (const GimpChannel *channel, gdouble gimp_channel_get_opacity (const GimpChannel *channel);
GimpRGB *color); void gimp_channel_set_opacity (GimpChannel *channel,
void gimp_channel_set_color (GimpChannel *channel, gdouble opacity);
const GimpRGB *color);
gboolean gimp_channel_get_show_masked (GimpChannel *channel); void gimp_channel_get_color (const GimpChannel *channel,
void gimp_channel_set_show_masked (GimpChannel *channel, GimpRGB *color);
gboolean show_masked); void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color);
void gimp_channel_scale (GimpChannel *channel, gboolean gimp_channel_get_show_masked (GimpChannel *channel);
gint new_width, void gimp_channel_set_show_masked (GimpChannel *channel,
gint new_height, gboolean show_masked);
GimpInterpolationType interpolation_type);
void gimp_channel_resize (GimpChannel *channel, void gimp_channel_scale (GimpChannel *channel,
gint new_width, gint new_width,
gint new_height, gint new_height,
gint offx, GimpInterpolationType interpolation_type);
gint offy); void gimp_channel_resize (GimpChannel *channel,
gint new_width,
gint new_height,
gint offx,
gint offy);
/* selection mask functions */ /* selection mask functions */

View File

@ -39,6 +39,7 @@
#include "paint-funcs/paint-funcs.h" #include "paint-funcs/paint-funcs.h"
#include "gimpimage.h" #include "gimpimage.h"
#include "gimpimage-projection.h"
#include "gimpimage-undo-push.h" #include "gimpimage-undo-push.h"
#include "gimpchannel.h" #include "gimpchannel.h"
#include "gimplayer.h" #include "gimplayer.h"
@ -272,6 +273,58 @@ gimp_channel_new (GimpImage *gimage,
return channel; return channel;
} }
GimpChannel *
gimp_channel_new_from_component (GimpImage *gimage,
GimpChannelType type,
const gchar *name,
const GimpRGB *color)
{
GimpChannel *channel;
TileManager *projection;
PixelRegion src;
PixelRegion dest;
gint width;
gint height;
gint pixel = -1;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (color != NULL, NULL);
switch (type)
{
case GIMP_RED_CHANNEL: pixel = RED_PIX; break;
case GIMP_GREEN_CHANNEL: pixel = GREEN_PIX; break;
case GIMP_BLUE_CHANNEL: pixel = BLUE_PIX; break;
case GIMP_GRAY_CHANNEL: pixel = GRAY_PIX; break;
case GIMP_INDEXED_CHANNEL: pixel = INDEXED_PIX; break;
case GIMP_ALPHA_CHANNEL:
switch (gimp_image_base_type (gimage))
{
case GIMP_RGB: pixel = ALPHA_PIX; break;
case GIMP_GRAY: pixel = ALPHA_G_PIX; break;
case GIMP_INDEXED: pixel = ALPHA_I_PIX; break;
}
break;
}
g_return_val_if_fail (pixel != -1, NULL);
projection = gimp_image_projection (gimage);
width = tile_manager_width (projection);
height = tile_manager_height (projection);
channel = gimp_channel_new (gimage, width, height, name, color);
pixel_region_init (&src, projection,
0, 0, width, height, FALSE);
pixel_region_init (&dest, GIMP_DRAWABLE (channel)->tiles,
0, 0, width, height, TRUE);
copy_component (&src, &dest, pixel);
return channel;
}
void void
gimp_channel_set_color (GimpChannel *channel, gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color) const GimpRGB *color)

View File

@ -70,36 +70,41 @@ struct _GimpChannelClass
/* function declarations */ /* function declarations */
GType gimp_channel_get_type (void) G_GNUC_CONST; GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage, GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width, gint width,
gint height, gint height,
const gchar *name, const gchar *name,
const GimpRGB *color); const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel); GimpChannel * gimp_channel_new_from_component (GimpImage *gimage,
void gimp_channel_set_opacity (GimpChannel *channel, GimpChannelType type,
gdouble opacity); const gchar *name,
const GimpRGB *color);
void gimp_channel_get_color (const GimpChannel *channel, gdouble gimp_channel_get_opacity (const GimpChannel *channel);
GimpRGB *color); void gimp_channel_set_opacity (GimpChannel *channel,
void gimp_channel_set_color (GimpChannel *channel, gdouble opacity);
const GimpRGB *color);
gboolean gimp_channel_get_show_masked (GimpChannel *channel); void gimp_channel_get_color (const GimpChannel *channel,
void gimp_channel_set_show_masked (GimpChannel *channel, GimpRGB *color);
gboolean show_masked); void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color);
void gimp_channel_scale (GimpChannel *channel, gboolean gimp_channel_get_show_masked (GimpChannel *channel);
gint new_width, void gimp_channel_set_show_masked (GimpChannel *channel,
gint new_height, gboolean show_masked);
GimpInterpolationType interpolation_type);
void gimp_channel_resize (GimpChannel *channel, void gimp_channel_scale (GimpChannel *channel,
gint new_width, gint new_width,
gint new_height, gint new_height,
gint offx, GimpInterpolationType interpolation_type);
gint offy); void gimp_channel_resize (GimpChannel *channel,
gint new_width,
gint new_height,
gint offx,
gint offy);
/* selection mask functions */ /* selection mask functions */

View File

@ -541,6 +541,25 @@ channels_edit_channel_query (GimpChannel *channel)
gtk_widget_show (options->query_box); gtk_widget_show (options->query_box);
} }
void
channels_duplicate_component_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *channel;
GimpRGB color;
return_if_no_image (gimage, data);
gimp_rgba_set (&color, 0, 0, 0, 0.5);
/* FIXME: hardcoded component */
channel = gimp_channel_new_from_component (gimage, GIMP_RED_CHANNEL,
"Component Copy",
&color);
gimp_image_add_channel (gimage, channel, -1);
gimp_image_flush (gimage);
}
/* private functions */ /* private functions */

View File

@ -46,5 +46,8 @@ void channels_new_channel_query (GimpImage *gimage,
gboolean interactive); gboolean interactive);
void channels_edit_channel_query (GimpChannel *channel); void channels_edit_channel_query (GimpChannel *channel);
void channels_duplicate_component_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __CHANNELS_COMMANDS_H__ */ #endif /* __CHANNELS_COMMANDS_H__ */

View File

@ -1562,6 +1562,25 @@ initial_inten_a_pixels (const guchar *src,
} }
} }
inline void
component_pixels (const guchar *src,
guchar *dest,
guint length,
guint bytes,
guint pixel)
{
src += pixel;
while (length --)
{
*dest = *src;
src += bytes;
dest++;
}
}
static void static void
layer_normal_mode (struct apply_layer_mode_struct *alms) layer_normal_mode (struct apply_layer_mode_struct *alms)
{ {

View File

@ -4182,6 +4182,32 @@ copy_gray_to_region (PixelRegion *src,
} }
} }
void
copy_component (PixelRegion *src,
PixelRegion *dest,
guint pixel)
{
gint h;
guchar *s;
guchar *d;
void *pr;
for (pr = pixel_regions_register (2, src, dest);
pr != NULL;
pr = pixel_regions_process (pr))
{
s = src->data;
d = dest->data;
h = src->h;
while (h --)
{
component_pixels (s, d, src->w, src->bytes, pixel);
s += src->rowstride;
d += dest->rowstride;
}
}
}
struct initial_regions_struct struct initial_regions_struct
{ {

View File

@ -340,6 +340,10 @@ void combine_mask_and_region (PixelRegion *, PixelRegion *, guint);
/* Copy a gray image to an intensity-alpha region */ /* Copy a gray image to an intensity-alpha region */
void copy_gray_to_region (PixelRegion *, PixelRegion *); void copy_gray_to_region (PixelRegion *, PixelRegion *);
/* Copy a component (indexed by pixel) to a 1-byte region */
void copy_component (PixelRegion *src,
PixelRegion *dest,
guint pixel);
void initial_region (PixelRegion *, PixelRegion *, void initial_region (PixelRegion *, PixelRegion *,
PixelRegion *, guchar *, PixelRegion *, guchar *,

View File

@ -55,16 +55,17 @@ static void run (gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals); GimpParam **return_vals);
static void do_checkerboard_pattern (GimpDrawable *drawable); static void do_checkerboard_pattern (GimpDrawable *drawable);
static gint inblock (gint pos, static gint inblock (gint pos,
gint size); gint size);
static gboolean do_checkerboard_dialog (gint32 image_ID, static gboolean do_checkerboard_dialog (gint32 image_ID,
GimpDrawable *drawable); GimpDrawable *drawable);
static void check_ok_callback (GtkWidget *widget, static void check_ok_callback (GtkWidget *widget,
gpointer data); gpointer data);
static void check_size_update_callback (GtkWidget *widget,
gpointer data);
static void check_size_update_callback(GtkWidget * widget, gpointer data);
GimpPlugInInfo PLUG_IN_INFO = GimpPlugInInfo PLUG_IN_INFO =
{ {
@ -206,7 +207,7 @@ do_checkerboard_pattern (GimpDrawable *drawable)
gimp_pixel_rgn_init (&dest_rgn, drawable, gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE); x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
progress = 0; progress = 0;
max_progress = (x2 - x1) * (y2 - y1); max_progress = (x2 - x1) * (y2 - y1);
/* Get the foreground and background colors */ /* Get the foreground and background colors */
@ -237,12 +238,12 @@ do_checkerboard_pattern (GimpDrawable *drawable)
} }
if (cvals.size == 0) if (cvals.size < 1)
{ {
/* make size 1 to prevent division by zero */ /* make size 1 to prevent division by zero */
cvals.size = 1; cvals.size = 1;
} }
for (pr = gimp_pixel_rgns_register (1, &dest_rgn); for (pr = gimp_pixel_rgns_register (1, &dest_rgn);
pr != NULL; pr != NULL;
pr = gimp_pixel_rgns_process (pr)) pr = gimp_pixel_rgns_process (pr))
@ -262,8 +263,8 @@ do_checkerboard_pattern (GimpDrawable *drawable)
if (cvals.mode) if (cvals.mode)
{ {
/* Psychobilly Mode */ /* Psychobilly Mode */
val = val = ((inblock (x, cvals.size) == inblock (y, cvals.size))
(inblock (x, cvals.size) == inblock (y, cvals.size)) ? 0 : 1; ? 0 : 1);
} }
else else
{ {
@ -271,11 +272,13 @@ do_checkerboard_pattern (GimpDrawable *drawable)
* Determine base factor (even or odd) of block * Determine base factor (even or odd) of block
* this x/y position is in. * this x/y position is in.
*/ */
xp = x/cvals.size; xp = x / cvals.size;
yp = y/cvals.size; yp = y / cvals.size;
/* if both even or odd, color sqr */ /* if both even or odd, color sqr */
val = ( (xp&1) == (yp&1) ) ? 0 : 1; val = ( (xp&1) == (yp&1) ) ? 0 : 1;
} }
for (bp = 0; bp < dest_rgn.bpp; bp++) for (bp = 0; bp < dest_rgn.bpp; bp++)
dest[bp] = val ? fg[bp] : bg[bp]; dest[bp] = val ? fg[bp] : bg[bp];
@ -300,8 +303,8 @@ static gint
inblock (gint pos, inblock (gint pos,
gint size) gint size)
{ {
static gint *in = NULL; /* initialized first time */ static gint *in = NULL; /* initialized first time */
gint len; gint len;
/* avoid a FP exception */ /* avoid a FP exception */
if (size == 1) if (size == 1)