Commits

iorodeo committed 1c8abf7

Worked on display flipping and rotation. Seems to be working.

Comments (0)

Files changed (2)

src/gui/camera_window.cpp

         if (isPreviewTab && !img.isNull()) 
         {
             previewPixmapOriginal_ = QPixmap::fromImage(img);
-            updateImageLabel(previewImageLabelPtr_, previewPixmapOriginal_, true);
+            updateImageLabel(previewImageLabelPtr_, previewPixmapOriginal_, true, true);
         }
 
         // TO DO ... Update plugin image
         if (isHistogramTab)
         {
             updateHistogramPixmap(histMat);
-            updateImageLabel(histogramImageLabelPtr_, histogramPixmapOriginal_, false);
+            updateImageLabel(histogramImageLabelPtr_, histogramPixmapOriginal_, false, false);
         }
 
         // Update statusbar message
 
     void CameraWindow::actionDisplayRotTriggered()
     {
-        // Get Rotation 
         QPointer<QAction> actionPtr = qobject_cast<QAction *>(sender());
-        if (actionPtr != NULL) {
-            QString rotString = actionPtr -> text();
-            std:: cout << "display rotation: " << rotString.toStdString() << std::endl;
-        }
+        imageRotation_ = actionToRotationMap_[actionPtr];
+        std:: cout << "display rotation: " << int(imageRotation_) << std::endl;
     }
 
 
         timer_ = false;
         flipVert_ = false;
         flipHorz_ = false;
+        imageRotation_ = IMAGE_ROTATION_0;
 
         imageDisplayFreq_ = DEFAULT_IMAGE_DISPLAY_FREQ;
         cameraPtr_ = std::make_shared<Lockable<Camera>>(guid);
         dummyImage.fill(QColor(Qt::gray).rgb());
         histogramPixmapOriginal_ = QPixmap::fromImage(dummyImage);
 
-        updateImageLabel(previewImageLabelPtr_, previewPixmapOriginal_, true);
-        updateImageLabel(pluginImageLabelPtr_, pluginPixmapOriginal_, false);
-        updateImageLabel(histogramImageLabelPtr_, histogramPixmapOriginal_, false);
+        updateImageLabel(previewImageLabelPtr_, previewPixmapOriginal_, true, true);
+        updateImageLabel(pluginImageLabelPtr_, pluginPixmapOriginal_, true, false);
+        updateImageLabel(histogramImageLabelPtr_, histogramPixmapOriginal_, false, false);
     }
 
 
         rotationActionGroupPtr_ -> addAction(actionDisplayRot90Ptr_);
         rotationActionGroupPtr_ -> addAction(actionDisplayRot180Ptr_);
         rotationActionGroupPtr_ -> addAction(actionDisplayRot270Ptr_);
-        actionDisplayRot0Ptr_ -> setChecked(true);
-        actionDisplayRot90Ptr_ -> setChecked(false);
-        actionDisplayRot180Ptr_ -> setChecked(false);
-        actionDisplayRot270Ptr_ -> setChecked(false);
+
+        actionToRotationMap_[actionDisplayRot0Ptr_] =  IMAGE_ROTATION_0;
+        actionToRotationMap_[actionDisplayRot90Ptr_] = IMAGE_ROTATION_90;
+        actionToRotationMap_[actionDisplayRot180Ptr_] = IMAGE_ROTATION_180;
+        actionToRotationMap_[actionDisplayRot270Ptr_] = IMAGE_ROTATION_270; 
+        
+        QMap<QAction*, ImageRotationType>:: iterator mapIt;
+        for (
+                mapIt = actionToRotationMap_.begin();
+                mapIt != actionToRotationMap_.end();
+                mapIt++
+            )
+        {
+            ImageRotationType rotType = *mapIt;
+            QAction *actionPtr = mapIt.key();
+            if (rotType == imageRotation_)
+            {
+                actionPtr -> setChecked(true);
+            }
+            else
+            {
+                actionPtr -> setChecked(false);
+            }
+        }
     }
 
 
     void CameraWindow::updateImageLabel(
             QLabel *imageLabelPtr, 
             QPixmap &pixmapOriginal,
+            bool flipAndRotate,
             bool addFrameCount
             )
     {
                 Qt::SmoothTransformation
                 );
         
+        // Flip and rotate pixmap if required
+        if (flipAndRotate) {
+            if ((imageRotation_ != IMAGE_ROTATION_0) || flipVert_ || flipHorz_ )
+            {
+                QTransform transform;
+                transform.rotate(-1.0*float(imageRotation_));
+                if (flipVert_)
+                {
+                    transform.scale(1.0,-1.0);
+                }
+                if (flipHorz_) 
+                {
+                    transform.scale(-1.0,1.0);
+                }
+                pixmapScaled = pixmapScaled.transformed(transform);
+            }
+        }
+
+        // Add frame count
         if (addFrameCount && (frameCount_ > 0))
         {
             QPainter painter(&pixmapScaled);
             painter.setPen(QColor(0,220,0));
             painter.drawText(5,12, msg);
         }
+
         imageLabelPtr -> setPixmap(pixmapScaled);
     }
 
     void CameraWindow::resizeImageLabel( 
             QLabel *imageLabelPtr, 
             QPixmap &pixmapOriginal, 
+            bool flipAndRotate,
             bool addFrameCount
             )
     {
         QSize sizeImageLabelPixmap = imageLabelPtr -> pixmap() -> size();
         if (sizeImageLabelPixmap != sizeAdjusted) 
         {
-            updateImageLabel(imageLabelPtr,pixmapOriginal,addFrameCount);
+            updateImageLabel(
+                    imageLabelPtr,
+                    pixmapOriginal,
+                    flipAndRotate,
+                    addFrameCount
+                    );
         }
     }
 

src/gui/camera_window.hpp

 #include <memory>
 #include <QDir>
 #include <QSize>
+#include <QMap>
 #include <QPointer>
 #include <QMainWindow>
 #include "ui_camera_window.h"
     template <class T> class LockableQueue;
 
 
+
     class CameraWindow : public QMainWindow, private Ui::CameraWindow
     {
         Q_OBJECT
         const double DEFAULT_IMAGE_DISPLAY_FREQ = 15.0; // Hz 
         const QSize PREVIEW_DUMMY_IMAGE_SIZE = QSize(320,256);
         const QSize DEFAULT_HISTOGRAM_IMAGE_SIZE = QSize(256,204);
+        enum ImageRotationType
+        { 
+            IMAGE_ROTATION_0=0,
+            IMAGE_ROTATION_90=90,
+            IMAGE_ROTATION_180=180,
+            IMAGE_ROTATION_270=270
+        };
 
         public:
 
             bool flipHorz_;
             QDir defaultSaveDir_;
             double imageDisplayFreq_;
+            ImageRotationType imageRotation_;
             unsigned long frameCount_;
 
             QPixmap previewPixmapOriginal_;
             QPointer<QSignalMapper> frameRateSignalMapperPtr_;
             QPointer<QSignalMapper> propertiesSignalMapperPtr_;
 
+            QMap<QAction*, ImageRotationType> actionToRotationMap_;
+
             std::shared_ptr<Lockable<Camera>> cameraPtr_;
             std::shared_ptr<LockableQueue<StampedImage>> newImageQueuePtr_;
 
             void updateImageLabel(
                     QLabel *imageLabelPtr, 
                     QPixmap &pixmapOriginal, 
+                    bool flipAndRotate=true,
                     bool addFrameCount=true
                     );
             void resizeImageLabel(
                     QLabel *imageLabelPtr, 
                     QPixmap &pixmapOriginal, 
+                    bool flipAndRotate=true,
                     bool addFrameCount=true
                     );
             void resizeAllImageLabels();