app/base/Makefile.am removed these files.
2007-04-01 Michael Natterer <mitch@gimp.org> * app/base/Makefile.am * app/base/brush-scale.[ch]: removed these files. * app/core/Makefile.am * app/core/gimpbrush-scale.[ch]: added the functions here as static utility functions. Also move the default implementations of GimpBrush::scale_size(), ::scale_mask() and ::scale_pixmap() here, including their utility functions. * app/core/gimpbrush.c: remove all scale stuff and include "gimpbrush-scale.h" instead. (gimp_brush_get_new_preview): use GimpBrush's scale functions instead of the now private ones. Cleanup. (gimp_brush_scale_mask) (gimp_brush_scale_pixmap): return a copy of the buf for scale == 1.0. svn path=/trunk/; revision=22213
This commit is contained in:
committed by
Michael Natterer
parent
a802571303
commit
c6733ac891
21
ChangeLog
21
ChangeLog
@ -1,3 +1,24 @@
|
||||
2007-04-01 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/base/Makefile.am
|
||||
* app/base/brush-scale.[ch]: removed these files.
|
||||
|
||||
* app/core/Makefile.am
|
||||
* app/core/gimpbrush-scale.[ch]: added the functions here as
|
||||
static utility functions. Also move the default implementations of
|
||||
GimpBrush::scale_size(), ::scale_mask() and ::scale_pixmap() here,
|
||||
including their utility functions.
|
||||
|
||||
* app/core/gimpbrush.c: remove all scale stuff and
|
||||
include "gimpbrush-scale.h" instead.
|
||||
|
||||
(gimp_brush_get_new_preview): use GimpBrush's scale functions
|
||||
instead of the now private ones. Cleanup.
|
||||
|
||||
(gimp_brush_scale_mask)
|
||||
(gimp_brush_scale_pixmap): return a copy of the buf for
|
||||
scale == 1.0.
|
||||
|
||||
2007-03-31 Michael Schumacher <schumaml@cvs.gnome.org>
|
||||
|
||||
* plug-ins/common/svg.c:
|
||||
|
||||
@ -10,8 +10,6 @@ libappbase_a_SOURCES = \
|
||||
base-types.h \
|
||||
boundary.c \
|
||||
boundary.h \
|
||||
brush-scale.c \
|
||||
brush-scale.h \
|
||||
color-balance.c \
|
||||
color-balance.h \
|
||||
colorize.c \
|
||||
|
||||
@ -56,6 +56,8 @@ libappcore_a_sources = \
|
||||
gimpbrush-header.h \
|
||||
gimpbrush-load.c \
|
||||
gimpbrush-load.h \
|
||||
gimpbrush-scale.c \
|
||||
gimpbrush-scale.h \
|
||||
gimpbrushclipboard.c \
|
||||
gimpbrushclipboard.h \
|
||||
gimpbrushgenerated.c \
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
/* GIMP - The GNU Image Manipulation Program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpbrush-scale.c
|
||||
*
|
||||
* 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
|
||||
@ -20,16 +22,125 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "base-types.h"
|
||||
#include "core-types.h"
|
||||
|
||||
#include "brush-scale.h"
|
||||
#include "temp-buf.h"
|
||||
#include "gimpbrush.h"
|
||||
#include "gimpbrush-scale.h"
|
||||
|
||||
#include "base/pixel-region.h"
|
||||
#include "base/temp-buf.h"
|
||||
|
||||
#include "paint-funcs/scale-funcs.h"
|
||||
|
||||
|
||||
MaskBuf *
|
||||
brush_scale_mask (MaskBuf *brush_mask,
|
||||
gint dest_width,
|
||||
gint dest_height)
|
||||
/* local function prototypes */
|
||||
|
||||
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,
|
||||
gint dest_width,
|
||||
gint dest_height);
|
||||
static MaskBuf * gimp_brush_scale_pixmap_down (MaskBuf *pixmap,
|
||||
gint dest_width,
|
||||
gint dest_height);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
void
|
||||
gimp_brush_real_scale_size (GimpBrush *brush,
|
||||
gdouble scale,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
*width = (gint) (brush->mask->width * scale + 0.5);
|
||||
*height = (gint) (brush->mask->height * scale + 0.5);
|
||||
}
|
||||
|
||||
TempBuf *
|
||||
gimp_brush_real_scale_mask (GimpBrush *brush,
|
||||
gdouble scale)
|
||||
{
|
||||
gint dest_width;
|
||||
gint dest_height;
|
||||
|
||||
gimp_brush_scale_size (brush, scale, &dest_width, &dest_height);
|
||||
|
||||
if (dest_width <= 0 || dest_height <= 0)
|
||||
return NULL;
|
||||
|
||||
if (scale <= 1.0)
|
||||
{
|
||||
/* Downscaling with brush_scale_mask is much faster than with
|
||||
* gimp_brush_scale_buf.
|
||||
*/
|
||||
return gimp_brush_scale_mask_down (brush->mask,
|
||||
dest_width, dest_height);
|
||||
}
|
||||
|
||||
return gimp_brush_scale_buf_up (brush->mask, dest_width, dest_height);
|
||||
}
|
||||
|
||||
TempBuf *
|
||||
gimp_brush_real_scale_pixmap (GimpBrush *brush,
|
||||
gdouble scale)
|
||||
{
|
||||
gint dest_width;
|
||||
gint dest_height;
|
||||
|
||||
gimp_brush_scale_size (brush, scale, &dest_width, &dest_height);
|
||||
|
||||
if (dest_width <= 0 || dest_height <= 0)
|
||||
return NULL;
|
||||
|
||||
if (scale <= 1.0)
|
||||
{
|
||||
/* Downscaling with brush_scale_pixmap is much faster than with
|
||||
* gimp_brush_scale_buf.
|
||||
*/
|
||||
return gimp_brush_scale_pixmap_down (brush->pixmap,
|
||||
dest_width, dest_height);
|
||||
}
|
||||
|
||||
return gimp_brush_scale_buf_up (brush->pixmap, dest_width, dest_height);
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static TempBuf *
|
||||
gimp_brush_scale_buf_up (TempBuf *brush_buf,
|
||||
gint dest_width,
|
||||
gint dest_height)
|
||||
{
|
||||
PixelRegion source_region;
|
||||
PixelRegion dest_region;
|
||||
TempBuf *dest_brush_buf;
|
||||
|
||||
pixel_region_init_temp_buf (&source_region, brush_buf,
|
||||
0, 0,
|
||||
brush_buf->width,
|
||||
brush_buf->height);
|
||||
|
||||
dest_brush_buf = temp_buf_new (dest_width, dest_height, brush_buf->bytes,
|
||||
0, 0, NULL);
|
||||
|
||||
pixel_region_init_temp_buf (&dest_region, dest_brush_buf,
|
||||
0, 0,
|
||||
dest_width,
|
||||
dest_height);
|
||||
|
||||
scale_region (&source_region, &dest_region, GIMP_INTERPOLATION_LINEAR,
|
||||
NULL, NULL);
|
||||
|
||||
return dest_brush_buf;
|
||||
}
|
||||
|
||||
static MaskBuf *
|
||||
gimp_brush_scale_mask_down (MaskBuf *brush_mask,
|
||||
gint dest_width,
|
||||
gint dest_height)
|
||||
{
|
||||
MaskBuf *scale_brush;
|
||||
gint src_width;
|
||||
@ -184,10 +295,10 @@ brush_scale_mask (MaskBuf *brush_mask,
|
||||
dest[1] += factor * src[1]; \
|
||||
dest[2] += factor * src[2];
|
||||
|
||||
MaskBuf *
|
||||
brush_scale_pixmap (MaskBuf *pixmap,
|
||||
gint dest_width,
|
||||
gint dest_height)
|
||||
static MaskBuf *
|
||||
gimp_brush_scale_pixmap_down (MaskBuf *pixmap,
|
||||
gint dest_width,
|
||||
gint dest_height)
|
||||
{
|
||||
MaskBuf *scale_brush;
|
||||
gint src_width;
|
||||
@ -1,6 +1,8 @@
|
||||
/* GIMP - The GNU Image Manipulation Program
|
||||
/* The GIMP -- an image manipulation program
|
||||
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
||||
*
|
||||
* gimpbrush-scale.h
|
||||
*
|
||||
* 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
|
||||
@ -16,16 +18,20 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __BRUSH_SCALE_H__
|
||||
#define __BRUSH_SCALE_H__
|
||||
#ifndef __GIMP_BRUSH_SCALE_H__
|
||||
#define __GIMP_BRUSH_SCALE_H__
|
||||
|
||||
|
||||
MaskBuf * brush_scale_mask (MaskBuf *brush_mask,
|
||||
gint dest_width,
|
||||
gint dest_height);
|
||||
MaskBuf * brush_scale_pixmap (MaskBuf *pixmap,
|
||||
gint dest_width,
|
||||
gint dest_height);
|
||||
/* virtual functions of GimpBrush, don't call directly */
|
||||
|
||||
void gimp_brush_real_scale_size (GimpBrush *brush,
|
||||
gdouble scale,
|
||||
gint *scaled_width,
|
||||
gint *scaled_height);
|
||||
TempBuf * gimp_brush_real_scale_mask (GimpBrush *brush,
|
||||
gdouble scale);
|
||||
TempBuf * gimp_brush_real_scale_pixmap (GimpBrush *brush,
|
||||
gdouble scale);
|
||||
|
||||
|
||||
#endif /* __BRUSH_SCALE_H__ */
|
||||
#endif /* __GIMP_BRUSH_SCALE_H__ */
|
||||
@ -24,15 +24,11 @@
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "base/base-types.h"
|
||||
#include "base/brush-scale.h"
|
||||
#include "base/pixel-region.h"
|
||||
#include "base/temp-buf.h"
|
||||
|
||||
#include "paint-funcs/scale-funcs.h"
|
||||
|
||||
#include "gimpbrush.h"
|
||||
#include "gimpbrush-load.h"
|
||||
#include "gimpbrush-scale.h"
|
||||
#include "gimpbrushgenerated.h"
|
||||
#include "gimpmarshal.h"
|
||||
|
||||
@ -82,17 +78,6 @@ static GimpBrush * gimp_brush_real_select_brush (GimpBrush *brush,
|
||||
static gboolean gimp_brush_real_want_null_motion (GimpBrush *brush,
|
||||
GimpCoords *last_coords,
|
||||
GimpCoords *cur_coords);
|
||||
static TempBuf * gimp_brush_scale_buf (TempBuf *brush_buf,
|
||||
gint dest_width,
|
||||
gint dest_height);
|
||||
static void gimp_brush_real_scale_size (GimpBrush *brush,
|
||||
gdouble scale,
|
||||
gint *scaled_width,
|
||||
gint *scaled_height);
|
||||
static TempBuf * gimp_brush_real_scale_mask (GimpBrush *brush,
|
||||
gdouble scale);
|
||||
static TempBuf * gimp_brush_real_scale_pixmap (GimpBrush *brush,
|
||||
gdouble scale);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GimpBrush, gimp_brush, GIMP_TYPE_DATA)
|
||||
@ -172,6 +157,7 @@ gimp_brush_set_property (GObject *object,
|
||||
case PROP_SPACING:
|
||||
gimp_brush_set_spacing (brush, g_value_get_double (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
@ -191,6 +177,7 @@ gimp_brush_get_property (GObject *object,
|
||||
case PROP_SPACING:
|
||||
g_value_set_double (value, brush->spacing);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
@ -254,49 +241,47 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
|
||||
gint height)
|
||||
{
|
||||
GimpBrush *brush = GIMP_BRUSH (viewable);
|
||||
gint brush_width;
|
||||
gint brush_height;
|
||||
TempBuf *mask_buf = NULL;
|
||||
TempBuf *pixmap_buf = NULL;
|
||||
TempBuf *return_buf = NULL;
|
||||
gint mask_width;
|
||||
gint mask_height;
|
||||
guchar transp[4] = { 0, 0, 0, 0 };
|
||||
guchar *mask;
|
||||
guchar *buf;
|
||||
gint x, y;
|
||||
gboolean scale = FALSE;
|
||||
|
||||
mask_buf = gimp_brush_get_mask (brush);
|
||||
pixmap_buf = gimp_brush_get_pixmap (brush);
|
||||
mask_buf = brush->mask;
|
||||
pixmap_buf = brush->pixmap;
|
||||
|
||||
brush_width = mask_buf->width;
|
||||
brush_height = mask_buf->height;
|
||||
mask_width = mask_buf->width;
|
||||
mask_height = mask_buf->height;
|
||||
|
||||
if (brush_width > width || brush_height > height)
|
||||
if (mask_width > width || mask_height > height)
|
||||
{
|
||||
gdouble ratio_x = (gdouble) brush_width / width;
|
||||
gdouble ratio_y = (gdouble) brush_height / height;
|
||||
gdouble ratio_x = (gdouble) width / (gdouble) mask_width;
|
||||
gdouble ratio_y = (gdouble) height / (gdouble) mask_height;
|
||||
gdouble scale = MIN (ratio_x, ratio_y);
|
||||
|
||||
brush_width = (gdouble) brush_width / MAX (ratio_x, ratio_y) + 0.5;
|
||||
brush_height = (gdouble) brush_height / MAX (ratio_x, ratio_y) + 0.5;
|
||||
|
||||
if (brush_width <= 0) brush_width = 1;
|
||||
if (brush_height <= 0) brush_height = 1;
|
||||
|
||||
mask_buf = brush_scale_mask (mask_buf, brush_width, brush_height);
|
||||
|
||||
if (pixmap_buf)
|
||||
if (scale != 1.0)
|
||||
{
|
||||
/* TODO: the scale function should scale the pixmap and the
|
||||
* mask in one run
|
||||
*/
|
||||
pixmap_buf = brush_scale_pixmap (pixmap_buf,
|
||||
brush_width, brush_height);
|
||||
}
|
||||
mask_buf = gimp_brush_scale_mask (brush, scale);
|
||||
|
||||
scale = TRUE;
|
||||
if (! mask_buf)
|
||||
mask_buf = temp_buf_new (1, 1, 1, 0, 0, transp);
|
||||
|
||||
if (pixmap_buf)
|
||||
pixmap_buf = gimp_brush_scale_pixmap (brush, scale);
|
||||
|
||||
mask_width = mask_buf->width;
|
||||
mask_height = mask_buf->height;
|
||||
|
||||
scale = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return_buf = temp_buf_new (brush_width, brush_height, 4, 0, 0, transp);
|
||||
return_buf = temp_buf_new (mask_width, mask_height, 4, 0, 0, transp);
|
||||
|
||||
mask = temp_buf_data (mask_buf);
|
||||
buf = temp_buf_data (return_buf);
|
||||
@ -305,9 +290,9 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
|
||||
{
|
||||
guchar *pixmap = temp_buf_data (pixmap_buf);
|
||||
|
||||
for (y = 0; y < brush_height; y++)
|
||||
for (y = 0; y < mask_height; y++)
|
||||
{
|
||||
for (x = 0; x < brush_width ; x++)
|
||||
for (x = 0; x < mask_width ; x++)
|
||||
{
|
||||
*buf++ = *pixmap++;
|
||||
*buf++ = *pixmap++;
|
||||
@ -318,9 +303,9 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
|
||||
}
|
||||
else
|
||||
{
|
||||
for (y = 0; y < brush_height; y++)
|
||||
for (y = 0; y < mask_height; y++)
|
||||
{
|
||||
for (x = 0; x < brush_width ; x++)
|
||||
for (x = 0; x < mask_width ; x++)
|
||||
{
|
||||
*buf++ = 0;
|
||||
*buf++ = 0;
|
||||
@ -375,90 +360,6 @@ gimp_brush_real_want_null_motion (GimpBrush *brush,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static TempBuf *
|
||||
gimp_brush_scale_buf (TempBuf *brush_buf,
|
||||
gint dest_width,
|
||||
gint dest_height)
|
||||
{
|
||||
PixelRegion source_region;
|
||||
PixelRegion dest_region;
|
||||
TempBuf *dest_brush_buf;
|
||||
|
||||
pixel_region_init_temp_buf (&source_region, brush_buf,
|
||||
0, 0,
|
||||
brush_buf->width,
|
||||
brush_buf->height);
|
||||
|
||||
dest_brush_buf = temp_buf_new (dest_width, dest_height, brush_buf->bytes,
|
||||
0, 0, NULL);
|
||||
|
||||
pixel_region_init_temp_buf (&dest_region, dest_brush_buf,
|
||||
0, 0,
|
||||
dest_width,
|
||||
dest_height);
|
||||
|
||||
scale_region (&source_region, &dest_region, GIMP_INTERPOLATION_LINEAR,
|
||||
NULL, NULL);
|
||||
|
||||
return dest_brush_buf;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_brush_real_scale_size (GimpBrush *brush,
|
||||
gdouble scale,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
*width = (gint) (brush->mask->width * scale + 0.5);
|
||||
*height = (gint) (brush->mask->height * scale + 0.5);
|
||||
}
|
||||
|
||||
static TempBuf *
|
||||
gimp_brush_real_scale_mask (GimpBrush *brush,
|
||||
gdouble scale)
|
||||
{
|
||||
gint dest_width;
|
||||
gint dest_height;
|
||||
|
||||
gimp_brush_scale_size (brush, scale, &dest_width, &dest_height);
|
||||
|
||||
if (dest_width <= 0 || dest_height <= 0)
|
||||
return NULL;
|
||||
|
||||
if (scale <= 1.0)
|
||||
{
|
||||
/* Downscaling with brush_scale_mask is much faster than with
|
||||
* gimp_brush_scale_buf.
|
||||
*/
|
||||
return brush_scale_mask (brush->mask, dest_width, dest_height);
|
||||
}
|
||||
|
||||
return gimp_brush_scale_buf (brush->mask, dest_width, dest_height);
|
||||
}
|
||||
|
||||
static TempBuf *
|
||||
gimp_brush_real_scale_pixmap (GimpBrush *brush,
|
||||
gdouble scale)
|
||||
{
|
||||
gint dest_width;
|
||||
gint dest_height;
|
||||
|
||||
gimp_brush_scale_size (brush, scale, &dest_width, &dest_height);
|
||||
|
||||
if (dest_width <= 0 || dest_height <= 0)
|
||||
return NULL;
|
||||
|
||||
if (scale <= 1.0)
|
||||
{
|
||||
/* Downscaling with brush_scale_pixmap is much faster than with
|
||||
* gimp_brush_scale_buf.
|
||||
*/
|
||||
return brush_scale_pixmap (brush->pixmap, dest_width, dest_height);
|
||||
}
|
||||
|
||||
return gimp_brush_scale_buf (brush->pixmap, dest_width, dest_height);
|
||||
}
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
@ -549,6 +450,9 @@ gimp_brush_scale_mask (GimpBrush *brush,
|
||||
g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
|
||||
g_return_val_if_fail (scale > 0.0, NULL);
|
||||
|
||||
if (scale == 1.0)
|
||||
return temp_buf_copy (brush->mask, NULL);
|
||||
|
||||
return GIMP_BRUSH_GET_CLASS (brush)->scale_mask (brush, scale);
|
||||
}
|
||||
|
||||
@ -560,6 +464,9 @@ gimp_brush_scale_pixmap (GimpBrush *brush,
|
||||
g_return_val_if_fail (brush->pixmap != NULL, NULL);
|
||||
g_return_val_if_fail (scale > 0.0, NULL);
|
||||
|
||||
if (scale == 1.0)
|
||||
return temp_buf_copy (brush->pixmap, NULL);
|
||||
|
||||
return GIMP_BRUSH_GET_CLASS (brush)->scale_pixmap (brush, scale);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user