1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* kernelgen -- Copyright (C) 2000 Sven Neumann <sven@gimp.org>
6
* Simple hack to create brush subsampling kernels. If you want to
7
* play with it, change some of the #defines at the top and copy
8
* the output to app/paint/gimpbrushcore-kernels.h.
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31
#define KERNEL_WIDTH 3 /* changing these makes no sense */
32
#define KERNEL_HEIGHT 3 /* changing these makes no sense */
33
#define KERNEL_SUM 256
35
#define THRESHOLD 0.25 /* try to change this one */
37
#define SQR(x) ((x) * (x))
40
create_kernel (double x,
43
double value[KERNEL_WIDTH][KERNEL_HEIGHT];
50
memset (value, 0, KERNEL_WIDTH * KERNEL_HEIGHT * sizeof (double));
56
for (j = 0; j < STEPS * KERNEL_HEIGHT; j++)
58
dist_y = y - (((double)j + 0.5) / (double)STEPS);
60
for (i = 0; i < STEPS * KERNEL_WIDTH; i++)
62
dist_x = x - (((double) i + 0.5) / (double) STEPS);
64
/* I've tried to use a gauss function here instead of a
65
threshold, but the result was not that impressive. */
66
w = (SQR (dist_x) + SQR (dist_y)) < THRESHOLD ? 1.0 : 0.0;
68
value[i / STEPS][j / STEPS] += w;
73
for (j = 0; j < KERNEL_HEIGHT; j++)
75
for (i = 0; i < KERNEL_WIDTH; i++)
77
w = (double) KERNEL_SUM * value[i][j] / sum;
78
printf (" %3d,", (int) (w + 0.5));
90
printf ("/* gimpbrushcore-kernels.h\n"
92
" * This file was generated using kernelgen as found in the tools dir.\n");
93
printf (" * (threshold = %g)\n", THRESHOLD);
95
printf ("#ifndef __GIMP_BRUSH_CORE_KERNELS_H__\n");
96
printf ("#define __GIMP_BRUSH_CORE_KERNELS_H__\n\n");
97
printf ("#define KERNEL_WIDTH %d\n", KERNEL_WIDTH);
98
printf ("#define KERNEL_HEIGHT %d\n", KERNEL_HEIGHT);
99
printf ("#define KERNEL_SUBSAMPLE %d\n", SUBSAMPLE);
100
printf ("#define KERNEL_SUM %d\n", KERNEL_SUM);
102
printf ("/* Brush pixel subsampling kernels */\n");
103
printf ("static const int subsample[%d][%d][%d] =\n{\n",
104
SUBSAMPLE + 1, SUBSAMPLE + 1, KERNEL_WIDTH * KERNEL_HEIGHT);
106
for (j = 0; j <= SUBSAMPLE; j++)
108
y = (double) j / (double) SUBSAMPLE;
112
for (i = 0; i <= SUBSAMPLE; i++)
114
x = (double) i / (double) SUBSAMPLE;
117
create_kernel (x, y);
118
printf (" }%s", i < SUBSAMPLE ? ",\n" : "\n");
121
printf (" }%s", j < SUBSAMPLE ? ",\n" : "\n");
126
printf ("#endif /* __GIMP_BRUSH_CORE_KERNELS_H__ */\n");