#include #include #include #include "cairoint.h" #include static cairo_filter_t cairo_filters[] = { CAIRO_FILTER_NEAREST, CAIRO_FILTER_BILINEAR, CAIRO_FILTER_NEAREST_MIPMAP_LINEAR, CAIRO_FILTER_LINEAR_MIPMAP_NEAREST, CAIRO_FILTER_TRILINEAR }; char* cairo_filter_strings[] = { "NEAREST", "BILINEAR", "NEAREST_MM_LINEAR", "LINEAR_MM_NEAREST", "TRILINEAR" }; const nbFilters = ARRAY_LENGTH(cairo_filters); const int src_sizes[] = { 512, }; const int nbSrcSizes = ARRAY_LENGTH(src_sizes); const int dest_sizes[] = { 840, 1026 }; const int nbDestSizes = ARRAY_LENGTH(dest_sizes); const int angle_DEG[] = { 0 }; const int nbAngles = ARRAY_LENGTH(angle_DEG); const int loopTest = 1; const int loopProgram = 1; int main (int argc, char *argv[]) { FILE *f; clock_t start, finish; cairo_surface_t *src, *dest; cairo_t *cr; int swc, shc, dwc, dhc, fc, lt, pc, ac; int srcWidth, srcHeight, destWidth, destHeight, angle; cairo_filter_t filter; char srcWidthStr[6], srcHeightStr[6], destWidthStr[6], destHeightStr[6], filterStr[30], angleStr[5]; char srcFilename[128], destFilename[256]; if (loopTest == 1) start = clock(); for (pc = 0; pc < loopProgram; pc++) { char* srcTag = "src"; char* destTag = "dest"; char* xTag = "x"; char* dashTag = "-"; char* toTag = "to"; char* destImagesTag = ".\\"; char* pngTag = ".png"; // find the test parameters for (swc = 0; swc < nbSrcSizes; swc++) { srcWidth = 1231;//src_sizes[swc]; // replace with this if you want variability on src images' width itoa(srcWidth, srcWidthStr, 10); for (shc = 0; shc < nbSrcSizes; shc++) { srcHeight = 1504;//src_sizes[shc]; // replace with this if you want variability on src images' height itoa(srcHeight, srcHeightStr, 10); for (dwc = 0; dwc < nbDestSizes; dwc++) { destWidth = dest_sizes[dwc]; itoa(destWidth, destWidthStr, 10); for (dhc = 0; dhc < nbDestSizes; dhc++) { destHeight = dest_sizes[dhc]; itoa(destHeight, destHeightStr, 10); for (ac = 0; ac < nbAngles; ac++) { angle = angle_DEG[ac]; itoa(angle, angleStr, 10); for (fc = 0; fc < nbFilters; fc++) { filter = cairo_filters[fc]; strcpy(filterStr, cairo_filter_strings[fc]); // string init srcFilename[0] = 0; destFilename[0] = 0; // build the source filename strcat(srcFilename, srcTag); strcat(srcFilename, srcWidthStr); strcat(srcFilename, xTag); strcat(srcFilename, srcHeightStr); strcat(srcFilename, pngTag); // build the destination filename strcat(destFilename, destImagesTag); strcat(destFilename, destTag); strcat(destFilename, srcWidthStr); strcat(destFilename, xTag); strcat(destFilename, srcHeightStr); strcat(destFilename, toTag); strcat(destFilename, destWidthStr); strcat(destFilename, xTag); strcat(destFilename, destHeightStr); strcat(destFilename, dashTag); strcat(destFilename, filterStr); strcat(destFilename, dashTag); strcat(destFilename, angleStr); strcat(destFilename, pngTag); // the test src = cairo_image_surface_create_from_png(srcFilename); dest = cairo_image_surface_create(CAIRO_FORMAT_RGB24, destWidth, destHeight); cr = cairo_create(dest); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); cairo_paint(cr); for (lt = 0; lt < loopTest; lt++) { if (loopTest != 1) if (lt == 1) start = clock(); cr = cairo_create(dest); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); cairo_paint(cr); cairo_scale(cr, (double)destWidth / (double)srcWidth, (double)destHeight / (double)srcHeight); cairo_rotate(cr, 2.0*M_PI*((double)angle_DEG[ac]/360.0)); cairo_set_source_surface(cr, src, 0, 0); cairo_pattern_set_filter (cairo_get_source (cr), filter); cairo_paint(cr); } finish = clock(); cairo_surface_write_to_png(dest, destFilename); cairo_destroy(cr); cairo_surface_destroy(src); cairo_surface_destroy(dest); } } } } } } } f = fopen("time.out", "w"); fprintf(f, "TEMPS : %d \n",finish-start); fclose(f); return 0; }