Ejemplo n.º 1
0
CString CImageWnd::GetPixelString(SapBuffer* pBuffer, CPoint pt, BOOL decimalDisplay, BOOL displayCoordinates)
{
   CString str = displayCoordinates ? _T("Pixel data not available") : _T("n/a");

   if (pBuffer && *pBuffer && (pt.x >= 0) && (pt.x < pBuffer->GetWidth()) && (pt.y >= 0) && (pt.y < pBuffer->GetHeight()))
   {
      CString text;
      SapFormat format = pBuffer->GetFormat();

      if (format == SapFormatHSI || format == SapFormatHSIP8)
      {
         SapDataHSI data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         text.Format(decimalDisplay ? _T("H:%03d S:%03d I:%03d") : _T("H:0x%02x S:0x%02x I:0x%02x"), data.H(), data.S(), data.I());
      }
      else if (format == SapFormatLAB || format == SapFormatLAB101010)
      {
         SapDataLAB data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         text.Format(decimalDisplay ? _T("L:%03d A:%03d B:%03d") : _T("L:0x%02x A:0x%02x B:0x%02x"), data.L(), data.A(), data.B());
      }
      else if (format == SapFormatLAB16161616)
      {
         SapDataLABA data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         text.Format(decimalDisplay ? _T("L:%05d A:%05d B:%05d") : _T("L:0x%04x A:0x%04x B:0x%04x"), data.L(), data.A(), data.B());
      }
      else if (format == SapFormatHSV)
      {
         SapDataHSV data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         text.Format(decimalDisplay ? _T("H:%03d S:%03d V:%03d") : _T("H:0x%02x S:0x%02x V:0x%02x"), data.H(), data.S(), data.V());
      }
      else if (CORDATA_FORMAT_IS_YUV(format))
      {
         SapDataYUV data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         text.Format(decimalDisplay ? _T("Y:%03d U:%03d V:%03d") : _T("Y:0x%02x U:0x%02x V:0x%02x"),data.Y(), data.U(), data.V());
      }
      else if (CORDATA_FORMAT_IS_RGB(format))
      {
         if ((format == SapFormatRGB8888) || (format == SapFormatRGB16161616))
         {
            SapDataRGBA data;
            pBuffer->ReadElement(pt.x, pt.y, &data);
            text.Format(decimalDisplay ? _T("R:%03d G:%03d B:%03d A:%03d") : _T("R:0x%02x G:0x%02x B:0x%02x A:0x%02x"), data.Red(), data.Green(), data.Blue(), data.Alpha());
         }
         else
         {
            SapDataRGB data;
            pBuffer->ReadElement(pt.x, pt.y, &data);
            text.Format(decimalDisplay ? _T("R:%03d G:%03d B:%03d") : _T("R:0x%02x G:0x%02x B:0x%02x"), data.Red(), data.Green(), data.Blue());
         }
      }
      else if (CORDATA_FORMAT_IS_MULTI(format))
      {
         int currentPage = 0;
         pBuffer->GetPage(&currentPage);

         SapDataRGBA data;
         pBuffer->ReadElement(pt.x, pt.y, &data);

         if (currentPage == 0)
         {
            text.Format(decimalDisplay ? _T("R:%03d G:%03d B:%03d") : _T("R:0x%02x G:0x%02x B:0x%02x"), data.Red(), data.Green(), data.Blue());
         }
         else
         {
            text.Format(decimalDisplay ? _T("%03d") : _T("0x%02x"), data.Alpha());
         }
      }
      else if (format == SapFormatRGBP8 || format == SapFormatLABP8 || format == SapFormatRGBP16 || format == SapFormatLABP16)
      {
         SapData data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         SapDataRGB dataRGB = data;

         CString sFormat = decimalDisplay ? _T("%03d") : _T("0x%02x");

         int page;
         pBuffer->GetParameter(CORBUFFER_PRM_PAGE, &page);

         if (page == 0)
            text.Format(sFormat, dataRGB.Red());
         else if (page == 1)
            text.Format(sFormat, dataRGB.Green());
         else if (page == 2)
            text.Format(sFormat, dataRGB.Blue());
      }
      else
      {
         SapDataMono data;
         pBuffer->ReadElement(pt.x, pt.y, &data);
         text.Format(decimalDisplay ? _T("%03d") : _T("0x%02x"), data.Mono());
      }

      if (text.GetLength() > 0 && displayCoordinates)
      {
         CString oldText = text;
         text.Format(_T("Position x:%03ld y:%03ld   Value %s"), pt.x, pt.y, oldText);
      }

      str = text;
   }

   return str;
}
CString CImageWnd::GetPixelString(CPoint point) 
{
   CString str = _T("[ Pixel data not available ]");

   // if there is no buffer to display, return right away
   if (m_pView == NULL || !(*m_pView) || m_pView->GetBuffer() == NULL || !m_pView->GetBuffer()->IsMapped())
      return str;

   if (IsPointInside(point) && *m_pView->GetBuffer())
	{
		CPoint pt = TranslateMousePos(point);

		// Get pixel value at cursor's position and create string according to pixel format
		CString text;
		SapFormat format = m_pView->GetBuffer()->GetFormat();

		if (format == SapFormatHSI || format == SapFormatHSIP8)
      {
         SapDataHSI data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld H:0x%04x S:0x%04x I:0x%04x ]"), pt.x, pt.y, data.H(), data.S(), data.I());
      }
		else if (format == SapFormatLAB || format == SapFormatLAB101010)
      {
         SapDataLAB data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld L:0x%04x A:0x%04x B:0x%04x ]"), pt.x, pt.y, data.L(), data.A(), data.B());
      }
		else if (format == SapFormatLAB16161616)
      {
         SapDataLABA data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld L:0x%04x A:0x%04x B:0x%04x ]"), pt.x, pt.y, data.L(), data.A(), data.B());
      }
		else if (format == SapFormatHSV)
      {
         SapDataHSV data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld H:0x%04x S:0x%04x V:0x%04x ]"), pt.x, pt.y, data.H(), data.S(), data.V());
      }
		else if (CORDATA_FORMAT_IS_YUV(format))
      {
         SapDataYUV data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld Y:0x%04x U:0x%04x V:0x%04x ]"), pt.x, pt.y, data.Y(), data.U(), data.V());
      }
		else if (CORDATA_FORMAT_IS_RGB(format))
      {
         if(format==SapFormatRGB16161616)
         {
            SapDataRGBA data;
            m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
            text.Format(_T("[ x:%03ld y:%03ld R:0x%04x G:0x%04x B:0x%04x ]"), pt.x, pt.y, data.Red(), data.Green(), data.Blue());
         }
         else
         {
            SapDataRGB data;
            m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
            text.Format(_T("[ x:%03ld y:%03ld R:0x%04x G:0x%04x B:0x%04x ]"), pt.x, pt.y, data.Red(), data.Green(), data.Blue());
         }
      }
		else if (format == SapFormatRGBP8 || format == SapFormatLABP8 || format == SapFormatRGBP16 || format == SapFormatLABP16)
      {

         SapData data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         SapDataRGB dataRGB = data;

         TCHAR fmtStr8[] = _T("[ x:%03ld y:%03ld value:%03d ]");
         TCHAR fmtStr16[] = _T("[ x:%03ld y:%03ld value:0x%04x ]");
         TCHAR* pFmtStr;

         if (format == SapFormatRGBP8 || format == SapFormatLABP8)
            pFmtStr = fmtStr8;
         else 
            pFmtStr = fmtStr16;

         int page;
         m_pView->GetBuffer()->GetParameter(CORBUFFER_PRM_PAGE,&page);

         if(page==0)
            text.Format(CString(pFmtStr), pt.x, pt.y, dataRGB.Red());
         else if(page==1)
            text.Format(CString(pFmtStr), pt.x, pt.y, dataRGB.Green());
         else if(page==2)
            text.Format(CString(pFmtStr), pt.x, pt.y, dataRGB.Blue());
      }
      else
      {
         SapDataMono data;
         m_pView->GetBuffer()->ReadElement(pt.x, pt.y, &data);
         text.Format(_T("[ x:%03ld y:%03ld value:0x%04x ]"), pt.x, pt.y, data.Mono());
      }

		// Append string to application title
		str = _T("  ") + CString(text);
	}

	return str;
}