app/base/base-types.h remove redundant and inconsistently used MaskBuf

2007-04-13  Michael Natterer  <mitch@gimp.org>

	* app/base/base-types.h
	* app/base/temp-buf.[ch]: remove redundant and inconsistently used
	MaskBuf type and API.

	* app/core/gimpbrush-scale.c
	* app/paint/gimpbrushcore.[ch]: use TempBuf and its API instead.
	This also optimizes away a useless memset() on brush scaling,
	we completely fill each of the created buffers anyway.


svn path=/trunk/; revision=22249
This commit is contained in:
Michael Natterer 2007-04-13 14:04:37 +00:00 committed by Michael Natterer
parent 5543191b0a
commit f2acde4c60
7 changed files with 81 additions and 107 deletions

View file

@ -1,3 +1,14 @@
2007-04-13 Michael Natterer <mitch@gimp.org>
* app/base/base-types.h
* app/base/temp-buf.[ch]: remove redundant and inconsistently used
MaskBuf type and API.
* app/core/gimpbrush-scale.c
* app/paint/gimpbrushcore.[ch]: use TempBuf and its API instead.
This also optimizes away a useless memset() on brush scaling,
we completely fill each of the created buffers anyway.
2007-04-12 Sven Neumann <sven@gimp.org>
* app/tools/gimprectangleselecttool.c: implement

View file

@ -68,7 +68,6 @@ typedef struct _PixelSurround PixelSurround;
typedef struct _SioxState SioxState;
typedef struct _TempBuf TempBuf;
typedef struct _TempBuf MaskBuf;
typedef struct _Tile Tile;
typedef struct _TileManager TileManager;

View file

@ -478,36 +478,3 @@ temp_buf_to_gray (TempBuf *src_buf,
break;
}
}
/******************************************************************
* Mask buffer functions *
******************************************************************/
MaskBuf *
mask_buf_new (gint width,
gint height)
{
static guchar empty = 0;
return temp_buf_new (width, height, 1, 0, 0, &empty);
}
void
mask_buf_free (MaskBuf *mask)
{
temp_buf_free ((TempBuf *) mask);
}
guchar *
mask_buf_data (MaskBuf *mask_buf)
{
return temp_buf_data ((TempBuf *) mask_buf);
}
guchar *
mask_buf_data_clear (MaskBuf *mask_buf)
{
return temp_buf_data_clear ((TempBuf *) mask_buf);
}

View file

@ -69,13 +69,4 @@ guchar * temp_buf_data_clear (TempBuf *buf);
gsize temp_buf_get_memsize (TempBuf *buf);
/* The mask buffer functions */
MaskBuf * mask_buf_new (gint width,
gint height);
void mask_buf_free (MaskBuf *mask_buf);
guchar * mask_buf_data (MaskBuf *mask_buf);
guchar * mask_buf_data_clear (MaskBuf *mask_buf);
#endif /* __TEMP_BUF_H__ */

View file

@ -38,10 +38,10 @@
static TempBuf * gimp_brush_scale_buf_up (TempBuf *brush_buf,
gint dest_width,
gint dest_height);
static MaskBuf * gimp_brush_scale_mask_down (MaskBuf *brush_mask,
static TempBuf * gimp_brush_scale_mask_down (TempBuf *brush_mask,
gint dest_width,
gint dest_height);
static MaskBuf * gimp_brush_scale_pixmap_down (MaskBuf *pixmap,
static TempBuf * gimp_brush_scale_pixmap_down (TempBuf *pixmap,
gint dest_width,
gint dest_height);
@ -137,12 +137,12 @@ gimp_brush_scale_buf_up (TempBuf *brush_buf,
return dest_brush_buf;
}
static MaskBuf *
gimp_brush_scale_mask_down (MaskBuf *brush_mask,
static TempBuf *
gimp_brush_scale_mask_down (TempBuf *brush_mask,
gint dest_width,
gint dest_height)
{
MaskBuf *scale_brush;
TempBuf *scale_brush;
gint src_width;
gint src_height;
gint value;
@ -159,12 +159,12 @@ gimp_brush_scale_mask_down (MaskBuf *brush_mask,
src_width = brush_mask->width;
src_height = brush_mask->height;
scale_brush = mask_buf_new (dest_width, dest_height);
scale_brush = temp_buf_new (dest_width, dest_height, 1, 0, 0, NULL);
g_return_val_if_fail (scale_brush != NULL, NULL);
/* get the data */
dest = mask_buf_data (scale_brush);
src = mask_buf_data (brush_mask);
dest = temp_buf_data (scale_brush);
src = temp_buf_data (brush_mask);
fx = fx0 = (src_width << 8) / dest_width;
fy = fy0 = (src_height << 8) / dest_height;
@ -295,12 +295,12 @@ gimp_brush_scale_mask_down (MaskBuf *brush_mask,
dest[1] += factor * src[1]; \
dest[2] += factor * src[2];
static MaskBuf *
gimp_brush_scale_pixmap_down (MaskBuf *pixmap,
static TempBuf *
gimp_brush_scale_pixmap_down (TempBuf *pixmap,
gint dest_width,
gint dest_height)
{
MaskBuf *scale_brush;
TempBuf *scale_brush;
gint src_width;
gint src_height;
gint value[3];
@ -322,8 +322,8 @@ gimp_brush_scale_pixmap_down (MaskBuf *pixmap,
g_return_val_if_fail (scale_brush != NULL, NULL);
/* get the data */
dest = mask_buf_data (scale_brush);
src = mask_buf_data (pixmap);
dest = temp_buf_data (scale_brush);
src = temp_buf_data (pixmap);
fx = fx0 = (src_width << 8) / dest_width;
fy = fy0 = (src_height << 8) / dest_height;

View file

@ -88,25 +88,25 @@ static gdouble gimp_brush_core_calc_brush_scale (GimpBrushCore *core,
gdouble pressure);
static inline void rotate_pointers (gulong **p,
guint32 n);
static MaskBuf * gimp_brush_core_subsample_mask (GimpBrushCore *core,
MaskBuf *mask,
static TempBuf * gimp_brush_core_subsample_mask (GimpBrushCore *core,
TempBuf *mask,
gdouble x,
gdouble y);
static MaskBuf * gimp_brush_core_pressurize_mask (GimpBrushCore *core,
MaskBuf *brush_mask,
static TempBuf * gimp_brush_core_pressurize_mask (GimpBrushCore *core,
TempBuf *brush_mask,
gdouble x,
gdouble y,
gdouble pressure);
static MaskBuf * gimp_brush_core_solidify_mask (GimpBrushCore *core,
MaskBuf *brush_mask,
static TempBuf * gimp_brush_core_solidify_mask (GimpBrushCore *core,
TempBuf *brush_mask,
gdouble x,
gdouble y);
static MaskBuf * gimp_brush_core_scale_mask (GimpBrushCore *core,
static TempBuf * gimp_brush_core_scale_mask (GimpBrushCore *core,
GimpBrush *brush);
static MaskBuf * gimp_brush_core_scale_pixmap (GimpBrushCore *core,
static TempBuf * gimp_brush_core_scale_pixmap (GimpBrushCore *core,
GimpBrush *brush);
static MaskBuf * gimp_brush_core_get_brush_mask (GimpBrushCore *core,
static TempBuf * gimp_brush_core_get_brush_mask (GimpBrushCore *core,
GimpBrushApplicationMode brush_hardness);
static void gimp_brush_core_invalidate_cache (GimpBrush *brush,
GimpBrushCore *core);
@ -799,7 +799,7 @@ gimp_brush_core_paste_canvas (GimpBrushCore *core,
GimpBrushApplicationMode brush_hardness,
GimpPaintApplicationMode mode)
{
MaskBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
TempBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
brush_hardness);
if (brush_mask)
@ -841,7 +841,7 @@ gimp_brush_core_replace_canvas (GimpBrushCore *core,
GimpBrushApplicationMode brush_hardness,
GimpPaintApplicationMode mode)
{
MaskBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
TempBuf *brush_mask = gimp_brush_core_get_brush_mask (core,
brush_hardness);
if (brush_mask)
@ -934,16 +934,17 @@ rotate_pointers (gulong **p,
p[i] = tmp;
}
static MaskBuf *
static TempBuf *
gimp_brush_core_subsample_mask (GimpBrushCore *core,
MaskBuf *mask,
TempBuf *mask,
gdouble x,
gdouble y)
{
MaskBuf *dest;
TempBuf *dest;
gdouble left;
guchar *m;
guchar *d;
guchar empty = TRANSPARENT_OPACITY;
const gint *k;
gint index1;
gint index2;
@ -1004,7 +1005,7 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
for (j = 0; j < KERNEL_SUBSAMPLE + 1; j++)
if (core->kernel_brushes[i][j])
{
mask_buf_free (core->kernel_brushes[i][j]);
temp_buf_free (core->kernel_brushes[i][j]);
core->kernel_brushes[i][j] = NULL;
}
@ -1012,8 +1013,9 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
core->cache_invalid = FALSE;
}
dest = mask_buf_new (mask->width + 2,
mask->height + 2);
dest = temp_buf_new (mask->width + 2,
mask->height + 2,
1, 0, 0, &empty);
/* Allocate and initialize the accum buffer */
for (i = 0; i < KERNEL_HEIGHT ; i++)
@ -1021,7 +1023,7 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
core->kernel_brushes[index2][index1] = dest;
m = mask_buf_data (mask);
m = temp_buf_data (mask);
for (i = 0; i < mask->height; i++)
{
for (j = 0; j < mask->width; j++)
@ -1038,7 +1040,7 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
}
/* store the accum buffer into the destination mask */
d = mask_buf_data (dest) + (i + dest_offset_y) * dest->width;
d = temp_buf_data (dest) + (i + dest_offset_y) * dest->width;
for (j = 0; j < dest->width; j++)
*d++ = (accum[0][j] + 127) / KERNEL_SUM;
@ -1050,7 +1052,7 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
/* store the rest of the accum buffer into the dest mask */
while (i + dest_offset_y < dest->height)
{
d = mask_buf_data (dest) + (i + dest_offset_y) * dest->width;
d = temp_buf_data (dest) + (i + dest_offset_y) * dest->width;
for (j = 0; j < dest->width; j++)
*d++ = (accum[0][j] + (KERNEL_SUM / 2)) / KERNEL_SUM;
@ -1066,9 +1068,9 @@ gimp_brush_core_subsample_mask (GimpBrushCore *core,
/* #define FANCY_PRESSURE */
static MaskBuf *
static TempBuf *
gimp_brush_core_pressurize_mask (GimpBrushCore *core,
MaskBuf *brush_mask,
TempBuf *brush_mask,
gdouble x,
gdouble y,
gdouble pressure)
@ -1076,7 +1078,8 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
static guchar mapi[256];
guchar *source;
guchar *dest;
MaskBuf *subsample_mask;
guchar empty = TRANSPARENT_OPACITY;
TempBuf *subsample_mask;
gint i;
/* Get the raw subsampled mask */
@ -1089,10 +1092,11 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
return subsample_mask;
if (core->pressure_brush)
mask_buf_free (core->pressure_brush);
temp_buf_free (core->pressure_brush);
core->pressure_brush = mask_buf_new (brush_mask->width + 2,
brush_mask->height + 2);
core->pressure_brush = temp_buf_new (brush_mask->width + 2,
brush_mask->height + 2,
1, 0, 0, &empty);
#ifdef FANCY_PRESSURE
@ -1169,8 +1173,8 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
/* Now convert the brush */
source = mask_buf_data (subsample_mask);
dest = mask_buf_data (core->pressure_brush);
source = temp_buf_data (subsample_mask);
dest = temp_buf_data (core->pressure_brush);
i = subsample_mask->width * subsample_mask->height;
while (i--)
@ -1179,15 +1183,16 @@ gimp_brush_core_pressurize_mask (GimpBrushCore *core,
return core->pressure_brush;
}
static MaskBuf *
static TempBuf *
gimp_brush_core_solidify_mask (GimpBrushCore *core,
MaskBuf *brush_mask,
TempBuf *brush_mask,
gdouble x,
gdouble y)
{
MaskBuf *dest;
TempBuf *dest;
guchar *m;
guchar *d;
guchar empty = TRANSPARENT_OPACITY;
gint dest_offset_x = 0;
gint dest_offset_y = 0;
gint i, j;
@ -1222,7 +1227,7 @@ gimp_brush_core_solidify_mask (GimpBrushCore *core,
for (j = 0; j < BRUSH_CORE_SOLID_SUBSAMPLE; j++)
if (core->solid_brushes[i][j])
{
mask_buf_free (core->solid_brushes[i][j]);
temp_buf_free (core->solid_brushes[i][j]);
core->solid_brushes[i][j] = NULL;
}
@ -1230,13 +1235,14 @@ gimp_brush_core_solidify_mask (GimpBrushCore *core,
core->solid_cache_invalid = FALSE;
}
dest = mask_buf_new (brush_mask->width + 2,
brush_mask->height + 2);
dest = temp_buf_new (brush_mask->width + 2,
brush_mask->height + 2,
1, 0, 0, &empty);
core->solid_brushes[dest_offset_y][dest_offset_x] = dest;
m = mask_buf_data (brush_mask);
d = (mask_buf_data (dest) +
m = temp_buf_data (brush_mask);
d = (temp_buf_data (dest) +
(dest_offset_y + 1) * dest->width +
(dest_offset_x + 1));
@ -1251,7 +1257,7 @@ gimp_brush_core_solidify_mask (GimpBrushCore *core,
return dest;
}
static MaskBuf *
static TempBuf *
gimp_brush_core_scale_mask (GimpBrushCore *core,
GimpBrush *brush)
{
@ -1280,7 +1286,7 @@ gimp_brush_core_scale_mask (GimpBrushCore *core,
core->last_scale_height = height;
if (core->scale_brush)
mask_buf_free (core->scale_brush);
temp_buf_free (core->scale_brush);
core->scale_brush = gimp_brush_scale_mask (brush, core->scale);
@ -1290,7 +1296,7 @@ gimp_brush_core_scale_mask (GimpBrushCore *core,
return core->scale_brush;
}
static MaskBuf *
static TempBuf *
gimp_brush_core_scale_pixmap (GimpBrushCore *core,
GimpBrush *brush)
{
@ -1319,7 +1325,7 @@ gimp_brush_core_scale_pixmap (GimpBrushCore *core,
core->last_scale_pixmap_height = height;
if (core->scale_pixmap)
mask_buf_free (core->scale_pixmap);
temp_buf_free (core->scale_pixmap);
core->scale_pixmap = gimp_brush_scale_pixmap (brush, core->scale);
@ -1328,12 +1334,12 @@ gimp_brush_core_scale_pixmap (GimpBrushCore *core,
return core->scale_pixmap;
}
static MaskBuf *
static TempBuf *
gimp_brush_core_get_brush_mask (GimpBrushCore *core,
GimpBrushApplicationMode brush_hardness)
{
GimpPaintCore *paint_core = GIMP_PAINT_CORE (core);
MaskBuf *mask;
TempBuf *mask;
mask = gimp_brush_core_scale_mask (core, core->brush);

View file

@ -49,25 +49,25 @@ struct _GimpBrushCore
gdouble scale;
/* brush buffers */
MaskBuf *pressure_brush;
TempBuf *pressure_brush;
MaskBuf *solid_brushes[BRUSH_CORE_SOLID_SUBSAMPLE][BRUSH_CORE_SOLID_SUBSAMPLE];
MaskBuf *last_solid_brush;
TempBuf *solid_brushes[BRUSH_CORE_SOLID_SUBSAMPLE][BRUSH_CORE_SOLID_SUBSAMPLE];
TempBuf *last_solid_brush;
gboolean solid_cache_invalid;
MaskBuf *scale_brush;
MaskBuf *last_scale_brush;
TempBuf *scale_brush;
TempBuf *last_scale_brush;
gint last_scale_width;
gint last_scale_height;
MaskBuf *scale_pixmap;
MaskBuf *last_scale_pixmap;
TempBuf *scale_pixmap;
TempBuf *last_scale_pixmap;
gint last_scale_pixmap_width;
gint last_scale_pixmap_height;
MaskBuf *kernel_brushes[BRUSH_CORE_SUBSAMPLE + 1][BRUSH_CORE_SUBSAMPLE + 1];
TempBuf *kernel_brushes[BRUSH_CORE_SUBSAMPLE + 1][BRUSH_CORE_SUBSAMPLE + 1];
MaskBuf *last_brush_mask;
TempBuf *last_brush_mask;
gboolean cache_invalid;
gdouble jitter;