summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/xinevideowidget.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/xinevideowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/xinevideowidget.cpp151
1 files changed, 80 insertions, 71 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
index 9b26d41..1d88cea 100644
--- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp
+++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
@@ -1,16 +1,16 @@
1 1
2/* 2/*
3                This file is part of the Opie Project 3                This file is part of the Opie Project
4 4
5 Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 5 Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
@@ -19,89 +19,90 @@
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qimage.h> 34#include <qimage.h>
35#include <qpainter.h> 35#include <qpainter.h>
36#include <qgfx_qws.h> 36#include <qgfx_qws.h>
37#include <qdirectpainter_qws.h> 37#include <qdirectpainter_qws.h>
38#include <qgfx_qws.h> 38#include <qgfx_qws.h>
39#include <qsize.h> 39#include <qsize.h>
40#include <qapplication.h> 40#include <qapplication.h>
41#include <qpainter.h> 41#include <qpainter.h>
42 42
43#include <qpe/resource.h> 43#include <qpe/resource.h>
44 44
45#include "xinevideowidget.h" 45#include "xinevideowidget.h"
46 46
47
47// 0 deg rot: copy a line from src to dst (use libc memcpy) 48// 0 deg rot: copy a line from src to dst (use libc memcpy)
48 49
49// 180 deg rot: copy a line from src to dst reversed 50// 180 deg rot: copy a line from src to dst reversed
50 51
51static inline void memcpy_rev ( void *dst, void *src, size_t len ) 52static inline void memcpy_rev ( void *dst, void *src, size_t len )
52{ 53{
53 ((char *) src) += len; 54 ((char *) src ) += len;
54 55
55 len >>= 1; 56 len >>= 1;
56 while ( len-- ) 57 while ( len-- )
57 *((short int *) dst) ++ = *--((short int *) src); 58 *((short int *) dst )++ = *--((short int *) src );
58} 59}
59 60
60// 90 deg rot: copy a column from src to dst 61// 90 deg rot: copy a column from src to dst
61 62
62static inline void memcpy_step ( void *dst, void *src, size_t len, size_t linestep ) 63static inline void memcpy_step ( void *dst, void *src, size_t len, size_t step )
63{ 64{
64 len >>= 1; 65 len >>= 1;
65 while ( len-- ) { 66 while ( len-- ) {
66 *((short int *) dst) ++ = *((short int *) src); 67 *((short int *) dst )++ = *((short int *) src );
67 ((char * ) src) += linestep; 68 ((char *) src ) += step;
68 } 69 }
69} 70}
70 71
71// 270 deg rot: copy a column from src to dst reversed 72// 270 deg rot: copy a column from src to dst reversed
72 73
73static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t linestep ) 74static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t step )
74{ 75{
75 len >>= 1; 76 len >>= 1;
76 77
77 ((char *) src) += ( len * linestep ); 78 ((char *) src ) += ( len * step );
78 79
79 while ( len-- ) { 80 while ( len-- ) {
80 ((char *) src) -= linestep; 81 ((char *) src ) -= step;
81 *((short int *) dst) ++ = *((short int *) src); 82 *((short int *) dst )++ = *((short int *) src );
82 } 83 }
83} 84}
84 85
85 86
86XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name ) 87XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name )
87 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase ) 88 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase )
88{ 89{
89 setBackgroundMode ( NoBackground ); 90 setBackgroundMode ( NoBackground );
90 91
91 m_logo = 0; 92 m_logo = 0;
92 m_buff = 0; 93 m_buff = 0;
93 m_bytes_per_line_fb = qt_screen-> linestep ( ); 94 m_bytes_per_line_fb = qt_screen-> linestep ( );
94 m_bytes_per_pixel = ( qt_screen-> depth ( ) + 7 ) / 8; 95 m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8;
95 m_rotation = 0; 96 m_rotation = 0;
96} 97}
97 98
98 99
99XineVideoWidget::~XineVideoWidget ( ) 100XineVideoWidget::~XineVideoWidget ( )
100{ 101{
101 delete m_logo; 102 delete m_logo;
102} 103}
103 104
104void XineVideoWidget::clear ( ) 105void XineVideoWidget::clear ( )
105{ 106{
106 m_buff = 0; 107 m_buff = 0;
107 repaint ( false ); 108 repaint ( false );
@@ -148,116 +149,124 @@ void XineVideoWidget::paintEvent ( QPaintEvent * )
148 case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break; 149 case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break;
149 default: break; 150 default: break;
150 } 151 }
151 152
152 // all of the following widths/heights are fb relative (0deg rotation) 153 // all of the following widths/heights are fb relative (0deg rotation)
153 154
154 uint leftfill = 0; // black border on the "left" side of the video frame 155 uint leftfill = 0; // black border on the "left" side of the video frame
155 uint framefill = 0; // "width" of the video frame 156 uint framefill = 0; // "width" of the video frame
156 uint rightfill = 0; // black border on the "right" side of the video frame 157 uint rightfill = 0; // black border on the "right" side of the video frame
157 uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect 158 uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect
158 159
159 if ( clip. left ( ) < framerect. left ( )) 160 if ( clip. left ( ) < framerect. left ( ))
160 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) < ? clipwidth; 161 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth;
161 if ( clip. right ( ) > framerect. right ( )) 162 if ( clip. right ( ) > framerect. right ( ))
162 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) < ? clipwidth; 163 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth;
163 164
164 framefill = clipwidth - ( leftfill + rightfill ); 165 framefill = clipwidth - ( leftfill + rightfill );
165 166
166 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) { 167 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) {
167 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) { 168 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) {
168 // "above" or "below" the video -> black 169 // "above" or "below" the video -> black
169 memset ( dst, 0, clipwidth ); 170 memset ( dst, 0, clipwidth );
170 } 171 }
171 else { 172 else {
172 if ( leftfill ) 173 if ( leftfill )
173 memset ( dst, 0, leftfill ); // "left" border -> black 174 memset ( dst, 0, leftfill ); // "left" border -> black
174 175
175 if ( framefill ) { // blit in the video frame 176 if ( framefill ) { // blit in the video frame
176 // see above for an explanation of the different memcpys 177 // see above for an explanation of the different memcpys
177 178
178 switch ( rot ) { 179 switch ( rot ) {
179 case 0: memcpy ( dst + leftfill, src, framefill ); break; 180 case 0: memcpy ( dst + leftfill, src, framefill ); break;
180 case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; 181 case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break;
181 case 2: memcpy_rev ( dst + leftfill, src, framefill ); break; 182 case 2: memcpy_rev ( dst + leftfill, src, framefill ); break;
182 case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; 183 case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break;
183 default: break; 184 default: break;
184 } 185 }
185 if ( rightfill )
186 memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black
187 } 186 }
187 if ( rightfill )
188 memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black
189 }
188 190
189 dst += m_bytes_per_line_fb; // advance one line in the framebuffer 191 dst += m_bytes_per_line_fb; // advance one line in the framebuffer
190 192
191 // advance one "line" in the xine frame data 193 // advance one "line" in the xine frame data
192 switch ( rot ) { 194 switch ( rot ) {
193 case 0: src += m_bytes_per_line_frame;break; 195 case 0: src += m_bytes_per_line_frame;break;
194 case 1: src -= m_bytes_per_pixel; break; 196 case 1: src -= m_bytes_per_pixel; break;
195 case 2: src -= m_bytes_per_line_frame; break; 197 case 2: src -= m_bytes_per_line_frame; break;
196 case 3: src += m_bytes_per_pixel; break; 198 case 3: src += m_bytes_per_pixel; break;
197 default: break; 199 default: break;
198 }
199 } 200 }
200 } 201 }
202 }
203 }
201 204
202 { 205 {
203 // QVFB hack by Martin Jones 206 // QVFB hack by Martin Jones
204 // We need to "touch" all affected clip rects with a normal QPainter in addition to the QDirectPainter 207 // We need to "touch" all affected clip rects with a normal QPainter in addition to the QDirectPainter
205 208
206 QPainter p ( this ); 209 QPainter p ( this );
207 210
208 for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) { 211 for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) {
209 p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [ i ]. topLeft ( )), qt_bug_workaround_clip_rects [ i ]. size ( )), QBrush ( NoBrush )); 212 p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [ i ]. topLeft ( )), qt_bug_workaround_clip_rects [ i ]. size ( )), QBrush ( NoBrush ));
210 }
211 }
212 } 213 }
213 } 214 }
215 }
216}
214 217
215 QImage *XineVideoWidget::logo ( ) const {
216 return m_logo;
217 }
218 218
219 void XineVideoWidget::setLogo ( QImage * image ) { 219QImage *XineVideoWidget::logo ( ) const
220 delete m_logo; 220{
221 m_logo = image; 221 return m_logo;
222 } 222}
223 223
224 void XineVideoWidget::setVideoFrame ( uchar * img, int w, int h, int bpl ) {
225 bool rot90 = (( -m_rotation ) & 1 );
226 224
227 if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height 225void XineVideoWidget::setLogo ( QImage* logo )
228 int d = w; 226{
229 w = h; 227 delete m_logo;
230 h = d; 228 m_logo = logo;
231 } 229}
232 230
233 m_lastframe = m_thisframe; 231void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl )
234 m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); 232{
233 bool rot90 = (( -m_rotation ) & 1 );
235 234
236 m_buff = img; 235 if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height
237 m_bytes_per_line_frame = bpl; 236 int d = w;
237 w = h;
238 h = d;
239 }
238 240
239 // only repaint the area that *really* needs to be repainted 241 m_lastframe = m_thisframe;
242 m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h );
240 243
241 repaint (( 244 m_buff = img;
242 } 245 m_bytes_per_line_frame = bpl;
243 246
244 void XineVideoWidget::resizeEvent ( QResizeEvent * ) { 247 // only repaint the area that *really* needs to be repainted
245 QSize s = size ( );
246 bool fs = ( s == qApp-> desktop ( ) -> size ( ));
247 248
248 // if we are in fullscreen mode, do not rotate the video 249 repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false );
249 // (!! the paint routine uses m_rotation + qt_screen-> transformOrientation() !!) 250}
251
252void XineVideoWidget::resizeEvent ( QResizeEvent * )
253{
254 QSize s = size ( );
255 bool fs = ( s == qApp-> desktop ( )-> size ( ));
250 256
251 m_rotation = fs ? -qt_screen-> transformOrientation ( ) : 0; 257 // if we are in fullscreen mode, do not rotate the video
258 // (!! the paint routine uses m_rotation + qt_screen-> transformOrientation() !!)
259 m_rotation = fs ? -qt_screen-> transformOrientation ( ) : 0;
252 260
253 if ( fs && qt_screen-> isTransformed ( )) 261 if ( fs && qt_screen-> isTransformed ( ))
254 s = qt_screen-> mapToDevice ( s ); 262 s = qt_screen-> mapToDevice ( s );
255 263
256 emit videoResized ( s ); 264 emit videoResized ( s );
257 } 265}
258 266
259 267
260 void XineVideoWidget::mouseReleaseEvent ( QMouseEvent * ) { 268void XineVideoWidget::mouseReleaseEvent ( QMouseEvent * /*me*/ )
261 emit clicked ( ); 269{
262 } 270 emit clicked();
271}
263 272