-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsis.c
More file actions
224 lines (191 loc) · 5.26 KB
/
Copy pathsis.c
File metadata and controls
224 lines (191 loc) · 5.26 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
// #include "cfgpath.h"
#include "cwalk.h"
#include "sis.h"
#include "stbimg.h"
int ImgFileFormat = SIS_IMGFMT_DFLT;
ind_t Tcolcount;
char depth_map_path[PATH_MAX] = {0};
char texture_path[PATH_MAX] = {0};
char DFileName[PATH_MAX] = {0};
char TFileName[PATH_MAX] = {0};
char SISFileName[PATH_MAX] = {0};
char CFGFileName[PATH_MAX] = {0};
col_t *DBuffer = NULL;
z_t zvalue[SIS_MAX_COLORS + 1];
cmap_t *SISred, *SISgreen, *SISblue;
col_rgb_t *SIScolorRGB;
cmap_t black_value, white_value;
int rand_grey_num, rand_col_num;
col_t white, black;
ind_t Dwidth, Dheight, SISwidth, SISheight, Twidth, Theight;
ind_t eye_dist, origin, halfstripwidth, halftriangwidth;
int SIStype, SIScompress, verbose;
bool invert;
bool mark;
char metric;
int resolution;
int debug;
double density;
void (*OpenDFile)(char *DFileName, ind_t * width, ind_t * height);
void (*OpenTFile)(char *TFileName, ind_t * width, ind_t * height);
void (*CreateSISBuffer)(ind_t width, ind_t height, int SIStype);
void (*CloseDFile)(void);
void (*CloseTFile)(ind_t height);
void (*CloseSISFile)(void);
void (*WriteSISFile)(void);
void (*ReadDBuffer)(ind_t r);
col_t(*ReadTPixel) (ind_t r, ind_t c);
// void (*WriteSISBuffer)(ind_t r);
void (*WriteSISColorBuffer)(ind_t r);
unsigned char *(*GetDFileBuffer)(void);
unsigned char *(*GetTFileBuffer)(void);
unsigned char *(*GetSISFileBuffer)(void);
const char *DefaultDFileName = "flowers.png";
const char *DefaultTFileName = "clover.png";
const char *DefaultSISFileName = "out.png";
pos_t DLinePosition, DLineStep;
ind_t SISLineNumber;
ind_t DLineNumber;
void
SetDefaults(void)
{
cwk_path_join(depth_map_path, DefaultDFileName, DFileName, PATH_MAX);
cwk_path_join(texture_path, DefaultTFileName, TFileName, PATH_MAX);
strncpy(SISFileName, DefaultSISFileName, PATH_MAX);
// SIStype = SIS_RANDOM_GREY;
SIStype = SIS_TEXT_MAP;
SISwidth = SISheight = 0;
algorithm = 2;
origin = -1; /* that means, it is set to SISwidth/2 later */
verbose = 0;
invert = false;
mark = 0;
metric = 'i';
resolution = 75;
oversam = 4;
eye_dist = 300;
t = 1.0;
u = 0.67;
rand_grey_num = 2;
rand_col_num = SIS_MAX_COLORS;
density = 0.5;
debug = 0;
}
void
InitFuncs(void)
{
OpenDFile = Stb_OpenDFile;
CloseDFile = Stb_CloseDFile;
ReadDBuffer = Stb_ReadDBuffer;
CreateSISBuffer = Stb_CreateSISBuffer;
OpenTFile = Stb_OpenTFile;
CloseTFile = Stb_CloseTFile;
CloseSISFile = Stb_CloseSISFile;
WriteSISFile = Stb_WriteSISFile;
ReadTPixel = Stb_ReadTPixel;
// WriteSISBuffer = Stb_WriteSISBuffer;
WriteSISColorBuffer = Stb_WriteSISColorBuffer;
GetDFileBuffer = Stb_GetDFileBuffer;
GetTFileBuffer = Stb_GetTFileBuffer;
GetSISFileBuffer = Stb_GetSISFileBuffer;
}
void
init_base(int argc, char **argv)
{
InitFuncs();
SISred = (cmap_t *) calloc(SIS_MAX_COLORS + 1, sizeof(cmap_t));
SISgreen = (cmap_t *) calloc(SIS_MAX_COLORS + 1, sizeof(cmap_t));
SISblue = (cmap_t *) calloc(SIS_MAX_COLORS + 1, sizeof(cmap_t));
SetDefaults();
/// If command line args are provided (with sis or sisui) or we're running non-gui sis with no args
if (argc > 1 || !gui) {
#ifndef IGNORE_CMDLINE_OPT
get_options(argc, argv);
#endif
}
#if 0
get_user_config_file(CFGFileName, sizeof(CFGFileName), "sis");
if (CFGFileName[0] == 0) {
// fprintf(stderr, "failed to load config file.\n");
}
// printf("loaded config file '%s'\n", CFGFileName);
#endif
}
#include <stdio.h>
#include <string.h>
#include <errno.h>
void
init_sis(void)
{
if (access(DFileName, R_OK) == -1) {
/// TODO don't use stdio here but return error and string
fprintf(stderr, "failed to access depthmap image file '%s': %s\n",
DFileName, strerror(errno));
exit(EXIT_FAILURE);
}
OpenDFile(DFileName, &Dwidth, &Dheight);
if (SIStype == SIS_TEXT_MAP) {
if (access(TFileName, R_OK) == -1) {
/// TODO don't use stdio here but return error and string
fprintf(stderr, "failed to access texture image file '%s': %s\n",
TFileName, strerror(errno));
exit(EXIT_FAILURE);
}
OpenTFile(TFileName, &Twidth, &Theight);
}
InitAlgorithm();
AllocBuffers();
CreateSISBuffer(SISwidth, SISheight, SIStype);
}
void
init_all(int argc, char **argv)
{
init_base(argc, argv);
init_sis();
}
void
finish_sis(void)
{
CloseDFile();
if (SIStype == SIS_TEXT_MAP) {
CloseTFile(Theight);
}
CloseSISFile();
FreeBuffers();
free(SISred);
free(SISgreen);
free(SISblue);
}
void
finish_all(void)
{
finish_sis();
}
void
render_sis(void)
{
for (SISLineNumber = 0; SISLineNumber < SISheight; SISLineNumber++) {
DLineNumber = (int)DLinePosition;
DLinePosition += DLineStep;
max_depth_in_row = SIS_MIN_DEPTH;
min_depth_in_row = SIS_MAX_DEPTH;
ReadDBuffer(DLineNumber); /// Read in one line of depth-map
if (algorithm < 4) {
CalcIdentLine(); /// My SIS-algorithm
InitSISBuffer(SISLineNumber); /// Fill in the right color indices,
FillRGBBuffer(SISLineNumber);
/// according to the SIS-type
} else {
InitSISBuffer(SISLineNumber); /// Fill in the right color indices,
asteer(SISLineNumber); /// Andrew Steer's SIS-algorithm
}
// WriteSISBuffer(SISLineNumber); /// Write one line of output
WriteSISColorBuffer(SISLineNumber); /// Write one line of output
if (verbose) {
show_statistics();
}
}
}