#include <allegro.h> #include <sp1.h> #include <tdgui.h> #include <jpeg.h> #include <algbm.h> #include <loadaud.h> #include <loadpng.h> static char *types[]={ "bmp","pcx","tga","lbm","jpg","xm","mod","s3m","sm1","wav","mid","mp3","fli", "flc","vga","bga","rle","dib","rl4","rl8","gif","tif","vst","afi","iff","vid", "pgm","ppm","kps","iax","xbm","spr","pse","voc","m15","mod","mtm","stm","ult", "san","jpe","aud","png","sp1", NULL}; static int pript[]={0,1,2,4,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,41,42,43}; static char *prips[]={ "BMP",//0 "PCX",//1 "TGA",//2 "JPG",//4 "VGA",//14 "BGA","RLE","DIB","RL4","RL8","GIF","TIF", "VST","AFI","IFF","VID","PGM","PPM","KPS", "IAX","XBM","SPR","PSE",//32 "AUD",//41 "PNG",//42 "SP1",//43 NULL }; char *pripona_getter(int index,int *list_size) { if(index<0){ *list_size=26; return NULL; } return prips[index]; } static char *sdstr[]={"8 bit","15 bit","16 bit","24 bit"}; char *sd_getter(int index,int *list_size) { if(index<0){ *list_size=4; return NULL; } return sdstr[index]; } static DIALOG the_pripona[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */ { d_billwin_proc, 220, 180, 200, 120, 0, 0, 0, 0, 0, 0, "CONVERT"}, { d_billtext_proc, 230, 200, 80, 90, 0, 0, 0, 0, 0, 0, "File type"}, { d_billtext_proc, 320, 200, 80, 90, 0, 0, 0, 0, 0, 0, "Color depth"}, { d_billlist_proc, 230, 210, 80, 85, 0, 0, 0, 0, 0, 0, pripona_getter}, { d_billlist_proc, 320, 210, 80, 40, 0, 0, 0, 0, 0, 0, sd_getter}, { d_billbutton_proc,320, 260, 80, 15, 0, 0, 0,D_EXIT, 0, 0, "OK"}, { d_billbutton_proc,320, 280, 80, 15, 0, 0, 0,D_EXIT, 0, 0, "Cancel"}, { NULL } //14 }; int sd; int cnvrt_tabulka() { char r; r=moveable_do_dialog(the_pripona,-1); while(keypressed()==TRUE); clear_keybuf(); if(r==-1) return -1; if(r==6) return -1; if(the_pripona[4].d1==0) sd=8; if(the_pripona[4].d1==1) sd=15; if(the_pripona[4].d1==2) sd=16; if(the_pripona[4].d1==3) sd=24; return pript[the_pripona[3].d1]; } void cnvrt_draw_koniec(int cnv,int unc,int err) { char tbuf[50]; show_mouse(0); clear_keybuf(); set_color_depth(8); tdbox1(screen,200,200,240,80,6); textout_centre(screen,font,"CONVERT",320,205,255); tdhline(screen,204,215,434); sprintf(tbuf,"Files converted : %d",cnv); textout(screen,font,tbuf,205,225,100); textout(screen,font,tbuf,206,226,0); sprintf(tbuf,"Uncompatible files : %d",unc); textout(screen,font,tbuf,205,235,100); textout(screen,font,tbuf,206,236,0); sprintf(tbuf,"Files containing error: %d",err); textout(screen,font,tbuf,205,245,100); textout(screen,font,tbuf,206,246,0); textout_centre(screen,font,"Press any key",320,265,255); show_mouse(screen); readkey(); clear_keybuf(); } void cnvrt_zmen(const char infile[256],char out[256],int t) { int i; for(i=0;i<256;i++){ out[i]=infile[i]; if(infile[i]=='.') break; } out[i+1]=0; strcat(out,types[t]); } int cnvrt_type(int k) { if(k>=0&&k<=2) return 0; if(k==3) return 4; // lbm if(k==4) return 6; // jpg if(k>=12&&k<=13) return 3; // fli,flc if(k>=14&&k<=32) return 5; // gbm if(k==10) return 1; if(k==9) return 2; // wav if(k==33) return 2; // voc if(k==11) return 1; if(k>=5&&k<=8) return 1; if(k>=34&&k<=38) return 1; if(k==39) return 3; // san if(k==40) return 6; // jpg if(k==41) return 7; // aud if(k==42) return 8; // png if(k==43) return 9; // sp1 } /* 0 - allegro bitmaps 1 - music (unsupported) 2 - wav,vod (only 2 aud) 3 - san,flc,fli (unsupported) 4 - lbm (only reading) 5 - gbm bitmaps 6 - jpeg 7 - aud 8 - png 9 - sp1 */ SAMPLE *cspl; BITMAP *cbmp; int convert(char infile[256],int t1,int t2) { char c1,ret=1,c2; PALETTE pal; char outfile[256]; c1=cnvrt_type(t1); c2=cnvrt_type(t2); cnvrt_zmen(infile,outfile,t2); set_color_depth(8); text_mode(-1); show_mouse(0); tdbox1(screen,220,200,200,80,6); textout_centre(screen,font,"CONVERT",320,205,255); tdhline(screen,222,215,418); textout(screen,font,infile,225,225,0); textout(screen,font,infile,226,226,100); textout_centre(screen,font,"TO",320,245,0); textout_centre(screen,font,"TO",321,246,100); textout(screen,font,outfile,225,265,0); textout(screen,font,outfile,226,266,100); show_mouse(screen); if(file_exists(outfile,0,0)!=0){ if(billalert("I have one question!","Destination file already exists.", "Overwrite?","&Yes","&No",'y','n')==2) return 0; } set_color_depth(sd); if(c1==0&&((c2==0)||(c2==5)||(c2==6)||(c2==8)||(c2==9))){cbmp=load_bitmap(infile,pal);ret=0;} if(c1==1) ret=1; if(c1==2&&c2==7){cspl=load_sample(infile);ret=0;} if(c1==3) ret=1; if(c1==4&&((c2==0)||(c2==5)||(c2==6)||(c2==8)||(c2==9))) {cbmp=load_bitmap(infile,pal);ret=0;} if(c1==5&&((c2==0)||(c2==5)||(c2==6)||(c2==8)||(c2==9))) {cbmp=load_gbm(infile,pal);ret=0;} if(c1==6&&((c2==0)||(c2==5)||(c2==6)||(c2==8)||(c2==9))) {cbmp=load_jpeg(infile,pal);ret=0;} if(c1==7) ret=1; if(c1==8&&((c2==0)||(c2==5)||(c2==6)||(c2==8)||(c2==9))) {cbmp=load_png(infile,pal);ret=0;} if(c1==9&&((c2==0)||(c2==5)||(c2==6)||(c2==8)||(c2==9))) {cbmp=load_sp1(infile);ret=0;} if(ret==0){ if((c1==0)||(c1==4)||(c1==5)||(c1==6)||(c1==8)||(c1==9)){ if(cbmp==0) ret=-1; else{ if(c2==0){save_bitmap(outfile,cbmp,pal);ret=0;} if(c2==5){save_gbm(outfile,cbmp,pal);ret=0;} if(c2==6){save_jpeg(outfile,cbmp,pal);ret=0;} if(c2==8){save_png(outfile,cbmp,pal);ret=0;} if(c2==9){write_sp1(cbmp,outfile);ret=0;} } } if(c1==2){ if(cspl==0) ret=-1; else{ if(c2==7){save_aud(outfile,cspl);ret=0;} } } } if(cbmp!=0) destroy_bitmap(cbmp); if(cspl!=0) destroy_sample(cspl); return ret; } /* Return: -1 : error in compatibility 0 : OK 1 : bad input file */