-
Notifications
You must be signed in to change notification settings - Fork 0
/
colsep.cpp
49 lines (39 loc) · 1 KB
/
colsep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Color separation exercise.
Compile: make colsep
Run: ./colsep fruit.bmp
*/
#include "picture.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 2) {
cout << "Usage: colsep infile.bmp" << endl;
return 1;
}
// open the file and construct a Picture object
Picture pic(argv[1]);
int height = pic.height();
int width = pic.width();
// create 3 more Pictures
// FILL in the constructor arguments
Picture redpic(____);
Picture bluepic(____);
Picture greenpic(____);
// separate the colors
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
Color color = pic.get(row, col);
int r = color.red;
int g = ____;
int b = ____;
redpic.set(row, col, Color(r, 0, 0));
greenpic._____;
bluepic._____;
}
}
// show the new pictures in 3 windows
redpic.show(true);
bluepic.show(true);
greenpic.show(true);
}