// ------------- haro ----------------------- int drawGIF(struct picinfo *gif) { //picinfo (in/out) - jmeno gifu a kam nakreslit //hPicinfo(in) - handle picinfo (jen pro anim.gify) //ModPic (out)- zda uchovat zmeny v picinfo // char drive[8], dir[80], name[16], ext[8]; // char *ext; struct GIFGLB GifGlb; struct GIFIMG GifImg; int ist, mark, interlac, NumImg = 0; int *mapio=NULL, *Mmapio[2]; int i, ire=1, TraCol, Prepni; unsigned int backg,code_start; int Transp = 0, GrCtrl = 0; short int tAnim = 0; // cas animace v setinach vteriny int disp = 0; // dispozice int ReaPal = 0; // zda se cetla local paleta int GlbPal = 0; // zda se cetla globalni paleta #ifdef XANIMGIF int vdx = 0, vdy = 0; #endif long CurPos, ReaBytes, BckAdr; char *pAktpal; unsigned char *pLocPal=NULL; // lolalni gif paleta int nLocPal=0; // delka loc. palety int bSaveBck1=0,bSaveBck2=0;// zda ukladat background pro animovane //*ModPic = 0; nahrazeno swapmod !! //basebackg=-1; //mp!! // fnsplit(gif->filename, drive, dir, name, ext); /* //no longer needed - drawGIF is always called from drawanyimage() ext=strrchr(gif->filename,'.'); if(ext && strcmpi(ext,".bmp") == 0) { // Kresli bmp ist = XCHdrawBMP(gif); return( ist ); } */ /* #ifdef XANIMGIF if(gif->palonly==0 && gif->sizeonly==0 && gif->IsInXms) { // Uz je v xms -> krelit z ni ist = XGifFromXms(gif, xg_video_XMS, vdx, vdy, &tAnim); return( ist ); } #endif */ New_read_gif: NumImg = 0; ist = ReadGHeader(gif, &GifGlb, &GlbPal); if((ist&1) == 0) //failure { /*ire = ist*/ a_close (filx); if(ist==6) //mp: kdyz to neni GIF, zkusit BMP return XCHdrawBMP(gif); else return 0; } pLocPal = farmalloc(768); // Buf. na lokalni palety if(pLocPal==NULL) memerr(); g_DrawFce = DrawLine; // fce volana uvnitr dekomprese /** #ifdef XANIMGIF if(ReaPal && gif->palonly==0 && gif->sizeonly==0) { if(pGifPal==NULL) { pGifPal = farmalloc(768); if(pGifPal==NULL) memerr(); } memcpy(pGifPal, gif->pal, 3*gif->npal); // jen pro anim nGifPal = gif->npal; // schovat glb. paletu gifu for(i=0; i<3*nGifPal; i++) pGifPal[i]>>=2; } #endif **/ // Hlavni cykl pres jednotlive bloky v GIFu Next_marker: mark = ReadGMarker(); if(mark < 0) { /*ire = 8*/; //ERRGIF if(NumImg == 0) goto Only_sp; else if(NumImg == 1) { ire = 1; //mp! goto Err_frame; } else { ire = 1; goto Add_to_anim; } //ERRGIF } else if(mark == 1) // Ext. blok { ist = ReadExtBlok(&Transp, &backg, &tAnim, &disp, &GrCtrl); if((ist&1)==0) { /*ire = 10*/ ire=1; goto Err_frame; } //mp! if(GrCtrl) // Cetlo se grf. ext. { //if(backg >= gif->npal) backg = gif->npal-1; // Toto se vyskytuje ?? gif->bgindex = backg; // back, nebo transp index swapmod = 1; // mark XSWAP as modified //RGB001 if(Transp && !gif->palismap && GlbPal) { gif->pal[3*backg ] = g_rT; gif->pal[3*backg+1] = g_gT; gif->pal[3*backg+2] = g_bT; } } } else if(mark == 2) // Img. blok { ist = ReadImgBlok(gif, &GifImg, &interlac, &code_start, GlbPal, &ReaPal, &nLocPal, pLocPal); if((ist&1)==0) { /*ire = 12*/ ire=1; goto Err_frame; } //mp! if(gif->sizeonly){ ire = 1; goto Only_sp; } //SaveBck if( Transp ) { //RGB001 if(ReaPal==0 && GlbPal) //!!mp ReaPal=1; //!!mp if(ReaPal ==1) { gif->pal[3*backg ] = g_rT; gif->pal[3*backg+1] = g_gT; gif->pal[3*backg+2] = g_bT; } else if(ReaPal == 2) { pLocPal[3*backg ] = g_rT; pLocPal[3*backg+1] = g_gT; pLocPal[3*backg+2] = g_bT; } //if(GifImg.screex2==GifGlb.screenwide && GifImg.screey2==GifGlb.screendeep) if(disp >= 2) bSaveBck1++; // max. velikost s transp else bSaveBck2++; // mensi nez. cele s transp } if(!gif->palismap || gif->palonly || xg_256==MM_Hic) { gif->palismap=0; if(gif->palonly) { if(GlbPal == 0) // Zadna globalni->vezmu lokalni { //mp!!begin //specialni filtry pro 16ti barevne mody if(egamode) for(i=0; i<3*gif->npal; i++) gif->pal[i]=egafilter(gif->pal[i]); else if(vga16mode && !vgamono) for(i=0; i<3*gif->npal; i++) gif->pal[i]=vgafilter(gif->pal[i]); else //mp!!end memcpy(gif->pal, pLocPal, 3*nLocPal); gif->npal = nLocPal; } ire = 1; goto Only_sp; } } CurPos = a_lseek(filx, 0, SEEK_CUR); // Pripravit scaling (bakground NE, pripadne vzdy zakazat),nebo oriznuti //if(NumImg == 0) { ist = PrepareScaleAndX(gif, NumImg, &Prepni); if(ist == 0) { ire = 1; goto Err_frame; } // gif mimo scr //if(Prepni) goto Prepni; -> kreslit prvni frame gifu -> zacykleni } if(xg_256 != MM_Hic) // * * * * * * * * * * * * * 16 color, 256 color { // Kde vezmu Mmapio ?? if(gif->palismap && ReaPal != 2) // uz mam mapu a img mema loc.paletu { Mmapio[1]=(int *)(gif->pal); } else // musim ji vyrobit { mapio=farmalloc(1024*sizeof(int)); if(!mapio) return(2); ist = PalForPaleteModes(gif, mapio, Mmapio, ReaPal, nLocPal, pLocPal); if(ist != 1) { /*ire=ist*/ ire=1; goto Err_frame;} //mp! } #ifdef XANIMGIF if(g_gifDrawXms == 0) { TraCol = IndexToTranspCol((int)gif->bgindex, (char*)Mmapio[1]); ist = XInitImgXms(gif, NumImg, Transp, TraCol, tAnim, disp); if(ist != 1) // Neni misto v XMS : prepnout na screen a znovu { goto Prepni; } } #endif ire = draw_gif(gif,code_start,interlac,Transp,Mmapio[1],NULL, &ReaBytes); if(mapio) { farfree(mapio); mapio = 0; } } else // * * * * * * * * * * * * * * * * * * * * * * * * * * * Hicolor... { if( ReaPal==2 ) pAktpal = (char *) pLocPal; else pAktpal = (char *)gif->pal; #ifdef XANIMGIF if(g_gifDrawXms == 0) { TraCol = IndexToTranspCol((int)gif->bgindex, pAktpal); ist = XInitImgXms(gif, NumImg, Transp, TraCol, tAnim, disp); if(ist != 1) // neni XMS ? { Prepni: a_close(filx); goto New_read_gif; } } #endif ire = draw_gif(gif,code_start,interlac,Transp,NULL,pAktpal, &ReaBytes); } ReaPal = 0; if(ire != 1) // chyby pri dekompresi gifu { ire = 1; // v NumImg je pocet OK framu //mp! // if(NumImg > 0) { goto Err_frame; } // else // { goto Only_sp; // } } NumImg++; CurPos = a_lseek(filx, CurPos+ReaBytes, SEEK_SET); disp = 0; //i=getch(); if(g_gifDrawXms == 1 && NumImg > 0) { // Nakreslit vzdy jen prvni ire = 1; goto Only_sp; } } else if(mark == 0) // OK end file { //char Msg[80]; //sprintf(Msg,"EndGIFN: DrawXMS=%d NumImg=%d",g_gifDrawXms,NumImg); //outs(Msg); //getch(); //ERRGIF Add_to_anim: #ifdef XANIMGIF if(NumImg > 1 && g_gifDrawXms == 0) // pridat k animovanym { if(g_NumAnim < MAX_ANIMATEGIF) { g_TableAnim[g_NumAnim].hPicInf = gif->hPicInfo; // ??? g_TableAnim[g_NumAnim].NextAnim = 0; // Cas pristi animace // SaveBck : Ulozit background ? if(bSaveBck1 /*&& bSaveBck2*/) { ist = XSaveBackToXMS(gif, GifGlb.screenwide, GifGlb.screendeep, &BckAdr); if(ist==0) { if(BckAdr) XGifFreeXMS(); // uvolnit alloc. XMS pro pozadi } else { gif->BckImg = BckAdr; swapmod = 1; } } g_NumAnim++; //outs("Add To Anim"); } } Err_frame: if(NumImg == 0) goto Only_sp; if(g_gifDrawXms == 0 && gif->IsInXms) // prvni obrazek z gifu v XMS { ist = XGifFromXms(gif, xg_video_XMS, vdx, vdy, &tAnim); // Je-li jeden frame, pak ho uvolnit if(NumImg == 1) { XGifFreeXMS(); } } #else Err_frame: ire = 1; #endif goto Only_sp; } goto Next_marker; Only_sp: if(pLocPal) farfree(pLocPal); a_close(filx); return( ire ); }
void main ( int argc, char * argv[] ) { FILE *config = NULL, *gif = NULL; char *sconfig = NULL, *sgif = NULL; char *optarg; char type; int i; /* globals */ xsize = 400, ysize = 150; type = 'd'; rate = 1250000; distcount = 10; do { /***************************************************************/ /* 0 : read program arguments */ while ( ( i = getopt1( argc, argv, "o:i:t:w:h:r:d:", &optarg ) ) != EOF ) { switch ( i ) { case 'i': sconfig = optarg; break; case 'o': sgif = optarg; break; case 'w': if ( optarg != NULL ) { xsize = atoi (optarg); } break; case 'r': if ( optarg != NULL ) { rate = atoi (optarg); } break; case 'd': if ( optarg != NULL ) { distcount = atoi (optarg); } break; case 'h': if ( optarg != NULL ) { ysize = atoi (optarg); } break; case 't': if ( optarg != NULL ) type = optarg[0]; if (type != 'd' && type != 'm' && type != 'w' && type != 'y' && type != 'x' ) { print_error(); exit (0); } break; case '?': print_error(); exit (0); break; default: break; } } if ( sgif == NULL || sconfig == NULL ) { print_error(); break; } /***************************************************************/ /* 1 : OPEN FILES */ gif = fopen ( sgif, "wb" ); if ( gif == NULL ) { fprintf ( stderr, "Error opening %s.\n", sgif ); fclose ( config ); break; } config = fopen ( sconfig, "r" ); if ( config == NULL ) { fprintf ( stderr, "Error opening %s.\n", sconfig ); break; } if ( type != 'x' ) { /***************************************************************/ for ( i = 0; i < distcount; i ++ ) { dist[i][0] = 0; dist[i][1] = 0; } { /* read first line ... */ unsigned long time, in, out; fscanf ( config, "%lu %lu %lu\n", &time, &in, &out ); /* read first line */ } switch ( type ) { case 'd': computes_distrib ( config, 288, 1, rate ); rounds = 288; /* 288 * 5' = 24 hours */ break; case 'w': computes_distrib ( config, 100, 6, rate ); /* 600 * 5', with mean on 6 (30')*/ computes_distrib ( config, 236, 1, rate ); rounds = 336; /* 336 * 30' = 7 days */ break; case 'm': computes_distrib ( config, 25, 24, rate ); /* 600 * 5', with mean on 24 (2hours) */ computes_distrib ( config, 150, 4, rate ); /* 600 *30', with mean on 4 */ computes_distrib ( config, 185, 1, rate ); rounds = 360; /* 260 * 2 hours = 30 days */ break; case 'y': computes_distrib ( config, 2,300, rate ); /* 600 * 5', with mean on 300 ~= 1 day */ computes_distrib ( config, 12, 50, rate ); /* 600 *30', with mean on 50 ~= 1 day */ computes_distrib ( config, 50, 12, rate ); /* 600 * 2h, with mean on 12 */ computes_distrib ( config, 300, 1, rate ); rounds = 364; break; } for ( i = 0; i < distcount; i ++ ) { printf ( "%u:%u,%u.\n", i, dist[i][0],dist[i][1] ); } /***************************************************************/ draw_gif ( gif ); /***************************************************************/ fclose ( gif ); fclose ( config ); break; } else { draw_distrib_gif ( config, gif ); fclose ( config ); fclose ( gif ); break; } } while ( TRUE ); }