Source

gd-libgd / tests / gdimagerotate / bug00067.c

#include <stdio.h>
#include <stdlib.h>
#include "gd.h"

#include "gdtest.h"

int main()
{
	gdImagePtr im, exp;
	char path[2048];
	const char *file_im = "gdimagerotate/remirh128.jpg";
	const char *file_exp = "gdimagerotate/bug00067";
	FILE *fp;
	int color;

	sprintf(path, "%s/%s", GDTEST_TOP_DIR, file_im);

	fp = fopen(path, "rb");

	if (!fp) {
		gdTestErrorMsg("opening Jpeg %s for reading failed.\n", path);
		return 1;
	}

	im = gdImageCreateFromJpeg(fp);

	fclose(fp);

	if (!im) {
		gdTestErrorMsg("loading %s failed.\n", path);
		return 1;
	}

	color = gdImageColorAllocate(im, 0, 0, 0);

	if (color < 0) {
		gdTestErrorMsg("allocation color from image failed.\n");
		gdImageDestroy(im);
		return 1;
	}

	int error = 0;

	for (int angle = 0; angle <= 180; angle += 15) {

		exp = gdImageRotateInterpolated(im, angle, color);

		if (!exp) {
			gdTestErrorMsg("rotating image failed for %03d.\n", angle);
			gdImageDestroy(im);
			return 1;
		}

		sprintf(path, "%s/%s_%03d_exp.png", GDTEST_TOP_DIR, file_exp, angle);

		if (!gdAssertImageEqualsToFile(path, exp)) {
			gdTestErrorMsg("comparing rotated image to %s failed.\n", path);
			error += 1;
		}

		gdImageDestroy(exp);
	}

	gdImageDestroy(im);

	return error;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.