forked from madsravn/easyCuda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (49 loc) · 1.71 KB
/
main.cpp
File metadata and controls
64 lines (49 loc) · 1.71 KB
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
61
#include <iostream>
#include <cstdlib>
#include "lodepng.h"
#include <cuda.h>
#include <cuda_runtime.h>
#include "kernels.h"
#include <functional>
int main(int argc, char** argv) {
if(argc != 3) {
std::cout << "Run with input image filename and filter value." << std::endl;
return 0;
}
// Read the arguments
const char* input_file = argv[1];
const int filter_option = atoi(argv[2]);
std::vector<unsigned char> in_image;
unsigned int width, height;
// Load the data
unsigned error = lodepng::decode(in_image, width, height, input_file);
if(error) std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
// Prepare the data
unsigned char* input_image = new unsigned char[(in_image.size()*3)/4];
unsigned char* output_image = new unsigned char[(in_image.size()*3)/4];
int where = 0;
for(int i = 0; i < in_image.size(); ++i) {
if((i+1) % 4 != 0) {
input_image[where] = in_image.at(i);
output_image[where] = 255;
where++;
}
}
// Run the filter on it
filter(input_image, output_image, width, height, filter_option);
// Prepare data for output
std::vector<unsigned char> out_image;
for(int i = 0; i < in_image.size(); ++i) {
out_image.push_back(output_image[i]);
if((i+1) % 3 == 0) {
out_image.push_back(255);
}
}
// Output the data
error = lodepng::encode("output_image.png", out_image, width, height);
//if there's an error, display it
if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl;
delete[] input_image;
delete[] output_image;
return 0;
}