# HG changeset patch # User John Tsiombikas # Date 1444344312 -10800 # Node ID c438411b801b67435a99e4e5803d4a9846cb7c22 # Parent 960cea2731c4c9e6da69069ac0b8d2d5b16fb397 latest changes from svn (saving grad files) diff -r 960cea2731c4 -r c438411b801b Makefile --- a/Makefile Tue Jun 19 05:30:45 2012 +0300 +++ b/Makefile Fri Oct 09 01:45:12 2015 +0300 @@ -2,8 +2,14 @@ obj = gradtool.o bin = gradtool -CFLAGS = -std=c89 -pedantic -Wall -g -LDFLAGS = -lglut -lGL +CFLAGS = -pedantic -Wall -g +LDFLAGS = $(libgl) + +ifeq ($(shell uname -s), Darwin) + libgl = -framework OpenGL -framework GLUT +else + libgl = -lGL -lglut +endif $(bin): $(obj) $(CC) -o $@ $(obj) $(LDFLAGS) @@ -15,7 +21,3 @@ .PHONY: install install: $(bin) cp $(bin) $(PREFIX)/bin/$(bin) - -.PHONY: uninstall -uninstall: - rm -f $(PREFIX)/bin/$(bin) diff -r 960cea2731c4 -r c438411b801b gradtool.c --- a/gradtool.c Tue Jun 19 05:30:45 2012 +0300 +++ b/gradtool.c Fri Oct 09 01:45:12 2015 +0300 @@ -1,6 +1,12 @@ #include #include +#include +#include +#ifdef __APPLE__ +#include +#else #include +#endif #define MAX_POS 512 @@ -23,7 +29,8 @@ void rm_val(struct track *track, float pos); float get_val(struct track *track, float pos); -void save(void); +int save_ppm(const char *fname, int img_width); +int save_grad(const char *fname); void key_handler(unsigned char key, int x, int y); void skey_handler(int key, int x, int y); @@ -256,22 +263,20 @@ } -#define IMG_X 256 -#define FNAME "grad.ppm" -void save(void) +int save_ppm(const char *fname, int img_width) { int i; FILE *fp; - if(!(fp = fopen(FNAME, "wb"))) { - perror("failed to write " FNAME); - return; + if(!(fp = fopen(fname, "wb"))) { + fprintf(stderr, "failed to write %s: %s\n", fname, strerror(errno)); + return -1; } - fprintf(fp, "P6\n%d %d\n255\n", IMG_X, 1); + fprintf(fp, "P6\n%d 1\n255\n", img_width); - for(i=0; ikeys->next; + + while(ptr) { + float t = (float)ptr->pos / (float)MAX_POS; + float r = get_val(&tred, t); + float g = get_val(&tgreen, t); + float b = get_val(&tblue, t); + + fprintf(fp, "%f\t%f %f %f\n", t, r, g, b); + ptr = ptr->next; + } + } + + fclose(fp); + return 0; } @@ -298,7 +334,12 @@ case 's': case 'S': - save(); + save_ppm("grad.ppm", 256); + break; + + case 'g': + case 'G': + save_grad("grad.grad"); break; case 'c':