~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to tools/kernelgen.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * kernelgen -- Copyright (C) 2000 Sven Neumann <sven@gimp.org>
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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.
 
23
 */
 
24
 
 
25
#include <math.h>
 
26
#include <stdio.h>
 
27
#include <string.h>
 
28
 
 
29
 
 
30
#define STEPS          64
 
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
 
34
#define SUBSAMPLE       4
 
35
#define THRESHOLD       0.25  /*  try to change this one         */
 
36
 
 
37
#define SQR(x) ((x) * (x))
 
38
 
 
39
static void
 
40
create_kernel (double x,
 
41
               double y)
 
42
{
 
43
  double value[KERNEL_WIDTH][KERNEL_HEIGHT];
 
44
  double dist_x;
 
45
  double dist_y;
 
46
  double sum;
 
47
  double w;
 
48
  int i, j;
 
49
 
 
50
  memset (value, 0, KERNEL_WIDTH * KERNEL_HEIGHT * sizeof (double));
 
51
  sum = 0.0;
 
52
 
 
53
  x += 1.0;
 
54
  y += 1.0;
 
55
 
 
56
  for (j = 0; j < STEPS * KERNEL_HEIGHT; j++)
 
57
    {
 
58
      dist_y = y - (((double)j + 0.5) / (double)STEPS);
 
59
 
 
60
      for (i = 0; i < STEPS * KERNEL_WIDTH; i++)
 
61
        {
 
62
          dist_x = x - (((double) i + 0.5) / (double) STEPS);
 
63
 
 
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;
 
67
 
 
68
          value[i / STEPS][j / STEPS] += w;
 
69
          sum += w;
 
70
        }
 
71
    }
 
72
 
 
73
  for (j = 0; j < KERNEL_HEIGHT; j++)
 
74
    {
 
75
      for (i = 0; i < KERNEL_WIDTH; i++)
 
76
        {
 
77
          w = (double) KERNEL_SUM * value[i][j] / sum;
 
78
          printf (" %3d,", (int) (w + 0.5));
 
79
        }
 
80
    }
 
81
}
 
82
 
 
83
int
 
84
main (int    argc,
 
85
      char **argv)
 
86
{
 
87
  int    i, j;
 
88
  double x, y;
 
89
 
 
90
  printf ("/* gimpbrushcore-kernels.h\n"
 
91
          " *\n"
 
92
          " *   This file was generated using kernelgen as found in the tools dir.\n");
 
93
  printf (" *   (threshold = %g)\n", THRESHOLD);
 
94
  printf (" */\n\n");
 
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);
 
101
  printf ("\n\n");
 
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);
 
105
 
 
106
  for (j = 0; j <= SUBSAMPLE; j++)
 
107
    {
 
108
      y = (double) j / (double) SUBSAMPLE;
 
109
 
 
110
      printf ("  {\n");
 
111
 
 
112
      for (i = 0; i <= SUBSAMPLE; i++)
 
113
        {
 
114
          x = (double) i / (double) SUBSAMPLE;
 
115
 
 
116
          printf ("    {");
 
117
          create_kernel (x, y);
 
118
          printf (" }%s", i < SUBSAMPLE ? ",\n" : "\n");
 
119
        }
 
120
 
 
121
      printf ("  }%s", j < SUBSAMPLE ? ",\n" : "\n");
 
122
    }
 
123
 
 
124
  printf ("};\n\n");
 
125
 
 
126
  printf ("#endif /* __GIMP_BRUSH_CORE_KERNELS_H__ */\n");
 
127
 
 
128
  return 0;
 
129
}