Commit 3c30a90b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

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.
parent 833a02bd
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>
* app/core/gimpimagefile.c (gimp_imagefile_create_thumbnail),
......@@ -541,6 +541,25 @@ channels_edit_channel_query (GimpChannel *channel)
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 */
......
......@@ -46,5 +46,8 @@ void channels_new_channel_query (GimpImage *gimage,
gboolean interactive);
void channels_edit_channel_query (GimpChannel *channel);
void channels_duplicate_component_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __CHANNELS_COMMANDS_H__ */
......@@ -39,6 +39,7 @@
#include "paint-funcs/paint-funcs.h"
#include "gimpimage.h"
#include "gimpimage-projection.h"
#include "gimpimage-undo-push.h"
#include "gimpchannel.h"
#include "gimplayer.h"
......@@ -272,6 +273,58 @@ gimp_channel_new (GimpImage *gimage,
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
gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color)
......
......@@ -70,36 +70,41 @@ struct _GimpChannelClass
/* function declarations */
GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
gdouble opacity);
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color);
gboolean gimp_channel_get_show_masked (GimpChannel *channel);
void gimp_channel_set_show_masked (GimpChannel *channel,
gboolean show_masked);
void gimp_channel_scale (GimpChannel *channel,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type);
void gimp_channel_resize (GimpChannel *channel,
gint new_width,
gint new_height,
gint offx,
gint offy);
GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
const GimpRGB *color);
GimpChannel * gimp_channel_new_from_component (GimpImage *gimage,
GimpChannelType type,
const gchar *name,
const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
gdouble opacity);
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color);
gboolean gimp_channel_get_show_masked (GimpChannel *channel);
void gimp_channel_set_show_masked (GimpChannel *channel,
gboolean show_masked);
void gimp_channel_scale (GimpChannel *channel,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type);
void gimp_channel_resize (GimpChannel *channel,
gint new_width,
gint new_height,
gint offx,
gint offy);
/* selection mask functions */
......
......@@ -39,6 +39,7 @@
#include "paint-funcs/paint-funcs.h"
#include "gimpimage.h"
#include "gimpimage-projection.h"
#include "gimpimage-undo-push.h"
#include "gimpchannel.h"
#include "gimplayer.h"
......@@ -272,6 +273,58 @@ gimp_channel_new (GimpImage *gimage,
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
gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color)
......
......@@ -70,36 +70,41 @@ struct _GimpChannelClass
/* function declarations */
GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
gdouble opacity);
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color);
gboolean gimp_channel_get_show_masked (GimpChannel *channel);
void gimp_channel_set_show_masked (GimpChannel *channel,
gboolean show_masked);
void gimp_channel_scale (GimpChannel *channel,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type);
void gimp_channel_resize (GimpChannel *channel,
gint new_width,
gint new_height,
gint offx,
gint offy);
GType gimp_channel_get_type (void) G_GNUC_CONST;
GimpChannel * gimp_channel_new (GimpImage *gimage,
gint width,
gint height,
const gchar *name,
const GimpRGB *color);
GimpChannel * gimp_channel_new_from_component (GimpImage *gimage,
GimpChannelType type,
const gchar *name,
const GimpRGB *color);
gdouble gimp_channel_get_opacity (const GimpChannel *channel);
void gimp_channel_set_opacity (GimpChannel *channel,
gdouble opacity);
void gimp_channel_get_color (const GimpChannel *channel,
GimpRGB *color);
void gimp_channel_set_color (GimpChannel *channel,
const GimpRGB *color);
gboolean gimp_channel_get_show_masked (GimpChannel *channel);
void gimp_channel_set_show_masked (GimpChannel *channel,
gboolean show_masked);
void gimp_channel_scale (GimpChannel *channel,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type);
void gimp_channel_resize (GimpChannel *channel,
gint new_width,
gint new_height,
gint offx,
gint offy);
/* selection mask functions */
......
......@@ -541,6 +541,25 @@ channels_edit_channel_query (GimpChannel *channel)
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 */
......
......@@ -46,5 +46,8 @@ void channels_new_channel_query (GimpImage *gimage,
gboolean interactive);
void channels_edit_channel_query (GimpChannel *channel);
void channels_duplicate_component_cmd_callback (GtkWidget *widget,
gpointer data);
#endif /* __CHANNELS_COMMANDS_H__ */
......@@ -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
layer_normal_mode (struct apply_layer_mode_struct *alms)
{
......
......@@ -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
{
......
......@@ -340,6 +340,10 @@ void combine_mask_and_region (PixelRegion *, PixelRegion *, guint);
/* Copy a gray image to an intensity-alpha region */
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 *,
PixelRegion *, guchar *,
......
......@@ -55,16 +55,17 @@ static void run (gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static void do_checkerboard_pattern (GimpDrawable *drawable);
static gint inblock (gint pos,
gint size);
static void do_checkerboard_pattern (GimpDrawable *drawable);
static gint inblock (gint pos,
gint size);
static gboolean do_checkerboard_dialog (gint32 image_ID,
GimpDrawable *drawable);
static void check_ok_callback (GtkWidget *widget,
gpointer data);
static gboolean do_checkerboard_dialog (gint32 image_ID,
GimpDrawable *drawable);
static void check_ok_callback (GtkWidget *widget,
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 =
{
......@@ -206,7 +207,7 @@ do_checkerboard_pattern (GimpDrawable *drawable)
gimp_pixel_rgn_init (&dest_rgn, drawable,
x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
progress = 0;
progress = 0;
max_progress = (x2 - x1) * (y2 - y1);
/* Get the foreground and background colors */
......@@ -237,12 +238,12 @@ do_checkerboard_pattern (GimpDrawable *drawable)
}
if (cvals.size == 0)
{
/* make size 1 to prevent division by zero */
cvals.size = 1;
}
if (cvals.size < 1)
{
/* make size 1 to prevent division by zero */
cvals.size = 1;
}
for (pr = gimp_pixel_rgns_register (1, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
......@@ -262,8 +263,8 @@ do_checkerboard_pattern (GimpDrawable *drawable)
if (cvals.mode)
{
/* Psychobilly Mode */
val =
(inblock (x, cvals.size) == inblock (y, cvals.size)) ? 0 : 1;
val = ((inblock (x, cvals.size) == inblock (y, cvals.size))
? 0 : 1);
}
else
{
......@@ -271,11 +272,13 @@ do_checkerboard_pattern (GimpDrawable *drawable)
* Determine base factor (even or odd) of block
* this x/y position is in.
*/
xp = x/cvals.size;
yp = y/cvals.size;
xp = x / cvals.size;
yp = y / cvals.size;
/* if both even or odd, color sqr */
val = ( (xp&1) == (yp&1) ) ? 0 : 1;
}
for (bp = 0; bp < dest_rgn.bpp; bp++)
dest[bp] = val ? fg[bp] : bg[bp];
......@@ -300,8 +303,8 @@ static gint
inblock (gint pos,
gint size)
{
static gint *in = NULL; /* initialized first time */
gint len;
static gint *in = NULL; /* initialized first time */
gint len;
/* avoid a FP exception */
if (size == 1)
......
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