(Disclaimer: This is not a "do my homework for me" thread. Also, it's more about libraries and WinAPI than C++.)
I'm currently working on an image scaling algorithm, and I would like to write a short C++ program to demonstrate it where you can import bitmaps, process them using the algorithm, and then export them. I'm sufficiently familiar with C++ so that implementing the algorithm won't be a problem, but the rest of the program is something of a hurdle. I've been looking for tutorials, but I couldn't find any complete programs that weren't needlessly complicated/bloated. All I'm looking for is a very, very small command line program (I imagine around 50 lines max) that imports pixel information from a bitmap into a 2D array (or just demonstrates how to access pixel information) and then exports that information into a bitmap.
If someone could direct me towards such an example program (or write one, I imagine this wouldn't take more than 5 minutes) then that would be very much appreciated.
My requirements are these:
- Uses only standard libraries.
- Can be compiled without Visual Studio, for example with MinGW/GCC.
- Loads a bitmap.
- Makes a minor change to the bitmap (e.g. paints a pixel black).
- Exports the bitmap.
That's it, all filenames etc. can be hardcoded and no user input is required. It would be nice if the program automatically loads information from the file header, but if that can't be done with standard libraries then I don't mind defining resolution etc. in the code. I don't even need any explanation/comments; if the program is short then I'll be able to quickly figure out how it works on my own.
The "uses only standard libraries" part is the problem.
BMP is not as really simple image format. You have to read file header, determine exactly which format is used, check color depth, if palette is used or not, if compression is used or not, read color info using this information and finally transform it into something usable.
Those "50 lines" will be probably spent on declaring all possible header variations and getting needed info from them.
Actuall loading (and especially specifying all compression methods) will take even more.
I have some code now to read, manipulate and write RAW files with predefined resolutions. Theoretically, this is enough for my purposes. However, being able to read or write BMP files would be a considerable improvement.
It's okay if only one specific but common BMP format is allowed, e.g. RGB24 or ARGB32, if the program would then be able to extract other information such as resolution from the header. Is this not possible with standard libraries?
It is possible, but you will have to iplement actual header format selection and check if current file is in allowed format yourself. (and maybe deal with little/big endian problem)