-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain_console.cc
130 lines (101 loc) · 3.22 KB
/
main_console.cc
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// Copyright 2013 Light Transport Entertainment Inc.
//
#ifdef _OPENMP
#include <omp.h>
#endif
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <fstream>
#include <vector>
#include <sstream>
#include "camera.h"
#include "timerutil.h"
#include "render.h"
#include "jpge.h"
namespace mallie {
namespace {
inline unsigned char fclamp(float x) {
int i = x * 255.5;
if (i < 0)
return 0;
if (i > 255)
return 255;
return (unsigned char)i;
}
void HDRToLDR(std::vector<unsigned char> &out, const std::vector<float> &in,
const std::vector<int> &in_count, int width, int height) {
out.resize(width * height * 3);
assert(in.size() == (width * height * 3));
// Simple [0, 1] -> [0, 255]
for (int i = 0; i < width * height * 3; i++) {
out[i] = fclamp(in[i] / in_count[i / 3]);
}
}
void SaveAsJPEG(const char *filename,
std::vector<unsigned char> &image, // RGB
int width, int height) {
jpge::params comp_params;
comp_params.m_quality = 100;
bool ret = jpge::compress_image_to_jpeg_file(filename, width, height, 3,
&image.at(0), comp_params);
assert(ret);
}
} // local
void DoMainConsole(Scene &scene, const RenderConfig &config) {
printf("[Mallie] Console mode\n");
#if 1
{
std::vector<float> image;
std::vector<int> count;
const int width = config.width;
const int height = config.height;
image.resize(width * height * 3);
count.resize(width * height);
mallie::Render(scene, config, image, count, config.eye, config.lookat, config.up, config.quat, 1);
std::string outfilename("output.jpg"); // fixme
std::vector<unsigned char> out;
HDRToLDR(out, image, count, width, height);
SaveAsJPEG(outfilename.c_str(), out, width, height);
printf("[Mallie] Output %s\n", outfilename.c_str());
}
#else
const_cast<RenderConfig &>(config).width = 600;
const_cast<RenderConfig &>(config).height = 600;
const_cast<RenderConfig &>(config).eye[0] = 0;
const_cast<RenderConfig &>(config).eye[1] = 1;
const_cast<RenderConfig &>(config).eye[2] = -4;
const int total_frame = 1;
for (int i = 0; i < total_frame; ++i) {
std::vector<float> image;
std::vector<int> count;
int width = config.width;
int height = config.height;
image.resize(width * height * 3);
count.resize(width * height);
double eye[3];
/*eye[0] = config.eye[0];
eye[1] = config.eye[1];
eye[2] = config.eye[2];*/
eye[0] = 4.0 * sin(2.0 * M_PI * i / total_frame);
eye[1] = 1.0;
eye[2] = 4.0 * cos(2.0 * M_PI * i / total_frame);
// mallie::RenderPanoramic(scene, config, image, count, eye, config.lookat,
// config.up, config.quat, /* stereo = */ false);
mallie::RenderPanoramic(scene, config, image, count, eye, config.lookat,
config.up, config.quat, /* stereo = */ true);
std::string outfilename;
{
std::stringstream ss;
ss << "output" << i << ".jpg";
outfilename = ss.str();
}
std::vector<unsigned char> out;
HDRToLDR(out, image, count, width, height);
SaveAsJPEG(outfilename.c_str(), out, width, height);
printf("[Mallie] Output %s\n", outfilename.c_str());
}
#endif
}
} // mallie