ppm.c
and pgm.c
,
each implementation file with its own header.
ppm
image module should take care of converting
the color image to a greyscale image.
main.c
code driver tests the modules by:
ppm_read(...)
to read in the PPM image
ppm_togrey(...)
to convert the PPM image
pgm_write(...)
to output the PGM image
ppm_free(...)
to free PPM image memory
pgm_free(...)
to free PGM image memory
ppm.c
and use three (1D) arrays for the R, G, B
channels.
pgm.h
header:
#ifndef PGM_H
#define PGM_H
typedef struct {
char *name; // filename
int cols; // width
int rows; // height
int maxc; // max color (usually 255)
char *magic; // magic number (expect 'P5')
float *data; // the pixels, stored as 1D array
} PGM;
PGM *pgm_alloc(int r, int c);
void pgm_free(PGM **img);
int pgm_read(const char *file);
int pgm_write(PGM *img, const char *file);
void pgm_white(PGM *img);
#endif
main.c
here is a
Makefile
that you can use to try to compile the project:
CC = gcc
INCLUDE = -I.
CFLAGS = -g
LDFLAGS = -L. -L/usr/lib
LDLIBS = -lc -lm
.c.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<
all: main
main: pgm.o ppm.o main.o
$(CC) -o $@ $@.o pgm.o ppm.o $(LDFLAGS) $(LDLIBS)
main.o: main.c
clean:
rm -f *.o
rm -rf main
Note that each line underneath the targets is indented by a tab, not just
spaces, this is important!
tar.gz
archive of your asg##/ directory, including:
README
file containing
Makefile
.h
headers and .c
source)
make clean
before tar
)
handin
notes