-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpicture_treat.cpp
102 lines (94 loc) · 2.81 KB
/
picture_treat.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "core/GLBmp.h"
#include "utils/GLDebug.h"
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include "GL/GLContext.h"
#include "GL/GLAutoFbo.h"
#include "GL/GLBitmapWork.h"
#include "GL/GLFilterWork.h"
#include "GL/GLMultiPassDrawWork.h"
#include "GL/GLDrawWork.h"
#define ENLARGE_P 1.0
using namespace std;
static string loadFiles(const char* name)
{
ifstream vertex(name);
GLASSERT(!vertex.fail());
ostringstream vertex_s;
vertex_s << vertex.rdbuf();
return vertex_s.str();
}
static IGLDrawWork* init_skin_detect_treat(int w, int h)
{
const char* vertex = "/Users/jiangxiaotang/Documents/shader/ShallowOnePass.vex";
const char* frag = "/Users/jiangxiaotang/Documents/shader/skin_with_lsd.fra";
map<string, float> firstunifom;
firstunifom["texelWidth"] = 1.0/w;
firstunifom["texelHeight"] = 0.0;
firstunifom["filterRatio"] = 1.0;
firstunifom["sigma_c"] = 30.0;
firstunifom["sigma_s"] = 0.1;
map<string, float> secondunifom;
secondunifom["texelWidth"] = 0.0;
secondunifom["texelHeight"] = 1.0/h;
secondunifom["filterRatio"] = 1.0;
secondunifom["sigma_c"] = 30.0;
secondunifom["sigma_s"] = 0.1;
vector<GPPtr<IGLDrawWork> > works;
works.push_back(new GLDrawWork(loadFiles(vertex), loadFiles(frag), &secondunifom));
works.push_back(new GLDrawWork(loadFiles(vertex), loadFiles(frag), &firstunifom));
return new GLMultiPassDrawWork(works);
}
GPPtr<GLBmp> pretreat(GPPtr<GLBmp> src)
{
GPPtr<IGLDrawWork> work = init_skin_detect_treat(src->width(), src->height());
GPPtr<GLBmp> dst = new GLBmp(src->width(), src->height());
GPPtr<GLTexture> srct = new GLTexture;
GPPtr<GLTexture> dstt = new GLTexture;
srct->upload(src->pixels(), src->width(), src->height());
dstt->upload(NULL, src->width(), src->height());
{
GLAutoFbo __fbo(*dstt);
float texpoints[] = {
0.0,0.0,
0.0,1.0,
1.0,0.0,
1.0,1.0
};
GLvboBuffer texcord(texpoints, 2, 4, GL_TRIANGLE_STRIP);
/*Treated picture*/
float points[] = {
-1.0, -1.0,
-1.0, 1.0,
1.0, -1.0,
1.0, 1.0
};
GLvboBuffer temp(points, 2, 4, GL_TRIANGLE_STRIP);
auto tex = srct.get();
work->onDraw(&tex, 1, &temp, &texcord);
dstt->download(dst->pixels());
}
return dst;
}
int main(int argc, char* argv[])
{
GLASSERT(argc>=4);
GLAutoContext __c;
const char* inputfile = argv[1];
const char* outputfile = argv[2];
std::string method = argv[3];//TODO
GPPtr<GLBmp> rgb_origin = new GLBmp(inputfile);
GPPtr<GLBmp> rgb;
if (method == "origin")
{
rgb = rgb_origin;
}
else
{
rgb = pretreat(rgb_origin);
}
rgb->save(outputfile);
return 1;
}