void do_test(int x, int y, int nx, int ny) { gdImagePtr im, imref, tmp; gdImagePtr same, same2; im = mkwhite(x, y); imref = mkwhite(x, y); same = gdImageScale(im, x, y); /* Trivial resize should be a straight copy. */ gdTestAssert(im != same); gdTestAssert(gdMaxPixelDiff(im, same) == 0); gdTestAssert(gdMaxPixelDiff(imref, same) == 0); /* Ensure that modifying im doesn't modify same (i.e. see if we * can catch them accidentally sharing the same pixel buffer.) */ mkblack(im); gdTestAssert(gdMaxPixelDiff(imref, same) == 0); gdImageDestroy(same); gdImageDestroy(im); /* Scale horizontally, vertically and both. */ scaletest(x, y, nx, y); scaletest(x, y, x, ny); scaletest(x, y, nx, ny); }
int main() { int method, i; for(method = GD_BELL; method <= GD_TRIANGLE; method++) { /* GD_WEIGHTED4 is unsupported. */ gdImagePtr im[2]; // printf("Method = %d\n", method); im[0] = gdImageCreateTrueColor(X, Y); im[1] = gdImageCreatePalette(X, Y); for (i = 0; i < 2; i++) { gdImagePtr result; // printf(" %s\n", i == 0 ? "truecolor" : "palette"); gdImageFilledRectangle(im[i], 0, 0, X-1, Y-1, gdImageColorExactAlpha(im[i], 255, 255, 255, 0)); gdImageSetInterpolationMethod(im[i], method); gdTestAssert(im[i]->interpolation_id == method); /* No getter yet. */ result = gdImageScale(im[i], NX, NY); gdTestAssert(result != NULL); gdTestAssert(result != im[i]); gdTestAssert(result->sx == NX && result->sy == NY); gdImageDestroy(result); gdImageDestroy(im[i]); }/* for */ }/* for*/ return gdNumFailures(); }/* main*/
int main() { gdImagePtr im; int error = 0; int c, c1, c2, c3, c4, color, i; im = gdImageCreateTrueColor(5, 5); c = gdImageColorExact(im, 255, 0, 255); c2 = gdImageColorExactAlpha(im, 255, 0, 255, 100); gdImageDestroy(im); if (gdTestAssert(c == 0xFF00FF) != 1) { error = -1; } if (gdTestAssert(c2 == 0x64FF00FF) != 1) { error = -1; } im = gdImageCreate(5, 5); c1 = gdImageColorAllocate(im, 255, 0, 255); c2 = gdImageColorAllocate(im, 255, 200, 0); c3 = gdImageColorAllocateAlpha(im, 255, 0, 255, 100); c1 = gdImageColorExact(im, 255, 0, 255); c2 = gdImageColorExact(im, 255, 200, 0); c3 = gdImageColorExactAlpha(im, 255, 0, 255, 100); c4 = gdImageColorExactAlpha(im, 255, 34, 255, 100); if (gdTestAssert(c1 == 0) != 1) { error = -1; } if (gdTestAssert(c2 == 1) != 1) { error = -1; } if (gdTestAssert(c3 == 2) != 1) { error = -1; } if (gdTestAssert(c4 == -1) != 1) { error = -1; } color = gdTrueColorAlpha(gdImageRed(im, c1), gdImageGreen(im, c1), gdImageBlue(im, c1), 0); if (gdTestAssert(color == 0xFF00FF) != 1) { error = -1; } color = gdTrueColorAlpha(gdImageRed(im, c2), gdImageGreen(im, c2), gdImageBlue(im, c2), 0); if (gdTestAssert(color == 0xFFC800) != 1) { error = -1; } color = gdTrueColorAlpha(gdImageRed(im, c3), gdImageGreen(im, c3), gdImageBlue(im, c3), 0); if (gdTestAssert(color == 0xFF00FF) != 1) { error = -1; } gdImageDestroy(im); return error; }
int main() { gdImagePtr im; int black; FILE *outFile; gdIOCtx *out; off_t length; /* create the test image */ im = gdImageCreate(11, 11); gdImageColorAllocate(im, 255, 255, 255); black = gdImageColorAllocate(im, 0, 0, 0); gdImageArc(im, 5, 5, 10, 10, 0, 360, black); /* write the file to disk, note the file length and delete the file */ outFile = gdTestTempFp(); out = gdNewFileCtx(outFile); gdTestAssert(out != NULL); gdImageXbmCtx(im, "github_bug_170.xbm", 1, out); out->gd_free(out); length = ftello(outFile); fclose(outFile); gdImageDestroy(im); gdTestAssertMsg(length == 250, "expected to write 250 bytes; %jd bytes written", (intmax_t) length); return gdNumFailures(); }
int main() { gdImagePtr im; int bordercolor, color; im = gdImageCreateTrueColor(100, 100); gdImageAlphaBlending(im, 1); gdImageSaveAlpha(im, 1); bordercolor = gdImageColorAllocateAlpha(im, 0, 0, 0, 2); color = gdImageColorAllocateAlpha(im, 0, 0, 0, 1); gdImageFillToBorder(im, 5, 5, bordercolor, color); color = gdImageGetPixel(im, 5, 5); gdImageDestroy(im); if (gdTestAssert(color==0x1000000)) { return 0; } else { printf("c: %X, expected %X\n", color, 0x1000000); return -1; } }
int main() { gdImagePtr im; void *data; int size = 0; im = gdImageCreate(100, 100); gdTestAssert(im != NULL); data = gdImagePngPtr(im, &size); gdTestAssert(data == NULL); gdImageDestroy(im); return gdNumFailures(); }
int main() { gdImagePtr im; FILE *fp = gdTestFileOpen("tga/bug00247.tga"); im = gdImageCreateFromTga(fp); gdTestAssert(im == NULL); fclose(fp); return gdNumFailures(); }
int main() { gdImagePtr im; FILE *fp; fp = gdTestFileOpen2("gd2", "bug00354a.gd2"); gdTestAssert(fp != NULL); im = gdImageCreateFromGd2(fp); gdTestAssert(im == NULL); fclose(fp); fp = gdTestFileOpen2("gd2", "bug00354b.gd2"); gdTestAssert(fp != NULL); im = gdImageCreateFromGd2(fp); gdTestAssert(im == NULL); fclose(fp); return gdNumFailures(); }
int main() { gdImagePtr im; void *data; int size, red; im = gdImageCreate(100, 100); gdImageSetResolution(im, 72, 300); red = gdImageColorAllocate(im, 0xFF, 0x00, 0x00); gdImageFilledRectangle(im, 0, 0, 99, 99, red); data = gdImageJpegPtr(im, &size, 10); gdImageDestroy(im); im = gdImageCreateFromJpegPtr(size, data); gdTestAssert(gdImageResolutionX(im) == 72); gdTestAssert(gdImageResolutionY(im) == 300); gdFree(data); gdImageDestroy(im); return 0; }
int main() { gdImagePtr im; FILE *fp; void *data; int size = 0; fp = gdTestFileOpen2("png", "bug00381_2.gd"); gdTestAssert(fp != NULL); im = gdImageCreateFromGd(fp); gdTestAssert(im != NULL); fclose(fp); data = gdImagePngPtr(im, &size); gdTestAssert(data == NULL); gdImageDestroy(im); return gdNumFailures(); }
void scaletest(int x, int y, int nx, int ny) { gdImagePtr im, imref, tmp, same; imref = mkwhite(x, y); im = mkwhite(x, y); tmp = gdImageScale(im, nx, ny); same = gdImageScale(tmp, x, y); /* Test the result to insure that it's close enough to the * original. */ gdTestAssert(gdMaxPixelDiff(im, same) < CLOSE_ENOUGH); /* Modify the original and test for a change again. (I.e. test * for accidentally shared memory.) */ mkblack(tmp); gdTestAssert(gdMaxPixelDiff(imref, same) < CLOSE_ENOUGH); gdImageDestroy(im); gdImageDestroy(tmp); gdImageDestroy(same); }/* scaletest*/
int main() { gdImagePtr im; void *data; int size, red; im = gdImageCreate(100, 100); gdImageSetResolution(im, 72, 300); red = gdImageColorAllocate(im, 0xFF, 0x00, 0x00); gdImageFilledRectangle(im, 0, 0, 99, 99, red); data = gdImageJpegPtr(im, &size, 10); gdImageDestroy(im); im = gdImageCreateFromJpegPtr(size, data); gdFree(data); if (!gdTestAssert(gdImageResolutionX(im) == 72) || !gdTestAssert(gdImageResolutionY(im) == 300)) { gdTestErrorMsg("failed image resolution X (%d != 72) or Y (%d != 300)\n", gdImageResolutionX(im), gdImageResolutionY(im)); gdImageDestroy(im); return 1; } gdImageDestroy(im); return 0; }
gdImagePtr mkwhite(int x, int y) { gdImagePtr im; im = gdImageCreateTrueColor(x, y); gdImageFilledRectangle(im, 0, 0, x-1, y-1, gdImageColorExactAlpha(im, 255, 255, 255, 0)); gdTestAssert(im != NULL); gdImageSetInterpolationMethod(im, GD_BICUBIC); // FP interp'n return im; }/* mkwhite*/
int main() { gdImagePtr im; char * giffiles[4] = {"bug00005_0.gif", "bug00005_1.gif", "bug00005_2.gif", "bug00005_3.gif"}; int valid[4] = {0, 0, 0, 0}; char *exp[4] = {NULL, NULL, "bug00005_2_exp.png", NULL}; const int files_cnt = 4; FILE *fp; int i = 0; int error = 0; char path[1024]; for (i=0; i < files_cnt; i++) { sprintf(path, "%s/gif/%s", GDTEST_TOP_DIR, giffiles[i]); fp = fopen(path, "rb"); if (!fp) { gdTestErrorMsg("<%s> Input file does not exist!\n", path); return 1; } im = gdImageCreateFromGif(fp); fclose(fp); if (valid[i]) { if (!im) { error = 1; } else { sprintf(path, "%s/gif/%s", GDTEST_TOP_DIR, exp[i]); if (!gdAssertImageEqualsToFile(path, im)) { error = 1; } gdImageDestroy(im); } } else { if (!gdTestAssert(im == NULL)) { error = 1; } } } return error; }
int main() { gdImagePtr im; FILE *fp; char *path; fp = gdTestFileOpen2("xbm", "x10_basic_read.xbm"); im = gdImageCreateFromXbm(fp); fclose(fp); gdTestAssert(im != NULL); path = gdTestFilePath2("xbm", "x10_basic_read_exp.png"); gdAssertImageEqualsToFile(path, im); gdFree(path); gdImageDestroy(im); return gdNumFailures(); }