summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/xinevideowidget.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
index 1ac9277..9e86041 100644
--- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp
+++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
@@ -1,304 +1,306 @@
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>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
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 <qdirectpainter_qws.h> 35#include <qdirectpainter_qws.h>
36#include <qgfx_qws.h> 36#include <qgfx_qws.h>
37#include <qsize.h> 37#include <qsize.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41 41
42#include "xinevideowidget.h" 42#include "xinevideowidget.h"
43 43
44 44
45// 0 deg rot: copy a line from src to dst (use libc memcpy) 45// 0 deg rot: copy a line from src to dst (use libc memcpy)
46 46
47// 180 deg rot: copy a line from src to dst reversed 47// 180 deg rot: copy a line from src to dst reversed
48 48
49/* 49/*
50 * This code relies the len be a multiply of 16bit 50 * This code relies the len be a multiply of 16bit
51 */ 51 */
52static inline void memcpy_rev ( void *_dst, void *_src, size_t len ) 52static inline void memcpy_rev ( void *_dst, void *_src, size_t len )
53{ 53{
54 54
55 /* 55 /*
56 * move the source to the end 56 * move the source to the end
57 */ 57 */
58 char *src_c = static_cast<char*>(_src) + len; 58 char *src_c = static_cast<char*>(_src) + len;
59 59
60 /* 60 /*
61 * as we copy by 16bit and not 8bit 61 * as we copy by 16bit and not 8bit
62 * devide the length by two 62 * devide the length by two
63 */ 63 */
64 len >>= 1; 64 len >>= 1;
65 65
66 short int* dst = static_cast<short int*>( _dst ); 66 short int* dst = static_cast<short int*>( _dst );
67 short int* src = reinterpret_cast<short int*>( src_c ); 67 short int* src = reinterpret_cast<short int*>( src_c );
68 68
69 /* 69 /*
70 * Increment dst after assigning 70 * Increment dst after assigning
71 * Decrement src before assigning becase we move backwards 71 * Decrement src before assigning becase we move backwards
72 */ 72 */
73 while ( len-- ) 73 while ( len-- )
74 *dst++ = *--src; 74 *dst++ = *--src;
75 75
76} 76}
77 77
78// 90 deg rot: copy a column from src to dst 78// 90 deg rot: copy a column from src to dst
79 79
80static inline void memcpy_step ( void *_dst, void *_src, size_t len, size_t step ) 80static inline void memcpy_step ( void *_dst, void *_src, size_t len, size_t step )
81{ 81{
82 short int *dst = static_cast<short int*>( _dst ); 82 short int *dst = static_cast<short int*>( _dst );
83 short int *src = static_cast<short int*>( _src ); 83 short int *src = static_cast<short int*>( _src );
84 84
85 len >>= 1; 85 len >>= 1;
86 86
87 /* 87 /*
88 * Copy 16bit from src to dst and move to the next address 88 * Copy 16bit from src to dst and move to the next address
89 */ 89 */
90 while ( len-- ) { 90 while ( len-- ) {
91 *dst++ = *src; 91 *dst++ = *src;
92 src = reinterpret_cast<short int*>(reinterpret_cast<char*>(src)+step); 92 src = reinterpret_cast<short int*>(reinterpret_cast<char*>(src)+step);
93 } 93 }
94} 94}
95 95
96// 270 deg rot: copy a column from src to dst reversed 96// 270 deg rot: copy a column from src to dst reversed
97 97
98static inline void memcpy_step_rev ( void *_dst, void *_src, size_t len, size_t step ) 98static inline void memcpy_step_rev ( void *_dst, void *_src, size_t len, size_t step )
99{ 99{
100 len >>= 1; 100 len >>= 1;
101 101
102 char *src_c = static_cast<char*>( _src ) + (len*step); 102 char *src_c = static_cast<char*>( _src ) + (len*step);
103 short int* dst = static_cast<short int*>( _dst ); 103 short int* dst = static_cast<short int*>( _dst );
104 short int* src = reinterpret_cast<short int*>( src_c ); 104 short int* src = reinterpret_cast<short int*>( src_c );
105 105
106 while ( len-- ) { 106 while ( len-- ) {
107 src_c -= step; 107 src_c -= step;
108 src = reinterpret_cast<short int*>( src_c ); 108 src = reinterpret_cast<short int*>( src_c );
109 *dst++ = *src; 109 *dst++ = *src;
110 } 110 }
111} 111}
112 112
113 113
114XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name ) 114XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name )
115 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase ) 115 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase )
116{ 116{
117 setBackgroundMode ( NoBackground ); 117 setBackgroundMode ( NoBackground );
118 118
119 m_logo = 0; 119 m_logo = 0;
120 m_buff = 0; 120 m_buff = 0;
121 m_bytes_per_line_fb = qt_screen-> linestep ( ); 121 m_bytes_per_line_fb = qt_screen-> linestep ( );
122 m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8; 122 m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8;
123 m_rotation = 0; 123 m_rotation = 0;
124} 124}
125 125
126 126
127XineVideoWidget::~XineVideoWidget ( ) 127XineVideoWidget::~XineVideoWidget ( )
128{ 128{
129 delete m_logo; 129 delete m_logo;
130} 130}
131 131
132void XineVideoWidget::clear ( ) 132void XineVideoWidget::clear ( )
133{ 133{
134 m_buff = 0; 134 m_buff = 0;
135 repaint ( false ); 135 repaint ( false );
136} 136}
137 137
138QSize XineVideoWidget::videoSize() const 138QSize XineVideoWidget::videoSize() const
139{ 139{
140 QSize s = size(); 140 QSize s = size();
141 bool fs = ( s == qApp->desktop()->size() ); 141 bool fs = ( s == qApp->desktop()->size() );
142 142
143 // if we are in fullscreen mode, do not rotate the video 143 // if we are in fullscreen mode, do not rotate the video
144 // (!! the paint routine uses m_rotation + qt_screen-> transformOrientation() !!) 144 // (!! the paint routine uses m_rotation + qt_screen-> transformOrientation() !!)
145 m_rotation = fs ? - qt_screen->transformOrientation() : 0; 145 m_rotation = fs ? - qt_screen->transformOrientation() : 0;
146 146
147 if ( fs && qt_screen->isTransformed() ) 147 if ( fs && qt_screen->isTransformed() )
148 s = qt_screen->mapToDevice( s ); 148 s = qt_screen->mapToDevice( s );
149 149
150 return s; 150 return s;
151} 151}
152 152
153void XineVideoWidget::paintEvent ( QPaintEvent * ) 153void XineVideoWidget::paintEvent ( QPaintEvent * )
154{ 154{
155 if ( m_buff == 0 ) { 155 if ( m_buff == 0 ) {
156 QPainter p ( this ); 156 QPainter p ( this );
157 p. fillRect ( rect ( ), black ); 157 p. fillRect ( rect ( ), black );
158 if ( m_logo ) 158 if ( m_logo )
159 p. drawImage ( 0, 0, *m_logo ); 159 p. drawImage ( 0, 0, *m_logo );
160 } 160 }
161 else { 161 else {
162 // Qt needs to be notified which areas were really updated .. strange 162 // Qt needs to be notified which areas were really updated .. strange
163 QArray <QRect> qt_bug_workaround_clip_rects; 163 QArray <QRect> qt_bug_workaround_clip_rects;
164 164
165 { 165 {
166 QDirectPainter dp ( this ); 166 QDirectPainter dp ( this );
167 167
168 int rot = dp. transformOrientation ( ) + m_rotation; // device rotation + custom rotation 168 int rot = dp. transformOrientation ( ) + m_rotation; // device rotation + custom rotation
169 169
170 uchar *fb = dp. frameBuffer ( ); 170 uchar *fb = dp. frameBuffer ( );
171 uchar *frame = m_buff; 171 uchar *frame = m_buff;
172 172
173 // where is the video frame in fb coordinates 173 // where is the video frame in fb coordinates
174 QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); 174 QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
175 175
176 qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); 176 qt_bug_workaround_clip_rects. resize ( dp. numRects ( ));
177 177
178 for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { 178 for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) {
179 const QRect &clip = dp. rect ( i ); 179 const QRect &clip = dp. rect ( i );
180 180
181 qt_bug_workaround_clip_rects [ i ] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); 181 qt_bug_workaround_clip_rects [ i ] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
182 182
183 uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); // clip x/y in the fb 183 uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); // clip x/y in the fb
184 uchar *src = frame; 184 uchar *src = frame;
185 185
186 // Adjust the start the source data based on the rotation (xine frame) 186 // Adjust the start the source data based on the rotation (xine frame)
187 switch ( rot ) { 187 switch ( rot ) {
188 case 0: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame )); break; 188 case 0: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame )); break;
189 case 1: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame ) + (( framerect. height ( ) - 1 ) * m_bytes_per_pixel )); break; 189 case 1: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame ) + (( framerect. height ( ) - 1 ) * m_bytes_per_pixel )); break;
190 case 2: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ) + (( framerect. height ( ) - 1 ) * m_bytes_per_line_frame )); break; 190 case 2: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ) + (( framerect. height ( ) - 1 ) * m_bytes_per_line_frame )); break;
191 case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break; 191 case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break;
192 default: break; 192 default: break;
193 } 193 }
194 194
195 // all of the following widths/heights are fb relative (0deg rotation) 195 // all of the following widths/heights are fb relative (0deg rotation)
196 196
197 uint leftfill = 0; // black border on the "left" side of the video frame 197 uint leftfill = 0; // black border on the "left" side of the video frame
198 uint framefill = 0; // "width" of the video frame 198 uint framefill = 0; // "width" of the video frame
199 uint rightfill = 0; // black border on the "right" side of the video frame 199 uint rightfill = 0; // black border on the "right" side of the video frame
200 uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect 200 uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect
201 201
202 if ( clip. left ( ) < framerect. left ( )) 202 if ( clip. left ( ) < framerect. left ( ))
203 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth; 203 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth;
204 if ( clip. right ( ) > framerect. right ( )) 204 if ( clip. right ( ) > framerect. right ( ))
205 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth; 205 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth;
206 206
207 framefill = clipwidth - ( leftfill + rightfill ); 207 framefill = clipwidth - ( leftfill + rightfill );
208 208
209 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) { 209 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) {
210 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) { 210 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) {
211 // "above" or "below" the video -> black 211 // "above" or "below" the video -> black
212 memset ( dst, 0, clipwidth ); 212 memset ( dst, 0, clipwidth );
213 } 213 }
214 else { 214 else {
215 if ( leftfill ) 215 if ( leftfill )
216 memset ( dst, 0, leftfill ); // "left" border -> black 216 memset ( dst, 0, leftfill ); // "left" border -> black
217 217
218 if ( framefill ) { // blit in the video frame 218 if ( framefill ) { // blit in the video frame
219 // see above for an explanation of the different memcpys 219 // see above for an explanation of the different memcpys
220 220
221 switch ( rot ) { 221 switch ( rot ) {
222 case 0: memcpy ( dst + leftfill, src, framefill & ~1 ); break; 222 case 0: memcpy ( dst + leftfill, src, framefill & ~1 ); break;
223 case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; 223 case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break;
224 case 2: memcpy_rev ( dst + leftfill, src, framefill ); break; 224 case 2: memcpy_rev ( dst + leftfill, src, framefill ); break;
225 case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; 225 case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break;
226 default: break; 226 default: break;
227 } 227 }
228 } 228 }
229 if ( rightfill ) 229 if ( rightfill )
230 memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black 230 memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black
231 } 231 }
232 232
233 dst += m_bytes_per_line_fb; // advance one line in the framebuffer 233 dst += m_bytes_per_line_fb; // advance one line in the framebuffer
234 234
235 // advance one "line" in the xine frame data 235 // advance one "line" in the xine frame data
236 switch ( rot ) { 236 switch ( rot ) {
237 case 0: src += m_bytes_per_line_frame;break; 237 case 0: src += m_bytes_per_line_frame;break;
238 case 1: src -= m_bytes_per_pixel; break; 238 case 1: src -= m_bytes_per_pixel; break;
239 case 2: src -= m_bytes_per_line_frame; break; 239 case 2: src -= m_bytes_per_line_frame; break;
240 case 3: src += m_bytes_per_pixel; break; 240 case 3: src += m_bytes_per_pixel; break;
241 default: break; 241 default: break;
242 } 242 }
243 } 243 }
244 } 244 }
245 } 245 }
246 246
247 { 247 {
248 // QVFB hack by Martin Jones 248 // QVFB hack by Martin Jones
249 // We need to "touch" all affected clip rects with a normal QPainter in addition to the QDirectPainter 249 // We need to "touch" all affected clip rects with a normal QPainter in addition to the QDirectPainter
250 250
251 QPainter p ( this ); 251 QPainter p ( this );
252 252
253 for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) { 253 for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) {
254 p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [ i ]. topLeft ( )), qt_bug_workaround_clip_rects [ i ]. size ( )), QBrush ( NoBrush )); 254 p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [ i ]. topLeft ( )), qt_bug_workaround_clip_rects [ i ]. size ( )), QBrush ( NoBrush ));
255 } 255 }
256 } 256 }
257 } 257 }
258} 258}
259 259
260 260
261QImage *XineVideoWidget::logo ( ) const 261QImage *XineVideoWidget::logo ( ) const
262{ 262{
263 return m_logo; 263 return m_logo;
264} 264}
265 265
266 266
267void XineVideoWidget::setLogo ( QImage* logo ) 267void XineVideoWidget::setLogo ( QImage* logo )
268{ 268{
269 delete m_logo; 269 delete m_logo;
270 m_logo = logo; 270 m_logo = logo;
271} 271}
272 272
273void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl ) 273void XineVideoWidget::setVideoFrame ( uchar* img, int w, int h, int bpl )
274{ 274{
275 bool rot90 = (( -m_rotation ) & 1 ); 275 bool rot90 = (( -m_rotation ) & 1 );
276 276
277 if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height 277 if ( rot90 ) { // if the rotation is 90 or 270 we have to swap width / height
278 int d = w; 278 int d = w;
279 w = h; 279 w = h;
280 h = d; 280 h = d;
281 } 281 }
282 282
283 m_lastframe = m_thisframe; 283 m_lastframe = m_thisframe;
284 m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); 284 m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h );
285 285
286 m_buff = img; 286 m_buff = img;
287 m_bytes_per_line_frame = bpl; 287 m_bytes_per_line_frame = bpl;
288 288
289 // only repaint the area that *really* needs to be repainted 289 // only repaint the area that *really* needs to be repainted
290 290
291 repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false ); 291 repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false );
292 // ensure that we always have a valid frame!
293 m_buff = 0;
292} 294}
293 295
294void XineVideoWidget::resizeEvent ( QResizeEvent * ) 296void XineVideoWidget::resizeEvent ( QResizeEvent * )
295{ 297{
296 emit videoResized( videoSize() ); 298 emit videoResized( videoSize() );
297} 299}
298 300
299 301
300void XineVideoWidget::mouseReleaseEvent ( QMouseEvent * /*me*/ ) 302void XineVideoWidget::mouseReleaseEvent ( QMouseEvent * /*me*/ )
301{ 303{
302 emit clicked(); 304 emit clicked();
303} 305}
304 306