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.

Dark GDK / Read the value of a point in an image. How?

Author
Message
IsGreen
15
Years of Service
User Offline
Joined: 4th Oct 2008
Location:
Posted: 18th Oct 2008 19:13
Generate map from bitmap. How?

I have a black and white image of a labyrinth (128x128 size), and I want to read the color of each point of the image.

The data will be stored in a boolean array(0 value for the color black, and value 1 for white)

There are commands in the DarkGDK for this? If so, what are.

Thanks. (Translation by google translator)
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 19th Oct 2008 04:25
if (dbPoint(x, y)) == 0)
arr[i] = 0;
else if (dbPoint(x, y) == dbRGB(255,255,255)
arr[i] = 1;
IsGreen
15
Years of Service
User Offline
Joined: 4th Oct 2008
Location:
Posted: 19th Oct 2008 08:50
Quote: "
if (dbPoint(x, y)) == 0)
arr = 0;
else if (dbPoint(x, y) == dbRGB(255,255,255)
arr = 1;
"


Thanks again Zuka.

I look under "bitmap", "sprite", "image" and even "memblocks" of the documentation of DarkGDK, at least "Basic2D" .

Now, I want to save the boolean array in a file, but in the section "file" of the documentation appears DarkGDK just that: "dbWriteWord", "dbWriteByte", "dbWriteLong", "dbWriteDirBlock", "dbWriteFileBlock", "dbWriteFloat", "dbWriteFile", "dbWriteMemblock", "dbWriteString", "dbWriteByteToFile".

Can I do this, or should I change the type of variable.

Greetings. (Translate by Google Translator)
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 19th Oct 2008 23:12
http://www.cplusplus.com/doc/tutorial/files.html

Here, use this.
Willie Mundermuffin
18
Years of Service
User Offline
Joined: 5th Jan 2006
Location:
Posted: 20th Oct 2008 06:31
Also, there is a MUCH faster alternative to dbPoint and dbDot. This alternative is to access the display memory directly to read and write. Here's a summary of how it works:

1. Lock the display memory for the window using dbLockPixels().
2. Obtain a pointer to the base address of the window's display memory using dbGetPixelsPointer(). As you'll see in my code, you have to cast the return value to an integer pointer, because the address is returned as an integer value, which is actually a VERY, VERY poor programming practice (shame, shame TGC). Probably done for compatibility with dbpro or something??? Not sure.
4. Go ahead and do your thing with this pointer, using dbGetPixelsPitch() to obtain the number of bytes per row. To convert this to the number of pixels per row (on a 32 bit OS), simply divide the result by 4, since an int is 32 bit, which is equal to 4 bytes, and each pixel uses 32 bits to store the color value within Dark GDK.
5. To finish, you MUST unlock the display memory. To do this, call dbUnlockPixels().
3. I know that's a lot to digest, so I've included the following two functions for easy reading/writing of pixels using this MUCH faster alternative to dbPoint and dbDot. Enjoy!



,Willie
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 20th Oct 2008 23:27
So why the heck are the functions so slow, then? Did they not change them since v1?
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 21st Oct 2008 00:42
Quote: "So why the heck are the functions so slow, then? Did they not change them since v1? "


It's simply how images work. Locking them allows for faster access, whereas the dbDot and dbPoint commands have to use a special method. Plus, dbDot and dbPoint require function-call overhead each use. The other access method is direct array editing.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
IsGreen
15
Years of Service
User Offline
Joined: 4th Oct 2008
Location:
Posted: 21st Oct 2008 00:50
Thank you all once again, for your help.

[To ErDa] Great website for learning c++, I need becouse I am beginning with DarkGDK. The beginning with c++ is hard but the names of many commands DarkGDK look very similar to those used in BASIC(Not all), and his name helps understand the role it undertakes.

[To Willie Mundermuffin] I was struck by your message, and thanks largely explained by the code. I am learning c++ recently, with the help of code examples that come with the DarkGDK and a tutorial. Your code has made me appreciate more pointers.

--------------------------------------------

I have read other posts where there are more people who say that some functions of slow DarkGDK, and recommend using other libraries to replace the commands of DarkGDK. When speaking of slow, it means milliseconds? I've tried the examples that come into DarkGDK and I do not seem slow.

Greetings. (Translate by Google Translator)

Login to post a reply

Server time is: 2024-09-30 09:16:49
Your offset time is: 2024-09-30 09:16:49