bool LogAverage::ComputeLuminance (RenderTreeBase& renderTree, iView* view,
	                                   float& averageLuminance, float& maxLuminance,
	                                   float& maxComponent, float& usedColorScale)
	{
	  int W, H;
	  csRef<iDataBuffer> computeData = GetResultData (renderTree, view, W, H,
	    usedColorScale);
	  if (computeData.IsValid ())
	  {
	    const float* rgba = (float*)computeData->GetData();
	    int numPixels = W * H;
	    float lumSum = 0;
	    float maxLum = 0;
	    float maxComp = 0;
	    for (int i = 0; i < numPixels; i++)
	    {
	      float r = *rgba++;
	      float g = *rgba++;
	      float b = *rgba++;
	      rgba++;
	      lumSum += g;
	      maxLum = csMax (maxLum, r);
	      maxComp = csMax (maxComp, b);
	    }
	    
	    int numOrgPixels = view->GetContext ()->GetWidth ()
	      * view->GetContext ()->GetHeight ();
	    averageLuminance = expf (1.0f/numOrgPixels * lumSum);
	    maxLuminance = maxLum;
	    maxComponent = maxComp;
	    return true;
	  }
	  return false;
	}
	bool Average::ComputeLuminance (RenderTreeBase& renderTree, iView* view,
	                                float& averageLuminance, float& maxLuminance,
	                                float& usedColorScale)
	{
	  int W, H;
	  csRef<iDataBuffer> computeData = GetResultData (renderTree, view, W, H,
	    usedColorScale);
	  if (computeData.IsValid ())
	  {
	    const uint8* bgra = computeData->GetUint8();
	    int numPixels = W * H;
	    float totalLum = 0;
	    float maxLum = 0;
	    for (int i = 0; i < numPixels; i++)
	    {
	      int b = *bgra++;
	      int g = *bgra++;
	      int r = *bgra++;
	      int a = *bgra++;
	      totalLum += (g+a)/510.0f;
	      if (b > r)
	        maxLum = csMax (maxLum, b/255.0f);
	      else
	        maxLum = csMax (maxLum, r/255.0f);
	    }
	    
	    averageLuminance = (totalLum / numPixels) * colorScale;
	    maxLuminance = maxLum;
	    return true;
	  }
	  return false;
	}
/*****************************************************************
 *          同 步 GET          *
 *****************************************************************/
HTTP_RESULTCODE	CHttp::SyncDownload(const std::string &strUrl, std::string & strResult)
{
	if (strUrl.empty())
	{
		return HTTPRESULT_FAIL;
	}

	if( m_bRunning )
	{
		return HTTPRESULT_FAIL;
	}

	m_bRunning	= true;
	Reset();	
	m_strUrl = strUrl;

	CURLcode eErrorCode = DoHttpGet();
	bool  bResult = GetResultData(strResult);
	m_bRunning	= false;

	if (bResult && CURLE_OK == eErrorCode)
	{
		return HTTPRESULT_OK;
	}	

	return GetErrorCode(eErrorCode);
}
/********************************************************************
 *         同 步 POST  ,Content-type: multipart/form-data            *
 *********************************************************************/
HTTP_RESULTCODE	CHttp::SyncUploadFormData(const std::string & strUrl, const std::map<std::string,std::string> & mapData, const std::map<std::string,std::string> & mapFile, std::string & strResult)
{
	if (strUrl.empty())
	{
		return HTTPRESULT_FAIL;
	}

	if( m_bRunning )
	{
		return HTTPRESULT_FAIL;
	}

	m_bRunning  = true;
	Reset();

	m_strUrl			  = strUrl;
	m_mapPostData =  mapData;
	m_mapPostFile	  =  mapFile;

	CURLcode eErrorCode = DoHttpPostFormData();
	std::string strTemp;
	bool  bResult = GetResultData(strResult);
	
	m_bRunning  = false;

	if (bResult && eErrorCode == CURLE_OK)
	{
		return HTTPRESULT_OK;
	}

	return GetErrorCode(eErrorCode);
}
Example #5
0
std::string AnswerGenerator::GetElement( DataElement element, const MatchedTemplate & matchedTemplate, const DBResultList & dbResultList )
{
	switch( element )
	{
	case FOCUS_TAG:
		return GetTagName( "focus", matchedTemplate );
	case FOCUS_TEXT:
		return GetWord( "focus", matchedTemplate );
	case TARGET_TAG:
		return GetTagName( "target", matchedTemplate );
	case TARGET_TEXT:
		return GetWord( "target", matchedTemplate );
	case COMPONENT1_TAG:
		return GetTagName( "component1", matchedTemplate );
	case COMPONENT1_TEXT:
		return GetWord( "component1", matchedTemplate );
	case COMPONENT2_TAG:
		return GetTagName( "component2", matchedTemplate );
	case COMPONENT2_TEXT:
		return GetWord( "component2", matchedTemplate );
	case RESULT_VALUE:
		return GetResultData( matchedTemplate._questionNo, dbResultList );
	case RESULT_LIST:
		return GetResultDataList( matchedTemplate._questionNo, dbResultList );
	}
	return "%?%";
}
Example #6
0
 unsigned GetResultData(__int64 start, int count, ITable * result) const
 {
     clib::recursive_mutex::scoped_lock proc(m_mutex);
     __int64 total;
     unsigned retVal = GetResultData(start, count, result, total);
     if (m_total && m_total < total)
         total = m_total;
     return retVal;
 }