16 ' ',
'.',
'\'',
'`',
'\'',
'-',
'^',
'\"',
'!',
17 '>',
';',
'=',
'0',
'i',
'j',
'l',
't',
'c',
18 'f',
'o',
'a',
'V',
'5',
'e',
'b',
'D',
'p',
19 'g',
'B',
'm',
'H',
'H',
'H',
'M',
'M',
'@'
22 typedef unsigned char Byte;
51 fprintf(stderr,
"Error allocating memory for image\n");
55 fp = fopen(fname,
"rb");
57 fprintf(stderr,
"Error opening file %s\n", fname);
63 if (fscanf(fp,
"P6\n%u%u%u%*c", &image->
width, &image->
height, &depth) != 3 || depth != 255u) {
64 fprintf(stderr,
"Error reading image\n");
72 if (image->
pixels == NULL) {
73 fprintf(stderr,
"Error allocating memory to image data\n");
81 fprintf(stderr,
"Error reading image data\n");
109 int idx = h*image->
width+w;
110 return image->
pixels[idx];
119 return (
Byte) (p.
r/3. + p.
g/3. + p.
b/3.);
126 unsigned H = W * 1.7;
129 for (h = 0; h < image->
height/H; ++h) {
130 for (w = 0; w < image->
width/W; ++w) {
131 unsigned i, j, b = 0;
132 for (i = 0; i < H; ++i)
133 for (j = 0; j < W; ++j) {
138 printf(
"%c",
ASCII[b]);
150 printf(
"fajlnev: "); fflush(stdout);
unsigned width
a kép szélessége pixelben
char ASCII[MAX_BRIGHT]
az ASCII karakterek tömbje
bitmap képet tároló struktúra típus
ennyi különböző fényességérték van
unsigned height
a kép magassága pixelben
egyetlen pixel adatait tartlmazó struktúra
unsigned char Byte
egybájtos típus
Byte r
a pixel piros színkomponense
void image_close(Image *image)
kép bezárása
void image_to_ascii(Image *image)
képet ASCII karakterekkel ábrázol
max. ilyen hosszú lehet a fájlnév
Byte b
a pixel kék színkomponense
Pixel get_pixel(Image *image, int h, int w)
a kép egy pixele indexek alapján
ilyen széles lesz az ASCII kép
Byte g
a pixel zöld színkomponense
Image * image_read(char *fname)
kép beolvasása PPM fájlból
Byte pixel_brightness(Pixel p)
egy pixel fényessége
Pixel * pixels
a pixelek dinamikus tömbje (sorfolytonos)
int main(void)
A főprogram.