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 / Resource - Array to Memblock -> Image

Author
Message
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 24th Nov 2011 20:17 Edited at: 5th May 2013 16:03
Hey there,

I have been trying to add a sort of watermark to my program by doing the folowing:

Array containing data of image (i used bin2c.exe, is there an alternative?):






After that I show it like this:



But it doesnt show anything, not a pixel!

Is this fixable? Or are there any other methods?

Thanks,

RedEye

Like = Follow!
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 24th Nov 2011 21:24 Edited at: 24th Nov 2011 21:30
I've recently been playing around with embedding a zip file into the resource file which is compiled along with your exe. The unzip gives you a couple of options, either extract a file from the embedded zip in the resource to memory, or extract to a file.

I do know you can use embedded files directly from a resource file but so far I've just used the strings, dialogs and zips.

From what I know you get the pointer using the MAKEINTRESOURCE() command. I'll have a nosey on google and see what I can find.

Apart from that, Chris Tate from the DBP forums has the information you might need on how to store a bitmap into a memblock and its header information. I've tried unpacking JPG's and PNG's directly to a memblock and they do not work. But I am sure that GDK has a hidden function that will load an image from memory.

EDIT: This has just jogged my memory...
http://us.generation-nt.com/answer/embedding-text-file-resources-into-visual-studio-2008-c-plus-plus-project-help-201764562.html

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 24th Nov 2011 22:00
Thanks for the answer! I read the link you linked me to and i find it very usefull! Altough I dont see a way of loading the image resource into the exe with that, or would you threat the image (png or bmp or jpg) the same as the example uses a txt file?

Quote: "But I am sure that GDK has a hidden function that will load an image from memory."


I had a search and it has something quite attracting:

dbMakeMemblockFromArray(memblock,dword arrayptr);

I could typecast the array WaterMarkLogo to a DWORD, and create out of the memblock an image? I tried didnt work, I will try with a bmp, maybe it is a error caused by the file type.

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 24th Nov 2011 22:25 Edited at: 24th Nov 2011 22:26
You weren't specifying the watermark's width/height/depth. Try this and see how it does:



JTK

Edit: oops. forgot to typecast the (*ptr) values...
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 24th Nov 2011 22:59
Quote: "Edit: oops. forgot to typecast the (*ptr) values..."


Wouldn't it then be?


(altough it crashes)

As I get 3 illegal redirections, with the code.

But what you are saying totally makes sense. Do I need to add more info being it a png file?

Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 24th Nov 2011 23:12 Edited at: 24th Nov 2011 23:12
O wait...

width*height*3 (rgb) = 144210 (this is what i calculated with the width and height of the image)

...this is around the same as what bin2c returns in ammount of elements in the array. which are: 144375, the differece is 165.
I dont know what those 165 belong to, probably some presettings? Width/height/depth or something?
It probably sounds normal to you guys, but i just found out! xD

So with this info i could do a for loop with writing to the memblock the whole time 3 elements? But what to do with the 165 wierd elements?

WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 25th Nov 2011 01:06
You should just be able to use memcpy() to copy the data from the embedded resource into a memblock.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 25th Nov 2011 08:48
Quote: "You should just be able to use memcpy() to copy the data from the embedded resource into a memblock."


Yeah, I have been trying to achieve that. Altough I think I am doing it the right way, there might be an error in my WaterMarkLogo array.

I would think that writing the data to the memblock would be safer as there is a difference of 165 and copying that to a memblock can overwrite some important info.

I will try more things, but if someone has more methods or fixes for the above code, i would be more than happy!

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 25th Nov 2011 12:50
You are right. Here, try this:



Hopefully this will do it for you. I think there's some confusion with your water mark logo array. Each element of the array is stored as a byte (8-bits), but the memblock/image data is expecting dword values (32-bits); in which case a simple memcpy() can't work.

Of course I could be wrong but that's what it seems like to me.

Regards,

JTK
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 25th Nov 2011 17:04 Edited at: 5th May 2013 16:04
Thanks for folowing the thread and trying to fix this. Appreciate it!

Yet I have tried what you recommended and besides that i think my array is still not right, writing to memblock (as yuo coded) doesnt work either! I attached my array so you can check it out. Maybe you find something wrong with it.

Regards,

RedEye

Like = Follow!

Attachments

Login to view attachments
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 25th Nov 2011 22:42
I think it would be easier if you just attached the watermark logo file itself.
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 25th Nov 2011 22:55 Edited at: 25th Nov 2011 22:56
Besides that it's my sig. Here you go: [attached to post]

The array was a bmp though. But maybe it works too with a png?

Attachments

Login to view attachments
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 26th Nov 2011 00:19 Edited at: 26th Nov 2011 00:20
It would probably make it much easy if you wrote a dummy program in DBP which loads the image, puts it into a memblock then saves the memblock out as a file. That way you can embed that file into the resource and copy it straight into a memblock.

EDIT: Even a BMP's header file is larger than that used by an image stored in a memblock.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Nov 2011 02:55 Edited at: 26th Nov 2011 03:02
As I had suspected, your bin2c.exe was actually dumping the entire contents of the file into a single byte array. That means that the .BMP header, [CHUNK], [THUNK] etc. information was all contained within that one array... The *real* image data was probably somewhere near the 165byte mark (thus your difference above).

Here's a new utility that you can use to generate a useful .h file to imbed graphics directly into the .EXE file as it would appear that you are trying to do...

NOTE: You could use WIN32 resource handling API (I believe that's what WLGfx is referring to) to do this as well, but here it is anyway (I've been working on a similar approach myself already):



Now, for this to work, copy/paste to a new project as this is a utility that will provide you with ideas on how to achieve what you are trying to...

Next, notice the #define CREATE_SOURCE_HEADER declaration. This declaration will determine what the utility will do.

If it is #defined, then the CreateSourceHeaderFromImage() function will create a new .H file for you to #include within your application.

If it is NOT #defined, then the CreateSourceHeaderFromImage() function will use the #included global values to build the image via a memblock (as you've been trying to do). Notice the additional #include...

Notice the call to dbSetImageColorKey() before calling the CreateSourceHeaderFromImage() function in both versions. It's very important...

I hope this code helps you out!

Regards,

JTK

Edit: Corrected some misleading comments...
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 26th Nov 2011 17:58
JTK, great code I must say, amazing work! It worked perfectly, I have read it through and I understand how it is achieving it.

I noticed something though, the image get's cut off. I am able to fix that by enlarging the picture, are you experience the same problem?

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Nov 2011 18:44
No, I can't say that I have. I have seen, while testing it, how it was making the image blocky when using the #include .h file. It seemed to be a result of testing with several different images and keeping the output .h filename the same. To alleviate it, I did a full project clean / rebuild. I think it may have to do with using precompiled headers. I'm not sure if you are using them, but give it a try.

Build->Batch Build... (selected project) [Clean]
Build->Batch Build... (selected project) [Rebuild]

It worked for me...

JTK
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 26th Nov 2011 19:24
I did that. But I meant this: screenshot attached

Attachments

Login to view attachments
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Nov 2011 19:39
No sir! See? You sure you didn't accidentally change the code somehow?

JTK

Attachments

Login to view attachments
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 26th Nov 2011 20:01 Edited at: 5th May 2013 16:05
Changed nothing. Here let me attach the whole project folder.

Regards,

RedEye

Like = Follow!

Attachments

Login to view attachments
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Nov 2011 20:51
I got the same results as you at first. Turns out that the watermark_logo.h was somehow corrupted. I deleted it and recreated it (#define CREATE_SOURCE_HEADER). When I commented out the #define and re-ran the program, it worked just fine.

Regards,
JTK
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 26th Nov 2011 21:09
Thats sooo wierd. I tried that and it still doesnt work, could you send your watermark_logo.h file so i can see if he loads that up what happens.

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Nov 2011 21:16
Here ya go. Compressed .zip file since original is 1.1MB

JTK

Attachments

Login to view attachments
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 26th Nov 2011 21:27
The computer is making me freak out, haha. That one works, thanks for that. I noticed that my produced array seems to be "enlarged" like the steps it is taking are somehow bigger (as the watermark_logo.h that i have has the same ammount of lines as yours do but my combination
occurs at the end and yours in 3/4 of the code, this would be the answer why it is cut off. Maybe with the step in the creation code where it checks for the sizeof(BYTE) (i dont see why as it should be the same on my computer as on yours, but i am thinking about steps as for now that is the only asnwer i can think off).

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 26th Nov 2011 22:29
Are you running 16 bit desktop color? Windows 7? Newer version of dx? There is something different with your system than mine. 32 bit desktop mode, Vista (sp 3 I think), Aug 2007 dx with updated Gdk libs...
Red Eye
16
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 27th Nov 2011 12:20 Edited at: 27th Nov 2011 12:21
32 Bit Windows 7 Aug 2007. Might be Windows 7 against Vista, maybe?

DarkGDK is ofcourse based on Aug 2007, so it uses those librarys, yet I can run DirectX 11.

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 27th Nov 2011 14:22
Quote: "
32 Bit Windows 7 Aug 2007. Might be Windows 7 against Vista, maybe?
"


Maybe. One thing you can try is to put an fflush() call (I think that's it) inside the if... Condition that places a new-line character after the 3rd pixel. Maybe your file buffer can't hold as much data? It is, after all, outputting 1.1mb before the file is being closed.

Note that the conversion process generating the .h file will slow down almost to a halt, but should keep the data intact.

Just an idea, something to try.

JTK
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 27th Nov 2011 19:29
As soon as I get a chance I'll write a simple tutorial on how to embed files in a resource and use them from within GDK. I use ResEdit for all my stuff at the moment. Once you've got the handle of the embedded file and the pointer to the data, then memcpy() can be used to put it into a memblock. Give us a short while cos I've over bloated on sunday dinner. I'll also try and put in to a simple function call for you. It will also save compile time on larger included files.

A quick note on compile time. If you have two files, .h and .cpp. The data you're including should be put into it's own .cpp file and an 'extern' reference to it in the header file. 99% of the time the .cpp file will not need recompiling as the object file already exists and the header file is used to reference the compiled data.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-11-19 06:27:35
Your offset time is: 2024-11-19 06:27:35