int main(int argc, char *argv[]) { GP_Context *img; /* Turn on debug messages */ GP_SetDebugLevel(10); if (argc != 2) { fprintf(stderr, "Takes an image as an parameter\n"); return 1; } img = GP_LoadImage(argv[1], NULL); if (img == NULL) { fprintf(stderr, "Failed to load image '%s':%s\n", argv[1], strerror(errno)); return 1; } if (GP_SavePNG(img, "out.png", NULL)) { fprintf(stderr, "Failed to save image %s", strerror(errno)); return 1; } return 0; }
int main(void) { GP_TIMER_DECLARE(oneshot, 30, 0, "Oneshot", callback1, NULL); GP_TIMER_DECLARE(recurrent, 0, 4, "Recurrent", callback1, NULL); GP_TIMER_DECLARE(random, 10, 0, "Random", callback3, NULL); GP_Timer timers[MAX]; GP_Timer *queue = NULL; uint64_t now; int i, ret; GP_SetDebugLevel(10); GP_TimerQueueInsert(&queue, 0, &oneshot); GP_TimerQueueInsert(&queue, 0, &recurrent); GP_TimerQueueInsert(&queue, 0, &random); for (i = 0; i < MAX; i++) { timers[i].expires = MAX - i; timers[i].period = 0; timers[i].Callback = callback1; timers[i].priv = NULL; sprintf(timers[i].id, "Timer%i", MAX - i); GP_TimerQueueInsert(&queue, 0, &timers[i]); } GP_TimerQueueDump(queue); GP_TimerQueueRemove(&queue, &timers[MAX-1]); GP_TimerQueueDump(queue); for (now = 0; now < 100; now += 3) { printf("NOW %u\n", (unsigned int) now); printf("-------------------------------------\n"); ret = GP_TimerQueueProcess(&queue, now); printf("Processed %i timer events\n", ret); printf("--------------------------------------\n"); GP_TimerQueueDump(queue); printf("--------------------------------------\n\n"); } return 0; }
/* * Check that GP_DEBUG() preserves errno. */ static int DEBUG_preserves_errno(void) { GP_SetDebugHandler(debug_handler); GP_SetDebugLevel(1); handler_called = 0; errno = 1; GP_DEBUG(1, "Debug message"); if (!handler_called) { tst_msg("Debug handler wasn't called"); return TST_FAILED; } if (errno != 1) { tst_msg("Errno not preserved"); return TST_FAILED; } return TST_SUCCESS; }
int main(int argc, char *argv[]) { const char *backend_opts = "X11"; print_instructions(); GP_SetDebugLevel(10); if (argc > 1) { font_path = argv[1]; fprintf(stderr, "\nLoading font '%s'\n", argv[1]); font = GP_FontFaceLoad(argv[1], 0, font_h); } win = GP_BackendInit(backend_opts, "Font Test", stderr); if (win == NULL) { fprintf(stderr, "Failed to initalize backend '%s'\n", backend_opts); return 1; } white_pixel = GP_ColorToContextPixel(GP_COL_WHITE, win->context); gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_LIGHT, win->context); dark_gray_pixel = GP_ColorToContextPixel(GP_COL_GRAY_DARK, win->context); black_pixel = GP_ColorToContextPixel(GP_COL_BLACK, win->context); red_pixel = GP_ColorToContextPixel(GP_COL_RED, win->context); blue_pixel = GP_ColorToContextPixel(GP_COL_BLUE, win->context); redraw_screen(); GP_BackendFlip(win); event_loop(); return 0; }
int main(int argc, char *argv[]) { GP_Backend *backend; const char *backend_opts = "X11:350x350"; int opt; GP_PixelType emul_type = GP_PIXEL_UNKNOWN; while ((opt = getopt(argc, argv, "b:h:p:")) != -1) { switch (opt) { case 'b': backend_opts = optarg; break; case 'p': emul_type = GP_PixelTypeByName(optarg); if (emul_type == GP_PIXEL_UNKNOWN) { fprintf(stderr, "Invalid pixel type '%s'\n", optarg); return 1; } break; case 'h': GP_BackendInit("help", NULL); return 0; break; default: fprintf(stderr, "Invalid paramter '%c'\n", opt); return 1; } } /* Turn on debug messages */ GP_SetDebugLevel(10); backend = GP_BackendInit(backend_opts, "Virtual Backend Example"); if (emul_type != GP_PIXEL_UNKNOWN) { GP_Backend *emul; /* * Create an emulated backend on the top of real backend. * * The GP_BACKEND_CALL_EXIT says that when calling exit on * emulated backend, the real backend exit will be called as * well. */ emul = GP_BackendVirtualInit(backend, emul_type, GP_BACKEND_CALL_EXIT); if (emul == NULL) { fprintf(stderr, "Failed to create Virtual Backend\n"); GP_BackendExit(backend); return 1; } /* Once created virtual backend behaves exactly like a real one */ backend = emul; } redraw(backend); for (;;) { if (backend->Poll) GP_BackendPoll(backend); usleep(1000); /* Read and parse events */ GP_Event ev; while (GP_BackendGetEvent(backend, &ev)) { GP_EventDump(&ev); switch (ev.type) { case GP_EV_KEY: switch (ev.val.key.key) { case GP_KEY_ESC: case GP_KEY_Q: GP_BackendExit(backend); return 0; break; } break; case GP_EV_SYS: switch(ev.code) { case GP_EV_SYS_RESIZE: GP_BackendResizeAck(backend); redraw(backend); break; } break; } } } GP_BackendExit(backend); return 0; }