/** Post-process files. Only valid for PNGs. */ void postprocess() { printf("Post-processing PNG files, resizing to %fx%f\n", maxwidth, maxheight); struct dirent *d; DIR *output_dir = opendir(outdir.c_str()); while ((d = readdir(output_dir)) != NULL) { if (fnmatch("*.png", d->d_name, FNM_PATHNAME | FNM_PERIOD) == 0) { infile = outdir + "/" + d->d_name; Cairo::RefPtr<Cairo::ImageSurface> imgs = Cairo::ImageSurface::create_from_png(infile); if ( (imgs->get_height() != maxheight) || (imgs->get_width() != maxwidth)) { // need to re-create char *tmpout = strdup((outdir + "/tmpXXXXXX").c_str()); FILE *f = fdopen(mkstemp(tmpout), "w"); outfile = tmpout; free(tmpout); Cairo::RefPtr<Cairo::ImageSurface> outs = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, (int)ceilf(maxwidth), (int)ceilf(maxheight)); double tx = (maxwidth - imgs->get_width()) / 2.0; double ty = (maxheight - imgs->get_height()) / 2.0; printf("Re-creating %s for post-processing, " "resizing from %ix%i, tx=%f, ty=%f\n", infile.c_str(), imgs->get_width(), imgs->get_height(), tx, ty); Cairo::RefPtr<Cairo::Context> cc = Cairo::Context::create(outs); if (white_bg) { cc->set_source_rgb(1, 1, 1); cc->paint(); } cc->set_source(imgs, tx, ty); cc->paint(); outs->write_to_png(&SkillGuiBatchRenderer::write_func, f); imgs.clear(); cc.clear(); outs.clear(); fclose(f); rename(outfile.c_str(), infile.c_str()); } } } closedir(output_dir); }