int main() { gdImagePtr src, dst; int r, g, b; void *p; int size = 0; int status = 0; CuTestImageResult result = {0, 0}; src = gdImageCreate(100, 100); if (src == NULL) { gdTestErrorMsg("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); g = gdImageColorAllocate(src, 0, 0xFF, 0); b = gdImageColorAllocate(src, 0, 0, 0xFF); gdImageFilledRectangle(src, 0, 0, 99, 99, r); gdImageRectangle(src, 20, 20, 79, 79, g); gdImageEllipse(src, 70, 25, 30, 20, b); #define OUTPUT_GD2(x) do { \ FILE *fp = gdTestTempFp(); \ gdImageGd2(x, fp, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED); \ fclose(fp); \ } while (0) OUTPUT_GD2(src); p = gdImageGd2Ptr(src, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED, &size); if (p == NULL) { status = 1; gdTestErrorMsg("p is null\n"); goto door0; } if (size <= 0) { status = 1; gdTestErrorMsg("size is non-positive\n"); goto door1; } dst = gdImageCreateFromGd2Ptr(size, p); if (dst == NULL) { status = 1; gdTestErrorMsg("could not create dst\n"); goto door1; } OUTPUT_GD2(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: gdFree(p); door0: gdImageDestroy(src); return status; }
int main() { gdImagePtr src, dst; int b; void *p; int size = 0; int status = 0; CuTestImageResult result = {0, 0}; src = gdImageCreate(100, 100); if (src == NULL) { printf("could not create src\n"); return 1; } gdImageColorAllocate(src, 0xFF, 0xFF, 0xFF); /* allocate white for background color */ b = gdImageColorAllocate(src, 0, 0, 0); gdImageRectangle(src, 20, 20, 79, 79, b); gdImageEllipse(src, 70, 25, 30, 20, b); #define OUTPUT_WBMP(name) do { \ FILE *fp = gdTestTempFp(); \ gdImageWBMP(name, 1, fp); \ fclose(fp); \ } while (0) OUTPUT_WBMP(src); p = gdImageWBMPPtr(src, &size, 1); if (p == NULL) { status = 1; printf("p is null\n"); goto door0; } if (size <= 0) { status = 1; printf("size is non-positive\n"); goto door1; } dst = gdImageCreateFromWBMPPtr(size, p); if (dst == NULL) { status = 1; printf("could not create dst\n"); goto door1; } OUTPUT_WBMP(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; printf("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: gdFree(p); door0: gdImageDestroy(src); return status; }
int main() { gdImagePtr im, ex; FILE *fp; gdScatter s; int colors[] = {0xFF0000, 0x00FF00}; CuTestImageResult r; fp = gdTestFileOpen("gdimagescatterex/bug00208.png"); im = gdImageCreateFromPng(fp); fclose(fp); if (!im) { fprintf(stderr, "could not create image\n"); return 1; } s.sub = 1; s.plus = 3; s.seed = 0; s.num_colors = 2; s.colors = colors; if (!gdImageScatterEx(im, &s)) { gdImageDestroy(im); fprintf(stderr, "could not scatter\n"); return 1; } fp = gdTestFileOpen("gdimagescatterex/bug00208_2.png"); ex = gdImageCreateFromPng(fp); fclose(fp); if (!ex) { fprintf(stderr, "could not create image\n"); gdImageDestroy(im); return 1; } r.pixels_changed = 0; gdTestImageDiff(im, ex, NULL, &r); gdImageDestroy(ex); gdImageDestroy(im); if (r.pixels_changed > 10000) { fprintf(stderr, "too much diff: %d\n", r.pixels_changed); return 1; } return 0; }
int main() { gdImagePtr src, dst; int r, g, b; void *p; int size = 0; int status = 0; CuTestImageResult result = {0, 0}; src = gdImageCreate(100, 100); if (src == NULL) { printf("could not create src\n"); return 1; } r = gdImageColorAllocate(src, 0xFF, 0, 0); g = gdImageColorAllocate(src, 0, 0xFF, 0); b = gdImageColorAllocate(src, 0, 0, 0xFF); gdImageFilledRectangle(src, 0, 0, 99, 99, r); gdImageRectangle(src, 20, 20, 79, 79, g); gdImageEllipse(src, 70, 25, 30, 20, b); #define OUTPUT_GIF(name) do { \ FILE *fp; \ \ fp = fopen("gif_im2im_" #name ".gif", "wb"); \ if (fp) { \ gdImageGif(name, fp); \ fclose(fp); \ } \ } while (0) OUTPUT_GIF(src); p = gdImageGifPtr(src, &size); if (p == NULL) { status = 1; printf("p is null\n"); goto door0; } if (size <= 0) { status = 1; printf("size is non-positive\n"); goto door1; } dst = gdImageCreateFromGifPtr(size, p); if (dst == NULL) { status = 1; printf("could not create dst\n"); goto door1; } OUTPUT_GIF(dst); gdTestImageDiff(src, dst, NULL, &result); if (result.pixels_changed > 0) { status = 1; printf("pixels changed: %d\n", result.pixels_changed); } gdImageDestroy(dst); door1: gdFree(p); door0: gdImageDestroy(src); return status; }
int gdTestImageCompareToImage(const char* file, unsigned int line, const char* message, gdImagePtr expected, gdImagePtr actual) { unsigned int width_a, height_a; unsigned int width_b, height_b; gdImagePtr surface_diff = NULL; CuTestImageResult result = {0, 0}; (void)message; if (!actual) { _gdTestErrorMsg(file, line, "Image is NULL\n"); goto fail; } width_a = gdImageSX(expected); height_a = gdImageSY(expected); width_b = gdImageSX(actual); height_b = gdImageSY(actual); if (width_a != width_b || height_a != height_b) { _gdTestErrorMsg(file, line, "Image size mismatch: (%ux%u) vs. (%ux%u)\n for %s vs. buffer\n", width_a, height_a, width_b, height_b, file); goto fail; } surface_diff = gdImageCreateTrueColor(width_a, height_a); gdTestImageDiff(expected, actual, surface_diff, &result); if (result.pixels_changed>0) { char file_diff[255]; char file_out[1024]; FILE *fp; int len, p; _gdTestErrorMsg(file, line, "Total pixels changed: %d with a maximum channel difference of %d.\n", result.pixels_changed, result.max_diff ); p = len = strlen(file); p--; /* Use only the filename (and store it in the bld dir not the src dir */ while(p > 0 && (file[p] != '/' && file[p] != '\\')) { p--; } sprintf(file_diff, "%s_%u_diff.png", file + p + 1, line); sprintf(file_out, "%s_%u_out.png", file + p + 1, line); fp = fopen(file_diff, "wb"); if (!fp) goto fail; gdImagePng(surface_diff,fp); fclose(fp); fp = fopen(file_out, "wb"); if (!fp) goto fail; gdImagePng(actual, fp); fclose(fp); } else { if (surface_diff) { gdImageDestroy(surface_diff); } return 1; } fail: if (surface_diff) { gdImageDestroy(surface_diff); } return 0; }