forked from Dwayne-Phillips/CIPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpi.c
executable file
·111 lines (92 loc) · 2.65 KB
/
dumpi.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
/***********************************************
*
* file dumpi.c
*
* Functions: This file contains
* main
*
* Purpose:
* This file contains a program that
* dumps the number values of an image
* to an ascii text file.
*
* External Calls:
* imageio.c - get_image_size
* read_image_array
* allocate_image_array
* free_image_array
*
* Modifications:
* 1 October 1998 - created to work with
* all I O routines in imageio.c.
*
*************************************************/
#include "cips.h"
int does_not_exist();
int get_image_size();
int read_image_array();
int free_image_array();
int main(argc, argv)
int argc;
char *argv[];
{
char in_name[MAX_NAME_LENGTH];
char out_name[MAX_NAME_LENGTH];
char *line, buffer[10];
int i, j;
long height, width;
short **the_image;
FILE *out_file;
/******************************************
*
* Ensure the command line is correct.
*
******************************************/
if(argc != 3){
printf("\nusage: dumpi input-image output-file");
exit(0);
}
strcpy(in_name, argv[1]);
strcpy(out_name, argv[2]);
/******************************************
*
* Ensure the input image exists.
* Create the output text file.
* Allocate an image array.
* Read the image and dump the nubmers
* to a text file.
*
******************************************/
if(does_not_exist(in_name)){
printf("\nERROR input file %s does not exist",
in_name);
exit(0);
} /* ends if does_not_exist */
if((out_file = fopen(out_name, "wt")) == NULL){
printf("\nERROR Could not open file %s",
out_name);
exit(2);
}
get_image_size(in_name, &height, &width);
the_image = allocate_image_array(height, width);
read_image_array(in_name, the_image);
line = malloc( ((width*4)+7) * sizeof(char *));
sprintf(line, " ");
for(i=0; i<width; i++){
sprintf(buffer, "%4d", i);
strcat(line, buffer);
}
strcat(line, "\n");
fputs(line, out_file);
for(i=0; i<height; i++){
sprintf(line, "%5d>", i);
for(j=0; j<width; j++){
sprintf(buffer, "-%3d", the_image[i][j]);
strcat(line, buffer);
}
strcat(line, "\n");
fputs(line, out_file);
}
free_image_array(the_image, height);
fclose(out_file);
} /* ends main */