示例#1
0
文件: readGIFplc.c 项目: afni/rmafni
/*****
* Name: 		_PLC_GIF_ScanlineProc
* Return Type: 	void
* Description: 	GZF scanline processor (decompresses data and orders it)
* In: 
*	plc:		current PLC
* Returns:
*	nothing.
*****/
void
_PLC_GIF_ScanlineProc(PLC *plc)
{
	Byte *input = NULL;
	PLCImageGIF *gif;
	Boolean done = False;
	int bytes_avail;

	_XmHTMLDebug(15, ("plc.c: _PLC_GIF_ScanlineProc for %s\n", plc->url));

	gif = &(plc->object->plc_gif_image);

	/*****
	* We can choose between two types of LZW decoders: the internal one or
	* an externally installed progressive decoder.
	* The internal decoder is fairly efficient for direct gif loading, but is
	* *HUGELY* slow for progressive gif loading: it forks of uncompress (or
	* gzip) each time LZWStreamUncompress is called. Therefore we collect
	* all data and call the internal decoder when all image data has been
	* received.
	* When an external gif decoder has been installed, we just proceed in the
	* same way as with the GZF scanline procedure: decode a chunk of data
	* each time and allow it to be transfered to the display.
	*****/
	if(gif->external_codec == False)
	{
		int len;
		Boolean have_all = False;
		bytes_avail = plc->left;

#ifndef PLC_WORKPROCS 
		do
		{
#endif	/* !PLC_WORKPROCS */

			/*****
			* get a new block of compressed data. This will automatically make
			* a new request for input data when there isn't enough data left
			* in the current input buffer.
			*****/
			if((len = _PLCGetDataBlock(plc, gif->gbuf)) != 0)
			{
				/* store block size */
				gif->ib.buffer[gif->ib.size++] = (Byte)len;

				/* append newly received data */
				(void)memcpy(gif->ib.buffer + gif->ib.size,
					gif->gbuf, len);

				/* new buffer size */
				gif->ib.size += len;

				/* bytes left in current buffer (+1 for block header) */
				bytes_avail -= (len + 1);

				/* prevent image transfer function from doing anything */
				gif->prev_pos = gif->data_pos = 0;
			}
			else
			{
				if(plc->plc_status == PLC_SUSPEND ||
					plc->plc_status == PLC_ABORT)
					return;
				/*
				* if plc_status == PLC_ACTIVE, we have a zero data block which
				* indicates the raster data end. For now we just consider this
				* as the end signal and start decoding the raster data.
				* For gif animations this would be the place to move to the
				* next frame.
				*/
				have_all = True;

				/* plug in a zero length data block and GIF terminator */
				gif->ib.buffer[gif->ib.size++] = (Byte)0;
				gif->ib.buffer[gif->ib.size++] = (Byte)1;
				gif->ib.buffer[gif->ib.size++] = (Byte)';';

			}
#ifndef PLC_WORKPROCS 
		}
		/* This test will be false if we made a new data request */
		while(bytes_avail == plc->left && have_all == False);
#endif	/* !PLC_WORKPROCS */

		/* we have got all image data, now decode it */
		if(have_all)
		{
			/* rewind image buffer */
			gif->ib.next = 0;

			/* now (re-)initialize the stream object */
			if((LZWStreamInit(gif->lstream)) <= 0)
			{
				/* this is an error */
				_XmHTMLWarning(__WFUNC__(plc->object->plc_any_image.owner,
					"_PLC_GIF_ScanlineProc"), gif->lstream->err_msg);
				plc->plc_status = PLC_ABORT;
				return;
			}

			/* convert data */
			LZWStreamConvert(gif->lstream);

			/* get uncompressed data */
			if((input = LZWStreamUncompress(gif->lstream,
				(int*)&gif->byte_count)) == NULL)
			{
				_XmHTMLWarning(__WFUNC__(plc->object->plc_any_image.owner,
					"_PLC_GIF_ScanlineProc"), gif->lstream->err_msg);
				/* rather fatal... */
				_XmHTMLWarning(__WFUNC__(plc->object->plc_any_image.owner,
					"_PLC_GIF_ScanlineProc"), XMHTML_MSG_114, plc->url);
				plc->plc_status = PLC_ABORT;
				return;
			}

			/* convert input data to raw image data */
			(void)DoImage((PLCImage*)gif, input);

			/* free input buffer */
			free(input);

			/* we are finished here */
			plc->obj_funcs_complete = True;
		}
	}
	else
	{
		/*****
		* External GIF decoder installed, proceeds in the same way as the
		* GZF decoder, except that now the external decoder is called
		* instead of the zlib routines.
		*****/
		XmHTMLGIFStream *gifstream = gif->gstream;
		int err;

		bytes_avail = plc->left;

#ifndef PLC_WORKPROCS 
		do
		{
#endif	/* !PLC_WORKPROCS */
			/*****
			* get a new block of compressed data. This will automatically make
			* a new request for input data when there isn't enough data left
			* in the current input buffer.
			*****/
			if((gifstream->avail_in =
					_PLCGetDataBlock(plc, gif->gbuf)) == 0)
			{
				if(plc->plc_status == PLC_SUSPEND ||
					plc->plc_status == PLC_ABORT)
					return;
				/*
				* if plc_status == PLC_ACTIVE, we have a zero data block which
				* indicates the raster data end. Put in a 0 length data
				* block, the gif terminator, set the gifstream state so the
				* caller knows to wrap things up and proceed.
				*/
				gif->gbuf[0] = (Byte)0;
				gif->gbuf[1] = (Byte)1;
				gif->gbuf[2] = (Byte)';';
				gifstream->avail_in = 3;
				gifstream->state = GIF_STREAM_FINAL;
			}

			gifstream->next_in = gif->gbuf;

			/* bytes left in current buffer (+1 for block header) */
			bytes_avail -= (gifstream->avail_in + 1);

			/* adjust output buffer */
			gifstream->next_out  = gif->buffer + gifstream->total_out;
			gifstream->avail_out = gif->buf_size - gifstream->total_out;

			/* uncompress it */
			err = gif->inflate(gifstream);

			/* check return value */
			if(err != GIF_STREAM_OK && err != GIF_STREAM_END)
			{
				_XmHTMLWarning(__WFUNC__(NULL, "_PLC_GIF_ScanlineProc"),
					XMHTML_MSG_115, plc->url,
					gifstream->msg ? gifstream->msg : "(unknown error)");
				plc->plc_status = PLC_ABORT;
				return;
			}

			/* this many uncompressed bytes available now */
			gif->byte_count = gifstream->total_out;

			/* convert input data to raw image data */
			done = DoImage((PLCImage*)gif, gif->buffer);

			/* and break if inflate has finished uncompressing our data. */
			if(err == GIF_STREAM_END || done == True)
				plc->obj_funcs_complete = True;
#ifndef PLC_WORKPROCS 
		}
		/* This test will be false if we made a new data request */
		while(bytes_avail == plc->left);
#endif	/* !PLC_WORKPROCS */
	}
}
示例#2
0
文件: readGIFplc.c 项目: afni/rmafni
/*****
* Name: 		_PLC_GZF_ScanlineProc
* Return Type: 	void
* Description: 	GZF scanline processor (decompresses data and orders it)
* In: 
*	plc:		current PLC
* Returns:
*	nothing.
*****/
void
_PLC_GZF_ScanlineProc(PLC *plc)
{
	int err, bytes_avail;
	PLCImageGZF *gzf;
	Boolean done = False;

	_XmHTMLDebug(15, ("plc.c: _PLC_GZF_ScanlineProc for %s\n", plc->url));

	gzf = &(plc->object->plc_gzf_image);

	/* bytes left in current input buffer */
	bytes_avail = plc->left;

#ifndef PLC_WORKPROCS 
	do
	{
#endif	/* !PLC_WORKPROCS */
		/*****
		* get a new block of compressed data. This will automatically make
		* a new request for input data when there isn't enough data left
		* in the current input buffer.
		*****/
		if((gzf->zstream.avail_in = _PLCGetDataBlock(plc, gzf->zbuf)) == 0)
		{
			/*
			* if plc_status == PLC_ACTIVE, we have a zero data block which
			* indicates the raster data end. For now we just consider this
			* as the end signal and return without further processing.
			* For gif animations this would be the place to move to the next
			* frame.
			*/
			return;	/* aborted, date ended or plc suspended */
		}
		gzf->zstream.next_in = gzf->zbuf;

		/* bytes left in current buffer (+1 for block header) */
		bytes_avail -= (gzf->zstream.avail_in + 1);

		/* adjust output buffer */
		gzf->zstream.next_out  = gzf->buffer + gzf->zstream.total_out;
		gzf->zstream.avail_out = gzf->buf_size - gzf->zstream.total_out;

		/* uncompress it */
		err = inflate(&gzf->zstream, Z_PARTIAL_FLUSH);	

		/* check return value */
		if(err != Z_OK && err != Z_STREAM_END)
		{
			_XmHTMLWarning(__WFUNC__(NULL, "_PLC_GZF_ScanlineProc"),
				XMHTML_MSG_108, plc->url, "", gzf->zstream.msg);
			plc->plc_status = PLC_ABORT;
			return;
		}

		/* this many uncompressed bytes available now */
		gzf->byte_count = gzf->zstream.total_out;

		/* convert input data to raw image data */
		done = DoImage((PLCImage*)gzf, gzf->buffer);

		/* and break if inflate has finished uncompressing our data. */
		if(err == Z_STREAM_END || done == True)
			plc->obj_funcs_complete = True;
#ifndef PLC_WORKPROCS 
	}
	/* This test will be false if we made a new data request */
	while(bytes_avail == plc->left);
#endif	/* !PLC_WORKPROCS */
}
示例#3
0
void CLuaUi::Tick()
{
    if (!m_Used)
        return;
    if (m_Type == LUAUIBUTTON)
    {
        int state = DoButton_Menu(&m_Id, m_pText, m_Checked, &m_Rect, m_Corners, m_Color);
        if (state != 0)
        {
            if (!m_pLuaFile->FunctionExist(m_pCallback))
                return;
            m_pLuaFile->FunctionPrepare(m_pCallback);
            m_pLuaFile->PushInteger(state);
            m_pLuaFile->PushInteger(m_Id);
            m_pLuaFile->FunctionExec();
        }
    }
    else if(m_Type == LUAUIEDITBOX)
    {
        DoEditBox(&m_Id, &m_Rect, m_pText, sizeof(m_pText), m_FontSize, &m_Offset, m_Hidden, m_Corners, m_Color);
    }
    else if(m_Type == LUAUILABEL)
    {
        CUIRect *pRect = &m_Rect;
        CUIRect Temp;
        pRect->HMargin(pRect->h>=20.0f?2.0f:1.0f, &Temp);
        m_pClient->TextRender()->TextColor(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
        if (m_Align == -1)
            m_pClient->UI()->DoLabelScaled(&Temp, m_pText, m_FontSize*ms_FontmodHeight, m_Align, Temp.w);
        else
            m_pClient->UI()->DoLabelScaled(&Temp, m_pText, m_FontSize*ms_FontmodHeight, m_Align);
        m_pClient->TextRender()->TextColor(1, 1, 1, 1);
    }
    else if(m_Type == LUAUIRECT)
    {
        CUIRect *pRect = &m_Rect;
        m_pClient->RenderTools()->DrawUIRect(pRect, m_Color, m_Corners, m_Rounding);
    }
    else if(m_Type == LUAUIIMAGE)
    {
        CUIRect *pRect = &m_Rect;
        int state = DoImage(&m_Id, m_TextureID, m_SpriteID, pRect);
        if (state != 0)
        {
            if (!m_pLuaFile->FunctionExist(m_pCallback))
                return;
            m_pLuaFile->FunctionPrepare(m_pCallback);
            m_pLuaFile->PushInteger(state);
            m_pLuaFile->PushInteger(m_Id);
            m_pLuaFile->FunctionExec();
        }
    }
    else if(m_Type == LUAUIIMAGEEX)
    {
        CUIRect *pRect = &m_Rect;
        int state = DoImageEx(&m_Id, m_TextureID, pRect, m_ClipX1,  m_ClipY1,  m_ClipX2,  m_ClipY2);
        if (state != 0)
        {
            if (!m_pLuaFile->FunctionExist(m_pCallback))
                return;
            m_pLuaFile->FunctionPrepare(m_pCallback);
            m_pLuaFile->PushInteger(state);
            m_pLuaFile->PushInteger(m_Id);
            m_pLuaFile->FunctionExec();
        }
    }
    else if(m_Type == LUAUILINE)
    {
        m_pClient->Graphics()->TextureSet(-1);
        m_pClient->Graphics()->BlendNormal();
        m_pClient->Graphics()->LinesBegin();
        m_pClient->Graphics()->SetColor(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
        IGraphics::CLineItem Line;
        Line = IGraphics::CLineItem(m_Rect.x, m_Rect.y, m_Rect.w, m_Rect.h);
        m_pClient->Graphics()->LinesDraw(&Line, 1);
        m_pClient->Graphics()->LinesEnd();
    }
    else if(m_Type == LUAUISLIDER)
    {
        float NewValue = 0;
        if (m_Direction == 0)
        {
            NewValue = DoScrollbarH(&m_Id, &m_Rect, m_Value, m_Color);
        }
        else
        {
            NewValue = DoScrollbarV(&m_Id, &m_Rect, m_Value, m_Color);
        }
        if (m_Value != NewValue)
        {
            m_Value = NewValue;
            if (!m_pLuaFile->FunctionExist(m_pCallback))
                return;
            m_pLuaFile->FunctionPrepare(m_pCallback);
            m_pLuaFile->PushFloat(m_Value);
            m_pLuaFile->PushInteger(m_Id);
            m_pLuaFile->FunctionExec();
        }
    }
}