@@ -38,4 +38,12 @@ inline std::array<float, 16> debayerProjection(const Size &inputSize,
};
}
+/* Return the visible sensor rectangle, before statistics Bayer alignment. */
+inline Rectangle debayerCrop(const Size &inputSize, const Size &nativeSize,
+ const Size &outputSize)
+{
+ const Size visibleSize = nativeSize.boundedToAspectRatio(outputSize);
+ return visibleSize.centeredTo(Rectangle(inputSize).center());
+}
+
} /* namespace libcamera */
@@ -323,18 +323,11 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,
outputSize_ = outputCfg.size;
nativeOutputSize_ = outSizeRange.max;
- window_.x = ((inputCfg.size.width - outputCfg.size.width) / 2) &
- ~(inputConfig_.patternSize.width - 1);
- window_.y = ((inputCfg.size.height - outputCfg.size.height) / 2) &
- ~(inputConfig_.patternSize.height - 1);
- window_.width = outputCfg.size.width;
- window_.height = outputCfg.size.height;
-
/*
- * Don't pass x,y from window_ since process() already adjusts for it.
- * But crop the window to 2/3 of its width and height for speedup.
+ * The GPU scales the visible sensor crop to outputSize_. Statistics
+ * consume the original input buffer, so use sensor coordinates here.
*/
- stats_->setWindow(Rectangle(window_.size()));
+ stats_->setWindow(debayerCrop(inputCfg.size, nativeOutputSize_, outputSize_));
inputBufferCount_ = inputCfg.bufferCount;
outputBufferCount_ = outputCfg.bufferCount;
@@ -111,7 +111,6 @@ private:
GLint contrastExpUniformDataIn_;
Size nativeOutputSize_;
- Rectangle window_;
std::unique_ptr<SwStatsCpu> stats_;
eGL egl_;
uint32_t width_;