gimp/app/base/brush-scale.c
Michael Natterer d240f623f1 new directory app/base/
2001-05-15  Michael Natterer  <mitch@gimp.org>

	* configure.in: new directory app/base/

	* app/Makefile.am
	* app/boundary.[ch]
	* app/brush_scale.[ch]
	* app/gimpchecks.h
	* app/gimplut.[ch]
	* app/pixel_processor.[ch]
	* app/pixel_region.[ch]
	* app/pixel_surround.[ch]
	* app/temp_buf.[ch]
	* app/tile.[ch]
	* app/tile_cache.[ch]
	* app/tile_manager.[ch]
	* app/tile_manager_pvt.h
	* app/tile_pvt.h
	* app/tile_swap.[ch]: moved to base/

	* app/base/Makefile.am
	* app/base/base-types.h
	* app/base/*: new directory for the sub-object pixel maniplation
	and storage stuff. Does not include Gtk+ or anything outside
	base/. Did some cleanup in all files.

	* app/appenums.h
	* app/apptypes.h
	* app/core/gimpimage.h: removed types which are now in
	base/base-types.h.

	* app/base/base-config.[ch]
	* app/gimprc.[ch]: put the config variables for base/ to their own
	file so base/ doesn not have to include gimprc.h (does not yet
	work, i.e. the variables are un-configurable right now)

	* app/main.c: set a log handler for "Gimp-Base".

	* app/paint-funcs/Makefile.am
	* app/paint-funcs/paint-funcs.[ch]: removed the color hash which
	maps RGB to color indices because it's a totally standalone system
	which has nothing to do with the paint-funcs and introduced a
	GimpImage dependency.

	paint-funcs/ should be considered on the same sub-object
	(glib-only) level as base/, only in a different directory.

	* app/core/Makefile.am
	* app/core/gimpimage-colorhash.[ch]: put the color hash here.

	* app/gimage.c: don't invalidate the color hash here...

	* app/core/gimpimage.c: ... but in the colormap_changed() default
	inplementation. Initialize the hash in class_init().

	* tools/pdbgen/Makefile.am: scan app/base/base-types.h for enums.

	* tools/pdbgen/enums.pl: regenerated.

	* app/[lots]
	* app/core/[of]
	* app/gui/[files]
	* app/pdb/[all]
	* app/tools/[over]
	* app/widgets/[the]
	* tools/pdbgen/pdb/[place]: changed #includes accordingly. And use
	base_config->value instead of the stuff from gimprc.h.
2001-05-15 11:25:25 +00:00

351 lines
6.6 KiB
C

/* The GIMP -- an 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 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.h>
#include "base-types.h"
#include "brush-scale.h"
#include "temp-buf.h"
MaskBuf *
brush_scale_mask (MaskBuf *brush_mask,
gint dest_width,
gint dest_height)
{
MaskBuf *scale_brush;
gint src_width;
gint src_height;
gint value;
gint area;
gint i, j;
gint x, x0, y, y0;
gint dx, dx0, dy, dy0;
gint fx, fx0, fy, fy0;
guchar *src, *dest;
g_return_val_if_fail (brush_mask != NULL &&
dest_width != 0 && dest_height != 0, NULL);
src_width = brush_mask->width;
src_height = brush_mask->height;
scale_brush = mask_buf_new (dest_width, dest_height);
g_return_val_if_fail (scale_brush != NULL, NULL);
/* get the data */
dest = mask_buf_data (scale_brush);
src = mask_buf_data (brush_mask);
fx = fx0 = (256.0 * src_width) / dest_width;
fy = fy0 = (256.0 * src_height) / dest_height;
area = fx0 * fy0;
x = x0 = 0;
y = y0 = 0;
dx = dx0 = 0;
dy = dy0 = 0;
for (i=0; i<dest_height; i++)
{
for (j=0; j<dest_width; j++)
{
value = 0;
fy = fy0;
y = y0;
dy = dy0;
if (dy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * dy * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * dy * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * dy * src[x + src_width * y];
dx = 256 - fx;
}
y++;
fy -= dy;
dy = 0;
}
while (fy >= 256)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * 256 * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * 256 * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * 256 * src[x + src_width * y];
dx = 256 - fx;
}
y++;
fy -= 256;
}
if (fy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * fy * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * fy * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * fy * src[x + src_width * y];
dx = 256 - fx;
}
dy = 256 - fy;
}
*dest++ = MIN ((value / area), 255);
x0 = x;
dx0 = dx;
}
x0 = 0;
dx0 = 0;
y0 = y;
dy0 = dy;
}
return scale_brush;
}
#define ADD_RGB(dest, factor, src) \
dest[0] += factor * src[0]; \
dest[1] += factor * src[1]; \
dest[2] += factor * src[2];
MaskBuf *
brush_scale_pixmap (MaskBuf *pixmap,
gint dest_width,
gint dest_height)
{
MaskBuf *scale_brush;
gint src_width;
gint src_height;
gint value[3];
gint factor;
gint area;
gint i, j;
gint x, x0, y, y0;
gint dx, dx0, dy, dy0;
gint fx, fx0, fy, fy0;
guchar *src, *src_ptr, *dest;
g_return_val_if_fail (pixmap != NULL && pixmap->bytes == 3 &&
dest_width != 0 && dest_height != 0, NULL);
src_width = pixmap->width;
src_height = pixmap->height;
scale_brush = temp_buf_new (dest_width, dest_height, 3, 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 (pixmap);
fx = fx0 = (256.0 * src_width) / dest_width;
fy = fy0 = (256.0 * src_height) / dest_height;
area = fx0 * fy0;
x = x0 = 0;
y = y0 = 0;
dx = dx0 = 0;
dy = dy0 = 0;
for (i=0; i<dest_height; i++)
{
for (j=0; j<dest_width; j++)
{
value[0] = 0;
value[1] = 0;
value[2] = 0;
fy = fy0;
y = y0;
dy = dy0;
if (dy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
factor = dx * dy;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
factor = 256 * dy;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
x++;
fx -= 256;
}
if (fx)
{
factor = fx * dy;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
dx = 256 - fx;
}
y++;
fy -= dy;
dy = 0;
}
while (fy >= 256)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
factor = dx * 256;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
factor = 256 * 256;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
x++;
fx -= 256;
}
if (fx)
{
factor = fx * 256;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
dx = 256 - fx;
}
y++;
fy -= 256;
}
if (fy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
factor = dx * fy;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
factor = 256 * fy;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
x++;
fx -= 256;
}
if (fx)
{
factor = fx * fy;
src_ptr = src + 3 * (x + y * src_width);
ADD_RGB (value, factor, src_ptr);
dx = 256 - fx;
}
dy = 256 - fy;
}
*dest++ = MIN ((value[0] / area), 255);
*dest++ = MIN ((value[1] / area), 255);
*dest++ = MIN ((value[2] / area), 255);
x0 = x;
dx0 = dx;
}
x0 = 0;
dx0 = 0;
y0 = y;
dy0 = dy;
}
return scale_brush;
}
#undef ADD_RGB