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 / Structure of IMAGE MEMBLOCKS and a possible formula error.

Author
Message
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 10th Mar 2005 08:00


In the pos=y*width+x line x and y should be changed to the coordinate of a pixel, x=0-99 and y=0-49 because the image is 100x50.

It doesn't seem to get the right color, so I'm either thinking it's the structure of the memblock I've mistaken or the formula calculating which byte to start the word at.

This is the format of the memblock I've supposed:

BYTE 0-3 are the WIDTH
BYTE 4-7 are the HEIGHT
BYTE 8-11 are the DEPTH (I don't use this in calculating, should I?)

BYTE 12-13 are the first pixel, presumably coordinate 0,0.
BYTE 14-15 are the second pixel, presumably coordinate 1,0.
So-on until:
BYTE 202-203 is at 1,1 when the WIDTH of the image was 100.
And more until:
BYTE 2020-2021 is at 10,10.

With

Where x and y both equal 0, 0*width+0=0, so pos=0.
Then the position (12+0*2) would return a 12, presumably the first BYTE of the actual pixel data after the headers. So using MEMBLOCK WORD, I should get BYTES 12 and 13, which, if the pixel is pure red (255,0,0), I should have "255,0,0" returned when I call the RGBR and it's related functions.

Unfortunately, "0,248,0" is returned.

What went wrong there?

This is the bitmap I was using: (Saved as a PNG for posting, convert back to BMP to test it.)



The first 3 pixels are pure red, green, and blue respectively, and the last red dot is pure red at coordinates 10,10. The black is 0,0,0 and the grey is 128,128,128.

Thanks for any help.

Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 10th Mar 2005 17:09
Your logic's right, from what I can see.

However, colour values are stored in DWords, and I think the order that the colours are stored in isn't actually RGB... I'm not sure what it is exactly, so you may want to experiment a little

Jess.


Team EOD :: Programmer/All-Round Nice Guy
Aust. Convention!
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 11th Mar 2005 07:31 Edited at: 11th Mar 2005 07:38
Isn't a DWORD 4 BYTES? 16 BIT bitmaps always have 2 BYTES per pixel, and the depth of the memblock when I called it was 16.

This is the read by BYTE of the first 100 BYTES in the memblock:

WIDTH
100 0 0 0

HEIGHT
50 0 0 0

DEPTH
16 0 0 0

PIXEL ONE
0 248

PIXEL TWO
227 7

PIXEL THREE
31 0

Then next pixels are black and are read as 0 0

All of the color formats in Photoshop 7 are 3 BYTES.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Mar 2005 07:57
If your running at a 32bit desktop res then regardless of the image's depth I think when you convert it to a memblock it gets changed to 32bit anyway. In image memblocks, the format of image data is like this:

alpha, blue, green, red

The first pixel value in the memblock starts at byte 12, this is because the header is from 0 to 11 bytes which is right for a 12 byte header.

A while ago(months ago actually) I made a set of functions for dealing with memblock functions. Maybe they'll help you work out how image memblocks work:




"Lets migrate like bricks" - Me
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 11th Mar 2005 08:04
This is what I'm interested in:

FUNCTION MEM_pointRGB(x,y)
memPos = (y*MEM_ATT_READ_WIDTH*4)+(x*4)
MEM_POINTBLUE = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+12)
MEM_POINTGREEN = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+13)
MEM_POINTRED = MEMBLOCK BYTE(MEM_ATT_READ_MBN,memPos+14)
ENDFUNCTION

I'm wondering if you read it BYTE by BYTE, and the order is BGR? If so, where is the Alpha you mentioned earlier?

I'll play around with it when I get finished with my homework.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Mar 2005 08:12
In my functions I left alpha out. If I were to include alpha it would probably be:



Infact I may be wrong - alpha may be on the other side(+15) but I'm pretty sure I'm right.


"Lets migrate like bricks" - Me
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 11th Mar 2005 08:20
One more thing before I can test this: in the MEM_setup function, what is the SetType variable for, and what should I enter?

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Mar 2005 08:25
1 for reading, 2 for writing. Check the attached document for more information..

Really I should update those functions, theres some stuff going on there that doesn't need to go on.


"Lets migrate like bricks" - Me

Attachments

Login to view attachments
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 11th Mar 2005 08:30 Edited at: 11th Mar 2005 08:31

That wouldn't happen to be DBPro code, whould it? I'm getting an Unknown Command at either the "SELECT SetType" or "CASE 1."

They're both highlighted as a command in DarkEdit for Classic.

EDIT: Nevermind, it was the MEM_ATT_READ_MBN and related, where were those functions?

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Mar 2005 08:37 Edited at: 11th Mar 2005 08:38
Oopsy, it is DBP code. Nevermind...oh, and you can't do globals in DBC either can you.

The best way to do it would be like this:



There, a set of functions to return various color values from a memblock specified in memNum.



"Lets migrate like bricks" - Me
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 11th Mar 2005 08:47
I'm still getting the wrong returns, am I using your functions correctly?



I'm getting 224,248,0 on a red pixel at 0,0.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Mar 2005 18:23
Maybes its the desktop rsolution your using. Are you running in 32bit mode?


"Lets migrate like bricks" - Me
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 12th Mar 2005 01:51
The DBPro image memblock format is different to the DBC one, I think.

Mr Blanky - This Time, It's Personal
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 12th Mar 2005 03:04 Edited at: 12th Mar 2005 03:06
Er..come to think of it, DBC apps I think run in a 16bit res. Damn

Try changing to a 32bit res at the start of the program then try it.


"Lets migrate like bricks" - Me
P Schnell
20
Years of Service
User Offline
Joined: 13th Feb 2005
Location:
Posted: 12th Mar 2005 06:31
Yes, it works with 32 bit display. I'll post what I'm making once I finish.

Thanks!

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 12th Mar 2005 06:53
Your welcome


"Lets migrate like bricks" - Me

Login to post a reply

Server time is: 2025-05-23 19:10:14
Your offset time is: 2025-05-23 19:10:14