Пример #1
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();
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
0
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
	mng_handle hmng = NULL;

	if (handle != NULL) {
		try {
			// allocate our stream data structure
			mngstuff *mymng = (mngstuff *)data;

			// set up the mng decoder for our stream
			hmng = mng_initialize(mymng, mymngalloc, mymngfree, MNG_NULL);

			if (hmng == MNG_NULL) {
				throw "could not initialize libmng";			
			}
			
			// set the colorprofile, lcms uses this
			mng_set_srgb(hmng, MNG_TRUE );
			// set white as background color
			WORD wRed, wGreen, wBlue;
			wRed = wGreen = wBlue = (255 << 8) + 255;
			mng_set_bgcolor(hmng, wRed, wGreen, wBlue);
			// if PNG Background is available, use it
			mng_set_usebkgd(hmng, MNG_TRUE );
			// no need to store chunks
			mng_set_storechunks(hmng, MNG_FALSE);
			// no need to wait: straight reading
			mng_set_suspensionmode(hmng, MNG_FALSE);

			// set the callbacks
			mng_setcb_errorproc(hmng, mymngerror);
			mng_setcb_openstream(hmng, mymngopenstream);
			mng_setcb_closestream(hmng, mymngclosestream);
			mng_setcb_readdata(hmng, mymngreadstream);
			mng_setcb_processheader(hmng, mymngprocessheader);
			mng_setcb_getcanvasline(hmng, mymnggetcanvasline);
			mng_setcb_refresh(hmng, mymngrefresh);
			mng_setcb_gettickcount(hmng, mymnggetticks);
			mng_setcb_settimer(hmng, mymngsettimer);
	
			// read in the bitmap
			mng_readdisplay(hmng);

			// read all bitmaps
			int retval = MNG_NOERROR;
			mng_datap pData = (mng_datap)hmng;
			while(pData->bReading) {
				retval = mng_display_resume(hmng);
				if((retval == MNG_NEEDTIMERWAIT) || (retval == MNG_FUNCTIONINVALID))
					break;
			}

			// temp store the newly created bitmap
			FIBITMAP *bitmap = mymng->bitmap;

			// cleanup and return the temp stored bitmap
			mng_cleanup(&hmng);

			return bitmap;

		} catch (const char *message) {
			FIBITMAP *bitmap = ((mngstuff *)mng_get_userdata(hmng))->bitmap;
			if(bitmap) {
				FreeImage_Unload(bitmap);
			}
			mng_cleanup(&hmng);
			FreeImage_OutputMessageProc(s_format_id, message);
		}
	}

	return NULL;
}	
Пример #5
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;
}
Пример #6
0
int main(int argc, char *argv[])
{
	int fbdev,c,option_index;
	unsigned int alpha;
	struct fb_var_screeninfo var;

	/* Check which console we're running on */
	init_consoles();
		
	/* allocate our stream data structure */
	mng = (mngstuff *) calloc(1, sizeof(*mng));
	if (mng == NULL) {
		fprintf(stderr, "could not allocate stream structure.\n");
		exit(0);
	}
	alpha = 100;
	mng->alpha = 100;
	mng->fbx = 15;
	mng->fby = 15;
	mng->background = NULL;

	while (1) {
		static struct option long_options[] = {
			{"help", 0, 0, 'h'},
			{"verbose", 0, 0, 'v'},
			{"alpha", 1, 0, 'a'},
			{"buffered", 0, 0, 'b'},
			{"signal", 0, 0, 's'},
			{"delta", 0, 0, 'd'},
			{"position", 0, 0, 'p'},
			{"version", 0, 0, 'V'},
			{"start-console",0,0,'S'},
			{"console",1,0,'c'},
			{0, 0, 0, 0}
		};

		c = getopt_long(argc, argv, "a:x:y:bh?vsd:pVSc:",
				long_options, &option_index);

		if (c == -1)
			break;

		switch (c) {
		case 'a':
			alpha = atoi(optarg);
			if (alpha > 100)
				alpha = 100;
			mng->alpha = alpha;
			break;
		case 'x':
			mng->fbx = atoi(optarg);
			break;
		case 'y':
			mng->fby = atoi(optarg);
			break;
		case 'd':
			delta = atoi(optarg);
			break;
		case '?':
		case 'h':
			usage(argv[0]);
			exit(0);
		case 'v':
			verbose = 1;
			break;
		case 's':
			waitsignal = 1;
			break;
		case 'b':
			buffered = 1;
			break;
		case 'p':
			dynpos = 1;
			break;
		case 'V':
			version();
			exit(0);
		case 'c':
			start_console=atoi(optarg);
		case 'S':
			sconly=1;
			break;
		default:
			break;
		}
	}

	if (optind >= argc) {
		printf("Which files do you want to play?\n");
		exit(0);
	}

	//init_consoles();
	
	/* Initialize framebuffer */
	fbdev = open("/dev/fb0", O_RDWR);
	if (fbdev < 0) {
		fprintf(stderr, "error while opening framebuffer.\n");
		exit(fbdev);
	}

	ioctl(fbdev, FBIOGET_VSCREENINFO, &var);
	mng->fbwidth = var.xres;
	mng->fbheight = var.yres;
	mng->fbbpp = var.bits_per_pixel;

	mng->display =
	    mmap(NULL, var.xres * var.yres * (var.bits_per_pixel >> 3),
		 PROT_WRITE | PROT_READ, MAP_SHARED, fbdev, 0);

	/* arrange to call the shutdown routine before we exit */
	atexit(&cleanup);

	while (optind < argc) {
		// leftover arguements are filenames.
		mng->filename = argv[optind++];

		/* set up the mng decoder for our stream */
		mng->mng = mng_initialize(mng, mngalloc, mngfree, MNG_NULL);
		if (mng->mng == MNG_NULL) {
			fprintf(stderr, "could not initialize libmng.\n");
			exit(1);
		}

		/* set the callbacks */
		mng_setcb_errorproc(mng->mng, mngerror);
		mng_setcb_openstream(mng->mng, mngopenstream);
		mng_setcb_closestream(mng->mng, mngclosestream);
		mng_setcb_readdata(mng->mng, mngreadstream);
		mng_setcb_gettickcount(mng->mng, mnggetticks);
		mng_setcb_settimer(mng->mng, mngsettimer);
		mng_setcb_processheader(mng->mng, mngprocessheader);
		mng_setcb_getcanvasline(mng->mng, mnggetcanvasline);
		mng_setcb_refresh(mng->mng, mngrefresh);
		/* FIXME: should check for errors here */

		signal(SIGINT, sigint_handler);
		signal(SIGTERM, sigterm_handler);

		mng_readdisplay(mng->mng);

		/* loop though the frames */
		while (mng->delay && run) {
			mdelay(mng->delay);
			mng->delay = 0;
			mng_display_resume(mng->mng);
			if (run == 2) {
				if (mng->alpha == 0)
					run = 0;
				mng->alpha -= delta;
				if (mng->alpha < 0)
					mng->alpha = 0;
			}
		}

		if (waitsignal && optind < argc) {
			signal(SIGUSR1, sigusr1_handler);
			run = 1;
			while (run) {
				sleep(2);
			}
		}

		memset(mng->copybuffer, 0,
		       4 * mng->width * mng->height);
		run = 1;
		mng->alpha = alpha;
		if (optind == argc) {	/* last file */
			restore_area();
		}
	}

	/* cleanup and quit */
	return mngquit(mng->mng);
}
Пример #7
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;
}