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 images in memblocks

Author
Message
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 19th May 2003 05:35
I don't usually ask for help, but I'm really getting kinda stumped on this one:

I want to create a function to fade between two images. I am using DBV1. I want to use memblocks to make the transition, but I've gotten stumped with getting rgb values from 16-bit images (24-bit would allow rgb() function to work correctly)

Heres what I've researched so far (spent most of my day off doing it)

Word's return 2-byte data (0-65535) or 16-bits (hence 16-bit images)
I've read that you have to bitshift to get the three components of rgb from http://www.darkbasicpro.com/apollo/view.php?t=6448&b=2. I think I understand that values will lose 8-bits (from 24-bit) in that the values will not be (0-255) instead (0-31) or 256 / 32 = 8. So the values converted into rgb would run like this: 0,8,16,24...255. However, I cannot find a way to do bitshifting in db without converting the decimal into strings, (which is obviously inefficient). I have not used binary in DB before but I understand how to read it. I have no problem making the interpolated transition, but I need to get over this hump to make it possible.

My questions are as follows:

1. Can DB write 24-bit images to memblocks with dwords (3-bytes) instead of words(2-bytes)? Hence no conversions need be made for rgb components.

2. Does anyone have clean functions similar to DB's built in RGB,RGBR,RGBG,RGBB that take in a number from 0-65535 and return correct rgb components?

Thank you all for your help in advance!
TH -Darksoft.net
http://www.darksoft.net/sigpic.jpg[/img]
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 19th May 2003 19:41
Well, knowone has replied yet, and here I am again with another simple question:

Does DBV1 support binary calculations including bitshifting?

TH -Darksoft.net
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 19th May 2003 19:57
what's bitshifting?

you can just use the point(X,Y) command

for example:

Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 19th May 2003 20:10
No, I'm using memblocks for the transition of 2 images. DB stores the images into the memblocks as 16-bit (2 bytes per pixel) a normal rgb() command returns a 3 byte decimal. The point command doesn't work in memblocks as they are not really 'images' instead just data.

Here is what I understand about rgb():

RGB returns a 24bit number, or:
Red | Green | Blue |
0000 0000 0000 0000 0000 0000

Each 'block' (8bits,0-255) contains a color component for the pixel.

I think DB stores into a memblock a 16-bit value for each pixel like this:
Red |Green|Blue |
0 00000 00000 00000
Which each 'block' (5-bits,0-31) contains a color component for the pixel.

I need to get the components out of the memblock 'word' (0-31 per component) Or get db to store the images as 24bit. I think I need to do some binary operations (bitshifting) to get the correct values out of the words (if I use 16bit which db uses).

Thanks

TH -Darksoft.net
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 19th May 2003 20:19
Oops, the bits didn't come out right, I'll seperate them
RGB returns a 24bit number, or each 'block' (8bits,0-255) contains a color component for the pixel like this:

Red
0000 0000
Green
0000 0000
Blue
0000 0000



I think DB stores into a memblock a 16-bit value for each pixel like this:

Red
00000
Green
00000
Blue
00000

Which each 'block' (5-bits,0-31) contains a color component for the pixel. Or 5-6-5, but I'm not sure.

I need to get the components out of the memblock 'word' (0-31 per component) Or get db to store the images as 24bit. I think I need to do some binary operations (bitshifting) to get the correct values out of the words (if I use 16bit which db uses). But I don't want to use bin$() and then work with a string (as its not effecient).

Thanks

TH -Darksoft.net
freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 19th May 2003 20:20
out of the memblock 'word' what do you mean by the memblock word?

can you explain bitshifting? I mean how it works

does DB always store 16 bit values, even when the display mode is set to 24 bit?
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 19th May 2003 21:26
Minor correction:

1. Can DB write 24-bit images to memblocks with dwords (4-bytes) instead of words(2-bytes)? Hence no conversions need be made for rgb components.


MEMBLOCK WORD
This command will read a word from the specified location of the memblock. The memblock must exist or the command will fail. The Position value is specified in bytes. The Word returned will be a value between 0 and 65535. The parameters must be specified using integer values.

SYNTAX
Return Value = MEMBLOCK WORD(Memblock Number, Position)



MEMBLOCK DWORD
This command will read a dword from the specified location of the memblock. The memblock must exist or the command will fail. The Position value is specified in bytes. The DWord returned will be a value between 0 and 2147483648. The parameters must be specified using integer values.

SYNTAX
Return Value = MEMBLOCK DWORD(Memblock Number, Position)

Here is an example of bitshifting 1 bit:
010100 = 24
001010 = 10

Check out this thread for a better understanding: http://www.darkbasicpro.com/apollo/view.php?t=6448&b=2

TH -Darksoft.net
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th May 2003 22:19
DB puts data into memblocks in the same format as you loaded them (except for compression of course).

Unfortunately, DB does *not* have bit-shifting or logical operators. If you want them, you'll have to simulate them with division and subtraction.

Here are examples of the easy ones:

freak
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 19th May 2003 22:20
ow that's a very long post...
do you think that such binary transformations are important when you make a game in DB?
Pricey
22
Years of Service
User Offline
Joined: 22nd Feb 2003
Location:
Posted: 19th May 2003 22:26
bitshifting? i thought that said something else then x-d

I don't know i can't tell!
I push the button and run like hell!
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 19th May 2003 22:50
I think I have it!
I don't have db here at work, so i did a little example in vb:



Colorval is the 2-byte representation of a color. I'm not sure about the order of the components, but when I get home, (or into my game office) I'll figure it out and write it here.

TH -Darksoft.net
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th May 2003 23:31
That will give the correct results, but the loop will kill your speed.

Try this instead, using the two functions I provided earlier.

Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 20th May 2003 01:22
Thanks for the code, I'll give it a shot.

TH -Darksoft.net
Ag3ntSm1th
22
Years of Service
User Offline
Joined: 13th May 2003
Location:
Posted: 20th May 2003 02:27
try to dust off and fire up qbasic. It has very good info in the help file about RGB values using a single decimal #. I'll try to remember to make a quick bit shifting function when i get home, then paste here. good luck
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 21st May 2003 00:09
IanM : your code seems to run about 4 times slower than mine. It does return the correct results, and I thank you for showing me how to emulate bitshifting on numbers.

Thanks

TH -Darksoft.net
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 21st May 2003 00:24
oops, looks like I'm wrong (i had a 0 being passed in so no big calculations were being done. Still DB's built in rgbr , rgbg, and rgbb over 640x480 takes 1.082 seconds, whereas yours took 4.256 seconds! There has got to be some clean and fast way to get results.

TH -Darksoft.net
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 23rd May 2003 20:49
Ok, heres what I have accomplished so far this week:

A function to save a image to a matrix, the resulting matrix containing 24 bit pixels or:
12 byte header + (3 bytes * width * height)
So a 10x10 image in size comes out = 12 + (3*10*10) = 312 bytes

A function to Interpolate between two 24bit image matrixes created from the first function. The function creates a 16-bit image matrix. I have been having problems getting db to make an image from a 24bit image matrix, so I convert the resultant image into 16bit.

I have run into a couple questions and problems:
1. I think I've found a bug in db where the image from "make image from matrix" cannot be textured onto 3d objects. I've gotten around it by making a temporary bitmap, pasting it onto it and then using "get image" to extract it into the same image. This does texture the object in the end, but its kinda kinky to get there.

2. The interpolation is rather slow, probably because I have to convert each 24bit pixel into 16 bit on every interpolation iteration. Can DB make an image from a 24bit image matrix? If so, what is the format for the matrix? There are a couple of things I'm going to test to see if I can get it to work including offsetting the pixels by 4 bytes instead of 3. The only other thing I can think of is to offset by 4 but start 1 byte into the dword. Any suggestions?

I have spent nearly an entire week working on this problem and all I'm going to use it for is to fade in a ghosted object!

Thanks again all!

TH -Darksoft.net
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th May 2003 01:01
I'm not too suprised that DB built in functions beat me on speed

Is there a particular reason you are working in 16bit?

IIRC, you can have 24 or 32 images in memblocks for DBClassic like you can in DBPro. You just use dwords instead of words, and offset by 4 bytes each time.

That would allow you to use the rgbr/rgbg/rgbb functions instead of the bit-shift stuff.
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 24th May 2003 01:18
how does db's 'make image from memblock' command interpret a 24bit memblock image? Do you have example code for extracting the image data?

Thanks

TH -Darksoft.net
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th May 2003 02:33
It's stored in this format:

12 byte header + (4 bytes * width * height)

Each 4 byte value is the actual RGB value of each pixel. That would allow you to use rgbr/rgbg/rgbb to extract each colour value from it. Just read the whole value using MEMBLOCK DWORD()
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 25th May 2003 03:05
Darksoft:

I haven't really read through the whole thread. But yes, I wrote a bunch of colour conversion and binary related functions some time back for DB#1..

http://www.Dblibraries.UnderwareDesign.com

However due to 'huge' function overhead per each call in Db classic. Don't use a functionj, rather build the code inline. I'd prolly go with some a look up tables personally, if you want to work in memory blocks..

Your could also build the interpolation frame, and split it into 2 arrays(1 per gun) and then just interpolation the gun and merge on output.

Then again you could always use FADE Object or FADE Bitmap..

l8r,
Kevin Picone
[url]www.underwaredesign.com[/url]
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 28th May 2003 19:17
Ok, I've tried a lot of things to get db's 'make image from memblock' to open a 24 bit image matrix.

Heres test 1:

0 : width
4 : height
8 : 24
12: 255
13: 255
14: 255
15: 255
16: 255
17: 255

when I pasted the image to the screen, it was 3 pixels all white (255,255,255). This would mean that db only used a word (2bytes per pixel) Whats up with that? It did the same for 32 rather than 24 for the bitdepth.

Thanks all again and again!

TH -Darksoft.net
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 28th May 2003 19:23
I used photoshop to create my jpg's. I made sure it was saving with 8bits per channel, hence they are 24bit jpgs without the alpha channel. So why does DB's 'make memblock from image' format it like its 16bit? If it formatted it in 24, I wouldn't have any problems. Originally I was just going to use this routine to go from black to an image. However I can use DB's 'fade bitmap' command (of which is extremely fast for what I'm doing). But I want to fade from one bitmap to another (say a picture of a pig to a picture of a monkey) and I don't want to have to make any conversions per component per pixel on each transition iteration (which kills speed). Its killing me that I haven't figured it out yet!!!

TH -Darksoft.net
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 28th May 2003 23:08
From memory DB stores it's loaded images in that same bit depth/format as the current screen mode.

Tried running your app in 24bit or 32Bit mode ?

l8r,
Kevin Picone
[url]www.underwaredesign.com[/url]
Darksoft
22
Years of Service
User Offline
Joined: 17th Sep 2002
Location: United States
Posted: 29th May 2003 00:08 Edited at: 29th May 2003 00:15
Ahhhh, thats why the following is happening:

0 : width
4 : height
8 : 24
12: 255
13: 255
14: 255
15: 255
16: 255
17: 255

when I pasted the image to the screen, it was 3 pixels all white (255,255,255). This would mean that db only used a word (2bytes per pixel) Because the app is in 16bit mode and db disregards the value at offset 8. That isn't very good, as I would have to have the app run in 24bit mode instead of 16 and I don't want to force that. Any suggestions now?

I suppose I could try writing a dll in assembly and use that to convert the 24bit pixel to a 16bit equivalent. But of course I'd have to learn asm!!

Thanks

TH -Darksoft.net

Login to post a reply

Server time is: 2025-05-18 01:46:59
Your offset time is: 2025-05-18 01:46:59