pgm.h
and ppm.h
header files.
Each pgm.h
and ppm.h
header file should also
include function prototypes to allocate, free, read, and write each
of the PGM and PPM images.
pgm.c
and ppm.c
, each
with its own header.
PGM *pgm_alloc(int r, int c);
void pgm_free(PGM **img);
PPM *ppm_alloc(int r, int c);
void ppm_free(PPM **img);
PGM *pgm_read(const char *file);
void pgm_write(PGM *img, const char *file);
PPM *ppm_read(const char *file);
void ppm_write(PPM *img, const char *file);
int ptype; // magic number (int part of 'P5' or 'P6')
int w,h; // width, height
int bpp; // bytes per pixel (1 or 3)
int max; // max color (usually 255)
char *name; // file name
float *gpix;
float *rpix;
float *gpix;
float *bpix;
pgmtest.c
to test the PGM module:
img = pgm_read("mandrill.pgm");
pgm_write(img,"copy.pgm");
pgm_free(&img);
img = ppm_read("mandrill.ppm");
ppm_write(img,"copy.ppm");
ppm_free(&img);
pgmtest.c
and
ppmtest.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: pgmtest ppmtest
pgmtest: pgm.o pgmtest.o
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
ppmtest: ppm.o ppmtest.o
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
pgmtest.o: pgmtest.c
ppmtest.o: ppmtest.c
pgm.o: pgm.c pgm.h
ppm.o: ppm.c ppm.h
clean:
rm -f *.o
rm -rf pgmtest ppmtest
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