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(int argc, char *argv[]) { GP_Context *img; struct callback_priv priv; GP_ProgressCallback callback = {.callback = progress_callback, .priv = &priv}; if (argc != 2) { fprintf(stderr, "Takes an image as an parameter\n"); return 1; } priv.op = "Loading"; priv.name = argv[1]; img = GP_LoadImage(argv[1], &callback); if (img == NULL) { fprintf(stderr, "Failed to load image '%s':%s\n", argv[1], strerror(errno)); return 1; } printf("\n"); priv.op = "Saving"; priv.name = "tmp.gfx"; if (GP_SaveTmpFile(img, priv.name, &callback)) { fprintf(stderr, "Failed to save temp file %s\n", strerror(errno)); return 1; } printf("\n"); GP_ContextFree(img); priv.op = "Loading"; img = GP_LoadTmpFile(priv.name, &callback); if (img == NULL) { fprintf(stderr, "Failed to load temp file %s\n", strerror(errno)); return 1; } priv.op = "Saving"; priv.name = "out.png"; printf("\n"); if (GP_SavePNG(img, "out.png", &callback)) { fprintf(stderr, "Failed to save image %s\n", strerror(errno)); return 1; } printf("\n"); return 0; }
int main(int argc, char *argv[]) { GP_Context *img; struct callback_priv priv; GP_ProgressCallback callback = {.callback = progress_callback, .priv = &priv}; if (argc != 2) { fprintf(stderr, "Takes an image as an parameter\n"); return 1; } priv.op = "Loading"; priv.name = argv[1]; img = GP_LoadImage(argv[1], &callback); if (img == NULL) { fprintf(stderr, "Failed to load image '%s': %s\n", argv[1], strerror(errno)); return 1; } printf("\n"); float box_kernel[] = { 0.0, 0.1, 1.0, 0.1, 0.0, 0.1, 0.5, 1.0, 0.5, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 0.1, 0.5, 1.0, 0.5, 0.1, 0.0, 0.1, 1.0, 0.1, 0.0, }; GP_FilterKernel2D box = { .w = 5, .h = 5, .div = 11.8, .kernel = box_kernel, }; priv.op = "Box Linear Convolution"; /* * Blur in-place, inner rectangle of the image. */ GP_FilterConvolutionEx(img, img->w/4, img->h/4, img->w/2, img->h/2, img, img->w/4, img->h/4, &box, &callback); printf("\n"); priv.op = "Saving"; priv.name = "out.png"; if (GP_SavePNG(img, "out.png", &callback)) { fprintf(stderr, "Failed to save image: %s", strerror(errno)); return 1; } printf("\n"); return 0; }