472,333 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 software developers and data experts.

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 1382
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal...
25
by: Neal | last post by:
According to the CSS lint at http://htmlhelp.org/tools/csscheck/, "The shorthand background property is more widely supported than...
11
by: Konrad Den Ende | last post by:
I have a function returning a string but the problem is that the color of it is blue which suits me well for some pages but not for others. Is it...
2
by: Haines Brown | last post by:
I have situations in which I define the color attribute for an element that is displayed against a background-image. For example, an incipit: ...
2
by: larryparker | last post by:
I'm really frustrated by what seems to be a ridiculously easy task, and yet.... I'm trying to create a web page with a series of entries, each...
7
by: Ryaby21 | last post by:
Please help! i have everything set up with my CSS HTML layout and its all good. im using 3 divs at the moment and what i want to to do now is to add...
3
by: SteveA | last post by:
This is my first post here, so please go easy on me. I'm working on a site for my family (aurigema.com) and after designing and redesigning the...
3
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I am creating a ControlTemplate for a ComboBox. This ComboBox will have a transparent background so it uses the control it is placed in...
2
by: kruczek | last post by:
Hi, I try add logo for myspace and appear "bug" or logo is here but without background. I need help, I am vocalist of band we always do by onself......
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.