int main(int argc,char *argv[]) { if (argc != 3) { fprintf(stderr,"usage: %s filein fileout\n",argv[0]); exit(1); } dofiles(argc,argv); if ((fp = fopen(FILEIN,"rb")) == NULL ) { fprintf(stderr,"%s: wrong input file %s\n",PROGNAME,FILEIN); exit(1); } pic = newpic(); while (1) { printf("k keeps the existing header\n"); printf("d deletes the header (translates into raw data format)\n"); printf("p prepends new header (translates from raw data format)\n"); printf("c changes to new header (d+p)\t>"); answer = getchar(); getchar(); printf("%c it is!\n\n",answer); if ((answer == 'd') || (answer == 'k') || (answer == 'c')) { if (readhead(pic,fp) == -1) exit(1); break; } if (answer == 'p') { /* request new header - no header to be read anymore */ printf("Fileid int, as defined in vis.h (0 for unsigned char image): "); scanf("%d",&(pic->fileid)); printf("New image width (x pixels): "); scanf("%d",&(pic->x)); printf("New image height (y pixels): "); scanf("%d",&(pic->y)); printf("Window x origin (float): "); scanf("%f",&(pic->xorigin)); printf("Window y origin (float): "); scanf("%f",&(pic->yorigin)); printf("Number of items (0 for x*y): "); scanf("%d",&(pic->items)); if (pic->items == 0) pic->items = (pic->x)*(pic->y); printf("Number of samples for each item: "); scanf("%d",&(pic->samples)); printf("New image history: "); scanf("%[^\n]",pic->history); getchar(); pic->magic = VIS_MAGIC; break; } printf("Unexpected response, please try again\n"); } while (1) { printf("d for diagonal reflection (rows into columns)\n"); printf("r rotate 90 deg anti-clockwise (diagonal & horizontal reflections)\n"); printf("n for no reflection or endian byte swapping: "); reverse = getchar(); getchar(); printf("%c it is!\n\n",reverse); if ((reverse=='d') || (reverse=='r') || (reverse=='n')) break; printf("Unexpected response - please try again or control-C\n"); } while (1) { printf("v for Libor Spacek's LVL format output\n"); printf("p for Jef Poskanzer's PGM or PPM output \t>"); wout = getchar(); getchar(); printf("%c it is!\n",wout); if (wout == 'v') break; if (wout == 'p') break; (void) printf("Unexpected response - please try again or control-C\n"); } /* no more user input the desired header must be known by now and be in *pic */ if ((reverse == 'd')||(reverse == 'r')) /* swap rows and columns */ { newdata(pic); chbufin = (unsigned char *)pic->data; swapping = pic->y; pic->y = pic->x; pic->x = swapping; sz = (pic->samples)*sizeofidtype(pic->fileid); for (count=0;count<pic->x;count++) if (reverse == 'r') for (county=(pic->y)-1;county>=0;county--) fread(&(chbufin[sz*(county*(pic->x)+count)]),sz,1,fp); else for (county=0;county<pic->y;county++) fread(&(chbufin[sz*(county*pic->x+count)]),sz,1,fp); } else readdata(pic,fp); fclose(fp); if (answer != 'd') switch (wout) { case 'v': writepic(pic,FILEOUT); break; case 'p': writepmpic(pic,FILEOUT); break; default: exit(1); } else { if ((fp = fopen(FILEOUT,"wb")) == NULL ) { fprintf(stderr,"%s: wrong output file %s\n",PROGNAME,FILEOUT); exit(1); } if (fwrite(pic->data,sizeofdata(pic),1,fp) == 0) { fprintf(stderr,"%s: failed to write data\n",PROGNAME); exit(1); } } exit(0); }
int main (int argc, char **argv) { SDL_Surface *s = NULL; if (argc == 1){ fprintf(stderr, "pictool: no input files\n"); exit(1); } if(argc == 2){ if(!strcmp(argv[1], "--help")){ show_help(); exit(0); } else{ if(picdetails(argv[1])){ fprintf(stderr, "pictool: bad format\n"); exit(4); } exit(0); } } if(argc == 3){ fprintf(stderr, "pictool: not enough arguments\n"); exit(2); } SDL_Init(SDL_INIT_VIDEO); if(argc == 5 && !strcmp(argv[4], "--topic")){ int error; dbgprintf(":: Loading from bitmap %s\n", argv[3]); s = SDL_LoadBMP(argv[3]); dbgprintf(":: Success\n"); if (error = writepic(argv[1], atoi(argv[2]), s)) { printf("Error writing pic: %d\n", error); exit(error); } SDL_FreeSurface(s); } else if(argc == 4 || !strcmp(argv[4], "--tobmp")){ if(readpic(argv[1], atoi(argv[2]), &s)){ fprintf(stderr, "pictool: conversion to bmp failed: bad format\n"); SDL_Quit(); exit(4); } dbgprintf(":: Saving to %s\n", argv[3]); if(SDL_SaveBMP(s, argv[3])){ fprintf(stderr, "pictool: saving to bmp failed\n"); SDL_Quit(); exit(6); } dbgprintf(":: Success\n"); SDL_FreeSurface(s); } else{ fprintf(stderr, "pictool: unrecognized argument\n"); SDL_Quit(); exit(5); } dbgprintf(":: SDLQuit\n"); SDL_Quit(); dbgprintf(":: Return\n"); return 0; }
void wxPicToolFrame::OnbtnImportOneClick(wxCommandEvent& event) { if (indexchoice_fb == -1) { wxMessageBox(_("Make a choice first, then give commands, sir."), _("I'm sorry, captain, I can't do much more")); return; } SDL_Init(SDL_INIT_VIDEO); wxString fn; fn.Printf("Tibia%d.bmp", indexchoice_fb); fn = txtOutput->GetValue() + "/" + fn; SDL_Surface* s = SDL_LoadBMP(fn.c_str()); if (!s) { wxString msg; msg = "It would be prudent to first make sure that " + fn + " exists, Master."; wxMessageBox(msg, _("I'm sorry, captain, I can't do much more")); SDL_Quit(); return; } int errorid; if (errorid = writepic(txtPic->GetValue().c_str(), indexchoice_fb, s)) { switch(errorid){ default: { wxString msg; msg.Printf((_( "Apparently, there is an issue with reading or writing ") + txtPic->GetValue() + ".\n" "\n" "Errid: %d\n" "Errno: %d\n" "Strerror: %s" ).c_str(), errorid, errno, strerror(errno)); wxMessageBox(msg, _("I'm sorry, captain, I can't do much more")); SDL_Quit(); return; } case -1: { wxString msg; msg.Printf((_( "File ") + txtPic->GetValue() + " does not exist.\n" "\n" "Errid: %d\n" "Errno: %d\n" "Strerror: %s" ).c_str(), errorid, errno, strerror(errno)); wxMessageBox(msg, _("I'm sorry, captain, I can't do much more")); SDL_Quit(); return; } case 92: // rename() failed case 93: { // rename's unlink() failed wxString msg; msg.Printf("Rename from __tmp__.pic failed.\n" "File has been outputted successfully into __tmp__pic, but you'll have to pick it up yourself.\n" "\n" "Errid: %d\n" "Errno: %d\n" "Strerror: %s", errorid, errno, strerror(errno)); wxMessageBox(msg, _("Aff")); SDL_Quit(); break; } } } wxMessageBox(_("Thou hast succeeded, mighty nightly lord!"), _("YOU WIN")); SDL_FreeSurface(s); SDL_Quit(); }