示例#1
0
void FPScreenMirror::reinitialize() {

	RECT keyDim = LEDController::getInstance()->getKeyBoardDimensions(allKeys);

	keyboardWidth = keyDim.right;
	keyboardHeight = keyDim.bottom;

	if (!captureWindowHDC || !currentProcessHWND) {
		return;
	}

	RECT targetRect;
	GetWindowRect(currentProcessHWND, &targetRect);

	int clientWidth = targetRect.right - targetRect.left; // -offsetLeft - offsetRight;
	int clientHeight = targetRect.bottom - targetRect.top; // -offsetTop - offsetBottom;


	// targetWidth = uiWidth - marginLeft * 2;
	// float aspectRatio = (float)keyboardHeight / (float)keyboardWidth;
	// targetHeight = (int)floor(targetWidth * aspectRatio);
	keyboardZoomFactor = (float)(clientWidth - offsetLeft - offsetRight) / (float)keyboardWidth;
	uiZoom = (float)targetWidth / (float)clientWidth;

	// create Alpha Screenhot Mask
	int cB = 80;
	if (mask) {
		delete mask;
	}
	mask = new Mat4b(targetHeight, targetWidth, CV_8UC4);
	for (int i = 0; i < cB; i++) {
		int c = (int)floor((float)i / (float)cB * (float)192);
		Scalar color(c, c, c, 255);
		cv::rectangle(*mask, cv::Point((int)floor(i), i), cv::Point(targetWidth - (int)floor(i), targetHeight - i), color, CV_FILLED, 8, 0);
	}

	// keyboard graphics
	int keyShadowSize = 4;

	if (keyboardFx) {
		delete keyboardFx;
	}
	keyboardFx = new Mat4b(targetHeight, targetWidth, Vec4b(0, 0, 0, 0));
	
	vector<CorsairLedPosition>::iterator it;
	it = allKeys.begin();
	for (; it != allKeys.end(); ) {
		cv::Rect keyRect(
			(int)floor((float)(it->left*keyboardZoomFactor + offsetLeft)*uiZoom * offsetScaleX),
			(int)floor((float)(it->top*keyboardZoomFactor + offsetTop)*uiZoom* offsetScaleY),
			(int)floor((float)it->width*keyboardZoomFactor*uiZoom * offsetScaleX),
			(int)floor((float)it->height*keyboardZoomFactor*uiZoom* offsetScaleY));

		for (int i = keyShadowSize; i > 0; i--) {
			int c = (int)floor((float)(keyShadowSize - i) / (float)keyShadowSize * (float)192);
			Scalar color(0, 0, 0, c);
			cv::rectangle(*keyboardFx, cv::Rect(keyRect.x - i, keyRect.y - (int)floor((float)i / 2), keyRect.width + i * 2, keyRect.height + i * 2), color, CV_FILLED, 8, 0);
		}
		++it;
	}

	initialized = true;
}
示例#2
0
bool FPScreenMirror::process() {

	if (!initialized) {
		reinitialize();
		return false;
	}
	
	if (!captureWindowHDC || !currentProcessHWND) {
		return false;
	}
	/*
	if (keyboardWidth < 1 || keyboardHeight < 1) {
		return false;
	}
	*/

	PerformanceStart();

	
	
	// get window bitmap as Mat screenshotMat
	RECT targetRect;
	GetWindowRect(currentProcessHWND, &targetRect);

	int clientWidth = targetRect.right - targetRect.left; // -offsetLeft - offsetRight;
	int clientHeight = targetRect.bottom - targetRect.top; // -offsetTop - offsetBottom;

	if ((targetRect.left < 0 && targetRect.top < 0 && targetRect.right < 0 && targetRect.bottom < 0) ||
		clientWidth < 0 || clientHeight < 0) {
		PerformanceStop();
		return false;
	}

	

	Mat* screenshotRaw = ImageFilterMat::hdc2mat(captureWindowHDC, 0, 0, clientWidth, clientHeight);
	if (screenshotRaw == NULL) {
		PerformanceStop();
		delete screenshotRaw;
		return false;
	}

	Mat4b screenshotMat = (Mat4b)*screenshotRaw;
	
	cv::Rect cropRect(cutLeft, cutTop, screenshotMat.cols - cutLeft - cutRight, screenshotMat.rows - cutTop - cutBottom);
	screenshotMat = Mat(screenshotMat, cropRect);
	
	blur(screenshotMat, screenshotMat, cv::Size(20, 20));
	resize(screenshotMat, screenshotMat, cv::Size(targetWidth, targetHeight), 2, 2, INTER_CUBIC);
	
	// ImageFilterMat::incSaturation(screenshotMat, 50, (float)0.7);


	LEDController::getInstance()->initializeFrame();

	
	Mat4b keyboardMat = Mat4b(*keyboardFx);

	
	
	// draw Keyboard
	
	vector<CorsairLedPosition>::iterator it = allKeys.begin();
	it = allKeys.begin();
	for (; it != allKeys.end(); ) {
		cv::Rect keyRect(
			(int)floor((float)(it->left*keyboardZoomFactor + offsetLeft)*uiZoom * offsetScaleX),
			(int)floor((float)(it->top*keyboardZoomFactor + offsetTop)*uiZoom* offsetScaleY),
			(int)floor((float)it->width*keyboardZoomFactor*uiZoom * offsetScaleX),
			(int)floor((float)it->height*keyboardZoomFactor*uiZoom* offsetScaleY));

	
		int overScanX = (int)keyRect.x - overscan;
		if (overScanX < 0) overScanX = 0;
		
		int overScanY = (int)keyRect.y - overscan;
		if (overScanY < 0) overScanY = 0;
		
		int overScanW = (int)keyRect.width + overscan * 2;
		if (overScanX + overScanW > keyboardMat.cols) overScanW = keyboardMat.cols - overScanX;
		
		int overScanH = (int)keyRect.height + overscan * 2;
		if (overScanY + overScanH > keyboardMat.rows) overScanH = keyboardMat.rows - overScanY;


		cv::Rect colorDetectionRect(overScanX, overScanY, overScanW, overScanH);

		try {
			Mat4b keyMat = Mat(screenshotMat, colorDetectionRect);
			resize(keyMat, keyMat, cv::Size(1, 1), 0, 0, INTER_CUBIC);
			Vec4b color = keyMat.at<Vec4b>(0, 0);

			LEDController::getInstance()->setKey(it->ledId, color[2], color[1], color[0]);
			cv::rectangle(keyboardMat, keyRect, Scalar(color[0], color[1], color[2], 255), CV_FILLED, 8, 0);
			cv::rectangle(keyboardMat, keyRect, Scalar(255, 255, 255, 128), 1, 8, 0);
			// cv::rectangle(keyboardMat, colorDetectionRect, Scalar(0, 0, 255, 128), 1, 8, 0);
		}
		catch (...) {
			// ups...
		}
		++it;
	}
	
	LEDController::getInstance()->updateFrame();
	
	// copy background to UI
	getBackgroundMat()->copyTo(drawUI);
	
	// ImageFilterMat::addAlphaMask(&screenshotMat, mask);
	
	
	ImageFilterMat::overlayImage(&drawUI, &screenshotMat, cv::Point(targetX, targetY));
	
	resize(keyboardMat, keyboardMat, cv::Size(targetWidth, targetHeight));
	ImageFilterMat::overlayImage(&drawUI, &keyboardMat, cv::Point(targetX, targetY));


	PerformanceDraw(getBackgroundMat()->cols - 130, 20);
	drawToWindow(&drawUI);

	// throwing away pointer, so opencv releases memory
	delete screenshotRaw;
	PerformanceStop();
	
	return true;
}
void
CGnuPlotStylePieChart::
drawKey(CGnuPlotPlot *plot, CGnuPlotRenderer *renderer)
{
  CGnuPlotPieChartStyleValue *value =
    CGnuPlotStyleValueMgrInst->getValue<CGnuPlotPieChartStyleValue>(plot);
  if (! value) return;

  //---

  CGnuPlotGroup *group = plot->group();

  const CGnuPlotKeyP     &key   = group->key();
//const CGnuPlotAxisData &xaxis = group->xaxis(1);

  if (! key->isDisplayed()) return;

  if (key->getFont().isValid())
    renderer->setFont(key->getFont());

  CGnuPlotFill fill(plot);

  //---

  CBBox2D rbbox = (key->isOutside() ? group->getRegionBBox() : renderer->range());

  //---

  CFontPtr font = renderer->getFont();

  double font_size = font->getCharAscent() + font->getCharDescent();

  double pw = renderer->pixelWidthToWindowWidth  (1);
  double ph = renderer->pixelHeightToWindowHeight(1);

  double bx = 8*pw;
  double by = 8*ph;
  double bw = font_size - 2;

  CSize2D size;

  double textWidth = 0.0, textHeight = 0.0;

  std::string header;

  if (key->hasTitle()) {
    header = key->title();

    if (header != "")
      textHeight += font_size*ph;
  }

  NameValueColors values = nameValueColors(plot, value->palette(), value->alpha());

  for (const auto &v : values) {
    std::string label = v.first;

    textWidth = std::max(textWidth, font->getStringWidth(label)*pw);

    textHeight += font_size*ph;
  }

  size = CSize2D(textWidth + bw*pw + 3*bx, textHeight + 2*by);

  CHAlignType halign = key->getHAlign();
  CVAlignType valign = key->getVAlign();

  double x1 = 0, y1 = 0;

  if      (halign == CHALIGN_TYPE_LEFT)
    x1 = rbbox.getLeft () + bx;
  else if (halign == CHALIGN_TYPE_RIGHT)
    x1 = rbbox.getRight() - bx - size.getWidth();
  else if (halign == CHALIGN_TYPE_CENTER)
    x1 = rbbox.getXMid() - size.getWidth()/2;

  if      (valign == CVALIGN_TYPE_TOP)
    y1 = rbbox.getTop   () - by - size.getHeight();
  else if (valign == CVALIGN_TYPE_BOTTOM)
    y1 = rbbox.getBottom() + by;
  else if (valign == CVALIGN_TYPE_CENTER)
    y1 = rbbox.getYMid() - size.getHeight()/2;

  double x2 = x1 + size.getWidth ();
  double y2 = y1 + size.getHeight();

  CBBox2D bbox(x1, y1, x2, y2);

  if (key->getFillBox()) {
    renderer->fillRect(bbox, fill.background());
  }

  if (key->getDrawBox()) {
    CRGBA c(0, 0, 0);

    if (key->hasLineType())
      c = CGnuPlotStyleInst->indexColor(key->getLineType());

    renderer->drawRect(bbox, c, 1);
  }

  double y = y2 - by;

  if (header != "") {
    renderer->drawHAlignedText(CPoint2D((x1 + x2)/2, y), HAlignPos(CHALIGN_TYPE_CENTER, 0),
                               VAlignPos(CVALIGN_TYPE_TOP, 0), header, CRGBA(0,0,0));

    y -= font_size*ph;
  }

  if (! renderer->isPseudo())
    plot->updatePieCacheSize(values.size());

  int pi = 0;

  for (const auto &v : values) {
    CGnuPlotPieObject *pieObject = 0;

    if (! renderer->isPseudo())
      pieObject = plot->pieObjects()[pi];

    //---

    const std::string   &name = v .first;
    const ValueColor    &vc   = v .second;
    const LineFillColor &lfc  = vc.second;

    double xx = (key->isReverse() ? x1 + bx : x2 - bw*pw - bx);
    double yy = y - font_size*ph/2;

    CPoint2D p1(xx, yy - bw*ph/2), p2(xx + bw*pw, yy + bw*ph/2);

    CBBox2D bbox(p1, p2);

    renderer->fillEllipse(bbox, lfc.second);
    renderer->drawEllipse(bbox, lfc.first, 1);

    //double lw = font->getStringWidth(name);

    CRGBA tc = CRGBA(0,0,0);

    if (key->isReverse())
      renderer->drawHAlignedText(CPoint2D(xx + bw*pw + bx, y), HAlignPos(CHALIGN_TYPE_LEFT, 0),
                                 VAlignPos(CVALIGN_TYPE_TOP, 0), name, tc);
    else
      renderer->drawHAlignedText(CPoint2D(xx - bx, y), HAlignPos(CHALIGN_TYPE_RIGHT, 0),
                                 VAlignPos(CVALIGN_TYPE_TOP, 0), name, tc);

    if (pieObject) {
      CBBox2D keyRect(x1, y - font_size*ph, x2, y);

      pieObject->setKeyRect(keyRect);

      //renderer->drawRect(keyRect, lfc.second, 1);
    }

    y -= font_size*ph;

    ++pi;
  }
}