Visibility against an unknown background

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Odalrick

    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

  • Paul McGuire

    #2
    Re: Visibility against an unknown background

    "Odalrick" <odalrick@hotma il.comwrote in message
    news:1161701658 .722683.46230@e 3g2000cwe.googl egroups.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


    Comment

    • Grant Edwards

      #3
      Re: Visibility against an unknown background

      On 2006-10-24, Odalrick <odalrick@hotma il.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

      Comment

      • Grant Edwards

        #4
        Re: Visibility against an unknown background

        On 2006-10-24, Grant Edwards <grante@visi.co mwrote:
        On 2006-10-24, Odalrick <odalrick@hotma il.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

        Comment

        • Sergei Organov

          #5
          Re: Visibility against an unknown background

          "Odalrick" <odalrick@hotma il.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.

          Comment

          • Fredrik Lundh

            #6
            Re: Visibility against an unknown background

            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.



            for some background.

            </F>

            Comment

            • Sergei Organov

              #7
              Re: Visibility against an unknown background

              Fredrik Lundh <fredrik@python ware.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.

              Comment

              • Grant Edwards

                #8
                Re: Visibility against an unknown background

                On 2006-10-24, Fredrik Lundh <fredrik@python ware.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!!

                Comment

                • Filip Salomonsson

                  #9
                  Re: Visibility against an unknown background

                  On 10/24/06, Sergei Organov <osv@javad.comw rote:
                  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

                  Comment

                  • Fredrik Lundh

                    #10
                    Re: Visibility against an unknown background

                    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>

                    Comment

                    • Ben Finney

                      #11
                      Re: Visibility against an unknown background

                      Grant Edwards <grante@visi.co mwrites:
                      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.c h/autofile/www/chapter2_105.ht ml>

                      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

                      Comment

                      • Sergei Organov

                        #12
                        Re: Visibility against an unknown background

                        "Filip Salomonsson" <filip.salomons son@gmail.comwr ites:
                        On 10/24/06, Sergei Organov <osv@javad.comw rote:
                        >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.

                        Comment

                        • Sergei Organov

                          #13
                          Re: Visibility against an unknown background

                          Fredrik Lundh <fredrik@python ware.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.

                          Comment

                          Working...