static Errcode push_screen_id(LONG timeid) { Errcode err; if (pushed_screen == 0) { if((err = save_pic(screen_name, vb.pencel,timeid,TRUE)) < 0) return(err); } pushed_screen++; return(0); }
static Errcode push_alt_id(LONG id) { Errcode err; if(pushed_alt == 0) { if(vl.alt_cel) { if((err = save_pic(alt_name, vl.alt_cel,id,TRUE)) < 0) return(err); pj_rcel_free(vl.alt_cel); vl.alt_cel = NULL; } } pushed_alt++; return(0); }
int main(int argc, char *argv[]) { image myPic; imageInfo picInfo; int count; char *outputType = NULL; int err; int aCrop = NO; int left = -1, right = -1, top = -1, bottom = -1; double xscale = 1, yscale = 1; double xs2, ys2; int xdim = 0, ydim = 0; int ditherMode = ' '; int mMono = NO; int outType = NO; int scaletofit = NO; int numBits = 1; char *outFile = NULL; char *type = NULL, *ext = NULL; char *p; int nv; double darken = 0; double contrast = 0; double rotate = 0; struct stat sbuf; int blend = NO; static char filename[MAXPATHLEN + 1] = ""; int negative = NO; int enhance = NO; formatInfo fInfo; count = getargs(argc, argv, "nbosabLiRiTiBixdydXiYidcmbpbsbbiDdSbKdfseird", &negative, &outputType, &aCrop, &left, &right, &top, &bottom, &xscale, &yscale, &xdim, &ydim, &ditherMode, &mMono, &outType, &scaletofit, &numBits, &darken, &blend, &contrast, &outFile, &enhance, &rotate ); if (count < 0 || count == argc) { if (count < 0 && -count != '-') fprintf(stderr, "Bad flag: %c\n", -count); fprintf(stderr, "Usage: %s [-options] filename\n" " options:\n" "\tn: make negative\n" "\to: string indicating output format\n" "\ta: auto crop non plotting areas\n" "\tL, R, T, B: specify where to crop picture\n" "\tx, y: specify scale factor in that direction\n" "\tX, Y: specify dimension of picture in that direction\n" "\td: select dither method: (D)ither, (T)hreshold, or (H)alftone\n" "\tm: convert image to monochrome\n" "\tp: dither image for output to printer\n" "\ts: scale image to fill up specified screen\n" "\tb: number of bits to dither to\n" "\tD: how much to brighten image\n" "\tK: contrast level\n" "\tS: blend pixels together when scaling\n" "\tf: file name to save to\n" "\te: contrast for enhance image\n" "\tr: number of degrees to rotate\n" , *argv); exit(1); } for (; count < argc; count++) { if ((err = load_pic(argv[count], &myPic))) { fprintf(stderr, "Cannot load file %s\nError: %s\n", argv[count], picErrorStr(err)); exit(1); } if (!getImageInfo(argv[count], &picInfo)) type = picInfo.extension; if (!outputType) outputType = type; if (!infoForFormat(outputType, &fInfo)) { ext = fInfo.extension; if (scaletofit && !xdim && !ydim && fInfo.maxWidth && fInfo.maxHeight) { xdim = fInfo.maxWidth; ydim = fInfo.maxHeight; } } if (mMono) makeMono(&myPic); if (left >= 0 || right >= 0 || top >= 0 || bottom >= 0) { if (left < 0) left = 0; if (right < 0) right = myPic.width - 1; if (top < 0) top = 0; if (bottom < 0) bottom = myPic.height - 1; cropImage(left, top, right, bottom, &myPic); } if (aCrop) autoCropImage(&myPic, 40); if (rotate) rotateImage(&myPic, (rotate * -3.141592) / 180.0); xs2 = xscale; ys2 = yscale; if (scaletofit) { if (!ydim && xdim) { xs2 = (double) xdim / ((double) myPic.width * xscale) * xscale; ys2 = ((double) xdim / ((double) myPic.width * xscale)) * yscale; } else if (ydim) { xs2 = ((double) ydim / ((double) myPic.height * yscale)) * xscale; ys2 = (double) ydim / ((double) myPic.height * yscale) * yscale; if (xdim && (myPic.width * xs2) > xdim) { xs2 = (double) xdim / ((double) myPic.width * xscale) * xscale; ys2 = ((double) xdim / ((double) myPic.width * xscale)) * yscale; } } } else { if (xdim) xs2 = (double) xdim / (double) myPic.width; if (ydim) ys2 = (double) ydim / (double) myPic.height; } xscale = xs2; yscale = ys2; scaleImage(xscale, yscale, blend, &myPic); if (darken || contrast) adjustImage(&myPic, contrast, darken); if (enhance) { makeMono(&myPic); enhanceImage(&myPic, enhance); } handle_dithering(ditherMode, &myPic, outType, numBits); if (negative) negateImage(&myPic); if (outFile) { strcpy(filename, outFile); if (!stat(filename, &sbuf) && (sbuf.st_mode & S_IFDIR)) { if (filename[strlen(filename) - 1] != '/') strcat(filename, "/"); if ((p = strrchr(argv[count], '/'))) strcat(filename, p + 1); else strcat(filename, argv[count]); } } else strcpy(filename, argv[count]); p = change_extension(filename, type, ext, 0); nv = 2; while (!stat(p, &sbuf)) { p = change_extension(filename, type, ext, nv); nv++; } if ((err = save_pic(p, outputType, &myPic))) { fprintf(stderr, "Cannot save file %s\nError: %s\n", p, picErrorStr(err)); exit(1); } fprintf(stderr, "Saved %s as %s\n", argv[count], p); freeImage(&myPic); } exit(0); return 0; }
static int load_fli_overlay(char *title, int how) /* returns ecode if can't do. This reports errors.*/ { Errcode err; Rcel *loadcel = NULL; Cmap *cmap = NULL; int usr_fit = 0; /* start off not knowing how to fit colors */ Flifile flif; int i = 0; int fit_option; int fcount; Vabortdat vd; Boolean overlay_fit; clear_struct(&flif); vd.totframes = &flif.hdr.frame_count; vd.frame = &i; set_abort_verify(olay_abort_verify,&vd); if((err = save_pic(screen_name, vb.pencel,0,TRUE)) < 0) goto error; if((err = pj_fli_open(title,&flif,JREADONLY)) < 0) goto error; /* allocate fli size cel to hold fli frame(s) */ if((err = valloc_ramcel(&loadcel,flif.hdr.width,flif.hdr.height)) < 0) goto error; if((err = pj_cmap_alloc(&cmap,COLORS)) < Success) goto error; if((err = pj_fli_seek_first(&flif)) < 0) goto error; for (i=0; i<flif.hdr.frame_count; i++) { if (i != 0 && vs.frame_ix == 0) { if (soft_qchoice(NULL, "comp_past") != 0) goto aborted; } if ((err = pj_fli_read_next(title,&flif,loadcel,0)) < 0) goto error; if (!cmaps_same(loadcel->cmap, vb.pencel->cmap)) { if (!usr_fit) { if((usr_fit = 1 + soft_qchoice(NULL, "comp_cmap")) <= 0) goto aborted; } fit_option = usr_fit; } else fit_option = 0; /* switch to get the color map into cmap */ switch (fit_option) { case 0: /* both are same. yea! */ case 2: /* keep current */ case 4: /* No Fit */ pj_cmap_copy(vb.pencel->cmap,cmap); break; case 3: /*use overlay cmap */ pj_cmap_copy(loadcel->cmap, cmap); goto do_screen_cfit; case 1: /* compromise cmap */ compromise_cmap(vb.pencel->cmap, loadcel->cmap, cmap); do_screen_cfit: cfit_rcel(vb.pencel,cmap); pj_cmap_copy(cmap,vb.pencel->cmap); see_cmap(); break; } if (i == 0) /* let user position first frame */ { save_undo(); switch (fit_option) /* figure out whether to fit cel to display * for user to position. */ { case 0: /* both are same. yea! */ case 3: /*use overlay cmap */ case 4: /* No Fit */ overlay_fit = FALSE; break; case 1: /* compromise cmap */ case 2: /* keep current */ overlay_fit = TRUE; break; } move_rcel(loadcel,overlay_fit,FALSE); if(!soft_yes_no_box("olay_start")) { load_pic(screen_name, vb.pencel, 0, TRUE); goto aborted; } /* we're committed now */ pj_delete(screen_name); dirties(); } switch (how) { case 0: /* over/under */ if(i != 0) save_undo(); if((err = may_cfit_blit_cel(loadcel, fit_option)) < 0) goto error; break; case 2: /* crossfade */ if ((fcount = flif.hdr.frame_count-1) == 0) fcount = 1; pj_rcel_copy(vb.pencel, undof); if((err = transpblit(loadcel, 0, FALSE, (i*(long)100+flif.hdr.frame_count/2)/fcount)) < Success) { goto error; } break; } if((err = sub_cur_frame()) < Success) goto error; if(poll_abort() < Success) goto aborted; vs.frame_ix++; check_loop(); if((err = unfli(vb.pencel,vs.frame_ix,1)) < 0) goto error; } err = 0; goto OUT; aborted: err = Err_abort; error: err = softerr(err,"!%s", "comp_load", title); OUT: pj_cmap_free(cmap); pj_rcel_free(loadcel); pj_fli_close(&flif); set_abort_verify(NULL); return(err); }