jboolean saveToFile(JNIEnv* env, jobject thiz, jstring path, int w, int h, const char* filetype) { char const * filepath = env->GetStringUTFChars(path, NULL); imginfo_t imginfo; imginfo.pixwidth = w; imginfo.pixheight = h; initInfo(filetype); calc_dimensions(&imginfo, s_state->plist); FILE* f = fopen(filepath,"w+"); if(f) { struct backend_s * b = info.backend; if (b->init_f) { if(b->init_f(f) != 0) { fclose(f); return JNI_FALSE; } } b->page_f(f, s_state->plist, &imginfo); if (b->term_f) { if(b->term_f(f) != 0) { fclose(f); return JNI_FALSE; } } fclose(f); return JNI_TRUE; } return JNI_FALSE; }
static void process_file(backend_t *b, const char *infile, const char *outfile, FILE *fin, FILE *fout) { int r; potrace_bitmap_t *bm = NULL; imginfo_t imginfo; int eof_flag = 0; /* to indicate premature eof */ int count; /* number of bitmaps successfully processed, this file */ potrace_state_t *st; for (count=0; ; count++) { /* read a bitmap */ r = bm_read(fin, info.blacklevel, &bm); switch (r) { case -1: /* system error */ fprintf(stderr, ""POTRACE": %s: %s\n", infile, strerror(errno)); exit(2); case -2: /* corrupt file format */ fprintf(stderr, ""POTRACE": %s: file format error: %s\n", infile, bm_read_error); exit(2); case -3: /* empty file */ if (count>0) { /* end of file */ return; } fprintf(stderr, ""POTRACE": %s: empty file\n", infile); exit(2); case -4: /* wrong magic */ if (count>0) { fprintf(stderr, ""POTRACE": %s: warning: junk at end of file\n", infile); return; } fprintf(stderr, ""POTRACE": %s: file format not recognized\n", infile); fprintf(stderr, "Possible input file formats are: pnm (pbm, pgm, ppm), bmp.\n"); exit(2); case 1: /* unexpected end of file */ fprintf(stderr, ""POTRACE": warning: %s: premature end of file\n", infile); eof_flag = 1; break; } /* prepare progress bar, if requested */ if (info.progress) { r = info.progress_bar->init(&info.param->progress, infile, count); if (r) { fprintf(stderr, ""POTRACE": %s\n", strerror(errno)); exit(2); } } else { info.param->progress.callback = NULL; } if (info.invert) { bm_invert(bm); } /* process the image */ st = potrace_trace(info.param, bm); if (!st || st->status != POTRACE_STATUS_OK) { fprintf(stderr, ""POTRACE": %s: %s\n", infile, strerror(errno)); exit(2); } /* calculate image dimensions */ imginfo.pixwidth = bm->w; imginfo.pixheight = bm->h; bm_free(bm); calc_dimensions(&imginfo, st->plist); r = b->page_f(fout, st->plist, &imginfo); if (r) { fprintf(stderr, ""POTRACE": %s: %s\n", outfile, strerror(errno)); exit(2); } potrace_state_free(st); if (info.progress) { info.progress_bar->term(&info.param->progress); } if (eof_flag || !b->multi) { return; } } /* not reached */ }