I want to make an application in which any asset/image's rgb information is copied on a text file and then he can use that text file on my other application which reads rgb data of all pixels and construct a new copy of that particular asset. It reduces chances of asset alteration or simply makes it hard for others to change actual asset (according to me atleast).

To be fair though, it's not that hard to write a program to construct a bitmap from R,G,B,R,G,B, etc.

It's harder if you perform a basic encryption and decryption of your assets because then people have to examine the binary of your program to figure out the key and how to decrypt the assets. Plus encryption works on any asset type - not just rgb images.

If you're so concerned about people not being able to use modified assets with that second application (I'm assuming the first app is a private one only you have access to and the second one is the public application that everyone else uses) your best bet is implementing a digital signature system:

Your application generates a digital signature for your assets, using a private key.Your other application checks that the signature is correct when it loads the assets. People won't be able to modify your assets without knowing the private key, as they won't be able to generate a valid digital signature.

4) Oscar Giner, as i said earlier I'm making it for information purpose only. But i would like to know how can i give my assets a digital signature. Is it done using allegro?

1. Generate a pair of public and private keys for a public-key cryptography algorithm (like RSA). Your first app will use the private key to generate the signature and your other app will use the public key to verify the signature.1. Generate a hash of the data (this is for performance reasons not for security, so just use the fastest hashing algorithm you can get).2. Encrypt the hash with the private key. This is the signature.3. When the other program wants to read the data you generate again the hash (using the exact same algorithm, both programs must generate the same hash for the same data) and decrypt the signature with the public key (remember, the signature is just the hash encrypted). The computed hash and the decrypted signature must be identical, otherwise the data has been modified.

Since no one knows the private key but you, if anyone tries to modify the data they won't be able to generate the signature (encrypted hash). Verifying the signature only requires the public key, so anyone can do that.

If you're only interested in validating that the content hasn't been tampered with, a simple hashing function is the easiest approach. A public/private key isn't necessary in this case because you aren't needing to prove the identity of the owner.

Generating a Hash

The easiest way to generate a hash of an image file is to use the get_sha256_hash_of_file() function from AllegroFlare. Simply pass the filename of the image to obtain the string.

Mark Oates, your answer for hash function came in handy to me. Thanks for that. But my original question still remains unanswered, how do i store rgb values of a single pixel of an image to a text file or config file(pls)? To quote again I'm using allegro 5.2.2 with code blocks compiler on windows 7. And secondly i want to know how to store them in a specific manner in a config file in the way i told in my last reply.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

Are you asking about basic file input/output or are you asking about accessing the pixel data? LennyLen already demonstrated writing the file in the second post (first you need to fopen the filename). One option to read it back in is using fscanf to read it as a formatted string in the reverse of fprintf. Those are C functions.

If you want a C++ solution then you'd use a std::ofstream and std::ifstream to write and read the file similarly to how you write data to the standard output (`std::cout`) (console) stream.

You can learn loads of information about writing and reading files in C or C++ with Google. We'd be happy to help you understand it if you have trouble.

There are a lot of optimizations you could make with these functions - for example, if you wanted to store multiple color values to a file you might fold get_image_color_at() and write_color_to_file() together (and possibly add a loop). Ideally, you should only open an ALLEGRO_BITMAP once.

Sorry late reply guys. Mark Oates, let me make self very very clear now, the function in allegro 5 lib "al_set_config_value()" takes a const char* as it's last parameter which is for the value to be written to a configuration file. The function "al_unmap_rgb()" takes unsigned char for the last 3 parameters, which are red, green and blue value of a pixel. Now my compiler "code::blocks v16.01" gives an error in the function that "it cannot convert unsigned char to const char*". Now how to solve that one. That's the problem I've been facing since LennyLen and Arthur Kalliokoski first replied. Please me with this problem.

Now I can't get the above to compile because it doesn't know the size of ALLEGRO_CONFIG or something, but it should get you closer to what you want.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

The best way to get help with this kind of problem is to post the exact error message text and ideally the code (or a shortened subset of the code) suffering from the error so that we don't have to go out of our way to invent a program that's nothing like what you're doing.

Looks like there's an example program (ex_config) that demonstrates it, and the source for that is available here by clicking on "ex_config":