forked from Dwayne-Phillips/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathround.c
executable file
·147 lines (127 loc) · 4.39 KB
/
round.c
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
/***********************************************
*
* file c:\cips\round.c
*
* Functions: This file contains
* main
*
* Purpose:
* This program takes an image file and
* rounds if off by copying a part of it
* to another file.
*
* External Calls:
* imageio.c - does_not_exit
* get_image_size
* allocate_image_array
* read_image_array
* is_a_tiff
* is_a_bmp
* create_allocate_tiff_file
* read_bmp_file_header
* read_bm_header
* create_allocate_bmp_file
* write_image_array
* free_image_array
*
*
* Modifications:
* 31 March 1991 - created
* 8 May 1993 - Made this program
* command line driven.
* 6 August 1998 - Made this work with
* entire image arrays at once.
* 18 September 1998 - modified to work with
* all I O routines in imageio.c.
*
***********************************************/
#include "cips.h"
main(argc, argv)
int argc;
char *argv[];
{
char response[80];
char name[80], name2[80];
int i = 0,
ie = 0,
il = 0,
j = 0,
in_length = 0,
out_length = 0,
in_width = 0,
out_width = 0;
short **the_image, **out_image;
struct bmpfileheader bmp_file_header;
struct bitmapheader bmheader;
struct tiff_header_struct tiff_file_header;
/******************************************
*
* Ensure the command line is correct.
*
******************************************/
if(argc < 5 ||
(argc > 5 && argc < 7)){
printf("\nusage: roundoff in-image out-image"
" length width [il ie]"
"\n"
"\n If you do not specify il ie"
" they will be set to 1 1."
"\n ll le will always be"
" il+length and ie+width"
"\n");
exit(0);
}
strcpy(name, argv[1]);
strcpy(name2, argv[2]);
out_length = atoi(argv[3]);
out_width = atoi(argv[4]);
if(argc > 5){
il = atoi(argv[5]);
ie = atoi(argv[6]);
}
if(does_not_exist(name)){
printf("\nERROR input file %s does not exist",
name);
exit(0);
}
get_image_size(name, &in_length, &in_width);
the_image = allocate_image_array(in_length,
in_width);
read_image_array(name, the_image);
/******************************************
*
* Create the output image and allocate
* the output image array.
*
******************************************/
if(is_a_tiff(name)){
read_tiff_header(name, &tiff_file_header);
tiff_file_header.image_length = out_length;
tiff_file_header.image_width = out_width;
create_allocate_tiff_file(name2,
&tiff_file_header);
}
if(is_a_bmp(name)){
read_bmp_file_header(name,
&bmp_file_header);
read_bm_header(name, &bmheader);
bmheader.height = out_length;
bmheader.width = out_width;
create_allocate_bmp_file(name2,
&bmp_file_header,
&bmheader);
}
out_image = allocate_image_array(out_length, out_width);
/******************************************
*
* Copy the input image array to the output
* image array per the input parameters.
*
******************************************/
for(i=0; i<out_length; i++)
for(j=0; j<out_width; j++)
out_image[i][j] = the_image[i+il][j+ie];
write_image_array(name2, out_image);
free_image_array(out_image, out_length);
free_image_array(the_image, in_length);
} /* ends main */