1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
#include <glib-object.h>
23
#include "base-types.h"
25
#include "brush-scale.h"
30
brush_scale_mask (MaskBuf *brush_mask,
41
gint dx, dx0, dy, dy0;
42
gint fx, fx0, fy, fy0;
45
g_return_val_if_fail (brush_mask != NULL &&
46
dest_width != 0 && dest_height != 0, NULL);
48
src_width = brush_mask->width;
49
src_height = brush_mask->height;
51
scale_brush = mask_buf_new (dest_width, dest_height);
52
g_return_val_if_fail (scale_brush != NULL, NULL);
55
dest = mask_buf_data (scale_brush);
56
src = mask_buf_data (brush_mask);
58
fx = fx0 = (256.0 * src_width) / dest_width;
59
fy = fy0 = (256.0 * src_height) / dest_height;
60
area = (fx0 * fy0) >> 8;
67
for (i=0; i<dest_height; i++)
69
for (j=0; j<dest_width; j++)
85
value += (dx * dy * src[x + src_width * y]) >> 8;
92
value += dy * src[x + src_width * y];
98
value += fx * dy * src[x + src_width * y] >> 8;
114
value += dx * src[x + src_width * y];
121
value += 256 * src[x + src_width * y];
127
value += fx * src[x + src_width * y];
142
value += (dx * fy * src[x + src_width * y]) >> 8;
149
value += fy * src[x + src_width * y];
155
value += (fx * fy * src[x + src_width * y]) >> 8;
161
*dest++ = MIN ((value / area), 255);
176
#define ADD_RGB(dest, factor, src) \
177
dest[0] += factor * src[0]; \
178
dest[1] += factor * src[1]; \
179
dest[2] += factor * src[2];
182
brush_scale_pixmap (MaskBuf *pixmap,
186
MaskBuf *scale_brush;
194
gint dx, dx0, dy, dy0;
195
gint fx, fx0, fy, fy0;
196
guchar *src, *src_ptr, *dest;
198
g_return_val_if_fail (pixmap != NULL && pixmap->bytes == 3 &&
199
dest_width != 0 && dest_height != 0, NULL);
201
src_width = pixmap->width;
202
src_height = pixmap->height;
204
scale_brush = temp_buf_new (dest_width, dest_height, 3, 0, 0, NULL);
205
g_return_val_if_fail (scale_brush != NULL, NULL);
208
dest = mask_buf_data (scale_brush);
209
src = mask_buf_data (pixmap);
211
fx = fx0 = (256.0 * src_width) / dest_width;
212
fy = fy0 = (256.0 * src_height) / dest_height;
213
area = (fx0 * fy0) >> 8;
220
for (i=0; i<dest_height; i++)
222
for (j=0; j<dest_width; j++)
240
factor = (dx * dy) >> 8;
241
src_ptr = src + 3 * (x + y * src_width);
242
ADD_RGB (value, factor, src_ptr);
250
src_ptr = src + 3 * (x + y * src_width);
251
ADD_RGB (value, factor, src_ptr);
257
factor = (fx * dy) >> 8;
258
src_ptr = src + 3 * (x + y * src_width);
259
ADD_RGB (value, factor, src_ptr);
276
src_ptr = src + 3 * (x + y * src_width);
277
ADD_RGB (value, factor, src_ptr);
285
src_ptr = src + 3 * (x + y * src_width);
286
ADD_RGB (value, factor, src_ptr);
293
src_ptr = src + 3 * (x + y * src_width);
294
ADD_RGB (value, factor, src_ptr);
309
factor = (dx * fy) >> 8;
310
src_ptr = src + 3 * (x + y * src_width);
311
ADD_RGB (value, factor, src_ptr);
319
src_ptr = src + 3 * (x + y * src_width);
320
ADD_RGB (value, factor, src_ptr);
326
factor = (fx * fy) >> 8;
327
src_ptr = src + 3 * (x + y * src_width);
328
ADD_RGB (value, factor, src_ptr);
334
*dest++ = MIN ((value[0] / area), 255);
335
*dest++ = MIN ((value[1] / area), 255);
336
*dest++ = MIN ((value[2] / area), 255);