bool fromNormalizedRGB(const float& _nr, const float& _ng, const float& _nb)
 {
   m_r = _nr * rMax();
   m_g = _ng * gMax();
   m_b = _nb * bMax();
   return true;
 }
 bool toNormalizedRGB(float& _nr, float& _ng, float& _nb) const
 {
   _nr = range(0.0f, m_r / rMax(), 1.0f);
   _ng = range(0.0f, m_g / gMax(), 1.0f);
   _nb = range(0.0f, m_b / bMax(), 1.0f);
   return true;
 }
Beispiel #3
0
void CDrawArea::SelfTest()
{
#ifdef _DEBUG
    CDrawArea a,b,c;
    CRect<int> rMax(0,0,640,400);
    CRect<int> r1(0,0,100,100);
    CRect<int> r2(0,0,500,300);
    CRect<int> r3(200,200,300,300);
    CRect<int> rTooBig(0,0,1000,1000);

    ASSERT(a.Size()==0);

    a.Combine(r1);
    ASSERT(a.Size()==1);
    ASSERT(a.Rect(0,rMax).Equals(r1));
    a.Combine(r3);
    ASSERT(a.Size()==2);
    ASSERT(a.Rect(0,rMax).Equals(r1));
    ASSERT(a.Rect(1,rMax).Equals(r3));
    a.Combine(r2);
    ASSERT(a.Size()==1);
    ASSERT(a.Rect(0,rMax).Equals(r2));
    a.Combine(rTooBig);
    ASSERT(a.Size()==1);
#endif
}
LRESULT CSkinWndHelper::OnSize(WPARAM wParam, LPARAM lParam)
{

	LRESULT lResult = CallWindowProc(m_oldWndProc,m_hWnd, WM_SIZE,wParam,lParam);

	UINT nType = wParam;
	int cx = LOWORD(lParam);
	int cy = HIWORD(lParam);


	if (nType != SIZE_MINIMIZED && nType != SIZE_MAXHIDE )
	{
		if (m_Rgn.m_hRgn)
		{
			m_Rgn.DeleteObject();
			m_Rgn.m_hRgn = NULL;
		}

		CRect rc;
		GetWindowRect(m_hWnd,&rc); //获得窗口矩形
		rc -= rc.TopLeft();
		m_Rgn.CreateRoundRectRgn(rc.left, rc.top,   rc.right+1, rc.bottom+1, 5, 5); //根据窗口矩形创建一个圆角矩形
		SetWindowRgn(m_hWnd,m_Rgn, TRUE); //根据圆角矩形指定的区域改变窗口的形状
	}

	CRect rcWnd;
	GetWindowRect(m_hWnd,&rcWnd);
	rcWnd.OffsetRect( -rcWnd.left, -rcWnd.top);

	if (m_bHaveMaxBox||m_bHaveMinBox)
	{
		CRect rMin(rcWnd.right - 74, 8, rcWnd.right-54, 30);
		m_TitleBtn[ID_MIN_BTN].SetRect(rMin);
		CRect rMax(rcWnd.right - 52, 8, rcWnd.right-32, 30);
		m_TitleBtn[ID_MAX_BTN].SetRect(rMax);
	}

	CRect rClose(rcWnd.right - 30, 8, rcWnd.right - 10, 30);
	m_TitleBtn[ID_CLOSE_BTN].SetRect(rClose);

	if (nType == SIZE_MAXIMIZED||
		nType == SIZE_RESTORED)
	{
		DoNcPaint();
	}

	return lResult;

}
 unsigned storeR() const
 {
   return roundf(range(0.0f, m_r, rMax()));
 }
Beispiel #6
0
/*! \brief Tests the **reduce_max** kernel.
 *  \details The kernel computes the maximum element of each row of an array. 
 */
TEST (Reduce, reduce_max)
{
    try
    {
        const unsigned int rows = 1024;
        const unsigned int cols = 1024;
        const unsigned int bufferInSize = cols * rows * sizeof (cl_uint);
        const unsigned int bufferOutSize = rows * sizeof (cl_uint);

        // Setup the OpenCL environment
        clutils::CLEnv clEnv;
        clEnv.addContext (0);
        clEnv.addQueue (0, 0, CL_QUEUE_PROFILING_ENABLE);
        clEnv.addProgram (0, kernel_filename_reduce);

        // Configure kernel execution parameters
        clutils::CLEnvInfo<1> info (0, 0, 0, { 0 }, 0);
        cl_algo::RBC::Reduce<cl_algo::RBC::ReduceConfig::MAX, cl_uint> rMax (clEnv, info);
        rMax.init (cols, rows);

        // Initialize data (writes on staging buffer directly)
        std::generate (rMax.hPtrIn, rMax.hPtrIn + bufferInSize / sizeof (cl_uint), RBC::rNum_R_0_1);
        // RBC::printBuffer ("Original:", rMax.hPtrIn, cols, rows);

        rMax.write ();  // Copy data to device
        
        rMax.run ();  // Execute kernels (~ 44 us)
        
        cl_uint *results = (cl_uint *) rMax.read ();  // Copy results to host
        // RBC::printBuffer ("Received:", results, 1, rows);

        // Produce reference array of distances
        cl_uint *refMax = new cl_uint[rows];
        auto func = [](cl_uint a, cl_uint b) -> bool { return a > b; };
        RBC::cpuReduce<cl_uint> (rMax.hPtrIn, refMax, cols, rows, func);
        // RBC::printBuffer ("Expected:", refMax, 1, rows);

        // Verify blurred output
        float eps = std::numeric_limits<float>::epsilon ();  // 1.19209e-07
        for (uint i = 0; i < rows; ++i)
            ASSERT_LT (std::abs (refMax[i] - results[i]), eps);

        // Profiling ===========================================================
        if (profiling)
        {
            const int nRepeat = 1;  /* Number of times to perform the tests. */

            // CPU
            clutils::CPUTimer<double, std::milli> cTimer;
            clutils::ProfilingInfo<nRepeat> pCPU ("CPU");
            for (int i = 0; i < nRepeat; ++i)
            {
                cTimer.start ();
                RBC::cpuReduce<cl_uint> (rMax.hPtrIn, refMax, cols, rows, func);
                pCPU[i] = cTimer.stop ();
            }
            
            // GPU
            clutils::GPUTimer<std::milli> gTimer (clEnv.devices[0][0]);
            clutils::ProfilingInfo<nRepeat> pGPU ("GPU");
            for (int i = 0; i < nRepeat; ++i)
                pGPU[i] = rMax.run (gTimer);

            // Benchmark
            pGPU.print (pCPU, "Reduce<MAX>");
        }

    }
    catch (const cl::Error &error)
    {
        std::cerr << error.what ()
                  << " (" << clutils::getOpenCLErrorCodeString (error.err ()) 
                  << ")"  << std::endl;
        exit (EXIT_FAILURE);
    }
}