gboolean gtk_mng_view_load_mng_from_memory_remaining (GtkMngView * mng_view, guchar * data_to_eat, guint data_size) { mng_read_pushdata (mng_view->MNG_handle, data_to_eat, data_size, MNG_FALSE); //printf("Calling read\n"); mng_read(mng_view->MNG_handle); //printf("mng_get_totalframes %d\n", mng_get_totalframes (mng_view->MNG_handle)); //printf("mng_get_totallayers %d\n", mng_get_totallayers (mng_view->MNG_handle)); //printf("mng_get_totalplaytime %d\n", mng_get_totalplaytime (mng_view->MNG_handle)); //printf("Iterate chunks\n"); int i = 0; mng_iterate_chunks (mng_view->MNG_handle, 0, myiterchunk); for (i = 0; i < 1000; i++) { //printf("calling iterate i %d\n", i); //printf("out of iterate\n"); } printf("Calling display\n"); //mng_display(mng_view->MNG_handle); //printf("Display over\n"); printf("mng_get_framecount %d\n", mng_get_framecount(mng_view->MNG_handle)); printf("mng_get_layercount %d\n", mng_get_layercount(mng_view->MNG_handle)); printf("mng_get_playtime %d\n", mng_get_playtime(mng_view->MNG_handle)); printf("mng_get_ticks %d\n", mng_get_ticks(mng_view->MNG_handle)); printf("mng_get_starttime %d\n", mng_get_starttime (mng_view->MNG_handle)); printf("mng_get_runtime %d\n", mng_get_runtime (mng_view->MNG_handle)); printf("mng_get_currentframe %d\n", mng_get_currentframe (mng_view->MNG_handle)); printf("mng_get_currentlayer %d\n", mng_get_currentlayer (mng_view->MNG_handle)); printf("mng_get_currentplaytime %d\n", mng_get_currentplaytime (mng_view->MNG_handle)); printf("mng_get_totalframes %d\n", mng_get_totalframes (mng_view->MNG_handle)); printf("mng_get_totallayers %d\n", mng_get_totallayers (mng_view->MNG_handle)); printf("mng_get_totalplaytime %d\n", mng_get_totalplaytime (mng_view->MNG_handle)); return TRUE; }
//--------------------------------------------------------------------------- bool __fastcall TMainForm::DumpTree( void ) { mng_handle hMNG; // let's initialize the library hMNG = mng_initialize( (mng_ptr)this, Alloc, Free, NULL ); if( !hMNG ) // did that work out ? { MNGError( hMNG, "Cannot initialize libmng." ); mng_cleanup( &hMNG ); // Always cleanup the library MsgBoxStop( "Bye!" ); Application->Terminate(); // Exit now } // setup callbacks if( (mng_setcb_openstream ( hMNG, OpenStream ) != 0) || (mng_setcb_closestream ( hMNG, CloseStream ) != 0) || (mng_setcb_processheader( hMNG,ProcessHeader ) != 0) || (mng_setcb_readdata ( hMNG, FileReadData ) != 0) ) { MNGError( hMNG, "Cannot set callbacks for libmng."); mng_cleanup( &hMNG ); // Always cleanup the library MsgBoxStop( "Bye!" ); Application->Terminate(); // Exit now } else { // read the file into memory if( mng_read( hMNG ) != 0 ) { // Because we read the whole file in first, // here is where bad input files first choke ! MNGError( hMNG, "Cannot read the file." ); mng_cleanup( &hMNG ); // Always cleanup the library return false; } else { // run through the chunk list if( mng_iterate_chunks( hMNG, 0, IterateChunks ) != 0 ) { MNGError( hMNG, "Error Getting Chunk info!" ); mng_cleanup( &hMNG ); // Always cleanup the library return false; // Errors may occur with bad chunk data } } } mng_cleanup( &hMNG ); // Always cleanup the library return true; }
int fixit (char * zFilenameI, char * zFilenameO) { userdatap pMydata; mng_retcode iRC; /* get a data buffer */ pMydata = (userdatap)calloc (1, sizeof (userdata)); if (pMydata == NULL) /* oke ? */ { fprintf (stderr, "Cannot allocate a data buffer.\n"); return 1; } pMydata->hFileO = 0; /* initialize some stuff! */ pMydata->hHandleI = MNG_NULL; pMydata->hHandleO = MNG_NULL; pMydata->bHasSAVE = MNG_FALSE; pMydata->bHasTERM = MNG_FALSE; pMydata->bIsJASC = MNG_TRUE; pMydata->iLastchunk = MNG_UINT_HUH; pMydata->iTermaction = 0; pMydata->iIteraction = 0; pMydata->iDelay = 0; pMydata->iItermax = 0; /* can we open the input file ? */ if ((pMydata->hFileI = fopen (zFilenameI, "rb")) == NULL) { /* error out if we can't */ fprintf (stderr, "Cannot open input file %s.\n", zFilenameI); return 1; } /* let's initialize the library */ pMydata->hHandleI = mng_initialize ((mng_ptr)pMydata, myalloc, myfree, MNG_NULL); if (!pMydata->hHandleI) /* did that work out ? */ { fprintf (stderr, "Cannot initialize libmng.\n"); iRC = 1; } else { /* some informatory messages */ fprintf (stderr, "Compiled with libmng %s.\n", MNG_VERSION_TEXT); fprintf (stderr, "Running with libmng %s.\n", mng_version_text()); /* setup callbacks */ if ( ((iRC = mng_setcb_openstream (pMydata->hHandleI, myopenstream )) != 0) || ((iRC = mng_setcb_closestream (pMydata->hHandleI, myclosestream )) != 0) || ((iRC = mng_setcb_readdata (pMydata->hHandleI, myreaddata )) != 0) || ((iRC = mng_setcb_errorproc (pMydata->hHandleI, myprocesserror)) != 0) ) fprintf (stderr, "Cannot set callbacks for libmng.\n"); else { /* reaad the file into memory */ if ((iRC = mng_read (pMydata->hHandleI)) != 0) fprintf (stderr, "Cannot read the input file.\n"); else { /* run through the chunk list to get TERM */ if ((iRC = mng_iterate_chunks (pMydata->hHandleI, 0, myiterchunk)) != 0) fprintf (stderr, "Cannot iterate the chunks.\n"); else { if (pMydata->iError) /* did the iteration fail somehow ? */ iRC = pMydata->iError; else { /* can we open the output file ? */ if ((pMydata->hFileO = fopen (zFilenameO, "wb")) == NULL) { /* error out if we can't */ fprintf (stderr, "Cannot open output file %s.\n", zFilenameO); iRC = 1; } else { /* let's initialize the library */ pMydata->hHandleO = mng_initialize ((mng_ptr)pMydata, myalloc, myfree, MNG_NULL); if (!pMydata->hHandleO) /* did that work out ? */ { fprintf (stderr, "Cannot initialize libmng.\n"); iRC = 1; } else { /* setup callbacks */ if ( ((iRC = mng_setcb_openstream (pMydata->hHandleO, myopenstream )) != 0) || ((iRC = mng_setcb_closestream (pMydata->hHandleO, myclosestream)) != 0) || ((iRC = mng_setcb_writedata (pMydata->hHandleO, mywritedata )) != 0) ) fprintf (stderr, "Cannot set callbacks for libmng.\n"); else { if ((iRC = mng_create (pMydata->hHandleO)) != 0) fprintf (stderr, "Cannot create a new MNG.\n"); else { /* run through the chunk again and create the new file */ if ((iRC = mng_iterate_chunks (pMydata->hHandleI, 0, myiterchunk)) != 0) fprintf (stderr, "Cannot iterate the chunks.\n"); else { /* did the iteration fail somehow ? */ if (pMydata->iError) iRC = pMydata->iError; else { /* now write the created new file !! */ if ((iRC = mng_write (pMydata->hHandleO)) != 0) fprintf (stderr, "Cannot write the output file.\n"); } } } } /* cleanup the library */ mng_cleanup (&pMydata->hHandleO); } /* cleanup output file */ fclose (pMydata->hFileO); } } } } } mng_cleanup (&pMydata->hHandleI); /* cleanup the library */ } fclose (pMydata->hFileI); /* cleanup input file and userdata */ free (pMydata); return iRC; }