New "colour" for drawPxel

Libraries, utilities, bootloaders...

New "colour" for drawPxel

Postby Matrix828 » Mon Aug 25, 2014 5:40 pm

How about, in addition to BLACK and WHITE colours we have an INVERT option?
Eg,
Code: Select all
gb.display.color = INVERT;
gb.display.drawPixel(x, y);


And obviously, if the pixel at (x, y) is white, then it will be set to black, and vise-versa.
Matrix828
 
Posts: 43
Joined: Tue Jul 22, 2014 7:44 pm

Re: New "colour" for drawPxel

Postby rodot » Wed Aug 27, 2014 10:06 am

Mmh why not, that could be interesting and wouldn't take a lot more coding at first glance.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: New "colour" for drawPxel

Postby DFX2KX » Wed Aug 27, 2014 9:39 pm

yeah, that seems useful. It'll be a teeny bit slower because of having to check pixels, but it wouldn't be that bad in the scheme of things.
DFX2KX
 
Posts: 250
Joined: Mon Apr 14, 2014 3:48 am

Re: New "colour" for drawPxel

Postby yodasvideoarcade » Wed Sep 03, 2014 12:41 pm

That would definetely be useful, especially when drawing bitmaps. You would easily recognize overlapping images since they come out inverted.

Basically it's just adding the bits together, no checking of pixels neccesary.
User avatar
yodasvideoarcade
 
Posts: 102
Joined: Sat Apr 19, 2014 10:48 am
Location: Frankfurt/Germany

Re: New "colour" for drawPxel

Postby rodot » Thu Sep 04, 2014 6:28 am

yodasvideoarcade wrote:Basically it's just adding the bits together, no checking of pixels neccesary.

You'll have to read the current color of the pixel in the display buffer in order to be able to invert it.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: New "colour" for drawPxel

Postby rodot » Sun Sep 07, 2014 10:40 am

I added the INVERT color in the last commit to the beta branch ;)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: New "colour" for drawPxel

Postby TheTurnipKing » Fri Sep 12, 2014 7:54 pm

Shouldn't you just be able to use a logical operation? The current value doesn't matter. Adding 1 should flip it from 1 to 0 OR 0 to 1.
TheTurnipKing
 
Posts: 13
Joined: Wed Sep 10, 2014 3:29 am

Re: New "colour" for drawPxel

Postby rodot » Fri Sep 12, 2014 8:13 pm

Of course the current value matters, how to you want to invert a pixel if you don't know its initial value :)
Yes it "just use a logical operation" as it's set the pixel to the opposite of its current value.
You can't just add 1 to a pixel because pixels are stored 8 by 8 in bytes (a byte contains 8 bits), and there is no bitwise addition.

But anyway now it's in the library and working, enjoy :)
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: New "colour" for drawPxel

Postby TheTurnipKing » Sat Sep 13, 2014 6:42 am

The initial value shouldn't matter if the content of the bit is just going to be flipped, especially if you can flip the bit either way with the same operation.

I'm pretty sure Arduino has bitwise operators, but I'm not yet familar with how the Gamebuino library is mapping the screen in memory.

Rightly enough, It probably is more hassle than it's worth on a 16mhz microcontroller though. I just remember a lot of this stuff from my 3.5mhz home micro days.
TheTurnipKing
 
Posts: 13
Joined: Wed Sep 10, 2014 3:29 am

Re: New "colour" for drawPxel

Postby rodot » Sat Sep 13, 2014 9:20 am

Well why not but how do you flip a single bit in a byte then ?
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Next

Return to Software Development

Who is online

Users browsing this forum: No registered users and 27 guests

cron