2000-05-29 16:40:29 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-07-14 22:14:30 +08:00
|
|
|
* kernel_gen -- Copyright (C) 2000 Sven Neumann <sven@gimp.org>
|
2000-05-29 16:40:29 +08:00
|
|
|
* Simple hack to create subsampling kernels for the brushes
|
|
|
|
* as used in app/paint_core.c.
|
|
|
|
* If you want to play with it, change some of the #defines at the
|
2001-01-22 09:46:28 +08:00
|
|
|
* top and copy the output to apps/tools/paint_core_kernels.h.
|
2003-07-14 22:14:30 +08:00
|
|
|
*
|
2000-05-29 16:40:29 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2003-07-14 22:14:30 +08:00
|
|
|
|
2000-05-29 16:40:29 +08:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
2003-07-14 22:14:30 +08:00
|
|
|
#include <string.h>
|
2000-05-29 16:40:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define STEPS 64
|
|
|
|
#define KERNEL_WIDTH 3 /* changing these makes no sense */
|
|
|
|
#define KERNEL_HEIGHT 3 /* changing these makes no sense */
|
|
|
|
#define SUBSAMPLE 4
|
|
|
|
#define THRESHOLD 0.25 /* try to change this one */
|
|
|
|
|
|
|
|
#define SQR(x) ((x) * (x))
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_kernel (double x,
|
|
|
|
double y)
|
|
|
|
{
|
|
|
|
double value[KERNEL_WIDTH][KERNEL_HEIGHT];
|
|
|
|
double dist_x;
|
|
|
|
double dist_y;
|
|
|
|
double sum;
|
|
|
|
double w;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
memset (value, 0, KERNEL_WIDTH * KERNEL_HEIGHT * sizeof (double));
|
|
|
|
sum = 0.0;
|
|
|
|
|
|
|
|
x += 1.0;
|
|
|
|
y += 1.0;
|
|
|
|
|
|
|
|
for (j = 0; j < STEPS * KERNEL_HEIGHT; j++)
|
|
|
|
{
|
|
|
|
dist_y = y - (((double)j + 0.5) / (double)STEPS);
|
|
|
|
|
|
|
|
for (i = 0; i < STEPS * KERNEL_WIDTH; i++)
|
|
|
|
{
|
|
|
|
dist_x = x - (((double)i + 0.5) / (double)STEPS);
|
2003-07-14 22:14:30 +08:00
|
|
|
|
2000-05-29 16:40:29 +08:00
|
|
|
/* I've tried to use a gauss function here instead of a
|
|
|
|
threshold, but the result was not that impressive. */
|
|
|
|
w = (SQR (dist_x) + SQR (dist_y)) < THRESHOLD ? 1.0 : 0.0;
|
|
|
|
|
|
|
|
value[i / STEPS][j / STEPS] += w;
|
|
|
|
sum += w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < KERNEL_HEIGHT; j++)
|
|
|
|
{
|
|
|
|
for (i = 0; i < KERNEL_WIDTH; i++)
|
|
|
|
{
|
|
|
|
w = 256.0 * (value[i][j] / sum);
|
|
|
|
printf (" %3d,", (int)w);
|
|
|
|
}
|
2003-07-14 22:14:30 +08:00
|
|
|
}
|
2000-05-29 16:40:29 +08:00
|
|
|
}
|
|
|
|
|
2003-07-14 22:14:30 +08:00
|
|
|
int
|
2000-05-29 16:40:29 +08:00
|
|
|
main (int argc,
|
|
|
|
char **argv)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
double x, y;
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
printf ("/* gimppaintcore-kernels.h\n"
|
2000-05-29 16:40:29 +08:00
|
|
|
" *\n"
|
|
|
|
" * This file was generated using kernelgen as found in the tools dir.\n");
|
|
|
|
printf (" * (threshold = %g)\n", THRESHOLD);
|
|
|
|
printf (" */\n\n");
|
2002-02-15 03:31:16 +08:00
|
|
|
printf ("#ifndef __GIMP_PAINT_CORE_KERNELS_H__\n");
|
|
|
|
printf ("#define __GIMP_PAINT_CORE_KERNELS_H__\n\n");
|
2002-02-13 22:50:37 +08:00
|
|
|
printf ("#define KERNEL_WIDTH %d\n", KERNEL_WIDTH);
|
|
|
|
printf ("#define KERNEL_HEIGHT %d\n", KERNEL_HEIGHT);
|
|
|
|
printf ("#define KERNEL_SUBSAMPLE %d\n", SUBSAMPLE);
|
2000-05-29 16:40:29 +08:00
|
|
|
printf ("\n\n");
|
|
|
|
printf ("/* Brush pixel subsampling kernels */\n");
|
2002-02-15 03:31:16 +08:00
|
|
|
printf ("static const int subsample[%d][%d][%d] =\n{\n",
|
2000-05-29 16:40:29 +08:00
|
|
|
SUBSAMPLE + 1, SUBSAMPLE + 1, KERNEL_WIDTH * KERNEL_HEIGHT);
|
2003-07-14 22:14:30 +08:00
|
|
|
|
2000-05-29 16:40:29 +08:00
|
|
|
for (j = 0; j <= SUBSAMPLE; j++)
|
|
|
|
{
|
|
|
|
y = (double)j / (double)(SUBSAMPLE);
|
2003-07-14 22:14:30 +08:00
|
|
|
|
|
|
|
printf (" {\n");
|
2000-05-29 16:40:29 +08:00
|
|
|
|
|
|
|
for (i = 0; i <= SUBSAMPLE; i++)
|
|
|
|
{
|
|
|
|
x = (double)i / (double)(SUBSAMPLE);
|
|
|
|
|
|
|
|
printf (" {");
|
|
|
|
create_kernel (x, y);
|
2003-07-14 22:14:30 +08:00
|
|
|
printf (" }%s", i < SUBSAMPLE ? ",\n" : "\n");
|
2000-05-29 16:40:29 +08:00
|
|
|
}
|
|
|
|
|
2003-07-14 22:14:30 +08:00
|
|
|
printf (" }%s", j < SUBSAMPLE ? ",\n" : "\n");
|
2000-05-29 16:40:29 +08:00
|
|
|
}
|
|
|
|
|
2002-02-15 03:31:16 +08:00
|
|
|
printf ("};\n\n");
|
|
|
|
|
2003-07-14 22:14:30 +08:00
|
|
|
printf ("#endif /* __GIMP_PAINT_CORE_KERNELS_H__ */\n");
|
2000-07-15 08:51:49 +08:00
|
|
|
|
2003-07-14 22:14:30 +08:00
|
|
|
return 0;
|
2000-05-29 16:40:29 +08:00
|
|
|
}
|