-
Notifications
You must be signed in to change notification settings - Fork 8
/
imagedemo.cpp
62 lines (49 loc) · 1.7 KB
/
imagedemo.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
50
51
52
53
54
55
56
57
58
59
60
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Mon 18 Apr 2022 06:34:46 PM UTC
// Last Modified: Mon 18 Apr 2022 06:34:49 PM UTC
// Filename: cli/imagedemo.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/cli/imagedemo.cpp
// Syntax: C++11
// vim: ts=3 noexpandtab nowrap
//
// Description: Demonstration of how to use PixelColor class
// to create simple images.
//
#include "humlib.h"
#include <iostream>
using namespace hum;
using namespace std;
void processFile (HumdrumFile& infile, Options& options);
double calculateNpviRhythm (HumdrumFile& infile, Options& option);
double calculateCvPitch (HumdrumFile& infile, Options& options);
string getReference (HumdrumFile& infile, const string& targetKey);
///////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv) {
Options options;
options.define("x|columns=i:4", "Number of columns in image");
options.define("y|rows=i:4", "Number of rows in image");
options.process(argc, argv);
int rows = options.getInteger("rows");
int cols = options.getInteger("columns");
vector<vector<PixelColor>> image(rows);
for (int y=0; y<(int)image.size(); y++) {
image[y].resize(cols);
for (int x=0; x<(int)image[y].size(); x++) {
image[y][x].setRedF((double)y/rows);
image[y][x].setBlueF((double)x/cols);
}
}
// Output image header:
cout << "P3" << endl;
cout << cols << " " << rows << endl;
cout << 255 << endl;
// Output image pixels:
for (int y=0; y<(int)image.size(); y++) {
for (int x=0; x<(int)image[y].size(); x++) {
cout << image[y][x] << " ";
}
cout << endl;
}
return 0;
}