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 Professional Discussion / Assembling a DWORD

Author
Message
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 7th Jun 2003 16:05 Edited at: 7th Jun 2003 16:06
Just a quick question.

Is there a command / short method to assemble a DWORD given four byte values?

I need this because the RGB command only allows you to specify the 3 colour values, not the fourth one for alpha (which is set to 255)

If there isn't a way of doing this its DLL time

I know this is possible using memblocks to write the alpha value, but for P5 I'll need this anyway.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Jun 2003 16:08
You would have to do the following :

From DWORD to bytes :

Part 1 = (value) & 0xFF
Part 2 = (value>>8) & 0xFF
Part 3 = (value>>16) & 0xFF
Part 4 = (value>>24) & 0xFF

Bytes to DWORD :

DWORD=(Part4<<24) | (Part3<<16) | (Part2<<8) | Part1

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 7th Jun 2003 16:15
DWORD = (Alpha<<24) + (Blue<<16) + (Green<<8) + Red
thats all you need ... unpacking though is a different matter entirely - but i'm sure if you search for BitRanging you'll find a function for it

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 7th Jun 2003 16:17 Edited at: 7th Jun 2003 16:19
Never mind - You can do it using memblocks

For unpacking DWORDS I just write the dword to a memblock and then read it byte by byte.

Sorry to bother everyone.

I'll probably make a DLL for convenience though.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 7th Jun 2003 16:27
Not very efficient - Toady's way is far better naturally - But what the heck



Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Jun 2003 18:45
Hmmm... might be worth doing a DLL before anyone else gets there...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jun 2003 19:19 Edited at: 7th Jun 2003 19:20
Why?



For the other extraction routines, use RGBR(), RGBG() and RGBB()
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 7th Jun 2003 19:37
'Cos I can...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 7th Jun 2003 21:21
@Ian

Because...

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jun 2003 21:36
Bighead
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 7th Jun 2003 22:32
@Ian:

When you use RGBB() routine on the obtained Dword the result is 0.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jun 2003 23:34
... a bug I wasn't aware of ... is Lee?
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 8th Jun 2003 00:26
It isn't a bug with DBP I don't think. This source code works fine:



as does with my routine:



Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
Bighead
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 8th Jun 2003 00:34
Well, I used Ian's code. You can find it below ...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th Jun 2003 01:56
Doh!

Damned case-insensitivity. My bad!

Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 8th Jun 2003 02:09
hehee... yeah, that is kinda weird to get used to isn't it lol
who knew there we so many ways of doing the exact same thing over and over again

you know you could use mempointers to



god the fun you can have hehee ... knowing me i've probably just got them in the wrong order - but it still makes sense

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 8th Jun 2003 03:16
Trifle inefficient though...
By the way, the source code for SystemTray is in the code section.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Bighead
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 8th Jun 2003 04:02
Ok, thanks everyone!!! [img]x-d [/img]
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 8th Jun 2003 10:23
hehee... alright cool Toad
and perhaps might be inefficient but it never ceases to suprise me just how many ways there are to do things until you really think about it.

Within the Epic battle of the fates the Shadow and the Angel will meet. With it will harbinger the very fight of good vs evil!
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 8th Jun 2003 13:37
Yes, there are usually so many ways to solve a problem, its daft...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!

Login to post a reply

Server time is: 2026-07-11 11:42:30
Your offset time is: 2026-07-11 11:42:30