source: pacpussensors/trunk/StdDbtPlayerComponents/ImageViewer.cpp

Last change on this file was 110, checked in by DHERBOMEZ Gérald, 9 years ago
  • minor modifications about dllexport and dllimport macros usages
File size: 2.8 KB
Line 
1/*********************************************************************
2// created: 2006/06/09 - 9:40
3// filename: ImageViewer.cpp
4//
5// author: Gerald Dherbomez
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id$
9//
10// purpose: Definition of the ImageViewer class
11//
12// todo : - think how to display geometric forms in the viewer (line,
13// circles, points, etc.)
14*********************************************************************/
15
16#define DEFAULT_IMAGE_WIDTH 320
17#define DEFAULT_IMAGE_HEIGHT 240
18#define DEFAULT_IMAGE_DEPTH 32
19
20#include "ImageViewer.h"
21
22#include <iostream>
23
24#include <QDebug>
25#include <QImage>
26#include <QMutex>
27#include <QPainter>
28#include <QPaintEvent>
29#include <QPixmap>
30
31namespace pacpus {
32
33using namespace std;
34
35//////////////////////////////////////////////////////////////////////////
36// constructor
37//////////////////////////////////////////////////////////////////////////
38ImageViewer::ImageViewer() : imageBuffer_(NULL)
39{
40 // setBackgroundMode(Qt::NoBackground);
41 setBackgroundRole(QPalette::Window);
42 imageBuffer_ = new QPixmap(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
43 resize(imageBuffer_->size());
44}
45
46
47//////////////////////////////////////////////////////////////////////////
48// destructor
49
50//////////////////////////////////////////////////////////////////////////
51ImageViewer::~ImageViewer()
52{
53 delete imageBuffer_;
54}
55
56//////////////////////////////////////////////////////////////////////////
57// slot
58// connect this to the signal that will send the image
59//////////////////////////////////////////////////////////////////////////
60void ImageViewer::display(QImage * image)
61{
62 //tic();
63 imageMutex_->lock();
64 if ( (image == NULL) || (image->isNull()) )
65 {
66 qDebug() << "ImageViewer: image is no more valid, not displayed";
67 }
68 else
69 {
70 if (imageBuffer_->size() != image->size())
71 resize(image->size());
72 *imageBuffer_ = QPixmap::fromImage(*image);
73 update();
74 }
75 imageMutex_->unlock();
76 //toc("imageViewer");
77
78}
79
80
81
82//////////////////////////////////////////////////////////////////////////
83// slot
84// activated when repaint() is called
85//////////////////////////////////////////////////////////////////////////
86void ImageViewer::paintEvent(QPaintEvent * e)
87{
88 QPainter painter(this);
89 painter.setClipRect(e->rect());
90 if (imageBuffer_) {
91 painter.drawPixmap(0,0,*imageBuffer_);
92 }
93}
94
95//////////////////////////////////////////////////////////////////////////
96void ImageViewer::setMutex(QMutex * imageMutex)
97{
98 imageMutex_ = imageMutex;
99}
100
101void ImageViewer::tic()
102{
103 tic_ = road_time();
104}
105
106void ImageViewer::toc(char * text)
107{
108 cout << "duration = " << (int)(road_time() - tic_) << " " << text << "\n";
109}
110
111}
Note: See TracBrowser for help on using the repository browser.