469,271 Members | 832 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Visibility against an unknown background

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

Oct 24 '06 #1
12 1308
"Odalrick" <od******@hotmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>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
Oct 24 '06 #2
On 2006-10-24, Odalrick <od******@hotmail.comwrote:
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.

--
Grant Edwards grante Yow! Can you MAIL a BEAN
at CAKE?
visi.com
Oct 24 '06 #3
On 2006-10-24, Grant Edwards <gr****@visi.comwrote:
On 2006-10-24, Odalrick <od******@hotmail.comwrote:
>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.
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.

--
Grant Edwards grante Yow! I just forgot my
at whole philosophy of life!!!
visi.com
Oct 24 '06 #4
"Odalrick" <od******@hotmail.comwrites:
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.

Oct 24 '06 #5
Sergei Organov wrote:
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>

Oct 24 '06 #6
Fredrik Lundh <fr*****@pythonware.comwrites:
Sergei Organov wrote:
>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,
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.

Oct 24 '06 #7
On 2006-10-24, Fredrik Lundh <fr*****@pythonware.comwrote:
Sergei Organov wrote:
>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,
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.

--
Grant Edwards grante Yow! The PILLSBURY
at DOUGHBOY is CRYING for
visi.com an END to BURT REYNOLDS
movies!!
Oct 24 '06 #8
On 10/24/06, Sergei Organov <os*@javad.comwrote:
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.
--
filip salomonsson
Oct 24 '06 #9
Sergei Organov wrote:
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.
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>

Oct 24 '06 #10
Grant Edwards <gr****@visi.comwrites:
The traditional way to draw lines on something with varying colors
is to use the "xor" operator when drawing the lines.
But first, negotiate a patent license for this highly innovative and
non-obvious technique that is "owned" as US Patent #4,197,590.

<URL:http://www.fourmilab.ch/autofile/www/chapter2_105.html>

Aren't monopolies on ideas wonderful?

--
\ "I'd like to see a nude opera, because when they hit those high |
`\ notes, I bet you can really see it in those genitals." -- Jack |
_o__) Handey |
Ben Finney

Oct 24 '06 #11
"Filip Salomonsson" <fi***************@gmail.comwrites:
On 10/24/06, Sergei Organov <os*@javad.comwrote:
>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.
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.

Oct 25 '06 #12
Fredrik Lundh <fr*****@pythonware.comwrites:
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.

Oct 25 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Chris Beall | last post: by
25 posts views Thread by Neal | last post: by
11 posts views Thread by Konrad Den Ende | last post: by
2 posts views Thread by Haines Brown | last post: by
3 posts views Thread by SteveA | last post: by
3 posts views Thread by =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.