#include <stdio.h>
#define X_SIZE 32
#define Y_SIZE 32
typedef unsigned char u_char;
void disp_img(int n);
void cut_img(void);
void load_image_data(char* f_name);
u_char image[Y_SIZE][X_SIZE * 10];
u_char img_a[10][Y_SIZE][X_SIZE];
int main()
{
int i;
load_image_data("number2.pgm");
cut_img();
for (i = 0; i < 10; i++) {
disp_img(i);
}
return 0;
}
void disp_img(int n)
{
int ix, iy;
for (iy = 0; iy < Y_SIZE; iy++) {
for (ix = 0; ix < X_SIZE; ix++) {
printf("%02x", img_a
[n
][iy
][ix
]); }
}
}
void cut_img(void)
{
int i, ix, iy;
for (i = 0; i < 10; i++) {
for (iy = 0; iy < Y_SIZE; iy++) {
for (ix = 0; ix < X_SIZE; ix++) {
img_a[i][iy][ix] = image[iy][X_SIZE * i + ix];
}
}
}
}
void load_image_data(char* f_name)
{
FILE* fp;
char buf[640];
errno_t err;
int x_size, y_size;
int max_gray;
int ix, iy;
err = fopen_s(&fp, f_name, "rb");
if (err) {
return;
}
// P5
fgets(buf
, sizeof buf
, fp
); if (buf[0] != 'P' || buf[1] != '5') {
return;
}
// x y
x_size = y_size = 0;
while (x_size == 0) {
fgets(buf
, sizeof buf
, fp
); if (buf[0] == '#') continue;
sscanf_s(buf, "%d%d", &x_size, &y_size);
}
// max
max_gray = 0;
while (max_gray == 0) {
fgets(buf
, sizeof buf
, fp
); if (buf[0] == '#') continue;
sscanf_s(buf, "%d", &max_gray);
}
for (iy = 0; iy < y_size; iy++) {
for (ix = 0; ix < x_size; ix++) {
image
[iy
][ix
] = fgetc(fp
); }
}
}
/*
img_a[8]
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffff0000000000ffffffffffffffffffffffffffffffffffffffffff
ffffffffff00ffffffffff0000ffffffffffffffffffffffffffffffffffffff
ffffffff00ffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffff0000ffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffff0000ffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffff0000ffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffff000000ffffffffffff00ffffffffffffffffffffffffffffffffffffff
ffffffff00000000ffffff00ffffffffffffffffffffffffffffffffffffffff
ffffffffff000000000000ffffffffffffffffffffffffffffffffffffffffff
ffffffffffff000000000000ffffffffffffffffffffffffffffffffffffffff
ffffffffff00ffffff00000000ffffffffffffffffffffffffffffffffffffff
ffffff0000ffffffffffff000000ffffffffffffffffffffffffffffffffffff
ffff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffff
ffff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffff
ffff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffff
ffff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffff
ffffff0000ffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffffff0000ffffffffff0000ffffffffffffffffffffffffffffffffffffff
ffffffffff000000000000ffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
img_a[9]
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffff0000000000ffffffffffffffffffffffffffffffffffffffffffff
ffffff0000ffffffffff00ffffffffffffffffffffffffffffffffffffffffff
ffff0000ffffffffffffff00ffffffffffffffffffffffffffffffffffffffff
ffff00ffffffffffffffffff00ffffffffffffffffffffffffffffffffffffff
ff0000ffffffffffffffffff00ffffffffffffffffffffffffffffffffffffff
ff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ff0000ffffffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffff0000ffffffffffffff000000ffffffffffffffffffffffffffffffffffff
ffffff0000ffffffffff00ff0000ffffffffffffffffffffffffffffffffffff
ffffffff000000000000ffff0000ffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffff0000ffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffff
ffff000000ffffffffffff0000ffffffffffffffffffffffffffffffffffffff
ffff000000ffffffffffff00ffffffffffffffffffffffffffffffffffffffff
ffff0000ffffffffffff0000ffffffffffffffffffffffffffffffffffffffff
ffffff00ffffffffff0000ffffffffffffffffffffffffffffffffffffffffff
ffffffff0000000000ffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
*/