178 |
kaklik |
1 |
#include <QtGui/QMouseEvent> |
|
|
2 |
#include "videoWidget.hh" |
|
|
3 |
|
|
|
4 |
using namespace mimas; |
|
|
5 |
|
|
|
6 |
VideoWidget::VideoWidget( QWidget *parent, Qt::WFlags ): |
|
|
7 |
QGLWidget( parent ), offsetX(0), offsetY(0), zoom(1.0) |
|
|
8 |
{ |
|
|
9 |
} |
|
|
10 |
|
|
|
11 |
void VideoWidget::setImage( const image< rgba< unsigned char > > &_img ) |
|
|
12 |
{ |
|
|
13 |
setImage( 0,0, _img.getWidth(), _img.getHeight(), _img ); |
|
|
14 |
} |
|
|
15 |
|
|
|
16 |
void VideoWidget::setImage( int _offsetX, int _offsetY, |
|
|
17 |
int _width, int _height, |
|
|
18 |
const image< rgba< unsigned char > > &_img ) |
|
|
19 |
{ |
|
|
20 |
offsetX = _offsetX; |
|
|
21 |
offsetY = _offsetY; |
|
|
22 |
img = _img; |
|
|
23 |
adaptSize( _width, _height ); |
|
|
24 |
update(); |
|
|
25 |
} |
|
|
26 |
|
|
|
27 |
void VideoWidget::wheelEvent( QWheelEvent *e ) |
|
|
28 |
{ |
|
|
29 |
zoom += e->delta() / 1200.0; |
|
|
30 |
if ( zoom < 0.1 ) zoom = 0.1; |
|
|
31 |
if ( zoom > 2.5 ) zoom = 2.5; |
|
|
32 |
adaptSize( img.getWidth(), img.getHeight() ); |
|
|
33 |
update(); |
|
|
34 |
} |
|
|
35 |
|
|
|
36 |
void VideoWidget::initializeGL(void) |
|
|
37 |
{ |
|
|
38 |
qglClearColor( QColor( 32, 32, 32 ) ); |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
void VideoWidget::resizeGL( int w, int h ) |
|
|
42 |
{ |
|
|
43 |
glViewport( 0, 0, (GLint)w, (GLint)h ); |
|
|
44 |
glMatrixMode( GL_PROJECTION ); |
|
|
45 |
glLoadIdentity(); |
|
|
46 |
glOrtho( 0, width(), height(), 0, -1, 1 ); |
|
|
47 |
glMatrixMode( GL_MODELVIEW ); |
|
|
48 |
} |
|
|
49 |
|
|
|
50 |
void VideoWidget::paintGL(void) |
|
|
51 |
{ |
|
|
52 |
glClear( GL_COLOR_BUFFER_BIT ); |
|
|
53 |
if ( img.initialised() ) { |
|
|
54 |
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); |
|
|
55 |
// glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); |
|
|
56 |
// glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 ); |
|
|
57 |
// glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 ); |
|
|
58 |
glRasterPos2f( offsetX * zoom, offsetY * zoom ); |
|
|
59 |
glPixelZoom( zoom, -zoom ); |
|
|
60 |
// Direct access to image-memory! |
|
|
61 |
glDrawPixels( img.getWidth(), img.getHeight(), |
|
|
62 |
GL_BGRA, GL_UNSIGNED_BYTE, img.rawData() ); |
|
|
63 |
}; |
|
|
64 |
}; |
|
|
65 |
|
|
|
66 |
void VideoWidget::adaptSize( int w, int h ) |
|
|
67 |
{ |
|
|
68 |
int |
|
|
69 |
newW = (int)( w * zoom ), |
|
|
70 |
newH = (int)( h * zoom ); |
|
|
71 |
if ( width() != newW || height() != newH ) { |
|
|
72 |
resize( newW, newH ); |
|
|
73 |
}; |
|
|
74 |
} |