//  This actually creates our FG_Graphic object for a PNG
UT_Error IE_ImpGraphic_Win32Native::importGraphic(UT_ByteBuf* pBB, 
												  FG_Graphic ** ppfg)
{
	std::string mimetype;
    UT_Error err = _convertGraphic(pBB, mimetype); 
    if (err != UT_OK) return err;
    
    /* Send Data back to AbiWord as PNG */
    FG_GraphicRaster *pFGR;
    pFGR = new FG_GraphicRaster();
    
    if(pFGR == NULL)
		return UT_IE_NOMEMORY;
    
	if (mimetype == "image/jpeg")
	{
		if(!pFGR->setRaster_JPEG(m_pBB))
		{
			DELETEP(pFGR);
			return UT_IE_FAKETYPE;
		}
	}
	else
	{
		if(!pFGR->setRaster_PNG(m_pBB))
		{
			DELETEP(pFGR);	
			return UT_IE_FAKETYPE;
		}
	}
    
    *ppfg = static_cast<FG_Graphic *>(pFGR);
    
    return UT_OK;
}
/*!
 * Convert an image data buffer into PNG image buffer.
 */
UT_Error IE_ImpGraphic_GdkPixbuf::importGraphic(UT_ByteBuf * pBB, FG_Graphic ** ppfg)
{
	std::string mimetype;
	GdkPixbuf * pixbuf = pixbufForByteBuf ( pBB, mimetype );
	UT_Error err = UT_OK;

	if (!pixbuf)
	{
		UT_DEBUGMSG (("GdkPixbuf: couldn't get image from loader!\n"));
		return UT_ERROR;
	}
	FG_GraphicRaster * pFGR = new FG_GraphicRaster();
	if(pFGR == NULL)
	{
		g_object_unref(G_OBJECT(pixbuf));
		DELETEP(m_pPngBB);
		return UT_IE_NOMEMORY;
	}

	if(mimetype == "image/jpeg") 
	{
		m_pPngBB = pBB;
		pBB = NULL;
		if(!pFGR->setRaster_JPEG(m_pPngBB)) 
		{
			DELETEP(pFGR);
			DELETEP(m_pPngBB);
			return UT_IE_FAKETYPE;
		}
	}
	else {
		// Initialize stuff to create our PNG.
		err = Initialize_PNG();
		if (err)
		{
			g_object_unref(G_OBJECT(pixbuf));
			return err;
		}

		err = _png_write(pixbuf);

		if(err == UT_OK) {
		
			if(!pFGR->setRaster_PNG(m_pPngBB)) 
			{
				DELETEP(pFGR);
				DELETEP(m_pPngBB);
				return UT_IE_FAKETYPE;
			}
		
		}
	}
	*ppfg = static_cast<FG_Graphic *>(pFGR);
	return err;
}