On Wed, 29 Aug 2001, Simon Budig wrote:

> Sven Neumann ([EMAIL PROTECTED]) wrote:
> > Instead of drawing brush pixmaps onto the canvas at
> > equidistant spots along the line as the paintbrush does, the pencil
> > tool could use a real line-drawing algorithm (Bresenham). This would
> > imply that our brushes couldn't be used with the pencil tool any 
> > longer since this algorithm would only work for rounded or square 
> > pencil tips (or am I wrong here?).
> I think you are wrong there  :-)
> You could calculate the intermediate points with Bresenham and then
> place the brushes on these points only (or a subset, according to the
> spacing). So the Pencil would place the brushes always at integer
> positions which results in perfect lines for 1-pixel brushes and
> usable lines with ornamental brushes.
> So if we have a 10-pixel wide brush with a spacing of 50 you could
> place it on every fifth pixel of the bresenham-calculated coordinates.
> Does this sound good?

Thank You guys. It seems drawing a good thin non-antialiased line is so
foar not implemented, I hope it will be. I could do it, but it would take
a long time for me to understand code and the whole conception of GIMP. By
now, I have the following idea to do it:

[c-like pseudocode]

typedef int (*tool_t)(double x, double y, double intensity, ...);
/* uses tool on x,y
for pencil: puts a single pixel, the nearest to (x,y)
        i.e. at ( (int)(x+0.5), (int)(y+0.5) )
        e.g. for (26.25,123.75) it's (26,124)
for paintbrush: alters four pixel nearest to x,y, with intensity
negative-correlated to distance from (x,y)
        i.e. altered are pixels: 
        ((int)x,(int)y) with intensity (1-fx)*(1-fy)*intensity
        ((int)x+1,(int)y) with intensity fx*(1-fy)*intensity
        ((int)x,(int)y+1) with intensity (1-fx)*fy*intensity
        ((int)x+1,(int)y+1) with intensity fx*fy*intensity
        where fx=x-(int)x, fy=y-(int)y
        (these are fractional parts of x,y)
        (for paintbrush, if intensity>1.0, more adjacent pixels may be

void draw_slash_line_using_a_tool(int x1, int y1, int x2, int y2, tool_t
tool, double intensity, ...)
  assume: x1!=x2, y1!=y2 (in these cases line is not slash)
  assume: x1<x2, y1<y2, x2-x1>=y2-y1 (all other seven possible cases are
                convertible to this by reasonable replacing +/-, x/y, 1/2)
  int dx=x2-x1;
  int dy=y2-y1;
  int x;
  for (x=x1; x<=x2; x++) {
  /* x2-x1+1 tool hits, all of them with integer x values and
        not-necessarily-integer y values, lying along line,
        more precisely on crosings of line and "meridians" of grid */

As you see, it's universal, and would draw line with any tool, if this
tool is correctly implemented to handle non-integer coordinates.

There could be problem if brush size is big and line has to be
half-transparent. E.g. brush radius is 10 and intensity is 0.5. There
would be 1-pixel-close overlapping brush hits, whose intensities would
accumulate. But this problem can easily be compensated if we use more
sophiscated tool_t function, which would reasonably decrease its intensity
(simply dividing nominal intensity by radius size and then by sine/cosine
value of line angle) for all pixels except two ends, and these two ends
would be painted with full nominal intensity, but only half of brush would
be painted (this half which does not overlap with any mid-line brush hit).

How do you all feel about it? Is it a good idea, or not? I think you will
be more able to implement it and insert in proper place in GIMP's source.
If would use a lot of time to analyze sources (in fact, I would have to
learn how to use GIMP sources and thouroughly study it) and find this
proper place, and although this I would however have doubts if this is
correct place and if it does not conflict with GIMP's internal
architecture, assumptions and whatever.

So please: 

If you have a bit of time to do it, do it. If no, tell me, I will however
try to do it for myself and I will send you results of my work, and I hope
this will be useful for you and will not make incompatibility forks.

Sorry for my bad english.

Grzes                  \_______________________|_______________________/
[EMAIL PROTECTED]                         (_)
'Nam chodzi o odglos paszczowo.'  'Patataj patataj patata...'

<annoy echelon> fbi militia bomb action president mossad delta force
militia action anthrax operation fbi codes top secret </annoy echelon>

Gimp-developer mailing list

Reply via email to