9 void load_image_data(
const char* file_name,
unsigned char *image1,
unsigned int * x_size1,
unsigned int * y_size1 )
19 printf(
"\n-----------------------------------------------------\n");
20 printf(
"Monochromatic image file input routine \n");
21 printf(
"-----------------------------------------------------\n\n");
22 printf(
" Only pgm binary file is acceptable\n\n");
23 printf(
"Name of input image file: %s\n", file_name);
24 fp = fopen(file_name,
"rb");
26 printf(
" The file doesn't exist!\n\n");
31 if (buffer[0] !=
'P' || buffer[1] !=
'5') {
32 printf(
" Mistaken file format, not P5!\n\n");
38 while (*x_size1 == 0 || *y_size1 == 0) {
40 if (buffer[0] !=
'#') {
41 sscanf(buffer,
"%d %d", x_size1, y_size1);
46 while (max_gray == 0) {
48 if (buffer[0] !=
'#') {
49 sscanf(buffer,
"%d", &max_gray);
53 printf(
"\n Image width = %d, Image height = %d\n", *x_size1, *y_size1);
54 printf(
" Maximum gray level = %d\n\n",max_gray);
56 printf(
" Image size exceeds %d x %d\n\n",
58 printf(
" Please use smaller images!\n\n");
62 printf(
" Invalid value of maximum gray level!\n\n");
66 for (y = 0; y < *y_size1; y++) {
67 for (x = 0; x < *x_size1; x++) {
71 printf(
"-----Image data input OK-----\n\n");
72 printf(
"-----------------------------------------------------\n\n");
76 void save_image_data(
const char* file_name,
unsigned char * image2,
unsigned int x_size2,
unsigned int y_size2)
84 printf(
"-----------------------------------------------------\n");
85 printf(
"Monochromatic image file output routine\n");
86 printf(
"-----------------------------------------------------\n\n");
87 printf(
"Name of output image file: %s\n", file_name);
88 fp = fopen(file_name,
"wb");
91 fputs(
"# Created by Image Processing\n", fp);
92 fprintf(fp,
"%d %d\n", x_size2, y_size2);
95 for (y = 0; y < y_size2; y++) {
96 for (x = 0; x < x_size2; x++) {
100 printf(
"\n-----Image data output OK-----\n\n");
101 printf(
"-----------------------------------------------------\n\n");
void save_image_data(const char *file_name, unsigned char *image2, unsigned int x_size2, unsigned int y_size2)
void load_image_data(const char *file_name, unsigned char *image1, unsigned int *x_size1, unsigned int *y_size1)
x
Return the smallest n such that 2^n >= _x.