/* Demonstrates minimal graphic toolkit 'gt'. On UNIX, use the supplied 'makefile' in this 'gt' directory. On for example Apple Macintosh (CodeWarrior for instance), just include this file together sourcefile 'gt.c' in the C project. You can set and get RGB-pixels and draw lines, and you can save your images in JPEG-format. Pieter Suurmond, april 3, 2004. */ #include #include #include "gt.h" /* Link with object gt.o. */ /*----------------------------------------------------------------------------------*/ int main() { /* Generate 5 images in current directory. */ short e; RGBPICp pic; /* Pointer to RGB picture object in memory. */ int n, x; char filename[64]; float hertz, RGBflt[3]; n = gtCreateMemRGB(&pic, /* Receive pointer to RGBPIC object here. */ 512, 240, /* Specify width and height. */ 255, 255, 255); /* Specify white background. */ if (n) { printf("gtCreateMemRGB() = %d\n", n); return 1; } /*------------------------------------ A SMALL RAINBOW: -----------------*/ gtInitHertzToRGBtables(); for (x = 0; x < 512; x++) { hertz = 40.0e13 + (37.0e13 * (float)x / 511.0); gtHertzToRGB(hertz, 1.0, RGBflt); gtDrawLine(pic, x, 2, /* From x1,y1 */ x, 50, /* to x2,y2. */ (unsigned char)(0.5 + RGBflt[0]), /* R. */ (unsigned char)(0.5 + RGBflt[1]), /* G. */ (unsigned char)(0.5 + RGBflt[2])); /* B. */ } /*-----------------------------------------------------------------------*/ n = 0; do { sprintf(filename, "graphicTest%d.jpg", n); /*------------------------------------*/ for (x=0; x<10; x++) { gtDrawLine(pic, 160, 120 + (4 * n), /* From x1,y1 */ 20 * n, 120 + 10 * x, /* to x2,y2. */ (unsigned char)(255 - 20 * n), /* R. */ (unsigned char)0, /* G. */ (unsigned char)(20 * n)); /* B. */ } gtDrawString(pic, 100, 100, /* x,y. */ 0, (unsigned char)(20 * n), 0, /* r,g,b. */ 1, filename); /* 1=transparent. */ gtDrawString(pic, 100, 120, /* x,y. */ 0, (unsigned char)(255-(20*n)), 0, /* r,g,b. */ 0, "Hello"); /* 0=white bg. */ /*------------------------------------*/ e = gtSaveMemRGB(pic, filename, 40 + (n * 10)); /* Increasing JPEG Quality: 40-80%. */ } while ((n++ < 5) && (!e)); /*-------------------------------------------------------------*/ gtDestroyMemRGB(&pic); if (e) { printf("Failed to save '%s' to disk.\n", filename); return 2; } return(0); }