I want to draw a 2-color picture on the screen from a series of points stored in memory (in bit series), e.g. in an array, to say, 128x128, that's a 256 byte array (128/8*128/8=256). What's the most efficient way to do this?
Posted on 2004-05-28 20:27:56 by optimus
I can think of two ways.
One of them would be to create a DIB from the bitmap, and blt that to screen. How fast this is, depends on whether your videocard can accelerate this process or not.

Another one would be to create a lookuptable with which you convert the bitmap to an 8/16/32-bit image, and then render that.
Eg, you grab 8 bits at a time from the bitmap, then you look it up into a table that maps 10100100 -> FF00FF0000FF0000. So you get 8 pixels at a time. This is just a single qword, so you could copy it with a single fild/fistp or movq/movq operation.
Posted on 2004-05-29 03:18:13 by Scali
Uhh, the second way makes some sense ^_^
Posted on 2004-05-29 08:44:22 by optimus
You could use this if you want to confuse people who will read your code (contractor) :)

``````
mov eax, num_4_bit
mul eax, 00204081h
and eax, 01010101h
lea eax, [eax*2 + eax]
lea eax, [eax*4 + eax]
``````

Mirno
Posted on 2004-05-29 11:39:32 by Mirno
I follow what your doing, but how did you come up with 00204081h ? to make this all work? Is there a method?

If i go 01010101h / 0000000Fh, i get 112233h

Which also apears to work.. (didnt check all 16 cases).

Regards,
:NaN:
Posted on 2004-05-29 13:24:50 by NaN
Oops I missed a final lea (or replace all 3 lea's with a single mul by 0FFh), I've only replicated the bottom 4 bits...

Now here comes the science bit!
By multiplying the four bit number (dcba) by 0204081h we get:
``````
dcba *
00000000 00100000 01000000 10000001 =
0000000d cba000dc ba000dcb a000dcba
00000001 00000001 00000001 00000001 AND
0000000d 0000000c 0000000b 0000000a
``````

The leas replicate the bottom bit across the whole byte (you can also just multiply by 0FFh).

Mirno
Posted on 2004-05-29 17:44:05 by Mirno

I want to draw a 2-color picture on the screen from a series of points stored in memory (in bit series), e.g. in an array, to say, 128x128, that's a 256 byte array (128/8*128/8=256). What's the most efficient way to do this?

IS this for the LCD plugin? Just to go off topic for a bit, I have successfully incorporated my Z80 CPU emulator into a plugin, it steps successfully too, also I have added 2 8-bit Output ports to the Z80 accessible by (later on) user defined I/O address (now locked at 0C0h and 0C1h). I can't wait to have that LCD plugin ready, wanna talk to it with the Z80 :D
Posted on 2004-05-29 19:52:28 by x86asm
Yes, that's it. Actually there are already a LED plugin and a basic LCD plugin included in ProEmulator. This LCD plugin was written by my classmate. It maps I/O space as display buffer (but now it maps a byte to a pixel). I will implement a better LCD plugin (maybe emulates a real LCD controller)
Posted on 2004-05-29 22:31:57 by optimus