static int test_load_PNG(const char *path) { GP_Context *img; errno = 0; img = GP_LoadPNG(path, NULL); if (img == NULL) { switch (errno) { case ENOSYS: tst_msg("Not Implemented"); return TST_SKIPPED; default: tst_msg("Got %s", strerror(errno)); return TST_FAILED; } } /* * TODO: check correct data. */ GP_ContextFree(img); return TST_SUCCESS; }
static int test_load_PNG_check_color(struct check_color_test *test) { GP_Context *img; errno = 0; img = GP_LoadPNG(test->path, NULL); if (img == NULL) { switch (errno) { case ENOSYS: tst_msg("Not Implemented"); return TST_SKIPPED; default: tst_msg("Got %s", strerror(errno)); return TST_FAILED; } } unsigned int x, y, fail = 0; for (x = 0; x < img->w; x++) { for (y = 0; y < img->w; y++) { GP_Pixel p = GP_GetPixel(img, x, y); if (p != test->pixel) { if (!fail) tst_msg("First failed at %u,%u %x %x", x, y, p, test->pixel); fail = 1; } } } if (!fail) tst_msg("Context pixels are correct"); GP_ContextFree(img); if (fail) return TST_FAILED; return TST_SUCCESS; }
static GP_Context *load(enum fmt fmt, const char *name) { char buf[256]; snprintf(buf, sizeof(buf), "%s.%s", name, strfmt(fmt)); switch (fmt) { case PNG: return GP_LoadPNG(buf, NULL); case JPG: return GP_LoadJPG(buf, NULL); case GIF: return GP_LoadGIF(buf, NULL); case BMP: return GP_LoadBMP(buf, NULL); default: tst_err("Trying to load %s image", strfmt(fmt)); exit(TST_UNTESTED); } }