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 / Memblocks made easy!

Author
Message
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Apr 2009 01:23 Edited at: 7th Apr 2009 01:26
I have been learning about memblocks and I've made some useful functions that make it easier to make memblocks for imaging and draw on them (my line drawing is 3x faster than db even when drawing just one line, which is a bit odd), but the stupid PS3 wont upload my db files so you'll have to wait till I go to the library.
So why did I start this thread!?
I want to ask a few questions about memblocks, there are some things that aren't explained in any help files or on the forums (that I can find).

How do 32bit and 16bit colours work? I used the normal rgb function for my memblock functions and that worked fine but I don't think 256^3 uses 32 bits?? Unless I'm doing the sums wrong.

That's the only question I have right now but I'm sure there will be more

can't read?
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 7th Apr 2009 01:28
32 bit color uses (per pixel):
1 byte (8 bits) - red
1 byte (8 bits) - green
1 byte (8 bits) - blue
1 byte (8 bits) - alpha

the alpha has to do with pngs and transparency

There are only 10 kinds of people in the world, those who understand binary and those who dont
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Apr 2009 01:35
Ah, so how does alpha fit in? Is it the highest valued? i.e
blue= 0 to 255 * 1
green= 0 to 255 * 256
red= 0 to 255 * 65536
alpha= 0 to 255 * 167???? (or whatever it is)

and does alpha actually work in dbc?

Thanks smartguy
ps liking the new avatar

can't read?
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 7th Apr 2009 01:37 Edited at: 7th Apr 2009 01:37
im not sure, i think bn2 posted on it a while back in another thread, has something to do with making a color invisible, but i cant recall
how

ps tnx, how bout my sig?

There are only 10 kinds of people in the world, those who understand binary and those who dont
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 7th Apr 2009 01:49
yeah alpha is from 0 (transparent) to 255 (opaque) like I said I'm not sure if you can actually get it translucent in DBC.

the sig is good!
mine is a bit rubbish but it makes me laugh every time I see on youtube when it wants you to type a security code before posting "can't read?"

can't read?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 7th Apr 2009 01:57
When you convert an image to a memblock, the alpha channel becomes useless for use within DBC. If you try to read all 4 bytes as a color from a memblock, DBC treats it as a float value. If you create your own save routine with a proper header for a specific image output format, you could, however, save the memblock information with the alpha channel intact.

If you are in 16 bit display mode, the image information will be stored as 2 bytes. You must use the proper conversion format to convert the 2 bytes to 3 byte color representation (RGB565, RGB555, RGB1555) depending on the graphics card.

Read carefully through this:

Color

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Apr 2009 02:45
Sorry I forgot to thank you!
thanks

[read to the end I realised a better way]
I wrote a little program to flip an image, but it didn't work. Now I see that alpha was probably the cause.
I read through your discussion with Ashingda and I think I get it.
So to make a mask that would get rid of the alpha i would do...

is alpha the largest byte?
how would I write out that mask in proper code? (assuming it's correct). Sorry if im asking obvious questions.

haha I WAS being stupid, i could just write a byte over the alpha, so yeah my official question is where, where, where, where's alpha??

1337 - "That's Numberwang!"
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Apr 2009 03:23
byte order in the memblock is BGRA

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 30th Apr 2009 03:26
u sure latch?

im pretty sure its

red
green
blue
alpha

but ive been wrong b4

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Apr 2009 03:33
here's a quick test:



Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 30th Apr 2009 04:10
so which is it latch?

i dont have DBC on this comp

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 30th Apr 2009 06:56 Edited at: 30th Apr 2009 07:00
BGRA

Numbers stored in memblocks are in what is called "little endian" order which means the lowset byte of the number is stored first and the highest byte is stored last.

run this example when you get a chance:



Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 30th Apr 2009 14:37
Thats interesting because just yesterday I was thinking how illogical the way we write numbers is; i.e. if you read 1000 you have to read all the digits before you can see that the 1 is worth a thousand. If we wrote it the other way round (little endian or what you called it) the first digit would always be units, the second would always be tens etc.
Is that why computers use it? Is all binary little endian?

Thanks you have just avoided some hair-tearing-out if I decide to write functions for manipulating individual bytes.

1337 - "That's Numberwang!"
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 30th Apr 2009 17:17
just wondering is it supposed to return this BOTH times?

25,205,95,7

New Site! Check it out \/
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 30th Apr 2009 17:44
thats what hes pointing out, it returns that in little endian reading AND reading a dword, thus showing that dwords are read in little endian

There are only 10 kinds of people in the world, those who understand binary and those who dont
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st May 2009 01:54
Quote: "Is that why computers use it? Is all binary little endian?"

Not all computers use it. Some use "big endian" which is highest byte to lowest byte. The individual bits in binary groups however, are always read from highest to lowest as far as I know:



Mortorola chip sets use big endian I think. Like apple, amiga...

All methods to keep software out of the box from being cross platform! (I don't know if that's the reason)

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st May 2009 02:49 Edited at: 1st May 2009 02:53
Quote: "All methods to keep software out of the box from being cross platform! (I don't know if that's the reason)"

so if I turn my PC upside-down it will run Mac Applications?

would there be any advantage to using memblocks for my text-based mafia game?
ooooh, joining ideas and threads together here

[edit]
just realised that is a very open-ended question.
Don't bother answering unless you really want to

1337 - "That's Numberwang!"
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 1st May 2009 03:25 Edited at: 3rd Jul 2009 03:33
Sure, why not? If you need to, you could create your own types with a memblock.

Maybe you have a character that has a name, some stats, and a weapon. Set up a memblock to store all those things:

name max characters = 20 so that'll be 20 bytes
health = maybe only from 0 to 100 - we could use a single byte instead of a 4 byte integer if we used an array or standard variable
attitude = same thing as health
has a weapon = maybe 1 byte again - just yes or no
weapon name = another string maybe 20 characters
weapon power = another byte or maybe a word - let's make it a word so it can be devastating if we want

So let's add up all those bytes: 20 + 1 + 1 + 1 + 20 + 2 = 45 bytes

So each character's type can be stored in 45 bytes. Now, depending on how many characters there are, we multiply 45 times that and that is the size of the memblock (we'll say 20 characters)

make memblock 1,45*20

To access a character, every 45 bytes is an index starting at 0:


Enjoy your day.

Login to post a reply

Server time is: 2025-06-08 07:21:29
Your offset time is: 2025-06-08 07:21:29