Exemple #1
0
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;
}
Exemple #2
0
ILboolean iLoadMngInternal()
{
	mng_handle mng;

	if (iCurImage == NULL) {
		ilSetError(IL_ILLEGAL_OPERATION);
		return IL_FALSE;
	}

	mng = mng_initialize(MNG_NULL, mymngalloc, mymngfree, MNG_NULL);
	if (mng == MNG_NULL) {
		ilSetError(IL_LIB_MNG_ERROR);
		return IL_FALSE;
	}

	// If .mng background is available, use it.
	mng_set_usebkgd(mng, MNG_TRUE);

	// Set the callbacks.
	mng_setcb_errorproc(mng, mymngerror);
    mng_setcb_openstream(mng, mymngopenstream);
    mng_setcb_closestream(mng, mymngclosestream);
    mng_setcb_readdata(mng, (mng_readdata)mymngreadstream);
	mng_setcb_gettickcount(mng, mymnggetticks);
	mng_setcb_settimer(mng, mymngsettimer);
	mng_setcb_processheader(mng, mymngprocessheader);
	mng_setcb_getcanvasline(mng, mymnggetcanvasline);
	mng_setcb_refresh(mng, mymngrefresh);

	mng_read(mng);
	mng_display(mng);

	return ilFixImage();
}
Exemple #3
0
bool
CMNGAnimation::Load(const char* filename, IFileSystem& fs)
{
  this->~CMNGAnimation();

  // open the file
  m_file = fs.Open(filename, IFileSystem::read);
  if (m_file == NULL) {
    return false;
  }

  // initialize MNG playback
  m_stream = mng_initialize(this, CB_Allocate, CB_Free, NULL);

  // set all of the callbacks
  mng_setcb_openstream(m_stream, CB_OpenStream);
  mng_setcb_closestream(m_stream, CB_CloseStream);
  mng_setcb_readdata(m_stream, CB_ReadData);
  mng_setcb_processheader(m_stream, CB_ProcessHeader);
  mng_setcb_gettickcount(m_stream, CB_GetTickCount);
  mng_setcb_getcanvasline(m_stream, CB_GetCanvasLine);
  mng_setcb_refresh(m_stream, CB_Refresh);
  mng_setcb_settimer(m_stream, CB_SetTimer);

  // do some reading
  if (mng_read(m_stream) != MNG_NOERROR) {
    return false;
  }

  return true;
}
Exemple #4
0
/**
**  Load a MNG
**
**  @param name  Name of the MNG file
*/
int Mng::Load(const std::string &name)
{
	this->name = LibraryFileName(name.c_str());
	handle = mng_initialize(this, my_alloc, my_free, MNG_NULL);
	if (handle == MNG_NULL) {
		return -1;
	}
	mng_setcb_openstream(handle, my_openstream);
	mng_setcb_closestream(handle, my_closestream);
	mng_setcb_readdata(handle, my_readdata);
	mng_setcb_processheader(handle, my_processheader);
	mng_setcb_processmend(handle, my_processmend);
	mng_setcb_getcanvasline(handle, my_getcanvasline);
	mng_setcb_refresh(handle, my_refresh);
	mng_setcb_gettickcount(handle, my_gettickcount);
	mng_setcb_settimer(handle, my_settimer);
	mng_setcb_errorproc(handle, my_errorproc);

	mng_read(handle);
	if (surface && iteration != 0x7fffffff) {
		mng_display(handle);
	}

	if (!surface || iteration == 0x7fffffff) {
		return -1;
	}
	return 0;
}
Exemple #5
0
/**
**  Load a MNG
**
**  @param name  Name of the MNG file
*/
int Mng::Load(const char *name)
{
	mng_retcode myretcode;
	char buf[PATH_MAX];

	LibraryFileName(name, buf, sizeof(buf));

	this->name = new_strdup(buf);
	handle = mng_initialize(this, my_alloc, my_free, MNG_NULL);
	if (handle == MNG_NULL) {
		return -1;
	}
	mng_setcb_openstream(handle, my_openstream);
	mng_setcb_closestream(handle, my_closestream);
	mng_setcb_readdata(handle, my_readdata);
	mng_setcb_processheader(handle, my_processheader);
	mng_setcb_processmend(handle, my_processmend);
	mng_setcb_getcanvasline(handle, my_getcanvasline);
	mng_setcb_refresh(handle, my_refresh);
	mng_setcb_gettickcount(handle, my_gettickcount);
	mng_setcb_settimer(handle, my_settimer);
	mng_setcb_errorproc(handle, my_errorproc);

	mng_read(handle);
	if (surface && iteration != 0x7fffffff) {
		myretcode = mng_display(handle);
	}

	if (!surface || iteration == 0x7fffffff) {
		return -1;
	}
	return 0;
}
Exemple #6
0
int main(int argc, char **argv)
{
	int i, rc;

	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
	SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
	SDL_EventState(SDL_QUIT, SDL_ENABLE);

	for (i = 1; i < argc; i++) {
		if (argv[i][0] == '-') {
			switch (argv[i][1]) {
			case 'h':
				usage(argc, argv);
				return 0;
			default:
				usage(argc, argv);
				return 1;
			}
			continue;
		}
		rc = mng_read(argv[i], argv[i], mng_callback);
		if (rc < 0)
			fprintf(stderr, "reading '%s' returned %d\n", argv[i], rc);
	}

	return 0;
}
Exemple #7
0
//---------------------------------------------------------------------------
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;
}
Exemple #8
0
/**
 * Read a MNG image.
 * This function returns always a null dat_ptr pointer because the
 * referenced image is stored in the mng context.
 * \param mng MNG context previously returned by mng_init().
 * \param pix_width Where to put the image width.
 * \param pix_height Where to put the image height.
 * \param pix_pixel Where to put the image bytes per pixel.
 * \param dat_ptr Where to put the allocated data pointer.
 * \param dat_size Where to put the allocated data size.
 * \param pix_ptr Where to put pointer at the start of the image data.
 * \param pix_scanline Where to put the length of a scanline in bytes.
 * \param pal_ptr Where to put the allocated palette data pointer. Set to 0 if the image is RGB.
 * \param pal_size Where to put the palette size in number of colors. Set to 0 if the image is RGB.
 * \param tick Where to put the number of tick of the frame. The effective time can be computed dividing by mng_frequency_get().
 * \param f File to read. 
 * \return
 *   - == 0 ok
 *   - == 1 end of the mng stream
 *   - < 0 error
 */
adv_error adv_mng_read(
	adv_mng* mng,
	unsigned* pix_width, unsigned* pix_height, unsigned* pix_pixel,
	unsigned char** dat_ptr, unsigned* dat_size,
	unsigned char** pix_ptr, unsigned* pix_scanline,
	unsigned char** pal_ptr, unsigned* pal_size,
	unsigned* tick,
	adv_fz* f)
{
	return mng_read(mng, pix_width, pix_height, pix_pixel,
		dat_ptr, dat_size, pix_ptr, pix_scanline,
		pal_ptr, pal_size, tick, f, 0);
}
Exemple #9
0
mng_handle mng_load(char* filename, int *width, int *height)
{
	mng_handle mngh;
	mng_anim *mng;

	mng = (mng_anim*)malloc(sizeof(mng_anim));
	if (!mng) {
		iprint(MSG_ERROR, "%s: Unable to allocate memory for MNG data\n",
				__FUNCTION__);
		return MNG_NULL;
	}

	memset(mng, 0, sizeof(mng_anim));
	mngh = mng_initialize(mng, fb_mng_memalloc, fb_mng_memfree,
			MNG_NULL);
	if (mngh == MNG_NULL) {
		iprint(MSG_ERROR, "%s: mng_initialize failed\n", __FUNCTION__);
		goto freemem_fail;
	}

	if (mng_init_callbacks(mngh)) {
		print_mng_error(mngh, "mng_init_callbacks failed");
		goto cleanup_fail;
	}

	/* Load the file into memory */
	if (!mng_readfile(mngh, filename))
		goto cleanup_fail;

	/* Read and parse the file */
	if (mng_read(mngh) != MNG_NOERROR) {
		/* Do something about it. */
		print_mng_error(mngh, "mng_read failed");
		goto cleanup_fail;
	}

	mng->num_frames = mng_get_totalframes(mngh);
	*width = mng->canvas_w;
	*height = mng->canvas_h;

	return mngh;

cleanup_fail:
	mng_cleanup(&mngh);
freemem_fail:
	free(mng);
	return MNG_NULL;
}
Exemple #10
0
/**
 * Read a MNG image and implicitely call adv_mng_done().
 * This function returns always a not null dat_ptr pointer.
 * The mng context is always destroyed. Also if an error
 * is returned.
 */
adv_error adv_mng_read_done(
	adv_mng* mng,
	unsigned* pix_width, unsigned* pix_height, unsigned* pix_pixel,
	unsigned char** dat_ptr, unsigned* dat_size,
	unsigned char** pix_ptr, unsigned* pix_scanline,
	unsigned char** pal_ptr, unsigned* pal_size,
	unsigned* tick,
	adv_fz* f)
{
	adv_error r;

	r = mng_read(mng, pix_width, pix_height, pix_pixel,
		dat_ptr, dat_size, pix_ptr, pix_scanline,
		pal_ptr, pal_size, tick, f, 1);

	if (r != 0)
		free(mng->dat_ptr);
	free(mng->dlt_ptr);
	free(mng);

	return r;
}
Exemple #11
0
bool ImageJngFile::Load (uint8 *iBuffer, size_t iSize)
{
  mng_retcode retcode;

  const int magicSize = 8;
  const char magicMNG[] = "\x8aMNG\x0d\x0a\x1a\x0a";
  const char magicJNG[] = "\x8bJNG\x0d\x0a\x1a\x0a";

  // check for magic JNG/MNG bytes. If not correct, we can skip
  // messing around w/ libmng entirely.
  if ((iSize < 8) || 
    ((memcmp ((void*)iBuffer, (void*)&magicMNG, magicSize)) &&
     (memcmp ((void*)iBuffer, (void*)&magicJNG, magicSize))))
  {
    return false;
  }

  handle = mng_initialize (mng_ptr(this), cb_alloc, 
                           cb_free, MNG_NULL);
  if (!handle)
  {
    Report (object_reg, CS_REPORTER_SEVERITY_WARNING,
      "failed to initialize libmng");
    return false;
  }

  buffer = iBuffer;
  bufptr = buffer;
  bufferSize = iSize;

  if ((mng_setcb_openstream (handle, cb_openstream) != MNG_NOERROR) ||
      (mng_setcb_closestream (handle, cb_closestream) != MNG_NOERROR) ||
      (mng_setcb_readdata (handle, cb_readdata) != MNG_NOERROR) ||
      (mng_setcb_processheader(handle, cb_processheader) != MNG_NOERROR) ||
      (mng_setcb_getcanvasline(handle, cb_getcanvasline) != MNG_NOERROR) ||
      (mng_setcb_refresh(handle, cb_imagerefresh) != MNG_NOERROR) ||
      (mng_setcb_gettickcount(handle, cb_gettickcount) != MNG_NOERROR) ||
      (mng_setcb_settimer(handle, cb_settimer) != MNG_NOERROR))
  {
    ReportLibmngError (object_reg, handle, "failed to set libmng callbacks");
    mng_cleanup (&handle);
    return false;
  }

  retcode = mng_read (handle);
  if (retcode != MNG_NOERROR)
  {
    if (retcode != MNG_INVALIDSIG) // maybe its just not an jng/mng...
      ReportLibmngError (object_reg, handle, "failed to read data");
    mng_cleanup (&handle);
    return false;
  }

  // Don't read PNGs 
  if (mng_get_sigtype (handle) == mng_it_png)
  {
    delete[] NewImage;
    mng_cleanup (&handle);
    return false;
  }

  // Even on still images, libmng issues timer requests.
  // so, as long as the requests are 'immediate' we continue
  // displaying. If a delay is requested we end loading.
  timer = 2;
  retcode = mng_display (handle);
  while ((retcode == MNG_NEEDTIMERWAIT) && (timer <= 1))
  {
    retcode = mng_display_resume (handle);
  }
  if ((retcode != MNG_NOERROR) && (retcode != MNG_NEEDTIMERWAIT))
  {
    ReportLibmngError (object_reg, handle, "failed to display data");
    mng_cleanup (&handle);
    return false;
  }
  doWait = (retcode == MNG_NEEDTIMERWAIT);
  animated = doWait;

  if (NewImage)
  {
    csRGBpixel *rgbImage = 
      csPackRGBA::CopyUnpackRGBAtoRGBpixel (NewImage, Width*Height);
    ConvertFromRGBA (rgbImage);
    // Subsequent images may contain alpha, so don't check
    if (!doWait) CheckAlpha();
  }

  if (mng_get_sigtype (handle) != mng_it_mng)
  {
    delete[] NewImage; NewImage = 0;
    mng_cleanup (&handle);
    handle = 0;
  }

  return true;
}
Exemple #12
0
/**
 * \brief MPlayer callback: Open MNG stream.
 * \param[in] demuxer demuxer structure
 * \return demuxer structure on success, \p NULL on error
 */
static demuxer_t * demux_mng_open(demuxer_t * demuxer)
{
    mng_priv_t * mng_priv;
    mng_handle h_mng;
    mng_retcode mng_ret;
    sh_video_t * sh_video;

    // create private data structure
    mng_priv = calloc(1, sizeof(mng_priv_t));

    //stream pointer into private data
    mng_priv->stream = demuxer->stream;

    // initialize MNG image instance
    h_mng = mng_initialize((mng_ptr)mng_priv, demux_mng_alloc,
                           demux_mng_free, MNG_NULL);
    if (!h_mng) {
        mp_msg(MSGT_DEMUX, MSGL_ERR,
               "demux_mng: could not initialize MNG image instance\n");
        free(mng_priv);
        return NULL;
    }

    // MNG image handle into private data
    mng_priv->h_mng = h_mng;

    // set required MNG callbacks
    if (mng_setcb_openstream(h_mng, demux_mng_openstream) ||
        mng_setcb_closestream(h_mng, demux_mng_closestream) ||
        mng_setcb_readdata(h_mng, demux_mng_readdata) ||
        mng_setcb_processheader(h_mng, demux_mng_processheader) ||
        mng_setcb_getcanvasline(h_mng, demux_mng_getcanvasline) ||
        mng_setcb_refresh(h_mng, demux_mng_refresh) ||
        mng_setcb_gettickcount(h_mng, demux_mng_gettickcount) ||
        mng_setcb_settimer(h_mng, demux_mng_settimer) ||
        mng_set_canvasstyle(h_mng, MNG_CANVAS_RGBA8)) {
        mp_msg(MSGT_DEMUX, MSGL_ERR,
               "demux_mng: could not set MNG callbacks\n");
        mng_cleanup(&h_mng);
        free(mng_priv);
        return NULL;
    }

    // start reading MNG data
    mng_ret = mng_read(h_mng);
    if (mng_ret) {
        mp_msg(MSGT_DEMUX, MSGL_ERR,
               "demux_mng: could not start reading MNG data: "
               "mng_retcode %d\n", mng_ret);
        mng_cleanup(&h_mng);
        free(mng_priv);
        return NULL;
    }

    // check that MNG header is processed now
    if (!mng_priv->header_processed) {
        mp_msg(MSGT_DEMUX, MSGL_ERR,
               "demux_mng: internal error: header not processed\n");
        mng_cleanup(&h_mng);
        free(mng_priv);
        return NULL;
    }

    // create a new video stream header
    sh_video = new_sh_video(demuxer, 0);

    // Make sure the demuxer knows about the new video stream header
    // (even though new_sh_video() ought to take care of it).
    // (Thanks to demux_gif.c for this.)
    demuxer->video->sh = sh_video;

    // Make sure that the video demuxer stream header knows about its
    // parent video demuxer stream (this is getting wacky), or else
    // video_read_properties() will choke.
    // (Thanks to demux_gif.c for this.)
    sh_video->ds = demuxer->video;

    // set format of pixels in video packets
    sh_video->format = mmioFOURCC(32, 'B', 'G', 'R');

    // set framerate to some value (MNG does not have a fixed framerate)
    sh_video->fps       = 5.0f;
    sh_video->frametime = 1.0f / sh_video->fps;

    // set video frame parameters
    sh_video->bih                = malloc(sizeof(*sh_video->bih));
    sh_video->bih->biCompression = sh_video->format;
    sh_video->bih->biWidth       = mng_priv->width;
    sh_video->bih->biHeight      = mng_priv->height;
    sh_video->bih->biBitCount    = 32;
    sh_video->bih->biPlanes      = 1;

    // Set start time to something > 0.
    //  - This is required for the variable frame time mechanism
    //    (GIF, MATROSKA, MNG) in video.c to work for the first frame.
    sh_video->ds->pts = MNG_START_PTS;

    // set private data in demuxer and return demuxer
    demuxer->priv = mng_priv;
    return demuxer;
}
Exemple #13
0
static bool sReadMNG(Stream &stream, GBitmap *bitmap)
{
   PROFILE_SCOPE(sReadMNG);
   mngstuff mnginfo;
   dMemset(&mnginfo, 0, sizeof(mngstuff));

   mng_handle mng = mng_initialize(&mnginfo, mngMallocFn, mngFreeFn, MNG_NULL);
   if(mng == NULL)
      return false;
   
   // setup the callbacks
   mng_setcb_errorproc(mng, mngFatalErrorFn);
   mng_setcb_openstream(mng, mngOpenDataFn);
   mng_setcb_closestream(mng, mngCloseDataFn);
   mng_setcb_readdata(mng, mngReadDataFn);
   mng_setcb_processheader(mng, mngProcessHeaderFn);
   mng_setcb_getcanvasline(mng, mngCanvasLineFn);
   mng_setcb_refresh(mng, mngRefreshFn);
   mng_setcb_gettickcount(mng, mngGetTicksFn);
   mng_setcb_settimer(mng, mngSetTimerFn);
   
   mnginfo.image = bitmap;
   mnginfo.stream = &stream;
   
   mng_read(mng);
   mng_display(mng);

   // hacks :(
   // libmng doesn't support returning data in gray/gray alpha format, 
   // so we grab as RGB/RGBA and just cut off the g and b
   mng_uint8 colorType = mng_get_colortype(mng);
   switch(colorType)
   {
      case MNG_COLORTYPE_GRAY:
      case MNG_COLORTYPE_JPEGGRAY:
         {
            GBitmap temp(*bitmap);
            bitmap->deleteImage();
            bitmap->allocateBitmap(temp.getWidth(), temp.getHeight(), false, GFXFormatA8);
            
            // force getColor to read in in the same color value for each channel
            // since the gray colortype has the real alpha in the first channel
            temp.setFormat( GFXFormatA8 );

            ColorI color;
            for(U32 row = 0; row < bitmap->getHeight(); row++)
            {
               for(U32 col = 0; col < bitmap->getWidth(); col++)
               {
                  temp.getColor(col, row, color);
                  bitmap->setColor(col, row, color);
               }
            }
         }

         break;
   }

   mng_cleanup(&mng);

   // Check this bitmap for transparency
   bitmap->checkForTransparency();

   return true;
}
Exemple #14
0
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;
}