Open main menu

CDOT Wiki β

Changes

TriForce

1,578 bytes added, 09:40, 4 March 2019
Assignment 2
=== Assignment 2 ===
 
EasyBMP Bitmap image library
(Sample Program: Image to black and white renderer)
 
Library: http://easybmp.sourceforge.net/
 
Sample code:
/**/
#include "EasyBMP.h"
 
using namespace std;
int main(int argc, char* argv[])
{
// Create a new Bitmap image with EasyBMP
BMP Background;
Background.ReadFromFile(argv[1]);
BMP Output;
int picWidth = Background.TellWidth();
int picHeight = Background.TellHeight();
Output.SetSize(Background.TellWidth(), Background.TellHeight());
Output.SetBitDepth(1);
for (int i = 1; i < picWidth - 1; ++i) {
for (int j = 1; j < picHeight - 1; ++j) {
int col = (Background(i, j)->Blue + Background(i, j)->Green + 10 * Background(i, j)->Red) / 12;
if (col > 127) {
Output(i, j)->Red = 255;
Output(i, j)->Blue = 255;
Output(i, j)->Green = 255;
}
else
{
Output(i, j)->Red = 0;
Output(i, j)->Blue = 0;
Output(i, j)->Green = 0;
}
}
}
Output.WriteToFile(argv[2]);
return 0;
}
/**/
 
The program was compiled using the following commands:
 
g++ -c -pg -g BW.cpp EasyBMP.cpp
g++ -pg BW.o EasyBMP.o -o BW
rm *.o
 
Attempted to run the program with a number of files (8K resolution):
 
////In progress
 
=== Assignment 3 ===