static void testcase1(const char *desc) { ggi_visual_t vis; ggi_color green, back; int err; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiSetGraphMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_8BIT); if(err < 0) { printassert(0, "Palettized mode not available.\n"); printsuccess(); ggiClose(vis); ggiExit(); return; } green.r = 100; green.g = 40000; green.b = 4000; err = ggiSetPalette(vis, GGI_PALETTE_DONTCARE, 1, &green); if (err < 0) { printfailure("Unable to install colormap with one entry.\n"); ggiClose(vis); ggiExit(); return; } printassert(err == (int)ggiMapColor(vis, &green), "ggiMapColor inconsistent with retval of ggiSetPalette.\n"); ggiUnmapPixel(vis, err, &back); if(green.r != back.r || green.g != back.g || green.b != back.b) { printfailure("Unexpected color from ggiUnmapPixel.\n"); ggiClose(vis); ggiExit(); return; } ggiSetGCForeground(vis, err); ggiDrawBox(vis, 0, 0, 3000, 3000); ggiFlush(vis); /* You should see a green square, how to test this? */ ggUSleep(5000000); printsuccess(); ggiClose(vis); ggiExit(); }
void _ggi_file_ppm_write(struct ggi_visual *vis) { unsigned char buf[200]; int x, y; ggi_pixel last; ggi_color col; /* PPM files rewind and write from scratch */ /* FIXME shouldn't we truncate the file as well? Size changes? */ _ggi_file_rewind(vis); /* write header info */ _ggi_file_write_string(vis, (const unsigned char *)"P6\n"); _ggi_file_write_string(vis, (const unsigned char *)PPM_INFO_STRING); snprintf((char *)buf, sizeof(buf), "%d %d\n255\n", LIBGGI_VIRTX(vis), LIBGGI_VIRTY(vis)); _ggi_file_write_string(vis, buf); /* write out the pixels */ ggiGetPixel(vis->instance.stem, 0, 0, &last); last = ~last; /* must be different from first pixel */ for (y=0; y < LIBGGI_VIRTY(vis); y++) for (x=0; x < LIBGGI_VIRTX(vis); x++) { ggi_pixel pix; ggiGetPixel(vis->instance.stem, x, y, &pix); if (pix != last) { ggiUnmapPixel(vis->instance.stem, pix, &col); } _ggi_file_write_byte(vis, (unsigned)(col.r >> 8)); _ggi_file_write_byte(vis, (unsigned)(col.g >> 8)); _ggi_file_write_byte(vis, (unsigned)(col.b >> 8)); last = pix; } _ggi_file_flush(vis); }