Drawing on surface

Hi there

What I have is a SDL surface that has an image on
it and I want to “draw” (lines dots)on top of it.
Currently I have 1 surface that holds the image
and 2nd surface to draw on to. What I want to do
is clear the drawing and restore the
backgroud image and then draw on it again.

What I want to achieve is how a zoom box
is used on an image like in gimp or photoshop
where you drag the zoom box to what ever size
you need and then zoom

Im just not sure how to do this with SDL

thanks

Simon wrote:

Hi there

What I have is a SDL surface that has an image on
it and I want to “draw” (lines dots)on top of it.
Currently I have 1 surface that holds the image
and 2nd surface to draw on to. What I want to do
is clear the drawing and restore the
backgroud image and then draw on it again.

What I want to achieve is how a zoom box
is used on an image like in gimp or photoshop
where you drag the zoom box to what ever size
you need and then zoom

Im just not sure how to do this with SDL

Hmm, the fastest solution would be XORing your line into the original
image. XORing it again will restore the original content. However this
will result in “inverted” colors.

Another approach would be to save just the pixels across you paint the
line. Putting these pixels back, restores the image. With just vertical
and horizontal lines, this is pretty fast as well.

Your idea will also work, assuming you set the background color of your
overlay surface to be the transparent color for blits. But for each
redraw, you will have to blit the background. clear the overlay. redraw
the overlay and finally blit the overlay.

I hope my ideas are helpful in a way,–
Karsten-O. Laux Lehrstuhl Digitialtechnik
@Karsten-O_Laux Fachbereich
Tel: 0631-205-4683 Elektrotechnik und Informationstechnik
Universit?t Kaiserslautern

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

“Karsten-O. Laux” wrote:

Simon wrote:

Hi there

What I have is a SDL surface that has an image on
it and I want to “draw” (lines dots)on top of it.
Currently I have 1 surface that holds the image
and 2nd surface to draw on to. What I want to do
is clear the drawing and restore the
backgroud image and then draw on it again.

What I want to achieve is how a zoom box
is used on an image like in gimp or photoshop
where you drag the zoom box to what ever size
you need and then zoom

Im just not sure how to do this with SDL

Hmm, the fastest solution would be XORing your line into the original
image. XORing it again will restore the original content. However this
will result in “inverted” colors.

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.>

Another approach would be to save just the pixels across you paint the
line. Putting these pixels back, restores the image. With just vertical
and horizontal lines, this is pretty fast as well.

Your idea will also work, assuming you set the background color of your
overlay surface to be the transparent color for blits. But for each
redraw, you will have to blit the background. clear the overlay. redraw
the overlay and finally blit the overlay.

I hope my ideas are helpful in a way,


Karsten-O. Laux Lehrstuhl Digitialtechnik
laux at eit.uni-kl.de Fachbereich
Tel: 0631-205-4683 Elektrotechnik und Informationstechnik
Universit?t Kaiserslautern

But it’s both the same speed on the ARM, and this saves one register :)))
Karsten, is that where you got it from ? :slight_smile:

All the best,
robOn Mon, Feb 07, 2000 at 03:36:30PM -0800, Sam Lantinga wrote:

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

does someone wana throw together some code to test the speed? id like to know
what arcitectures which is faster on but have absolutly no time right now.

Robert Linden wrote:> On Mon, Feb 07, 2000 at 03:36:30PM -0800, Sam Lantinga wrote:

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

But it’s both the same speed on the ARM, and this saves one register :)))
Karsten, is that where you got it from ? :slight_smile:

All the best,
rob

Hi
Just wanted to say thanks for the help :slight_smile:

sorry for the useless post :slight_smile:

For x86 anyway I believe the XOR method is only used for historical
reasons, an XOR was a lot fast than a string copy. Do asm programmers
still use xor ax,ax or is that lost in the mists of time?:slight_smile:

Long live the confused,
Akawaka.–
Bother, said Pooh as he wrung out his lambskin condoms to dry.

On Tue, 8 Feb 2000, Jess wrote:

does someone wana throw together some code to test the speed? id like to know
what arcitectures which is faster on but have absolutly no time right now.

Robert Linden wrote:

On Mon, Feb 07, 2000 at 03:36:30PM -0800, Sam Lantinga wrote:

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

But it’s both the same speed on the ARM, and this saves one register :)))
Karsten, is that where you got it from ? :slight_smile:

All the best,
rob

on Die, 08 Feb 2000 Robert Linden wrote:>On Mon, Feb 07, 2000 at 03:36:30PM -0800, Sam Lantinga wrote:

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

But it’s both the same speed on the ARM, and this saves one register :)))
Karsten, is that where you got it from ? :slight_smile:

nope, it is just boolean algebra. :wink:

regards,


Karsten-O. Laux (@Karsten_Laux)

Yah asm programmers still use xor ax,ax in some
situations. It’s usually faster that way but it all
depends. I’m speaking from the point of view of
someone who actually writes win32 programs in
assembly…call me crazy

Jared>For x86 anyway I believe the XOR method is only used

for historical reasons, an XOR was a lot fast than a
string copy. Do asm programmers still use xor ax,ax
or is that lost in the mists of time?:slight_smile:
Long live the confused,
Akawaka.


Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.

Jared wrote:

Yah asm programmers still use xor ax,ax in some
situations. It’s usually faster that way but it all
depends. I’m speaking from the point of view of

When is there something faster than xor eax, eax? mov eax, 0 ‘and’ and
eax, 0 both have longer opcodes so the only time I can think of where
the latter are faster is when the first one doesn’t pair but the latter
ones do. Can this be? I bailed out at asm optimization a long time ago,
so could you enlighten me :wink:

someone who actually writes win32 programs in
assembly…call me crazy

you are crazy ;–)--
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

on Die, 08 Feb 2000 Karsten-Olaf Laux wrote:

on Die, 08 Feb 2000 Robert Linden wrote:

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

But it’s both the same speed on the ARM, and this saves one register :)))
Karsten, is that where you got it from ? :slight_smile:

nope, it is just boolean algebra. :wink:

sorry for this short reply …

Why using xor ?
xor your lines onto an background image has the big advantage, that you do not
need to save the background. you simply draw the line a second time and the
original image is restored.
This is very nice for selection boxes… but as I mentioned, you will probably
get funny colors. As I remember right, the implementation of monochrome
mousecursors usually use the “xor trick”. (hmm …)

so far,>>On Mon, Feb 07, 2000 at 03:36:30PM -0800, Sam Lantinga wrote:


Karsten-O. Laux (@Karsten_Laux)

Karsten-Olaf Laux wrote:

on Die, 08 Feb 2000 Karsten-Olaf Laux wrote:

on Die, 08 Feb 2000 Robert Linden wrote:

hmm, using 3 XOR’s you can swap the pixels in the one image with ones in
the other (is this what your refering to?) im not sure about speed though.

a = xor(a,b)
b = xor(a,b)
a = xor(a,b)

that would swap a and b so the value of be is now the value of a and vise
versa. you jsut do it again to switch back.

It’s a very cool trick, but I’ve benchmarked it on the x86, and it is slower
than tmp = a; a = b; b = tmp;

But it’s both the same speed on the ARM, and this saves one register :)))
Karsten, is that where you got it from ? :slight_smile:

nope, it is just boolean algebra. :wink:

sorry for this short reply …

Why using xor ?
xor your lines onto an background image has the big advantage, that you do not
need to save the background. you simply draw the line a second time and the
original image is restored.
This is very nice for selection boxes… but as I mentioned, you will probably
get funny colors. As I remember right, the implementation of monochrome
mousecursors usually use the “xor trick”. (hmm …)

why would you get funny colors? it simply switches the data doesnt alter it, as
long as they arent indexed colors and you switch all of each pixel i dont see how
this would cause “funny colors”

Jess> >>On Mon, Feb 07, 2000 at 03:36:30PM -0800, Sam Lantinga wrote:

so far,


Karsten-O. Laux (klaux at rhrk.uni-kl.de)

Funny as in reversed, opposed to, say, a pure red selection-box-line.
Of course only while pixels are swapped/XORed, at the end the colors will
be ok again.

All the best,
robOn Wed, Feb 09, 2000 at 06:09:08AM -0600, Jess wrote:

why would you get funny colors? it simply switches the data doesnt alter it, as
long as they arent indexed colors and you switch all of each pixel i dont see how
this would cause “funny colors”

/* K6: mov reg,0 is slightly faster than xor reg,reg but is 3 bytes
longer. */

Markus

---- Markus F.X.J. Oberhumer <@Markus_F.X.J_Oberhum> ----
---- http://wildsau.idv.uni-linz.ac.at/mfx/ ----
---- 5E CB 5C 85 DE AF 9E BF E9 DA 7E 6A 39 F8 CC 67 ----

                         3 WARPS TO URANUSOn 08-Feb-2000 Daniel Vogel wrote:

Jared wrote:

Yah asm programmers still use xor ax,ax in some
situations. It’s usually faster that way but it all
depends. I’m speaking from the point of view of

When is there something faster than xor eax, eax? mov eax, 0 ‘and’ and
eax, 0 both have longer opcodes so the only time I can think of where
the latter are faster is when the first one doesn’t pair but the latter
ones do. Can this be? I bailed out at asm optimization a long time ago,
so could you enlighten me :wink:

From gcc-2.95.2/gcc/config/i386/i386.md :