<commit_before>#include "hearthstone.h"

#include "osx_window_capture.h"

DEFINE_SINGLETON_SCOPE(Hearthstone)

Hearthstone::Hearthstone() {
  capture = new OSXWindowCapture("Hearthstone");
}

Hearthstone::~Hearthstone() {
  if(capture != NULL)
    delete capture;
}

bool Hearthstone::IsRunning() {
  return capture->WindowFound();
}

QPixmap Hearthstone::Capture(int vx, int vy, int vw, int vh) {
  int x, y, w, h;

  int realCanvasWidth = capture->GetWidth();
  int realCanvasHeight = capture->GetHeight();

  int virtualCanvasWidth = VIRTUAL_CANVAS_WIDTH;
  int virtualCanvasHeight = VIRTUAL_CANVAS_HEIGHT;

  float scaleRatioX = (float)realCanvasWidth / virtualCanvasWidth;
  float scaleRatioY = (float)realCanvasHeight / virtualCanvasHeight;

  float dx = (vx - virtualCanvasWidth/2);
  float dy = (vy - virtualCanvasHeight/2);

  float realCanvasAspectRatio = (float)realCanvasWidth / realCanvasHeight;
  float virtualCanvasAspectRatio = (float)virtualCanvasWidth / virtualCanvasHeight;

  w = vw * scaleRatioX;
  h = vh * scaleRatioY;

  float canvasRatio = virtualCanvasAspectRatio / realCanvasAspectRatio;

  if(canvasRatio < 1.0f) {
    // width relative to height is increased compared to the virtual canvas, meaning
    // the image is squeezed in x
    dx *= canvasRatio;
    w *= canvasRatio;
  } else if(canvasRatio > 1.0f) {
    // same but height is squeezed in y
    dy *= canvasRatio;
    h *= canvasRatio;
  }

  x = realCanvasWidth/2 + dx * scaleRatioX;
  y = realCanvasHeight/2 + dy * scaleRatioY;

  return capture->Capture(x, y, w, h);
}

void Hearthstone::SetWindowCapture(WindowCapture *wc) {
  if(capture != NULL)
    delete capture;

  capture = wc;
}<commit_msg>make detection more resilient<commit_after>#include "hearthstone.h"

#include "osx_window_capture.h"

DEFINE_SINGLETON_SCOPE(Hearthstone)

Hearthstone::Hearthstone() {
  capture = new OSXWindowCapture("Hearthstone");
}

Hearthstone::~Hearthstone() {
  if(capture != NULL)
    delete capture;
}

bool Hearthstone::IsRunning() {
  return capture->WindowFound();
}

QPixmap Hearthstone::Capture(int vx, int vy, int vw, int vh) {
  int x, y, w, h;

  int realCanvasWidth = capture->GetWidth();
  int realCanvasHeight = capture->GetHeight();

  int virtualCanvasWidth = VIRTUAL_CANVAS_WIDTH;
  int virtualCanvasHeight = VIRTUAL_CANVAS_HEIGHT;

  float dx = (vx - virtualCanvasWidth/2);
  float dy = (vy - virtualCanvasHeight/2);
  float scale = (float)realCanvasHeight / virtualCanvasHeight;

  // Rounding here is important for dhash calc
  x = roundf(realCanvasWidth/2 + dx * scale);
  y = roundf(realCanvasHeight/2 + dy * scale);
  w = roundf(vw * scale);
  h = roundf(vh * scale);

  return capture->Capture(x, y, w, h);
}

void Hearthstone::SetWindowCapture(WindowCapture *wc) {
  if(capture != NULL)
    delete capture;

  capture = wc;
}
{'fraction_non_alphanumeric': 0.11413427561837455, 'fraction_numerical': 0.004240282685512367, 'mean_word_length': 4.402671755725191, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6676420', 'n_tokens_mistral': 983, 'n_tokens_neox': 933, 'n_words': 232}