forked from Dwayne-Phillips/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiso.c
More file actions
executable file
·189 lines (149 loc) · 4.79 KB
/
iso.c
File metadata and controls
executable file
·189 lines (149 loc) · 4.79 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
/*********************************************
*
* file iso.c
*
* Functions: This file contains
* main
* lineup
*
* Purpose:
* This program performs a simple
* form of isometric transform
* where the vertical is angled.
*
* External Calls:
* imageio.c
* create_resized_image_file
* read_image_array
* write_image_array
* get_image_size
* allocate_image_array
* free_image_array
*
* Modifications:
* 15 May 1999 - created
*
***********************************************/
#include "cips.h"
int does_not_exist();
int create_image_file();
int get_image_size();
int read_image_array();
int free_image_array();
int write_image_array();
int create_resized_image_file();
int lineup();
#define FILL 200
#define FILL2 150
#define MOREROWS 100
#define DEGREESPERRADIAN 57.29577952
short **the_image;
short **out_image;
int main(argc, argv)
int argc;
char *argv[];
{
char in_name[MAX_NAME_LENGTH],
out_name[MAX_NAME_LENGTH];
double tantheta;
float scale;
int i, ii, j, jj, theta;
int space, value;
long length1, length2, width1, width2;
long bigxshift, xshift;
short height, max;
/* Check the command line and obtain
the parameters. */
if(argc != 6){
printf(
"\n\nusage: iso in-file out-file theta space value"
"\n theta in integer degrees plus or minus"
"\n (stay away from 90 degrees)"
"\n space is spacing to draw lines on output"
"\n value = 0 use black dots on top of image"
"\n value = 1 use actual image values\n");
exit(0);
}
strcpy(in_name, argv[1]);
strcpy(out_name, argv[2]);
theta = atoi(argv[3]);
space = atoi(argv[4]);
value = atoi(argv[5]);
/* check input file */
if(does_not_exist(in_name)){
printf("\nERROR input file %s does not exist",
in_name);
exit(0);
} /* ends if does_not_exist */
/* get size of input file and calculate size
of output file. output file will depend
on the angle theta */
get_image_size(in_name, &length1, &width1);
tantheta = tan( (double)(theta)/DEGREESPERRADIAN);
bigxshift = tantheta*(double)(length1);
if(bigxshift < 0) bigxshift = bigxshift * (-1);
length2 = length1 + MOREROWS + MOREROWS;
width2 = width1 + bigxshift;
create_resized_image_file(in_name, out_name,
length2, width2);
/* allocate the image arrays */
the_image = allocate_image_array(length1, width1);
out_image = allocate_image_array(length2, width2);
/* fill the output image with FILL */
for(i=0; i<length2; i++)
for(j=0; j<width2; j++)
out_image[i][j] = FILL;
read_image_array(in_name, the_image);
/* Scale the height of the output image */
max = 0;
for(i=0; i<length1; i++){
for(j=0; j<width1; j++){
if(the_image[i][j] > max)
max = the_image[i][j];
} /* ends loop over j */
} /* ends loop over i */
if(max > MOREROWS)
scale = (float)(max)/(float)(MOREROWS);
else
scale = max;
if(scale < 1.0)
scale = 1.0;
/* Loop through the input image and place
the pixels in the output image. */
for(i=0; i<length1; i++){
for(j=0; j<width1; j++){
if(i%space == 0){
ii = i + MOREROWS;
xshift = tantheta*(double)(i);
if(i == 0 && theta <= 0)
jj = j + bigxshift + xshift;
if(i == 0 && theta > 0)
jj = j + xshift;
if(i != 0 && theta <= 0)
jj = j + bigxshift + xshift;
if(i != 0 && theta > 0)
jj = j + xshift;
out_image[ii][jj] = the_image[i][j];
height = the_image[i][j]/scale;
lineup(out_image, ii, ii-height, jj);
if(value == 0)
out_image[ii-height][jj] = 0;
else
out_image[ii-height][jj] =
the_image[i][j];
} /* ends if j%space */
} /* ends loop over j */
} /* ends loop over i */
write_image_array(out_name, out_image);
free_image_array(the_image, length1);
free_image_array(out_image, length2);
} /* ends main */
int lineup(image, start_row, end_row, column)
int start_row, end_row, column;
short **image;
{
int i;
for(i=start_row; i>end_row; i--)
image[i][column] = FILL2;
return(1);
} /* ends lineup */