1. 程式人生 > >vaps RGB畫素顯示控制元件

vaps RGB畫素顯示控制元件

1. 修改 vxtPLDisplay 工程,在vaps的圖形繪製層增加畫素繪製函式的宣告和定義

修改 vxtPLGraphicsImpl.h

VXT_PL_GRAPHICS_VIRTUAL_SPEC void vDrawPixels(const vxtRCoord& a_rBottomLeft, const vxtRCoord& a_rTopRight, void *pixel, int width, int height);

 修改 vxtPLGraphicsImplInl.h 

VXT_PL_GRAPHICS_INLINE_SPEC void vxtPLGraphicsImpl::vDrawPixels(const vxtRCoord& a_rBottomLeft, const vxtRCoord& a_rTopRight, void *pixel, int width, int height)
{
	const vxtRTMatrix2d &rMat = rGetMatrix();
	glRasterPos2i((rMat.m_11 * a_rBottomLeft.X) + (rMat.m_12 * a_rBottomLeft.Y) + rMat.m_13,
		(rMat.m_21 * a_rBottomLeft.X) + (rMat.m_22 * a_rBottomLeft.Y) + rMat.m_23);
	glDrawPixels(574, 574, GL_BGR_EXT, GL_UNSIGNED_BYTE, pixel);
}

2.  修改  vxtClsImage 工程,給圖片控制元件增加呼叫繪製畫素的功能

修改 vxtClsImage.h ,增加以下成員

   void CreateRenderTargetShareMemory(int size, TCHAR* name);
   void FreeShareMemory();
   HANDLE m_hMemRenderTarget;
   void *m_pMemRenderTarget;
   int m_nWidth;
   int m_nHeight;

修改vxtClsImage.cpp,增加成員函式

void vxtClsImage::CreateRenderTargetShareMemory(int size, TCHAR* name)
{
	m_hMemRenderTarget = CreateFileMapping((HANDLE)0xffffffffffffffff,
		NULL,
		PAGE_READWRITE,
		0,
		size,
		name);
	m_pMemRenderTarget = MapViewOfFile(m_hMemRenderTarget, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
}

void vxtClsImage::FreeShareMemory()
{
	UnmapViewOfFile(m_pMemRenderTarget);
	CloseHandle(m_hMemRenderTarget);
}

修改vxtClsImage.cpp,修改下面兩個程式函式

char testdata[574 * 574 * 3];

void vxtClsImage::vDraw(vxtRTDrawMode & a_rMode)
{
#if VXT_CGRUNTIME_MODE
   VXT_PRE_GROBJECT_VDRAW_PARAM_PRECONDITION;
   VXT_PRE(IsVisible());
   /// @pre This function must only be called from functions of ::vxtRTDrawMode.
#endif
   if (mp_AlphaValue == CREATE_VIDEO_IMAGE_1)
   {
#if 0
	   for (int i = 0; i < 574 * 574 * 3; i++)
	   {
		   if (i % 3 == 0)
			   testdata[i] = 255;
		   else if (i % 3 == 1)
			   testdata[i] = 0;
		   else if (i % 3 == 2)
			   testdata[i] = 0;
		   testdata[i] = rand() % 255;
	   }
#endif
	   vxtPLGraphics& rGraphics = a_rMode.rGetGraphics();
	   const vxtRTImage &rImage = mp_Index->rGetImage();
	   if (rImage.IsAllocated())
	   {
		   vxtRCoord Point1 = { mp_Position.GetFieldX(), mp_Position.GetFieldY() };
		   vxtRCoord Point2 = { mp_Position.GetFieldX() + mp_Size.GetFieldX(), mp_Position.GetFieldY() + mp_Size.GetFieldY() };

		   if (m_pMemRenderTarget != NULL)
		   {
			   rGraphics.vDrawPixels(Point1, Point2, m_pMemRenderTarget, m_nWidth, m_nHeight);
			   vRequireUpdate();
		   }
	   }
	   return;
   }

   if( 0 != mp_AlphaValue )
   {
      vxtPLGraphics& rGraphics = a_rMode.rGetGraphics();

      const vxtRTImage &rImage = mp_Index->rGetImage();

      if(rImage.IsAllocated())
      {
         vxtColorRGBA ImageColor = { VXT_MAX_PIXEL_LEVEL, 
                                     VXT_MAX_PIXEL_LEVEL,
                                     VXT_MAX_PIXEL_LEVEL,
                                     mp_AlphaValue };

         //--------------------------------------------------------------------
         // Coding Standard Deviation: MISRA C++ 2008 6-2-2 
         // Description: Floating-point expressions shall not be directly or 
         //              indirectly tested for equality or inequality. 
         // Rationale: Direct equality test is used as a fast way to single 
         //            out and optimize the most-used no-rotation case.
         //--------------------------------------------------------------------
         // PRQA S 3270 1 
         if (0.0F == mp_RotationAngle)
         {
            vxtRCoord Point1 = {mp_Position.GetFieldX(), mp_Position.GetFieldY()};

            // SCS.LAN.EXPR.ARITH.ERROR
            // DC1.RT.GENERAL.EXTENT_LIMIT.01 impose all graphics to be located 
            // inside the maximum extent bounding box (+- VXT_RT_GEOMETRY_MAX), 
            // therefore limiting the values of mp_Position and mp_Size to that range.
            // Adding two floats in that interval cannot overflow.
            vxtRCoord Point2 = {mp_Position.GetFieldX() + mp_Size.GetFieldX(),
                                mp_Position.GetFieldY() + mp_Size.GetFieldY() };

			rGraphics.vDrawImage(rImage, Point1, Point2, ImageColor);
         }
         else
         {
            // General case of drawing a rotated image
            vxtRCoord Zero = { 0.0F, 0.0F};
            vxtRCoord Size = { mp_Size.GetFieldX(), mp_Size.GetFieldY() };

            rGraphics.vPushTrans();

            rGraphics.vTranslate(mp_Position.GetFieldX(), mp_Position.GetFieldY());

            rGraphics.vRotate(mp_RotationAngle);

            rGraphics.vDrawImage(rImage, Zero, Size, ImageColor);

            rGraphics.vPopTrans();
         }
      }
   }
}


void vxtClsImage::vUpdate(const vxtRTTopContext & a_rTopContext)
{
   vFixSizeIfNeeded(a_rTopContext, VXT_FALSE);
   if (mp_AlphaValue == CREATE_VIDEO_IMAGE_1)
		vRequireDraw(a_rTopContext);
}

修改vxtClsImage.cpp,增加一個巨集定義

#define CREATE_VIDEO_IMAGE_1 50