Visibility against an unknown background

O

Odalrick

I need to draw visible lines on pictures with wxPython. That means I
can't simply use, for instance, a black line since it wont be visible
on a black or dark picture.

Painting applications like the GIMP accomplish this by altering the
colour of the line based on the colour of the pixel it covers, but the
only way I can think of doing that is getting each pixel, transforming
the colour then painting it on the screen, which seems like a horribly
inefficient way do it.

I could use alternating colour on the lines, but I don't think that
will be good enough for my taste.

I think I will use a partially transparent bitmap with a hole in the
appropriate place and move the hole as needed.

I realized the last solution as I was writing this and I think it will
work fairly well, but I'm still wondering if there is another, better
solution i might have missed.

/Odalrick
 
P

Paul McGuire

Odalrick said:
I need to draw visible lines on pictures with wxPython. That means I
can't simply use, for instance, a black line since it wont be visible
on a black or dark picture.

Painting applications like the GIMP accomplish this by altering the
colour of the line based on the colour of the pixel it covers, but the
only way I can think of doing that is getting each pixel, transforming
the colour then painting it on the screen, which seems like a horribly
inefficient way do it.

I could use alternating colour on the lines, but I don't think that
will be good enough for my taste.

I think I will use a partially transparent bitmap with a hole in the
appropriate place and move the hole as needed.

I realized the last solution as I was writing this and I think it will
work fairly well, but I'm still wondering if there is another, better
solution i might have missed.

/Odalrick
You could try outlining in a light color. For example, draw a 3-pixel-wide
white or light gray line, and then overlay your 1-pixel-wide black line.
Over light backgrounds, the outline will disappear; over dark backgrounds,
the outline will look like a hole in the background to show your black line.

-- Paul
 
G

Grant Edwards

I need to draw visible lines on pictures with wxPython. That means I
can't simply use, for instance, a black line since it wont be visible
on a black or dark picture.

Painting applications like the GIMP accomplish this by altering the
colour of the line based on the colour of the pixel it covers,
Yup.

but the only way I can think of doing that is getting each
pixel, transforming the colour then painting it on the screen,
which seems like a horribly inefficient way do it.

That's not how it's generally done. When you draw a line, most
graphics toolkits allow you to specify an "operator" that is
applied to the existing pixel and the line-color to determine
the new pixel color. The traditional way to draw lines on
something with varying colors is to use the "xor" operator when
drawing the lines.
 
G

Grant Edwards

That's not how it's generally done. When you draw a line, most
graphics toolkits allow you to specify an "operator" that is
applied to the existing pixel and the line-color to determine
the new pixel color. The traditional way to draw lines on
something with varying colors is to use the "xor" operator when
drawing the lines.

Oh, another big benefit from using the xor operator is that you
can restore the pixmap to it's original state by simply
repeating the exact same line-draw operation. That makes it
trivial to do things like rubber-banding.
 
S

Sergei Organov

Odalrick said:
I need to draw visible lines on pictures with wxPython. That means I
can't simply use, for instance, a black line since it wont be visible
on a black or dark picture.

Painting applications like the GIMP accomplish this by altering the
colour of the line based on the colour of the pixel it covers, but the
only way I can think of doing that is getting each pixel, transforming
the colour then painting it on the screen, which seems like a horribly
inefficient way do it.

There is a better way to do it. Check if the toolkit has line drawing
mode that XORs the line color with the background, then draw using this
mode and white color of the line.

-- Sergei.
 
F

Fredrik Lundh

Sergei said:
There is a better way to do it. Check if the toolkit has line drawing
mode that XORs the line color with the background, then draw using this
mode and white color of the line.

which means that the selection looks like crap most of the time, and
doesn't work at all on medium gray or b/w dithered patterns.

for most cases, "marching ants" is a much better approach (usually done
by drawing alternating stippled patterns). see e.g.

http://en.wikipedia.org/wiki/Marching_ants

for some background.

</F>
 
S

Sergei Organov

Fredrik Lundh said:
which means that the selection looks like crap most of the time,

The selection? What selection? Did the OP or me talk about selection?
and doesn't work at all on medium gray or b/w dithered patterns.

Yes, every method has its pros and cons, but XOR is probably most
efficient.
for most cases, "marching ants" is a much better approach (usually done
by drawing alternating stippled patterns). see e.g.

Where "most cases" depends on application. I'd be very upset to see,
say, 5-6 highly intersecting scientific plots on the same picture drawn
using the "marching ants" approach.

Besides, the marching ants doesn't work for printing :(

-- Sergei.
 
G

Grant Edwards

which means that the selection looks like crap most of the
time,

Possibly -- depending on your defnition of "crap". ;)
and doesn't work at all on medium gray or b/w dithered
patterns.

That depends on what you use as your source color. Mostly
people use use white like I mentioned. I wouldn't say it
doesn't work "at all", since I've always been able to see a
slightly different gray or stippled line, but there are
colors/patterns where an XOR'ed white line doesn't stand out
well.

Xoring a color other than white will should show up better on
gray. There will still be colors/patterns that any color won't
show up on when Xor'ed, but by picking a color other than
white, you'll probably run across it less often.
for most cases, "marching ants" is a much better approach
(usually done by drawing alternating stippled patterns).

That's what the GIMP does, and it is highly visible on any
background. However, it's far more complex (it requires both
animation and some sort of backing store). It's especially
difficult to do with curved or diagonal lines.
 
F

Filip Salomonsson

I'd be very upset to see, say, 5-6 highly intersecting
scientific plots on the same picture drawn using the
"marching ants" approach.

I'd be a bit upset to see scientific plots *on a picture* at all,
regardless of approach.
 
F

Fredrik Lundh

Sergei said:
>
> Yes, every method has its pros and cons, but XOR is probably most
> efficient.

back in the days when backing store was expensive, and memory bandwidth
was limited, maybe. contemporary graphics hardware is something radi-
cally different.
Where "most cases" depends on application. I'd be very upset to see,
say, 5-6 highly intersecting scientific plots on the same picture drawn
using the "marching ants" approach.

but the mostly random colors you get from XOR wouldn't upset your color
vision subsystem?

to solve your specific case, I'd use bitmask algebra to generate alpha
layers (or masks/stencil buffers), and use standard compositing to
generate the final result.

</F>
 
S

Sergei Organov

Filip Salomonsson said:
I'd be a bit upset to see scientific plots *on a picture* at all,
regardless of approach.

Sorry, probably I just wrongly used the word "picture" here, I didn't
mean to mean something like "photo". Maybe "canvas" should have been a
better word.

-- Sergei.
 
S

Sergei Organov

Fredrik Lundh said:
Sergei Organov wrote:
[...]
Where "most cases" depends on application. I'd be very upset to see,
say, 5-6 highly intersecting scientific plots on the same picture drawn
using the "marching ants" approach.

but the mostly random colors you get from XOR wouldn't upset your color
vision subsystem?

Here I don't care much about particular colors, -- it's enough for them
to be different.
to solve your specific case, I'd use bitmask algebra to generate alpha
layers (or masks/stencil buffers), and use standard compositing to
generate the final result.

Well, it's enough for me to know that you won't use marching ants for
that ;)

-- Sergei.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top