From 86524a77bdacffa718677531e56992ae0d119c60 Mon Sep 17 00:00:00 2001
From: Sebastian Hahta <joseha@utu.fi>
Date: Thu, 5 Dec 2019 13:01:55 +0200
Subject: [PATCH] fix scaling

---
 components/codecs/include/ftl/codecs/bitrates.hpp           | 2 +-
 components/codecs/src/bitrates.cpp                          | 6 ++++--
 components/codecs/src/encoder.cpp                           | 2 +-
 .../rgbd-sources/src/sources/stereovideo/stereovideo.cpp    | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/components/codecs/include/ftl/codecs/bitrates.hpp b/components/codecs/include/ftl/codecs/bitrates.hpp
index 4502b7a3b..fbacb4979 100644
--- a/components/codecs/include/ftl/codecs/bitrates.hpp
+++ b/components/codecs/include/ftl/codecs/bitrates.hpp
@@ -49,7 +49,7 @@ enum struct definition_t : uint8_t {
 	Invalid
 };
 
-definition_t findClosestDefinition(int width, int height);
+definition_t findDefinition(int width, int height);
 
 /**
  * Get width in pixels of definition.
diff --git a/components/codecs/src/bitrates.cpp b/components/codecs/src/bitrates.cpp
index 9474054d2..37889f5a5 100644
--- a/components/codecs/src/bitrates.cpp
+++ b/components/codecs/src/bitrates.cpp
@@ -50,10 +50,12 @@ int ftl::codecs::getHeight(definition_t d) {
 	return resolutions[static_cast<int>(d)].height;
 }
 
-definition_t ftl::codecs::findClosestDefinition(int width, int height) {
+definition_t ftl::codecs::findDefinition(int width, int height) {
 	int best = 0;
+	bool smaller = true;
+
 	for(const Resolution res : resolutions) {
-		if ((res.width >= width) && (res.height >= height)) {
+		if ((res.width == width) && (res.height == height)) {
 			return static_cast<definition_t>(best);
 		}
 		best++;
diff --git a/components/codecs/src/encoder.cpp b/components/codecs/src/encoder.cpp
index 428f2f49d..7c7f9a358 100644
--- a/components/codecs/src/encoder.cpp
+++ b/components/codecs/src/encoder.cpp
@@ -72,7 +72,7 @@ Encoder::~Encoder() {
 
 bool Encoder::encode(const cv::cuda::GpuMat &in, preset_t preset,
 			const std::function<void(const ftl::codecs::Packet&)> &cb) {
-	const definition_t definition = ftl::codecs::findClosestDefinition(in.size().width, in.size().height);
+	const definition_t definition = ftl::codecs::findDefinition(in.size().width, in.size().height);
 	const bitrate_t bitrate = bitrate_t::High;
 
 	return encode(in, definition, bitrate, cb);
diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp
index 9a6f6bf30..01afccee4 100644
--- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp
+++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp
@@ -92,7 +92,7 @@ void StereoVideoSource::init(const string &file) {
 	pipeline_depth_->append<ftl::operators::DiscontinuityMask>("discontinuity_mask");
 	pipeline_depth_->append<ftl::operators::AggreMLS>("mls");  // Perform MLS (using smoothing channel)
 
-	calib_ = ftl::create<Calibrate>(host_, "calibration", depth_size_, stream_);
+	calib_ = ftl::create<Calibrate>(host_, "calibration", color_size_, stream_);
 	if (!calib_->isCalibrated()) LOG(WARNING) << "Cameras are not calibrated!";
 
 	// Generate camera parameters from camera matrix
-- 
GitLab