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.

Newcomers DBPro Corner / Memblock Cutting Off Last 3 Bytes?

Author
Message
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 31st Aug 2013 22:42
I'm somewhat new to the world of Memblocks, but they seem simple in principle. The problem I'm having is displaying all the bytes of an Image Memblock. It always cuts off the last 3, no matter what size the image is.

Is this due to a resizing issue, or do I need to upgrade/update my copy of DBPro?

I've attached a 4-pixel (2x2) image for use with this code:



D.D.

Attachments

Login to view attachments
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Sep 2013 01:56 Edited at: 1st Sep 2013 02:36
This infographic should help you →

and code:




Formerly OBese87.

Attachments

Login to view attachments
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 1st Sep 2013 17:06
Hi Libervurto,

I'm a little confused by the output of your code...

If there are 4 bytes to represent each pixel (Blue,Green,Red,Alpha) doesn't your code only give the first (Blue) value?

D.D.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 1st Sep 2013 21:34
A DWORD is made up of 4 bytes.
Your code would work if you used memblock byte instead.


"Why do programmers get Halloween and Christmas mixed up?"
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 1st Sep 2013 22:51
Thanks Rudolpho!

Works perfectly now!

D.D.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Sep 2013 03:54
Quote: "Your code would work if you used memblock byte instead."

Ugh, that is technically true but not helpful to a beginner. He is confused about datatypes, and simply printing every byte in the memblock is not useful. The three header values must be read/written as DWORDS, not four BYTES. The pixel data can be broken down into bytes but this obscures the fact that db colour values are DWORDS.



Formerly OBese87.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Sep 2013 14:39 Edited at: 4th Sep 2013 14:41
Perhaps, but since he was writing it the way he did I assumed he was well aware of that; his code states he intended to write the four "parts" of the width, height and depth fields. In the same way it prints four values per pixel. Since, using DBPro's standard 32-bit format, each byte corresponds to the red, green, blue and alpha channels respectively, I think that way of looking at it is quite suitable, rather than presenting a packed colour value to him.

And then we have this line in the opening post:
Quote: "The problem I'm having is displaying all the bytes of an Image Memblock. "




"Why do programmers get Halloween and Christmas mixed up?"
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Sep 2013 20:42
Quote: " The three header values must be read/written as DWORDS, not four BYTES"


They should be, but they don't have to be.



Derek, I have a memblock tutorial online you can take a look at.
http://dbcodecorner.com/darkbasic/tutorial_memblocks.pdf

The other tutorials on my site should be up later today. I just realized several of the links stopped working (i think I moved a folder)

Login to post a reply

Server time is: 2024-11-23 09:57:40
Your offset time is: 2024-11-23 09:57:40