app/paint-funcs/paint-funcs-generic.h implement copy_color() and

2006-05-16  Michael Natterer  <mitch@gimp.org>

	* app/paint-funcs/paint-funcs-generic.h
	* app/paint-funcs/paint-funcs.[ch]: implement copy_color() and
	copy_color_pixels() which copy only the color bytes into a dest
	that has one byte less than src. Renamed component_pixels() to
	copy_component_pixels().

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpbrushclipboard.[ch]: new GimpBrush subclass that
	auto-updates its contents from gimp->global_buffer.

	* app/core/gimp.c (gimp_real_initialize): add a clipboard brush to
	the brush factory. Fixes bug #111082.
This commit is contained in:
Michael Natterer 2006-05-16 13:11:47 +00:00 committed by Michael Natterer
parent a450ba46bb
commit d15a6191b6
9 changed files with 439 additions and 8 deletions

View File

@ -1,3 +1,19 @@
2006-05-16 Michael Natterer <mitch@gimp.org>
* app/paint-funcs/paint-funcs-generic.h
* app/paint-funcs/paint-funcs.[ch]: implement copy_color() and
copy_color_pixels() which copy only the color bytes into a dest
that has one byte less than src. Renamed component_pixels() to
copy_component_pixels().
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpbrushclipboard.[ch]: new GimpBrush subclass that
auto-updates its contents from gimp->global_buffer.
* app/core/gimp.c (gimp_real_initialize): add a clipboard brush to
the brush factory. Fixes bug #111082.
2006-05-16 Sven Neumann <sven@gimp.org>
* plug-ins/*/*.c: declared GimpPlugInInfo and GimpParamDef arrays

View File

@ -52,6 +52,8 @@ libappcore_a_sources = \
gimpbrush-header.h \
gimpbrush-load.c \
gimpbrush-load.h \
gimpbrushclipboard.c \
gimpbrushclipboard.h \
gimpbrushgenerated.c \
gimpbrushgenerated.h \
gimpbrushpipe.c \

View File

@ -87,7 +87,8 @@ typedef struct _GimpToolInfo GimpToolInfo;
typedef struct _GimpDataFactory GimpDataFactory;
typedef struct _GimpData GimpData;
typedef struct _GimpBrush GimpBrush;
typedef struct _GimpBrush GimpBrush;
typedef struct _GimpBrushClipboard GimpBrushClipboard;
typedef struct _GimpBrushGenerated GimpBrushGenerated;
typedef struct _GimpBrushPipe GimpBrushPipe;
typedef struct _GimpGradient GimpGradient;

View File

@ -51,6 +51,7 @@
#include "gimpbrush.h"
#include "gimpbrush-load.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushclipboard.h"
#include "gimpbrushpipe.h"
#include "gimpbuffer.h"
#include "gimpcontext.h"
@ -501,6 +502,8 @@ gimp_real_initialize (Gimp *gimp,
{ gimp_palette_load, NULL /* legacy loader */, TRUE }
};
GimpData *clipboard_brush;
if (gimp->be_verbose)
g_print ("INIT: gimp_real_initialize\n");
@ -564,6 +567,13 @@ gimp_real_initialize (Gimp *gimp,
/* add the builtin FG -> BG etc. gradients */
gimp_gradients_init (gimp);
/* add the clipboard brush */
clipboard_brush = gimp_brush_clipboard_new (gimp);
gimp_data_make_internal (GIMP_DATA (clipboard_brush));
gimp_container_add (gimp->brush_factory->container,
GIMP_OBJECT (clipboard_brush));
g_object_unref (clipboard_brush);
/* register all internal procedures */
status_callback (NULL, _("Internal Procedures"), 0.2);
gimp_pdb_init_procs (gimp);

View File

@ -0,0 +1,293 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpbrushclipboard.c
* Copyright (C) 2006 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "core-types.h"
#include "base/temp-buf.h"
#include "base/pixel-region.h"
#include "paint-funcs/paint-funcs.h"
#include "gimp.h"
#include "gimpbuffer.h"
#include "gimpbrushclipboard.h"
#include "gimpimage.h"
#include "gimppickable.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_GIMP
};
/* local function prototypes */
static GObject * gimp_brush_clipboard_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_brush_clipboard_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_brush_clipboard_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
#if 0
static GimpData * gimp_brush_clipboard_duplicate (GimpData *data);
#endif
static void gimp_brush_clipboard_buffer_changed (Gimp *gimp,
GimpBrush *brush);
G_DEFINE_TYPE (GimpBrushClipboard, gimp_brush_clipboard, GIMP_TYPE_BRUSH)
#define parent_class gimp_brush_clipboard_parent_class
static void
gimp_brush_clipboard_class_init (GimpBrushClipboardClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
#if 0
GimpDataClass *data_class = GIMP_DATA_CLASS (klass);
#endif
object_class->constructor = gimp_brush_clipboard_constructor;
object_class->set_property = gimp_brush_clipboard_set_property;
object_class->get_property = gimp_brush_clipboard_get_property;
#if 0
data_class->duplicate = gimp_brush_clipboard_duplicate;
#endif
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp", NULL, NULL,
GIMP_TYPE_GIMP,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_brush_clipboard_init (GimpBrushClipboard *brush)
{
brush->gimp = NULL;
}
static GObject *
gimp_brush_clipboard_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpBrushClipboard *brush;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
brush = GIMP_BRUSH_CLIPBOARD (object);
g_assert (GIMP_IS_GIMP (brush->gimp));
g_signal_connect_object (brush->gimp, "buffer-changed",
G_CALLBACK (gimp_brush_clipboard_buffer_changed),
brush, 0);
gimp_brush_clipboard_buffer_changed (brush->gimp, GIMP_BRUSH (brush));
return object;
}
static void
gimp_brush_clipboard_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (object);
switch (property_id)
{
case PROP_GIMP:
brush->gimp = GIMP (g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_brush_clipboard_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (object);
switch (property_id)
{
case PROP_GIMP:
g_value_set_object (value, brush->gimp);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
#if 0
static GimpData *
gimp_brush_clipboard_duplicate (GimpData *data)
{
GimpBrushClipboard *brush = GIMP_BRUSH_CLIPBOARD (data);
return gimp_brush_clipboard_new (brush->gimp);
}
#endif
GimpData *
gimp_brush_clipboard_new (Gimp *gimp)
{
GimpBrushClipboard *brush;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
brush = g_object_new (GIMP_TYPE_BRUSH_CLIPBOARD,
"name", _("Clipboard"),
"gimp", gimp,
NULL);
return GIMP_DATA (brush);
}
/* private functions */
static void
gimp_brush_clipboard_buffer_changed (Gimp *gimp,
GimpBrush *brush)
{
gint width;
gint height;
if (brush->mask)
{
temp_buf_free (brush->mask);
brush->mask = NULL;
}
if (brush->pixmap)
{
temp_buf_free (brush->pixmap);
brush->pixmap = NULL;
}
if (gimp->global_buffer)
{
TileManager *tiles = gimp->global_buffer->tiles;
GimpImageType type = gimp_buffer_get_image_type (gimp->global_buffer);
width = gimp_buffer_get_width (gimp->global_buffer);
height = gimp_buffer_get_height (gimp->global_buffer);
brush->mask = temp_buf_new (width, height, 1, 0, 0, NULL);
brush->pixmap = temp_buf_new (width, height, 3, 0, 0, NULL);
/* copy the alpha channel into the brush's mask */
if (GIMP_IMAGE_TYPE_HAS_ALPHA (type))
{
PixelRegion bufferPR;
PixelRegion maskPR;
pixel_region_init (&bufferPR, tiles,
0, 0, width, height, FALSE);
pixel_region_init_temp_buf (&maskPR, brush->mask,
0, 0, width, height);
extract_alpha_region (&bufferPR, NULL, &maskPR);
}
else
{
temp_buf_data_clear (brush->mask);
}
/* copy the color channels into the brush's pixmap */
if (GIMP_IMAGE_TYPE_IS_RGB (type))
{
PixelRegion bufferPR;
PixelRegion pixmapPR;
pixel_region_init (&bufferPR, tiles,
0, 0, width, height, FALSE);
pixel_region_init_temp_buf (&pixmapPR, brush->pixmap,
0, 0, width, height);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (type))
copy_color (&bufferPR, &pixmapPR);
else
copy_region (&bufferPR, &pixmapPR);
}
else
{
PixelRegion bufferPR;
PixelRegion tempPR;
TempBuf *temp = temp_buf_new (width, height, 1, 0, 0, NULL);
pixel_region_init (&bufferPR, tiles,
0, 0, width, height, FALSE);
pixel_region_init_temp_buf (&tempPR, temp,
0, 0, width, height);
if (GIMP_IMAGE_TYPE_HAS_ALPHA (type))
copy_component (&bufferPR, &tempPR, 0);
else
copy_region (&bufferPR, &tempPR);
temp_buf_copy (temp, brush->pixmap);
temp_buf_free (temp);
}
}
else
{
guchar color = 0;
width = 17;
height = 17;
brush->mask = temp_buf_new (width, height, 1, 0, 0, &color);
}
brush->x_axis.x = width / 2;
brush->x_axis.y = 0;
brush->y_axis.x = 0;
brush->y_axis.y = height / 2;
gimp_data_dirty (GIMP_DATA (brush));
}

View File

@ -0,0 +1,57 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpbrushclipboard.h
* Copyright (C) 2006 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_BRUSH_CLIPBOARD_H__
#define __GIMP_BRUSH_CLIPBOARD_H__
#include "gimpbrush.h"
#define GIMP_TYPE_BRUSH_CLIPBOARD (gimp_brush_clipboard_get_type ())
#define GIMP_BRUSH_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRUSH_CLIPBOARD, GimpBrushClipboard))
#define GIMP_BRUSH_CLIPBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_BRUSH_CLIPBOARD, GimpBrushClipboardClass))
#define GIMP_IS_BRUSH_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_BRUSH_CLIPBOARD))
#define GIMP_IS_BRUSH_CLIPBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_BRUSH_CLIPBOARD))
#define GIMP_BRUSH_CLIPBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BRUSH_CLIPBOARD, GimpBrushClipboardClass))
typedef struct _GimpBrushClipboardClass GimpBrushClipboardClass;
struct _GimpBrushClipboard
{
GimpBrush parent_instance;
Gimp *gimp;
};
struct _GimpBrushClipboardClass
{
GimpBrushClass parent_class;
};
GType gimp_brush_clipboard_get_type (void) G_GNUC_CONST;
GimpData * gimp_brush_clipboard_new (Gimp *gimp);
#endif /* __GIMP_BRUSH_CLIPBOARD_H__ */

View File

@ -1844,11 +1844,11 @@ initial_inten_a_pixels (const guchar *src,
}
inline void
component_pixels (const guchar *src,
guchar *dest,
guint length,
guint bytes,
guint pixel)
copy_component_pixels (const guchar *src,
guchar *dest,
guint length,
guint bytes,
guint pixel)
{
src += pixel;
@ -1861,6 +1861,26 @@ component_pixels (const guchar *src,
}
}
inline void
copy_color_pixels (const guchar *src,
guchar *dest,
guint length,
guint bytes)
{
const guint alpha = bytes - 1;
while (length --)
{
guint b;
for (b = 0; b < alpha; b++)
dest[b] = src[b];
src += bytes;
dest += bytes - 1;
}
}
static void
layer_normal_mode (struct apply_layer_mode_struct *alms)

View File

@ -4056,7 +4056,30 @@ copy_component (PixelRegion *src,
while (h--)
{
component_pixels (s, d, src->w, src->bytes, pixel);
copy_component_pixels (s, d, src->w, src->bytes, pixel);
s += src->rowstride;
d += dest->rowstride;
}
}
}
void
copy_color (PixelRegion *src,
PixelRegion *dest)
{
gpointer pr;
for (pr = pixel_regions_register (2, src, dest);
pr != NULL;
pr = pixel_regions_process (pr))
{
const guchar *s = src->data;
guchar *d = dest->data;
gint h = src->h;
while (h--)
{
copy_color_pixels (s, d, src->w, src->bytes);
s += src->rowstride;
d += dest->rowstride;
}

View File

@ -78,12 +78,17 @@ void gray_to_rgb_pixels (const guchar *src,
guint length,
guint bytes);
void component_pixels (const guchar *src,
void copy_component_pixels (const guchar *src,
guchar *dest,
guint length,
guint bytes,
guint pixel);
void copy_color_pixels (const guchar *src,
guchar *dest,
guint length,
guint bytes);
/* apply the mask data to the alpha channel of the pixel data */
void apply_mask_to_alpha_channel (guchar *src,
const guchar *mask,
@ -424,6 +429,10 @@ void copy_component (PixelRegion *src,
PixelRegion *dest,
guint pixel);
/* Copy the color bytes (without alpha channel) to a src_bytes-1 - byte region */
void copy_color (PixelRegion *src,
PixelRegion *dest);
void initial_region (PixelRegion *src,
PixelRegion *dest,
PixelRegion *mask,