diff --git a/share/examples/gpanel/Makefile b/share/examples/gpanel/Makefile index 38876c0..a89ca24 100644 --- a/share/examples/gpanel/Makefile +++ b/share/examples/gpanel/Makefile @@ -1,6 +1,6 @@ CC = cc LIBS = -lgpanel -PROG = tft tftetris pixel line rect fill circle font +PROG = tft tftetris pixel line rect fill circle font color speed FONTS = 5x7.o 6x9.o digits20.o digits32.o lucidasans11.o lucidasans15.o \ lucidasans7.o lucidasans9.o verdana7.o @@ -31,6 +31,12 @@ fill: fill.c circle: circle.c $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) +color: color.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) + +speed: speed.c lucidasans15.o + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) speed.c lucidasans15.o $(LIBS) + font: font.c $(FONTS) $(CC) $(CFLAGS) -o $@ $(LDFLAGS) font.c $(FONTS) $(LIBS) diff --git a/share/examples/gpanel/color.c b/share/examples/gpanel/color.c new file mode 100644 index 0000000..07beee5 --- /dev/null +++ b/share/examples/gpanel/color.c @@ -0,0 +1,65 @@ +/* + * Display a color palette. + * Assume RGB 5-6-5 color format. + * Color is a 16-bit value: rrrrrggggggbbbbb, where rrrrr, + * gggggg and bbbbb are red, green and blue components. + */ +#include +#include + +int xsize, ysize; + +int scale_red(int x, int y) +{ + int r; + + r = 32 * y * (xsize-x-1) / xsize / ysize; + if (r > 31) + r = 31; + return r; +} + +int scale_green(int x, int y) +{ + int g; + + g = 64 * x / xsize; + if (g > 63) + g = 63; + return g; +} + +int scale_blue(int x, int y) +{ + int b; + + b = 32 * (ysize-y-1) * (xsize-x-1) / xsize / ysize; + if (b > 31) + b = 31; + return b; +} + +int main() +{ + char *devname = "/dev/tft0"; + int x, y, r, g, b, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + printf("Display color palette.\n"); + for (y=0; y +#include +#include + +#define NPIXELS 100000 +#define NLINES 3000 +#define NRECT 1000 +#define NCIRCLES 1000 +#define NCHARS 10000 + +extern const struct gpanel_font_t font_lucidasans15; + +int xsize, ysize; + +/* + * Get current time in milliseconds. + */ +unsigned current_msec() +{ + struct timeval t; + + gettimeofday(&t, 0); + return t.tv_sec * 1000 + t.tv_usec / 1000; +} + +/* + * Compute elapsed time in milliseconds. + */ +unsigned elapsed_msec(unsigned t0) +{ + struct timeval t1; + unsigned msec; + + gettimeofday (&t1, 0); + msec = t1.tv_sec * 1000 + t1.tv_usec / 1000; + msec -= t0; + if (msec < 1) + msec = 1; + return msec; +} + +int main() +{ + char *devname = "/dev/tft0"; + int x, y, x1, y1, color, i, r, sym; + unsigned t0, msec; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + /* Use fixed seed, for repeatability. */ + srand(1); + printf("Graphics speed:\n"); + sync(); + usleep(500000); + + /* + * Pixels. + */ + t0 = current_msec(); + for (i=0; i