diff --git a/include/grabber/video/EncoderThread.h b/include/grabber/video/EncoderThread.h index 51008d3e..12f90096 100644 --- a/include/grabber/video/EncoderThread.h +++ b/include/grabber/video/EncoderThread.h @@ -31,7 +31,7 @@ public: PixelFormat pixelFormat, uint8_t* sharedData, int size, int width, int height, int lineLength, int cropLeft, int cropTop, int cropBottom, int cropRight, - VideoMode videoMode, FlipMode flipMode, int pixelDecimation); + VideoMode videoMode, bool bottomUp, FlipMode flipMode, int pixelDecimation); void process(); @@ -55,7 +55,7 @@ private: int _cropTop; int _cropBottom; int _cropRight; - + bool _bottomUp; FlipMode _flipMode; VideoMode _videoMode; bool _doTransform; @@ -96,14 +96,14 @@ public: PixelFormat pixelFormat, uint8_t* sharedData, int size, int width, int height, int lineLength, int cropLeft, int cropTop, int cropBottom, int cropRight, - VideoMode videoMode, FlipMode flipMode, int pixelDecimation) + VideoMode videoMode, bool bottomUp, FlipMode flipMode, int pixelDecimation) { auto encThread = qobject_cast(_thread); if (encThread != nullptr) encThread->setup(pixelFormat, sharedData, size, width, height, lineLength, cropLeft, cropTop, cropBottom, cropRight, - videoMode, flipMode, pixelDecimation); + videoMode, bottomUp, flipMode, pixelDecimation); } bool isBusy() diff --git a/include/utils/ImageResampler.h b/include/utils/ImageResampler.h index 7aba7a40..f82c0538 100644 --- a/include/utils/ImageResampler.h +++ b/include/utils/ImageResampler.h @@ -15,6 +15,7 @@ public: void setVerticalPixelDecimation(int decimator) { _verticalDecimation = decimator; } void setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom); void setVideoMode(VideoMode mode) { _videoMode = mode; } + void setBottomUp(bool isBottomUp) { _bottomUp = isBottomUp; } void setFlipMode(FlipMode mode) { _flipMode = mode; } void processImage(const uint8_t * data, int width, int height, int lineLength, PixelFormat pixelFormat, Image & outputImage) const; @@ -26,6 +27,7 @@ private: int _cropTop; int _cropBottom; VideoMode _videoMode; + bool _bottomUp; FlipMode _flipMode; }; diff --git a/libsrc/grabber/video/EncoderThread.cpp b/libsrc/grabber/video/EncoderThread.cpp index e891c821..83ad321d 100644 --- a/libsrc/grabber/video/EncoderThread.cpp +++ b/libsrc/grabber/video/EncoderThread.cpp @@ -40,7 +40,7 @@ void EncoderThread::setup( PixelFormat pixelFormat, uint8_t* sharedData, int size, int width, int height, int lineLength, int cropLeft, int cropTop, int cropBottom, int cropRight, - VideoMode videoMode, FlipMode flipMode, int pixelDecimation) + VideoMode videoMode, bool bottomUp, FlipMode flipMode, int pixelDecimation) { _lineLength = lineLength; _pixelFormat = pixelFormat; @@ -51,6 +51,7 @@ void EncoderThread::setup( _cropTop = cropTop; _cropBottom = cropBottom; _cropRight = cropRight; + _bottomUp = bottomUp; _flipMode = flipMode; _videoMode = videoMode; _pixelDecimation = pixelDecimation; @@ -81,6 +82,7 @@ void EncoderThread::setup( #endif _imageResampler.setVideoMode(_videoMode); + _imageResampler.setBottomUp(_bottomUp); _imageResampler.setFlipMode(_flipMode); _imageResampler.setCropping(_cropLeft, _cropRight, _cropTop, _cropBottom); _imageResampler.setHorizontalPixelDecimation(_pixelDecimation); diff --git a/libsrc/grabber/video/mediafoundation/MFGrabber.cpp b/libsrc/grabber/video/mediafoundation/MFGrabber.cpp index 1cacf4aa..301e8b28 100644 --- a/libsrc/grabber/video/mediafoundation/MFGrabber.cpp +++ b/libsrc/grabber/video/mediafoundation/MFGrabber.cpp @@ -541,7 +541,7 @@ void MFGrabber::process_image(const void *frameImageBuffer, int size) { if (!_threadManager->_threads[i]->isBusy()) { - _threadManager->_threads[i]->setup(_pixelFormat, (uint8_t*)frameImageBuffer, size, _width, _height, _lineLength, _cropLeft, _cropTop, _cropBottom, _cropRight, _videoMode, _flipMode, _pixelDecimation); + _threadManager->_threads[i]->setup(_pixelFormat, (uint8_t*)frameImageBuffer, size, _width, _height, _lineLength, _cropLeft, _cropTop, _cropBottom, _cropRight, _videoMode, (_pixelFormat == PixelFormat::BGR24), _flipMode, _pixelDecimation); _threadManager->_threads[i]->process(); break; } diff --git a/libsrc/grabber/video/v4l2/V4L2Grabber.cpp b/libsrc/grabber/video/v4l2/V4L2Grabber.cpp index e6256d7e..80f6de07 100644 --- a/libsrc/grabber/video/v4l2/V4L2Grabber.cpp +++ b/libsrc/grabber/video/v4l2/V4L2Grabber.cpp @@ -1046,7 +1046,7 @@ bool V4L2Grabber::process_image(const void *p, int size) { if (!_threadManager->_threads[i]->isBusy()) { - _threadManager->_threads[i]->setup(_pixelFormat, (uint8_t*)p, size, _width, _height, _lineLength, _cropLeft, _cropTop, _cropBottom, _cropRight, _videoMode, _flipMode, _pixelDecimation); + _threadManager->_threads[i]->setup(_pixelFormat, (uint8_t*)p, size, _width, _height, _lineLength, _cropLeft, _cropTop, _cropBottom, _cropRight, _videoMode, false, _flipMode, _pixelDecimation); _threadManager->_threads[i]->process(); result = true; break; diff --git a/libsrc/utils/ImageResampler.cpp b/libsrc/utils/ImageResampler.cpp index b205e0d3..7dca4a15 100644 --- a/libsrc/utils/ImageResampler.cpp +++ b/libsrc/utils/ImageResampler.cpp @@ -10,6 +10,7 @@ ImageResampler::ImageResampler() , _cropTop(0) , _cropBottom(0) , _videoMode(VideoMode::VIDEO_2D) + , _bottomUp(false) , _flipMode(FlipMode::NO_CHANGE) { } @@ -53,7 +54,24 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i int xDestStart, xDestEnd; int yDestStart, yDestEnd; - switch (_flipMode) + FlipMode flipMode; + if (!_bottomUp) + { + flipMode = _flipMode; + } + else + { + if (_flipMode == FlipMode::NO_CHANGE) + flipMode = FlipMode::HORIZONTAL; + else if (_flipMode == FlipMode::HORIZONTAL) + flipMode = FlipMode::NO_CHANGE; + else if (_flipMode == FlipMode::VERTICAL) + flipMode = FlipMode::BOTH; + else if (_flipMode == FlipMode::BOTH) + flipMode = FlipMode::VERTICAL; + } + + switch (flipMode) { case FlipMode::NO_CHANGE: xDestStart = 0;