Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 16-bit mode bitmaps...

Author
Message
IronHoof2
21
Years of Service
User Offline
Joined: 21st Dec 2003
Location:
Posted: 16th May 2004 09:49
in 16 bit screen res. I cant seem to get the RGB values from the memblock bitmap...

how do i get the individual RGB from the memblock?

like so
set display mdoe 320,240,16
make memblock from bitmap 1,2

from there i dont know where to start.. can someone help?

I am I was
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 16th May 2004 14:50
(a) try not to run in 16 bit...on most cards it will be slower since the hardware blitters etc are optimised for 32bit and need to do extra work to handle 16bit (breaking bytes down to blocks of four or five bits for example)

(b) 16 bit has two ways of encodeing the colour, one uses five bits for each colour value and one bit for alpha, the other uses four bits for each colour and four for the alpha, some cards don`t support the second and go for the broader colour range allowed by the first method and ignore the alpha

(c)why not just lock the pixels and get the rgb direct from the bitmap rather than try to extract them from a memblock (or is this a speed issue thing?)

(d)DB has some issues with 16 bit colour and some cards (like 3DFX), transparency and ghosting will not look right for a start, you may well be best sticking to 32bit since thats what DB works best in, plus it`s easier to work with, 1 byte for red/green/blue and one for the alpha, much easier to work with with DB`s memblock write/read commands that handle bytes, words, and floats easily, bitwise you need to read a byte and then get cute with it to extract the data you want, then rebiuld the byte with the modified 5 bits embedded, a lot of work that is best avoided.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
IronHoof2
21
Years of Service
User Offline
Joined: 21st Dec 2003
Location:
Posted: 17th May 2004 02:51
THis is simple to answer, Im using DBclassic with the enhancment pack from darkMAtter and the next upgrade package after that.

Im not using 3d, im using 2d I just need a fast way to transfer the bitmap to an array and anything is faster than point specially on the fly. Its for my ROTOZOOMER which is fast but getting the image into the array is not,

step 1. transfer bitmap into memblock
step 2. move the memblock image into an array
step 3. run rotozoomer - without point!

Doy you have code to extract the values? and where in the memblock should I begin reading from? 24 bytes after the header?

I know alot about bitmaps except for the 16-bit ones.

Just work with me here I can fallow pretty closely.

I am I was
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 17th May 2004 22:28
the trouble is that I don`t know of any true bytewise operators, you could chop the value up after using bin$ with left$ and right$, but strings are slow, so thats gonna be way slower than you want for so many values, the other way would be to use bytewise operators, for example a byte 10110111 &nded with 00011111 would give you 10111, just what you want, but as far as I know DB does not have logical and/or/xor/not for values, just booleans (it returns 1 or 0) so fast extraction of the values for 16 bit would be a problem, and I don`t know what format the file would be in, IIRC Cattlerustler did a program with memblocks to add lighting to an image, you might like to ask him if the memblock image had any specific format, I would have thought it just straightforward copy of the memory bitmap, 1st value=pixel1 2nd=pixel2 etc, I don`t think it has an header, thats just for bitmap files AFAIK.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
IronHoof2
21
Years of Service
User Offline
Joined: 21st Dec 2003
Location:
Posted: 17th May 2004 22:51
It has a few and is
& is and
| is or
! is not

xor and mod is emulated and so is bitshifting

Function BSL(Initial,ShiftAmount)
ANW=Initial*(2^ShiftAmount)
EndFunction ANW

Function BSR(Initial,ShiftAmount)
ANW=Initial/(2^ShiftAmount)
EndFunction ANW

Funcion Mod(a,b)
c=a/b:m=a-(c*b)
EndFunction m

Function Xor(a,b)
r=(a|b)-(a&b)
EndFunction r

so, now which section of each byte is what color? "i can detect if its one type or not by the format of each byte if i know how its stored"

I am I was
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 17th May 2004 23:50
I just did a few tests and there are 5 bits to a colour, 5 bits for blue, 5 for red and 5 for green, they are in that order, you need to get the second byte and and it with 11111 to get the correct value for the green, then you and the same value with 11100000 and divide by 32, then you add the values from the high byte by getting the value from anding 00000011 then shift it and add to the other part of the number, that gives you red, then you just have the last part of the high byte, just and that with 01111100 to get the blue value and then divide by 4 to shift it 2 places right, that will give the r,g and b values for the colour of one pixel, a word of warning, the program MUST be in full screen exclusive mode, any of the windowed modes will return 32 bit colour data if you have windows set to 32 bit (got me scratching my head did that since I was compiling in full screen windowed), obviously db/dx only emulates 16 bit in windowed modes, I havent made any code since it may take some serious debugging to get working correctly, the first byte starts at 12, so a value of 124 placed into that location gives blue, while a value of 31 placed into the next will give green, the five bits that span the two bytes will be the red component, if I get more time tommorow then I may run up an example , cheers.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
IronHoof2
21
Years of Service
User Offline
Joined: 21st Dec 2003
Location:
Posted: 18th May 2004 02:19
Im using the First Darkbasic not DBPRO so fullscreen isnt a problem.

Yea I found the blue on accident got a perfect image in JUST blue....

Looking forward to seeing your example

I am I was
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 18th May 2004 22:37
Umm! this was along the lines of what I meant, but it refuses to compile, I guess I have some error in the & syntax, but with no idea what it should be you will just have to try to make sense of it, I havent the time at the moment, I was just able to spare the time to run this up, but I expected it to work (at least sortof), no time to debug, be my guest.



cheers.

Mentor.

PC1: P4 hyperthreading 3ghz, 1gig mem, 2x160gig hd`s, Nvidia FX5900 gfx, 6 way surround sound, PC2: AMD 1.2ghz, 512mb ram, FX5200 ultra gfx, stereo 16 bit soundblaster, ups.
TIGER
22
Years of Service
User Offline
Joined: 31st Aug 2002
Location: Argentina
Posted: 22nd May 2004 05:37
This took me a long time to find out.
Use theese formulas to read and write 16bit memblocks

rem extract colors from memblock word
r=(c/1024)*4
g=(c-(c/2048*2048))/8
b=(c-(c/32*32))*8


rem write colors into memblock word
c=(b/8)+((g/8)*64)+((r/16)*4096)

Login to post a reply

Server time is: 2025-05-24 03:34:41
Your offset time is: 2025-05-24 03:34:41