示例#1
0
inline boost::optional<std::string> type_from_filename(std::string const& filename)

{
    typedef boost::optional<std::string> result_type;
    if (is_png(filename)) return result_type("png");
    if (is_jpeg(filename)) return result_type("jpeg");
    if (is_tiff(filename)) return result_type("tiff");
    if (is_pdf(filename)) return result_type("pdf");
    if (is_svg(filename)) return result_type("svg");
    if (is_ps(filename)) return result_type("ps");
    return result_type();
}
示例#2
0
int main(void) {
    struct dirent **namelist;
    int i, n, N;
    unsigned char *image = NULL;
    float *image_bw_f;
    unsigned char *image_bw_u8;
    float *image_out_old;
    float *image_out_new;
    char fullpath[255];
    char outpath_old[255];
    char outpath_new[255];
    int imW, imH;

    float sigma;
    float err;

    sigma = 1.0;

    N = scandir("demo_simplexy_images", &namelist, is_input_image, alphasort);
    if (N < 0) {
        perror("scandir");
        return 1;
    }

    for (n = 0; n < N; n++) {

        strcpy(fullpath, "demo_simplexy_images/");
        strcat(fullpath, namelist[n]->d_name);

        strcpy(outpath_old, "demo_simplexy_images/out_");
        strcat(outpath_old, namelist[n]->d_name);
        outpath_old[strlen(outpath_old)-4] = '\0';
        strcat(outpath_old, "_old");
        strcat(outpath_old, ".png");

        strcpy(outpath_new, "demo_simplexy_images/out_");
        strcat(outpath_new, namelist[n]->d_name);
        outpath_new[strlen(outpath_new)-4] = '\0';
        strcat(outpath_new, "_new");
        strcat(outpath_new, ".png");

        fprintf(stderr,"demo_dsmooth: loading %s ", fullpath);

        if (is_png(namelist[n])) {
            fprintf(stderr, "as a PNG\n");
            image = cairoutils_read_png(fullpath, &imW, &imH);
        }

        if (is_jpeg(namelist[n])) {
            fprintf(stderr, "as a JPEG\n");
            image = cairoutils_read_jpeg(fullpath, &imW, &imH);
        }

        image_bw_u8 = to_bw_u8(image, imW, imH);
        image_bw_f = malloc(sizeof(float) * imW * imH);
        for (i = 0; i < imW*imH; i++) {
            image_bw_f[i] = (float)image_bw_u8[i];
        }

        image_out_old = malloc(sizeof(float)*imW*imH);
        image_out_new = malloc(sizeof(float)*imW*imH);

        fprintf(stderr,"demo_dsmooth: running %s through dsmooth\n", fullpath);
        dsmooth(image_bw_f, imW, imH, sigma, image_out_old);

        fprintf(stderr,"demo_dsmooth: running %s through dsmooth2\n", fullpath);
        dsmooth2(image_bw_f, imW, imH, sigma, image_out_new);

        err = 0.0;
        for (i = 0; i < imW*imH; i++) {
            err += fabs(image_out_old[i]-image_out_new[i]);
        }
        err = err / (imW*imH);

        fprintf(stderr, "demo_dsmooth: error between smooths: %f per pixel\n", err);

        //		fprintf(stderr, "demo_dsmooth: writing old dsmoothed image to %s\n", outpath_old);
        //		cairoutils_write_png(outpath_old, to_cairo_bw(image_out_old, imW, imH), imW, imH);

        //		fprintf(stderr, "demo_dsmooth: writing new dsmoothed image to %s\n", outpath_new);
        //		cairoutils_write_png(outpath_new, to_cairo_bw(image_out_new, imW, imH), imW, imH);

        free(namelist[n]);
        free(image);
        free(image_bw_f);
        free(image_bw_u8);
        free(image_out_old);
        free(image_out_new);

    }
    free(namelist);

    return 0;
}
示例#3
0
int is_image(const struct dirent *de) {
    return is_jpeg(de) || is_png(de);
}