app: move all GimpBrush members to a private struct

Add and use accessors for width, height, x_axis and y_axis.
This commit is contained in:
Michael Natterer 2014-10-12 01:16:32 +02:00
parent 13a626a304
commit 5d8824f42e
20 changed files with 345 additions and 240 deletions

View File

@ -68,6 +68,7 @@ libappcore_a_sources = \
gimpbrush-header.h \
gimpbrush-load.c \
gimpbrush-load.h \
gimpbrush-private.h \
gimpbrush-transform.c \
gimpbrush-transform.h \
gimpbrushcache.c \

View File

@ -29,6 +29,7 @@
#include "gimpbrush.h"
#include "gimpbrush-header.h"
#include "gimpbrush-load.h"
#include "gimpbrush-private.h"
#include "gimptempbuf.h"
#include "gimp-intl.h"
@ -256,10 +257,10 @@ gimp_brush_load_brush (GimpContext *context,
NULL);
g_free (name);
brush->mask = gimp_temp_buf_new (header.width, header.height,
babl_format ("Y u8"));
brush->priv->mask = gimp_temp_buf_new (header.width, header.height,
babl_format ("Y u8"));
mask = gimp_temp_buf_get_data (brush->mask);
mask = gimp_temp_buf_get_data (brush->priv->mask);
size = header.width * header.height * header.bytes;
switch (header.bytes)
@ -332,9 +333,9 @@ gimp_brush_load_brush (GimpContext *context,
{
guchar buf[8 * 1024];
brush->pixmap = gimp_temp_buf_new (header.width, header.height,
babl_format ("R'G'B' u8"));
pixmap = gimp_temp_buf_get_data (brush->pixmap);
brush->priv->pixmap = gimp_temp_buf_new (header.width, header.height,
babl_format ("R'G'B' u8"));
pixmap = gimp_temp_buf_get_data (brush->priv->pixmap);
for (i = 0; success && i < size;)
{
@ -379,11 +380,11 @@ gimp_brush_load_brush (GimpContext *context,
return NULL;
}
brush->spacing = header.spacing;
brush->x_axis.x = header.width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = header.height / 2.0;
brush->priv->spacing = header.spacing;
brush->priv->x_axis.x = header.width / 2.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = header.height / 2.0;
return brush;
}
@ -667,15 +668,15 @@ gimp_brush_load_abr_brush_v12 (GDataInputStream *input,
g_free (name);
brush->spacing = abr_sampled_brush_hdr.spacing;
brush->x_axis.x = width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = height / 2.0;
brush->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
brush->priv->spacing = abr_sampled_brush_hdr.spacing;
brush->priv->x_axis.x = width / 2.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = height / 2.0;
brush->priv->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
mask = gimp_temp_buf_get_data (brush->mask);
mask = gimp_temp_buf_get_data (brush->priv->mask);
size = width * height * bytes;
compress = abr_read_char (input, error);
@ -809,15 +810,15 @@ gimp_brush_load_abr_brush_v6 (GDataInputStream *input,
g_free (name);
brush->spacing = 25; /* real value needs 8BIMdesc section parser */
brush->x_axis.x = width / 2.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = height / 2.0;
brush->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
brush->priv->spacing = 25; /* real value needs 8BIMdesc section parser */
brush->priv->x_axis.x = width / 2.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = height / 2.0;
brush->priv->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
mask = gimp_temp_buf_get_data (brush->mask);
mask = gimp_temp_buf_get_data (brush->priv->mask);
/* data decoding */
if (! compress)

View File

@ -0,0 +1,38 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GIMP_BRUSH_PRIVATE_H__
#define __GIMP_BRUSH_PRIVATE_H__
struct _GimpBrushPrivate
{
GimpTempBuf *mask; /* the actual mask */
GimpTempBuf *pixmap; /* optional pixmap data */
gint spacing; /* brush's spacing */
GimpVector2 x_axis; /* for calculating brush spacing */
GimpVector2 y_axis; /* for calculating brush spacing */
gint use_count; /* for keeping the caches alive */
GimpBrushCache *mask_cache;
GimpBrushCache *pixmap_cache;
GimpBrushCache *boundary_cache;
};
#endif /* __GIMP_BRUSH_PRIVATE_H__ */

View File

@ -38,7 +38,7 @@
/* local function prototypes */
static void gimp_brush_transform_bounding_box (GimpTempBuf *brush,
static void gimp_brush_transform_bounding_box (GimpBrush *brush,
const GimpMatrix3 *matrix,
gint *x,
gint *y,
@ -67,11 +67,11 @@ gimp_brush_real_transform_size (GimpBrush *brush,
GimpMatrix3 matrix;
gint x, y;
gimp_brush_transform_matrix (gimp_temp_buf_get_width (brush->mask),
gimp_temp_buf_get_height (brush->mask),
gimp_brush_transform_matrix (gimp_brush_get_width (brush),
gimp_brush_get_height (brush),
scale, aspect_ratio, angle, &matrix);
gimp_brush_transform_bounding_box (brush->mask, &matrix, &x, &y, width, height);
gimp_brush_transform_bounding_box (brush, &matrix, &x, &y, width, height);
}
/*
@ -172,10 +172,10 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
*/
const guint fraction_bitmask = pow(2, fraction_bits) - 1 ;
source = brush->mask;
source = gimp_brush_get_mask (brush);
src_width = gimp_temp_buf_get_width (source);
src_height = gimp_temp_buf_get_height (source);
src_width = gimp_brush_get_width (brush);
src_height = gimp_brush_get_height (brush);
gimp_brush_transform_matrix (src_width, src_height,
scale, aspect_ratio, angle, &matrix);
@ -186,13 +186,13 @@ gimp_brush_real_transform_mask (GimpBrush *brush,
src_width_minus_one = src_width - 1;
src_height_minus_one = src_height - 1;
gimp_brush_transform_bounding_box (source, &matrix,
gimp_brush_transform_bounding_box (brush, &matrix,
&x, &y, &dest_width, &dest_height);
gimp_matrix3_translate (&matrix, -x, -y);
gimp_matrix3_invert (&matrix);
result = gimp_temp_buf_new (dest_width, dest_height,
gimp_temp_buf_get_format (brush->mask));
gimp_temp_buf_get_format (source));
dest = gimp_temp_buf_get_data (result);
src = gimp_temp_buf_get_data (source);
@ -471,10 +471,10 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
*/
const guint fraction_bitmask = pow(2, fraction_bits)- 1 ;
source = brush->pixmap;
source = gimp_brush_get_pixmap (brush);
src_width = gimp_temp_buf_get_width (source);
src_height = gimp_temp_buf_get_height (source);
src_width = gimp_brush_get_width (brush);
src_height = gimp_brush_get_height (brush);
gimp_brush_transform_matrix (src_width, src_height,
scale, aspect_ratio, angle, &matrix);
@ -485,13 +485,13 @@ gimp_brush_real_transform_pixmap (GimpBrush *brush,
src_width_minus_one = src_width - 1;
src_height_minus_one = src_height - 1;
gimp_brush_transform_bounding_box (source, &matrix,
gimp_brush_transform_bounding_box (brush, &matrix,
&x, &y, &dest_width, &dest_height);
gimp_matrix3_translate (&matrix, -x, -y);
gimp_matrix3_invert (&matrix);
result = gimp_temp_buf_new (dest_width, dest_height,
gimp_temp_buf_get_format (brush->pixmap));
gimp_temp_buf_get_format (source));
dest = gimp_temp_buf_get_data (result);
src = gimp_temp_buf_get_data (source);
@ -683,8 +683,8 @@ gimp_brush_transform_matrix (gdouble width,
{
const gdouble center_x = width / 2;
const gdouble center_y = height / 2;
gdouble scale_x = scale;
gdouble scale_y = scale;
gdouble scale_x = scale;
gdouble scale_y = scale;
if (aspect_ratio < 0.0)
{
@ -708,15 +708,15 @@ gimp_brush_transform_matrix (gdouble width,
/* private functions */
static void
gimp_brush_transform_bounding_box (GimpTempBuf *brush,
gimp_brush_transform_bounding_box (GimpBrush *brush,
const GimpMatrix3 *matrix,
gint *x,
gint *y,
gint *width,
gint *height)
{
const gdouble w = gimp_temp_buf_get_width (brush);
const gdouble h = gimp_temp_buf_get_height (brush);
const gdouble w = gimp_brush_get_width (brush);
const gdouble h = gimp_brush_get_height (brush);
gdouble x1, x2, x3, x4;
gdouble y1, y2, y3, y4;
gdouble temp_x;

View File

@ -30,6 +30,7 @@
#include "gimpbrush.h"
#include "gimpbrush-boundary.h"
#include "gimpbrush-load.h"
#include "gimpbrush-private.h"
#include "gimpbrush-transform.h"
#include "gimpbrushcache.h"
#include "gimpbrushgenerated.h"
@ -149,6 +150,8 @@ gimp_brush_class_init (GimpBrushClass *klass)
1.0, 5000.0, 20.0,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_type_class_add_private (klass, sizeof (GimpBrushPrivate));
}
static void
@ -160,14 +163,15 @@ gimp_brush_tagged_iface_init (GimpTaggedInterface *iface)
static void
gimp_brush_init (GimpBrush *brush)
{
brush->mask = NULL;
brush->pixmap = NULL;
brush->priv = G_TYPE_INSTANCE_GET_PRIVATE (brush,
GIMP_TYPE_BRUSH,
GimpBrushPrivate);
brush->spacing = 20;
brush->x_axis.x = 15.0;
brush->x_axis.y = 0.0;
brush->y_axis.x = 0.0;
brush->y_axis.y = 15.0;
brush->priv->spacing = 20;
brush->priv->x_axis.x = 15.0;
brush->priv->x_axis.y = 0.0;
brush->priv->y_axis.x = 0.0;
brush->priv->y_axis.y = 15.0;
}
static void
@ -175,34 +179,34 @@ gimp_brush_finalize (GObject *object)
{
GimpBrush *brush = GIMP_BRUSH (object);
if (brush->mask)
if (brush->priv->mask)
{
gimp_temp_buf_unref (brush->mask);
brush->mask = NULL;
gimp_temp_buf_unref (brush->priv->mask);
brush->priv->mask = NULL;
}
if (brush->pixmap)
if (brush->priv->pixmap)
{
gimp_temp_buf_unref (brush->pixmap);
brush->pixmap = NULL;
gimp_temp_buf_unref (brush->priv->pixmap);
brush->priv->pixmap = NULL;
}
if (brush->mask_cache)
if (brush->priv->mask_cache)
{
g_object_unref (brush->mask_cache);
brush->mask_cache = NULL;
g_object_unref (brush->priv->mask_cache);
brush->priv->mask_cache = NULL;
}
if (brush->pixmap_cache)
if (brush->priv->pixmap_cache)
{
g_object_unref (brush->pixmap_cache);
brush->pixmap_cache = NULL;
g_object_unref (brush->priv->pixmap_cache);
brush->priv->pixmap_cache = NULL;
}
if (brush->boundary_cache)
if (brush->priv->boundary_cache)
{
g_object_unref (brush->boundary_cache);
brush->boundary_cache = NULL;
g_object_unref (brush->priv->boundary_cache);
brush->priv->boundary_cache = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@ -239,7 +243,7 @@ gimp_brush_get_property (GObject *object,
switch (property_id)
{
case PROP_SPACING:
g_value_set_double (value, brush->spacing);
g_value_set_double (value, gimp_brush_get_spacing (brush));
break;
default:
@ -255,8 +259,8 @@ gimp_brush_get_memsize (GimpObject *object,
GimpBrush *brush = GIMP_BRUSH (object);
gint64 memsize = 0;
memsize += gimp_temp_buf_get_memsize (brush->mask);
memsize += gimp_temp_buf_get_memsize (brush->pixmap);
memsize += gimp_temp_buf_get_memsize (brush->priv->mask);
memsize += gimp_temp_buf_get_memsize (brush->priv->pixmap);
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
@ -269,8 +273,8 @@ gimp_brush_get_size (GimpViewable *viewable,
{
GimpBrush *brush = GIMP_BRUSH (viewable);
*width = gimp_temp_buf_get_width (brush->mask);
*height = gimp_temp_buf_get_height (brush->mask);
*width = gimp_temp_buf_get_width (brush->priv->mask);
*height = gimp_temp_buf_get_height (brush->priv->mask);
return TRUE;
}
@ -282,8 +286,8 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
gint height)
{
GimpBrush *brush = GIMP_BRUSH (viewable);
const GimpTempBuf *mask_buf = NULL;
const GimpTempBuf *pixmap_buf = NULL;
const GimpTempBuf *mask_buf = brush->priv->mask;
const GimpTempBuf *pixmap_buf = brush->priv->pixmap;
GimpTempBuf *return_buf = NULL;
gint mask_width;
gint mask_height;
@ -292,9 +296,6 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
gint x, y;
gboolean scaled = FALSE;
mask_buf = brush->mask;
pixmap_buf = brush->pixmap;
mask_width = gimp_temp_buf_get_width (mask_buf);
mask_height = gimp_temp_buf_get_height (mask_buf);
@ -386,8 +387,8 @@ gimp_brush_get_description (GimpViewable *viewable,
return g_strdup_printf ("%s (%d × %d)",
gimp_object_get_name (brush),
gimp_temp_buf_get_width (brush->mask),
gimp_temp_buf_get_height (brush->mask));
gimp_temp_buf_get_width (brush->priv->mask),
gimp_temp_buf_get_height (brush->priv->mask));
}
static void
@ -395,14 +396,14 @@ gimp_brush_dirty (GimpData *data)
{
GimpBrush *brush = GIMP_BRUSH (data);
if (brush->mask_cache)
gimp_brush_cache_clear (brush->mask_cache);
if (brush->priv->mask_cache)
gimp_brush_cache_clear (brush->priv->mask_cache);
if (brush->pixmap_cache)
gimp_brush_cache_clear (brush->pixmap_cache);
if (brush->priv->pixmap_cache)
gimp_brush_cache_clear (brush->priv->pixmap_cache);
if (brush->boundary_cache)
gimp_brush_cache_clear (brush->boundary_cache);
if (brush->priv->boundary_cache)
gimp_brush_cache_clear (brush->priv->boundary_cache);
GIMP_DATA_CLASS (parent_class)->dirty (data);
}
@ -416,27 +417,27 @@ gimp_brush_get_extension (GimpData *data)
static void
gimp_brush_real_begin_use (GimpBrush *brush)
{
brush->mask_cache =
brush->priv->mask_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_unref, 'M', 'm');
brush->pixmap_cache =
brush->priv->pixmap_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_temp_buf_unref, 'P', 'p');
brush->boundary_cache =
brush->priv->boundary_cache =
gimp_brush_cache_new ((GDestroyNotify) gimp_bezier_desc_free, 'B', 'b');
}
static void
gimp_brush_real_end_use (GimpBrush *brush)
{
g_object_unref (brush->mask_cache);
brush->mask_cache = NULL;
g_object_unref (brush->priv->mask_cache);
brush->priv->mask_cache = NULL;
g_object_unref (brush->pixmap_cache);
brush->pixmap_cache = NULL;
g_object_unref (brush->priv->pixmap_cache);
brush->priv->pixmap_cache = NULL;
g_object_unref (brush->boundary_cache);
brush->boundary_cache = NULL;
g_object_unref (brush->priv->boundary_cache);
brush->priv->boundary_cache = NULL;
}
static GimpBrush *
@ -461,20 +462,26 @@ gimp_brush_get_checksum (GimpTagged *tagged)
GimpBrush *brush = GIMP_BRUSH (tagged);
gchar *checksum_string = NULL;
if (brush->mask)
if (brush->priv->mask)
{
GChecksum *checksum = g_checksum_new (G_CHECKSUM_MD5);
g_checksum_update (checksum, gimp_temp_buf_get_data (brush->mask),
gimp_temp_buf_get_data_size (brush->mask));
if (brush->pixmap)
g_checksum_update (checksum, gimp_temp_buf_get_data (brush->pixmap),
gimp_temp_buf_get_data_size (brush->pixmap));
g_checksum_update (checksum, (const guchar *) &brush->spacing, sizeof (brush->spacing));
g_checksum_update (checksum, (const guchar *) &brush->x_axis, sizeof (brush->x_axis));
g_checksum_update (checksum, (const guchar *) &brush->y_axis, sizeof (brush->y_axis));
checksum_string = g_strdup (g_checksum_get_string (checksum));
g_checksum_update (checksum,
gimp_temp_buf_get_data (brush->priv->mask),
gimp_temp_buf_get_data_size (brush->priv->mask));
if (brush->priv->pixmap)
g_checksum_update (checksum,
gimp_temp_buf_get_data (brush->priv->pixmap),
gimp_temp_buf_get_data_size (brush->priv->pixmap));
g_checksum_update (checksum,
(const guchar *) &brush->priv->spacing,
sizeof (brush->priv->spacing));
g_checksum_update (checksum,
(const guchar *) &brush->priv->x_axis,
sizeof (brush->priv->x_axis));
g_checksum_update (checksum,
(const guchar *) &brush->priv->y_axis,
sizeof (brush->priv->y_axis));
g_checksum_free (checksum);
}
@ -519,9 +526,9 @@ gimp_brush_begin_use (GimpBrush *brush)
{
g_return_if_fail (GIMP_IS_BRUSH (brush));
brush->use_count++;
brush->priv->use_count++;
if (brush->use_count == 1)
if (brush->priv->use_count == 1)
GIMP_BRUSH_GET_CLASS (brush)->begin_use (brush);
}
@ -529,11 +536,11 @@ void
gimp_brush_end_use (GimpBrush *brush)
{
g_return_if_fail (GIMP_IS_BRUSH (brush));
g_return_if_fail (brush->use_count > 0);
g_return_if_fail (brush->priv->use_count > 0);
brush->use_count--;
brush->priv->use_count--;
if (brush->use_count == 0)
if (brush->priv->use_count == 0)
GIMP_BRUSH_GET_CLASS (brush)->end_use (brush);
}
@ -582,8 +589,8 @@ gimp_brush_transform_size (GimpBrush *brush,
aspect_ratio == 0.0 &&
((angle == 0.0) || (angle == 0.5) || (angle == 1.0)))
{
*width = gimp_temp_buf_get_width (brush->mask);
*height = gimp_temp_buf_get_height (brush->mask);;
*width = gimp_temp_buf_get_width (brush->priv->mask);
*height = gimp_temp_buf_get_height (brush->priv->mask);;
return;
}
@ -611,7 +618,7 @@ gimp_brush_transform_mask (GimpBrush *brush,
scale, aspect_ratio, angle,
&width, &height);
mask = gimp_brush_cache_get (brush->mask_cache,
mask = gimp_brush_cache_get (brush->priv->mask_cache,
width, height,
scale, aspect_ratio, angle, hardness);
@ -622,7 +629,7 @@ gimp_brush_transform_mask (GimpBrush *brush,
angle == 0.0 &&
hardness == 1.0)
{
mask = gimp_temp_buf_copy (brush->mask);
mask = gimp_temp_buf_copy (brush->priv->mask);
}
else
{
@ -633,7 +640,7 @@ gimp_brush_transform_mask (GimpBrush *brush,
hardness);
}
gimp_brush_cache_add (brush->mask_cache,
gimp_brush_cache_add (brush->priv->mask_cache,
(gpointer) mask,
width, height,
scale, aspect_ratio, angle, hardness);
@ -654,14 +661,14 @@ gimp_brush_transform_pixmap (GimpBrush *brush,
gint height;
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
g_return_val_if_fail (brush->pixmap != NULL, NULL);
g_return_val_if_fail (brush->priv->pixmap != NULL, NULL);
g_return_val_if_fail (scale > 0.0, NULL);
gimp_brush_transform_size (brush,
scale, aspect_ratio, angle,
&width, &height);
pixmap = gimp_brush_cache_get (brush->pixmap_cache,
pixmap = gimp_brush_cache_get (brush->priv->pixmap_cache,
width, height,
scale, aspect_ratio, angle, hardness);
@ -672,7 +679,7 @@ gimp_brush_transform_pixmap (GimpBrush *brush,
angle == 0.0 &&
hardness == 1.0)
{
pixmap = gimp_temp_buf_copy (brush->pixmap);
pixmap = gimp_temp_buf_copy (brush->priv->pixmap);
}
else
{
@ -683,7 +690,7 @@ gimp_brush_transform_pixmap (GimpBrush *brush,
hardness);
}
gimp_brush_cache_add (brush->pixmap_cache,
gimp_brush_cache_add (brush->priv->pixmap_cache,
(gpointer) pixmap,
width, height,
scale, aspect_ratio, angle, hardness);
@ -712,7 +719,7 @@ gimp_brush_transform_boundary (GimpBrush *brush,
scale, aspect_ratio, angle,
width, height);
boundary = gimp_brush_cache_get (brush->boundary_cache,
boundary = gimp_brush_cache_get (brush->priv->boundary_cache,
*width, *height,
scale, aspect_ratio, angle, hardness);
@ -733,7 +740,7 @@ gimp_brush_transform_boundary (GimpBrush *brush,
* properly implemented
*/
if (boundary)
gimp_brush_cache_add (brush->boundary_cache,
gimp_brush_cache_add (brush->priv->boundary_cache,
(gpointer) boundary,
*width, *height,
scale, aspect_ratio, angle, hardness);
@ -748,7 +755,7 @@ gimp_brush_get_mask (const GimpBrush *brush)
g_return_val_if_fail (brush != NULL, NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->mask;
return brush->priv->mask;
}
GimpTempBuf *
@ -757,7 +764,23 @@ gimp_brush_get_pixmap (const GimpBrush *brush)
g_return_val_if_fail (brush != NULL, NULL);
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
return brush->pixmap;
return brush->priv->pixmap;
}
gint
gimp_brush_get_width (const GimpBrush *brush)
{
g_return_val_if_fail (GIMP_IS_BRUSH (brush), 0);
return gimp_temp_buf_get_width (brush->priv->mask);
}
gint
gimp_brush_get_height (const GimpBrush *brush)
{
g_return_val_if_fail (GIMP_IS_BRUSH (brush), 0);
return gimp_temp_buf_get_height (brush->priv->mask);
}
gint
@ -765,7 +788,7 @@ gimp_brush_get_spacing (const GimpBrush *brush)
{
g_return_val_if_fail (GIMP_IS_BRUSH (brush), 0);
return brush->spacing;
return brush->priv->spacing;
}
void
@ -774,11 +797,29 @@ gimp_brush_set_spacing (GimpBrush *brush,
{
g_return_if_fail (GIMP_IS_BRUSH (brush));
if (brush->spacing != spacing)
if (brush->priv->spacing != spacing)
{
brush->spacing = spacing;
brush->priv->spacing = spacing;
g_signal_emit (brush, brush_signals[SPACING_CHANGED], 0);
g_object_notify (G_OBJECT (brush), "spacing");
}
}
static const GimpVector2 fail = { 0.0, 0.0 };
GimpVector2
gimp_brush_get_x_axis (const GimpBrush *brush)
{
g_return_val_if_fail (GIMP_IS_BRUSH (brush), fail);
return brush->priv->x_axis;
}
GimpVector2
gimp_brush_get_y_axis (const GimpBrush *brush)
{
g_return_val_if_fail (GIMP_IS_BRUSH (brush), fail);
return brush->priv->y_axis;
}

View File

@ -30,23 +30,14 @@
#define GIMP_BRUSH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BRUSH, GimpBrushClass))
typedef struct _GimpBrushClass GimpBrushClass;
typedef struct _GimpBrushPrivate GimpBrushPrivate;
typedef struct _GimpBrushClass GimpBrushClass;
struct _GimpBrush
{
GimpData parent_instance;
GimpData parent_instance;
GimpTempBuf *mask; /* the actual mask */
GimpTempBuf *pixmap; /* optional pixmap data */
gint spacing; /* brush's spacing */
GimpVector2 x_axis; /* for calculating brush spacing */
GimpVector2 y_axis; /* for calculating brush spacing */
gint use_count; /* for keeping the caches alive */
GimpBrushCache *mask_cache;
GimpBrushCache *pixmap_cache;
GimpBrushCache *boundary_cache;
GimpBrushPrivate *priv;
};
struct _GimpBrushClass
@ -137,9 +128,15 @@ const GimpBezierDesc * gimp_brush_transform_boundary (GimpBrush *brush,
GimpTempBuf * gimp_brush_get_mask (const GimpBrush *brush);
GimpTempBuf * gimp_brush_get_pixmap (const GimpBrush *brush);
gint gimp_brush_get_width (const GimpBrush *brush);
gint gimp_brush_get_height (const GimpBrush *brush);
gint gimp_brush_get_spacing (const GimpBrush *brush);
void gimp_brush_set_spacing (GimpBrush *brush,
gint spacing);
GimpVector2 gimp_brush_get_x_axis (const GimpBrush *brush);
GimpVector2 gimp_brush_get_y_axis (const GimpBrush *brush);
#endif /* __GIMP_BRUSH_H__ */

View File

@ -27,6 +27,7 @@
#include "gimp.h"
#include "gimpbuffer.h"
#include "gimpbrush-private.h"
#include "gimpbrushclipboard.h"
#include "gimpimage.h"
#include "gimptempbuf.h"
@ -179,16 +180,16 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
gint width;
gint height;
if (brush->mask)
if (brush->priv->mask)
{
gimp_temp_buf_unref (brush->mask);
brush->mask = NULL;
gimp_temp_buf_unref (brush->priv->mask);
brush->priv->mask = NULL;
}
if (brush->pixmap)
if (brush->priv->pixmap)
{
gimp_temp_buf_unref (brush->pixmap);
brush->pixmap = NULL;
gimp_temp_buf_unref (brush->priv->pixmap);
brush->priv->pixmap = NULL;
}
if (gimp->global_buffer)
@ -200,15 +201,15 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
width = MIN (gimp_buffer_get_width (gimp->global_buffer), 1024);
height = MIN (gimp_buffer_get_height (gimp->global_buffer), 1024);
brush->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
brush->pixmap = gimp_temp_buf_new (width, height,
babl_format ("R'G'B' u8"));
brush->priv->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
brush->priv->pixmap = gimp_temp_buf_new (width, height,
babl_format ("R'G'B' u8"));
/* copy the alpha channel into the brush's mask */
if (babl_format_has_alpha (format))
{
dest_buffer = gimp_temp_buf_create_buffer (brush->mask);
dest_buffer = gimp_temp_buf_create_buffer (brush->priv->mask);
gegl_buffer_set_format (dest_buffer, babl_format ("A u8"));
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
@ -217,12 +218,12 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
}
else
{
memset (gimp_temp_buf_get_data (brush->mask), 255,
memset (gimp_temp_buf_get_data (brush->priv->mask), 255,
width * height);
}
/* copy the color channels into the brush's pixmap */
dest_buffer = gimp_temp_buf_create_buffer (brush->pixmap);
dest_buffer = gimp_temp_buf_create_buffer (brush->priv->pixmap);
gegl_buffer_copy (buffer, NULL, dest_buffer, NULL);
@ -233,14 +234,15 @@ gimp_brush_clipboard_buffer_changed (Gimp *gimp,
width = 17;
height = 17;
brush->mask = gimp_temp_buf_new (width, height, babl_format ("Y u8"));
gimp_temp_buf_data_clear (brush->mask);
brush->priv->mask = gimp_temp_buf_new (width, height,
babl_format ("Y u8"));
gimp_temp_buf_data_clear (brush->priv->mask);
}
brush->x_axis.x = width / 2;
brush->x_axis.y = 0;
brush->y_axis.x = 0;
brush->y_axis.y = height / 2;
brush->priv->x_axis.x = width / 2;
brush->priv->x_axis.y = 0;
brush->priv->y_axis.x = 0;
brush->priv->y_axis.y = height / 2;
gimp_data_dirty (GIMP_DATA (brush));
}

View File

@ -228,7 +228,7 @@ gimp_brush_generated_load (GimpContext *context,
hardness, aspect_ratio, angle));
g_free (name);
brush->spacing = spacing;
gimp_brush_set_spacing (brush, spacing);
return g_list_prepend (NULL, brush);

View File

@ -27,6 +27,7 @@
#include "core-types.h"
#include "gimpbrush-private.h"
#include "gimpbrushgenerated.h"
#include "gimpbrushgenerated-load.h"
#include "gimpbrushgenerated-save.h"
@ -253,18 +254,18 @@ gimp_brush_generated_dirty (GimpData *data)
GimpBrushGenerated *brush = GIMP_BRUSH_GENERATED (data);
GimpBrush *gbrush = GIMP_BRUSH (brush);
if (gbrush->mask)
gimp_temp_buf_unref (gbrush->mask);
if (gbrush->priv->mask)
gimp_temp_buf_unref (gbrush->priv->mask);
gbrush->mask = gimp_brush_generated_calc (brush,
brush->shape,
brush->radius,
brush->spikes,
brush->hardness,
brush->aspect_ratio,
brush->angle,
&gbrush->x_axis,
&gbrush->y_axis);
gbrush->priv->mask = gimp_brush_generated_calc (brush,
brush->shape,
brush->radius,
brush->spikes,
brush->hardness,
brush->aspect_ratio,
brush->angle,
&gbrush->priv->x_axis,
&gbrush->priv->y_axis);
GIMP_DATA_CLASS (parent_class)->dirty (data);
}

View File

@ -29,6 +29,7 @@
#include "core-types.h"
#include "gimpbrush-load.h"
#include "gimpbrush-private.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipe-load.h"
@ -212,11 +213,11 @@ gimp_brush_pipe_load (GimpContext *context,
pipe->current = pipe->brushes[0];
/* just to satisfy the code that relies on this crap */
GIMP_BRUSH (pipe)->spacing = pipe->current->spacing;
GIMP_BRUSH (pipe)->x_axis = pipe->current->x_axis;
GIMP_BRUSH (pipe)->y_axis = pipe->current->y_axis;
GIMP_BRUSH (pipe)->mask = pipe->current->mask;
GIMP_BRUSH (pipe)->pixmap = pipe->current->pixmap;
GIMP_BRUSH (pipe)->priv->spacing = pipe->current->priv->spacing;
GIMP_BRUSH (pipe)->priv->x_axis = pipe->current->priv->x_axis;
GIMP_BRUSH (pipe)->priv->y_axis = pipe->current->priv->y_axis;
GIMP_BRUSH (pipe)->priv->mask = pipe->current->priv->mask;
GIMP_BRUSH (pipe)->priv->pixmap = pipe->current->priv->pixmap;
return g_list_prepend (NULL, pipe);
}

View File

@ -25,6 +25,7 @@
#include "core-types.h"
#include "gimpbrush-private.h"
#include "gimpbrushpipe.h"
#include "gimpbrushpipe-load.h"
@ -128,8 +129,8 @@ gimp_brush_pipe_finalize (GObject *object)
pipe->index = NULL;
}
GIMP_BRUSH (pipe)->mask = NULL;
GIMP_BRUSH (pipe)->pixmap = NULL;
GIMP_BRUSH (pipe)->priv->mask = NULL;
GIMP_BRUSH (pipe)->priv->pixmap = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}

View File

@ -327,8 +327,8 @@ gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
paint_core->pixel_dist);
scale = paint_options->brush_size /
MAX (gimp_temp_buf_get_width (core->main_brush->mask),
gimp_temp_buf_get_height (core->main_brush->mask)) *
MAX (gimp_brush_get_width (core->main_brush),
gimp_brush_get_height (core->main_brush)) *
gimp_dynamics_get_linear_value (core->dynamics,
GIMP_DYNAMICS_OUTPUT_SIZE,
&current_coords,
@ -548,14 +548,14 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
}
/* calculate the distance traveled in the coordinate space of the brush */
temp_vec = core->brush->x_axis;
temp_vec = gimp_brush_get_x_axis (core->brush);
gimp_vector2_mul (&temp_vec, core->scale);
gimp_vector2_rotate (&temp_vec, core->angle * G_PI * 2);
mag = gimp_vector2_length (&temp_vec);
xd = gimp_vector2_inner_product (&delta_vec, &temp_vec) / (mag * mag);
temp_vec = core->brush->y_axis;
temp_vec = gimp_brush_get_y_axis (core->brush);
gimp_vector2_mul (&temp_vec, core->scale);
gimp_vector2_rotate (&temp_vec, core->angle * G_PI * 2);
@ -733,9 +733,14 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
if (core->jitter > 0.0)
{
gdouble dyn_jitter;
gdouble jitter_dist;
gint32 jitter_angle;
GimpVector2 x_axis;
GimpVector2 y_axis;
gdouble dyn_jitter;
gdouble jitter_dist;
gint32 jitter_angle;
x_axis = gimp_brush_get_x_axis (core->brush);
y_axis = gimp_brush_get_y_axis (core->brush);
dyn_jitter = (core->jitter *
gimp_dynamics_get_linear_value (core->dynamics,
@ -749,11 +754,11 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
0, BRUSH_CORE_JITTER_LUTSIZE);
current_coords.x +=
(core->brush->x_axis.x + core->brush->y_axis.x) *
(x_axis.x + y_axis.x) *
jitter_dist * core->jitter_lut_x[jitter_angle] * core->scale;
current_coords.y +=
(core->brush->y_axis.y + core->brush->x_axis.y) *
(y_axis.y + x_axis.y) *
jitter_dist * core->jitter_lut_y[jitter_angle] * core->scale;
}
@ -1476,8 +1481,8 @@ gimp_brush_core_eval_transform_dynamics (GimpBrushCore *core,
{
if (core->main_brush)
core->scale = paint_options->brush_size /
MAX (gimp_temp_buf_get_width (core->main_brush->mask),
gimp_temp_buf_get_height (core->main_brush->mask));
MAX (gimp_brush_get_width (core->main_brush),
gimp_brush_get_height (core->main_brush));
else
core->scale = -1;
@ -1565,7 +1570,7 @@ gimp_brush_core_color_area_with_pixmap (GimpBrushCore *core,
const GimpTempBuf *brush_mask;
g_return_if_fail (GIMP_IS_BRUSH (core->brush));
g_return_if_fail (core->brush->pixmap != NULL);
g_return_if_fail (gimp_brush_get_pixmap (core->brush) != NULL);
/* scale the brushes */
pixmap_mask = gimp_brush_core_transform_pixmap (core, core->brush);

View File

@ -164,8 +164,8 @@ gimp_convolve_motion (GimpPaintCore *paint_core,
fade_point));
gimp_convolve_calculate_matrix (convolve, options->type,
gimp_temp_buf_get_width (brush_core->brush->mask) / 2,
gimp_temp_buf_get_height (brush_core->brush->mask) / 2,
gimp_brush_get_width (brush_core->brush) / 2,
gimp_brush_get_height (brush_core->brush) / 2,
rate);
/* need a linear buffer for gimp_gegl_convolve() */

View File

@ -169,7 +169,7 @@ _gimp_paintbrush_motion (GimpPaintCore *paint_core,
paint_appl_mode = GIMP_PAINT_INCREMENTAL;
}
else if (brush_core->brush && brush_core->brush->pixmap)
else if (brush_core->brush && gimp_brush_get_pixmap (brush_core->brush))
{
/* otherwise check if the brush has a pixmap and use that to
* color the area

View File

@ -281,10 +281,13 @@ brush_get_info_invoker (GimpProcedure *procedure,
if (brush)
{
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->mask));
color_bpp = brush->pixmap ? babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->pixmap)) : 0;
GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
color_bpp = pixmap ? babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap)) : 0;
}
else
success = FALSE;
@ -332,21 +335,24 @@ brush_get_pixels_invoker (GimpProcedure *procedure,
if (brush)
{
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->mask));
num_mask_bytes = gimp_temp_buf_get_height (brush->mask) *
gimp_temp_buf_get_width (brush->mask) * mask_bpp;
mask_bytes = g_memdup (gimp_temp_buf_get_data (brush->mask),
GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
width = gimp_temp_buf_get_width (mask);
height = gimp_temp_buf_get_height (mask);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
num_mask_bytes = gimp_temp_buf_get_height (mask) *
gimp_temp_buf_get_width (mask) * mask_bpp;
mask_bytes = g_memdup (gimp_temp_buf_get_data (mask),
num_mask_bytes);
if (brush->pixmap)
if (pixmap)
{
color_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->pixmap));
num_color_bytes = gimp_temp_buf_get_height (brush->pixmap) *
gimp_temp_buf_get_width (brush->pixmap) *
color_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap));
num_color_bytes = gimp_temp_buf_get_height (pixmap) *
gimp_temp_buf_get_width (pixmap) *
color_bpp;
color_bytes = g_memdup (gimp_temp_buf_get_data (brush->pixmap),
color_bytes = g_memdup (gimp_temp_buf_get_data (pixmap),
num_color_bytes);
}
}

View File

@ -110,8 +110,8 @@ brushes_get_brush_invoker (GimpProcedure *procedure,
if (brush)
{
name = g_strdup (gimp_object_get_name (brush));
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush);
spacing = gimp_brush_get_spacing (brush);
}
else
@ -214,14 +214,16 @@ brushes_get_brush_data_invoker (GimpProcedure *procedure,
if (brush)
{
GimpTempBuf *mask = gimp_brush_get_mask (brush);
actual_name = g_strdup (gimp_object_get_name (brush));
opacity = 1.0;
spacing = gimp_brush_get_spacing (brush);
paint_mode = 0;
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
length = gimp_temp_buf_get_data_size (brush->mask);
mask_data = g_memdup (gimp_temp_buf_get_data (brush->mask), length);
width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush);
length = gimp_temp_buf_get_data_size (mask);
mask_data = g_memdup (gimp_temp_buf_get_data (mask), length);
}
else
success = FALSE;

View File

@ -449,7 +449,7 @@ gimp_brush_editor_notify_brush (GimpBrushGenerated *brush,
else if (! strcmp (pspec->name, "spacing"))
{
adj = editor->spacing_data;
value = GIMP_BRUSH (brush)->spacing;
value = gimp_brush_get_spacing (GIMP_BRUSH (brush));
}
if (adj)

View File

@ -259,11 +259,12 @@ gimp_brush_select_run_callback (GimpPdbDialog *dialog,
GError **error)
{
GimpBrush *brush = GIMP_BRUSH (object);
GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpArray *array;
GimpValueArray *return_vals;
array = gimp_array_new (gimp_temp_buf_get_data (brush->mask),
gimp_temp_buf_get_data_size (brush->mask),
array = gimp_array_new (gimp_temp_buf_get_data (mask),
gimp_temp_buf_get_data_size (mask),
TRUE);
return_vals =
@ -275,8 +276,8 @@ gimp_brush_select_run_callback (GimpPdbDialog *dialog,
G_TYPE_DOUBLE, gimp_context_get_opacity (dialog->context) * 100.0,
GIMP_TYPE_INT32, GIMP_BRUSH_SELECT (dialog)->spacing,
GIMP_TYPE_INT32, gimp_context_get_paint_mode (dialog->context),
GIMP_TYPE_INT32, gimp_temp_buf_get_width (brush->mask),
GIMP_TYPE_INT32, gimp_temp_buf_get_height (brush->mask),
GIMP_TYPE_INT32, gimp_brush_get_width (brush),
GIMP_TYPE_INT32, gimp_brush_get_height (brush),
GIMP_TYPE_INT32, array->length,
GIMP_TYPE_INT8_ARRAY, array,
GIMP_TYPE_INT32, closing,

View File

@ -241,10 +241,13 @@ HELP
if (brush)
{
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->mask));
color_bpp = brush->pixmap ? babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->pixmap)) : 0;
GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
color_bpp = pixmap ? babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap)) : 0;
}
else
success = FALSE;
@ -292,21 +295,24 @@ HELP
if (brush)
{
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->mask));
num_mask_bytes = gimp_temp_buf_get_height (brush->mask) *
gimp_temp_buf_get_width (brush->mask) * mask_bpp;
mask_bytes = g_memdup (gimp_temp_buf_get_data (brush->mask),
GimpTempBuf *mask = gimp_brush_get_mask (brush);
GimpTempBuf *pixmap = gimp_brush_get_pixmap (brush);
width = gimp_temp_buf_get_width (mask);
height = gimp_temp_buf_get_height (mask);
mask_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (mask));
num_mask_bytes = gimp_temp_buf_get_height (mask) *
gimp_temp_buf_get_width (mask) * mask_bpp;
mask_bytes = g_memdup (gimp_temp_buf_get_data (mask),
num_mask_bytes);
if (brush->pixmap)
if (pixmap)
{
color_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (brush->pixmap));
num_color_bytes = gimp_temp_buf_get_height (brush->pixmap) *
gimp_temp_buf_get_width (brush->pixmap) *
color_bpp = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (pixmap));
num_color_bytes = gimp_temp_buf_get_height (pixmap) *
gimp_temp_buf_get_width (pixmap) *
color_bpp;
color_bytes = g_memdup (gimp_temp_buf_get_data (brush->pixmap),
color_bytes = g_memdup (gimp_temp_buf_get_data (pixmap),
num_color_bytes);
}
}

View File

@ -91,8 +91,8 @@ sub brushes_get_brush {
if (brush)
{
name = g_strdup (gimp_object_get_name (brush));
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush);
spacing = gimp_brush_get_spacing (brush);
}
else
@ -180,14 +180,16 @@ sub brushes_get_brush_data {
if (brush)
{
GimpTempBuf *mask = gimp_brush_get_mask (brush);
actual_name = g_strdup (gimp_object_get_name (brush));
opacity = 1.0;
spacing = gimp_brush_get_spacing (brush);
paint_mode = 0;
width = gimp_temp_buf_get_width (brush->mask);
height = gimp_temp_buf_get_height (brush->mask);
length = gimp_temp_buf_get_data_size (brush->mask);
mask_data = g_memdup (gimp_temp_buf_get_data (brush->mask), length);
width = gimp_brush_get_width (brush);
height = gimp_brush_get_height (brush);
length = gimp_temp_buf_get_data_size (mask);
mask_data = g_memdup (gimp_temp_buf_get_data (mask), length);
}
else
success = FALSE;