combing red green and blue files to make a .ppm file in a C programme - c

i currently have 3 files, a red, a green and blue component file(s) and i need to code a program that will combine these three files into a single readable ppm file. how/whats the best route for me to take for this? thanks
Sam

You mean, like this: rgb3toppm.c?
If you're doing this as an exercise, you can look at the source code for that utility. If you just need the utility, you'll probably find rgb3toppm in your netpbm distribution.

Related

Playing a Frequency in OpenAL in C

I am trying to write a program to play a frequency for a time. I can't find any way of simply just playing a certain frequency. How do I go about doing this in OpenAL?
I eventually found a video on properly reading form a WAV file (huge credit to this video) and how a WAV file is formatted (explained here in detail) and did some trial-and-error work until I figured out how to do it. I figured that if I could make a WAV-style file with the frequencies in them and set up the OpenAL buffer and source manually, it would work.
I ran into some trouble when I found that the format differed from the first explanation of WAV file format I found, as some apparently have additional meta-data, which I had to test for and skip over when trying to load a WAV file. Then I made a WAV file containing the frequencies and played it, which worked as well as I could have hoped for.
Here's another article about how bit-depth works that really helped me understand what I was doing.
Hopefully this helps anyone else who is trying to do something similar to this!

What is the difference between .bin and .dat file?

When writing to a binary file, when should I use .bin vs .dat? If I'm just trying to store information not meant to be read by humans, like item description/serial number pair, does it matter which one I pick if I'm just trying to make it unreadable from a text editor?
Let me give you some brief details about these files :
.BIN File : The BIN file type is primarily associated with 'Binary File'. Binary files are used for a wide variety of content and can be associated with a great many different programs. In general, a .BIN file will look like garbage when viewed in a file editor.
.DAT File : The DAT file type is primarily associated with 'Data'. Can be just about anything: text, graphic, or general binary data. Data file in special format or ASCII.
Reference:
Abhijit Banerjee answered that question on quora
.dat is a more frequently used suffix for binary data. It doesn't matter what extension you pick, as long as you are on Unix or Linux based systems.
Sufixes can mean whatever you want them to mean... Those rules are more like guidelines than actual rules...
However, BIN seems like a short to binary, so a BIN file will likely hold data in binary form. DAT seems like a short to data, so a DAT file will contain information in whatever format the developer of the program that reads that file seems fit (ASCII, Binary, a mix of them, something else entirely)
On a UNIX system, there is no difference. The extensions are interchangeable.
If you do not put any extension, it makes it kinda hard for someone not knowing what the file's extension should be, to open the file. Additionally, with Unix or Linux, if you place a dot (period) before the file name, the file hides itself.

Reading colour value from png file in C

I have to load colours value from *.png file in c. Something like imread in matlab. I learned png file construction, tried to open file as binary and write to matrix, but I probably done something wrong. I alao tried to search, but I couldn't find suitable library.
Any advice how can I do that or which library should I use?
You're going to need to decompress the zlib compression on the PNG first (if there is any) before you can get to the raw color values. The easiest way to do this is through the free libpng. You will find many examples here and elsewhere on how to do just that.

How to build a searchable database?

I would like to create (or use, if one already exists) a command-line based app that creates, modifies and searches a database.
This database would ideally be a simple text file where each line is an entry.
As in this simple example:
Apple Fruit Malus Green/Red 55
Banana Fruit Musa acuminata Yellow 68
Carrot Veget. D. carota Orange 35
Let's say this text is stored in ~/database.txt
I'd like to be able to search for all entries that are of the type fruit (returning, Apple and Banana) or all entries that have kilocalories that are less than 60 (returning Apple and Carrot) on the command line.
The returns should happen through standard terminal output and should look like this:
$mydatabasesearch cal '<60'
Apple Fruit Malus Green/Red 55
Carrot Veget. D. carota Orange 35
Also, being able to add to the database through the command line would be awesome!
Is there anything around that does this? If not, how would you recommend I write such an app? I know a bit of C++ but that's it...
Take a look at sqlite. It is a bit more complex than plain text files, but a lot more powerful.
Plain text files are not really considered databases.
If you want to stick to textfiles and the commandline, have a look at the usual unix utilities like grep, awk, and the coreutils package (cat, cut, uniq,...) which work on plaintext files. Add those commands to a shellscript and you're done.
As soon as you move to some sort of database system you won't have textfiles as storage anymore.
Aside the already mentioned sqlite, the Berkeley DB library might also be worth a look if you want to write your own program. Both libraries should be good in your case since they don't require an external database server (like mysql)
You can do this in Unix anyway with a delimited file SED and maybe some simple commandline perl which you can wrap in a bash script. There is a good tutorial for the data manipulation at wikibooks and the SED you could use is probably all here and in the part two tutorial.

C program to display a jpeg or bmp or pcx file

What is the code in 'c' to display a picture file like jpeg file or bmp file or pcx file.
For example the picture may be available in desktop and the program during execution must be given the path of the file as input and should display the image.(If it is in command line,it'll be excellent).
Platform:Windows xp
Turbo c compiler(or turboc++)
Well, you'll definitely want to take a look at libjpeg:
http://en.wikipedia.org/wiki/Libjpeg
Working with bmp files is actually pretty easy, since there isn't any compression to deal with:
http://en.wikipedia.org/wiki/BMP_file_format

Resources