Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to xor a bitmap using Direct2D

562 views
Skip to first unread message

Matt Houser

unread,
Aug 25, 2009, 3:28:01 PM8/25/09
to
How can I draw an ID2D1Bitmap object to a ID2D1RenderTarget in an xor fashion?

I cannot seem to find an appropriate API call.

Thanks,
...Matt

Richard [Microsoft Direct3D MVP]

unread,
Aug 25, 2009, 7:33:56 PM8/25/09
to
[Please do not mail me a copy of your followup]

=?Utf-8?B?TWF0dCBIb3VzZXI=?= <MattH...@discussions.microsoft.com> spake the secret code
<7578FE24-C035-4535...@microsoft.com> thusly:

>How can I draw an ID2D1Bitmap object to a ID2D1RenderTarget in an xor fashion?

Are you trying to do rubber banding?

In GDI you would do this using xor with the old position of the
rubber-banded geometry and then xor the new position.

In a GPU accelerated environment, you just clear the back buffer and
render the whole scene again.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>

Matt Houser

unread,
Aug 26, 2009, 12:22:02 PM8/26/09
to
"Richard [Microsoft Direct3D MVP]" wrote:

> Are you trying to do rubber banding?
>
> In GDI you would do this using xor with the old position of the
> rubber-banded geometry and then xor the new position.
>
> In a GPU accelerated environment, you just clear the back buffer and
> render the whole scene again.

No, I am not trying to rubberband.

I have many elements on-screen of varying colours. In our GDI
implementation, in order for certain elements on "stick out" and not blend
into the background, we do an xor border around the element. This way, the
border will always be seen.

How can I accomplish the same using Direct2D?

...Matt

Richard [Microsoft Direct3D MVP]

unread,
Aug 26, 2009, 5:10:56 PM8/26/09
to
[Please do not mail me a copy of your followup]

=?Utf-8?B?TWF0dCBIb3VzZXI=?= <MattH...@discussions.microsoft.com> spake the secret code

<06B58182-8FD8-4E04...@microsoft.com> thusly:

>I have many elements on-screen of varying colours. In our GDI
>implementation, in order for certain elements on "stick out" and not blend
>into the background, we do an xor border around the element. This way, the
>border will always be seen.
>
>How can I accomplish the same using Direct2D?

Can you post a link to a screen shot of what your existing app does so
I can see the visual result?

Matt Houser

unread,
Aug 26, 2009, 5:37:02 PM8/26/09
to
Here is the desired effect: http://www.houser.ca/Pulse/xor1.jpg

You'll notice that the triangle and circle are surrounded by a noticable
border regardless of the colour the user chooses for the background. As
well, if there are any other objects below the triangle or circle (like the
black line), the border does not get obscured by those objects. The triangle
and circle is always noticable to the user.

...Matt

Richard [Microsoft Direct3D MVP]

unread,
Aug 26, 2009, 7:37:37 PM8/26/09
to
[Please do not mail me a copy of your followup]

=?Utf-8?B?TWF0dCBIb3VzZXI=?= <MattH...@discussions.microsoft.com> spake the secret code

<E6F13566-2576-4B0F...@microsoft.com> thusly:

There are a couple of choices here that you could try.

First, you could try using a GDI DC on the render target, but that's
going to be slow due to the nature of GDI.

Second, you could draw the border as stipple pattern of alternating
white and black pixels so that the border would be visible. This is
what most drawing programs like Photoshop do to indicate a selection
boundary while ensuring contrast against an arbitrary background.

Matt Houser

unread,
Aug 27, 2009, 10:16:01 AM8/27/09
to
Thanks,

So in summary, there's no way to xor using Direct2D. So we'll have to find
alternatives. I can work with that.

Is it technically difficult to xor using hardware, or was it a design
decision that Direct2D not support it? Is it possible that it may be added
in the future? I just would like to know why it's not supported so I can
explain it to people who will ask.

Thanks,
...Matt

Ivan Brugiolo [MSFT]

unread,
Aug 28, 2009, 2:57:13 AM8/28/09
to
Any bitwise operation on colors (excluding color space issues,
gamma correction issues and pixel representation issues)
requires bitwise operator support,
that is generally available in the pixel-shader level of D3D10 or greater.
D2D runs on 10Level9 or greater, and,
it is effectively limited to capabilities of 9L hardware.

On everage, a good approximation of XOR can be obtained
by programming the blend-mode of the output-merger-state so that it does
an inversion of the destination with 0 contribution from the source
(called DestInvert mode).

Changing the output merger in the middle of an arbitrary
batch of drawing operations may have undefined results
(based upon triangle culling rules, Z-buffers, and other tricks that
you can use to implement 2D on top of a 3D pipeline).

GDI interop, as already recommended, seems the most feasible
approach. That operation may even be partially hadware
accelerated on WDDM 1.1 drivers on Win7.

--

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Matt Houser" <MattH...@discussions.microsoft.com> wrote in message
news:8FAF7BE2-38D9-4822...@microsoft.com...

0 new messages