Diffstat (limited to 'noncore/multimedia/opieplayer2/xinevideowidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/xinevideowidget.cpp | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp index 4b69044..98446a0 100644 --- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp +++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp | |||
@@ -1,230 +1,267 @@ | |||
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 Max Reiss <harlekin@handhelds.org> | 5 | Copyright (c) 2002 Max Reiss <harlekin@handhelds.org> |
6 | Copyright (c) 2002 LJP <> | 6 | Copyright (c) 2002 LJP <> |
7 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> | 7 | Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> |
8 | =. | 8 | =. |
9 | .=l. | 9 | .=l. |
10 | .>+-= | 10 | .>+-= |
11 | _;:, .> :=|. This program is free software; you can | 11 | _;:, .> :=|. This program is free software; you can |
12 | .> <`_, > . <= redistribute it and/or modify it under | 12 | .> <`_, > . <= redistribute it and/or modify it under |
13 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 13 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
14 | .="- .-=="i, .._ License as published by the Free Software | 14 | .="- .-=="i, .._ License as published by the Free Software |
15 | - . .-<_> .<> Foundation; either version 2 of the License, | 15 | - . .-<_> .<> Foundation; either version 2 of the License, |
16 | ._= =} : or (at your option) any later version. | 16 | ._= =} : or (at your option) any later version. |
17 | .%`+i> _;_. | 17 | .%`+i> _;_. |
18 | .i_,=:_. -<s. This program is distributed in the hope that | 18 | .i_,=:_. -<s. This program is distributed in the hope that |
19 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 19 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
20 | : .. .:, . . . without even the implied warranty of | 20 | : .. .:, . . . without even the implied warranty of |
21 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 21 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
22 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 22 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
23 | ..}^=.= = ; Library General Public License for more | 23 | ..}^=.= = ; Library General Public License for more |
24 | ++= -. .` .: details. | 24 | ++= -. .` .: details. |
25 | : = ...= . :.=- | 25 | : = ...= . :.=- |
26 | -. .:....=;==+<; You should have received a copy of the GNU | 26 | -. .:....=;==+<; You should have received a copy of the GNU |
27 | -_. . . )=. = Library General Public License along with | 27 | -_. . . )=. = Library General Public License along with |
28 | -- :-=` this library; see the file COPYING.LIB. | 28 | -- :-=` this library; see the file COPYING.LIB. |
29 | If not, write to the Free Software Foundation, | 29 | If not, write to the Free Software Foundation, |
30 | Inc., 59 Temple Place - Suite 330, | 30 | Inc., 59 Temple Place - Suite 330, |
31 | Boston, MA 02111-1307, USA. | 31 | Boston, MA 02111-1307, USA. |
32 | 32 | ||
33 | */ | 33 | */ |
34 | 34 | ||
35 | #include <qimage.h> | 35 | #include <qimage.h> |
36 | #include <qpainter.h> | 36 | #include <qpainter.h> |
37 | #include <qgfx_qws.h> | 37 | #include <qgfx_qws.h> |
38 | #include <qdirectpainter_qws.h> | 38 | #include <qdirectpainter_qws.h> |
39 | #include <qgfx_qws.h> | 39 | #include <qgfx_qws.h> |
40 | #include <qsize.h> | 40 | #include <qsize.h> |
41 | #include <qapplication.h> | ||
41 | 42 | ||
42 | #include <qpe/resource.h> | 43 | #include <qpe/resource.h> |
43 | 44 | ||
44 | #include "xinevideowidget.h" | 45 | #include "xinevideowidget.h" |
45 | 46 | ||
47 | |||
46 | static inline void memcpy_rev ( void *dst, void *src, size_t len ) | 48 | static inline void memcpy_rev ( void *dst, void *src, size_t len ) |
47 | { | 49 | { |
48 | ((char *) src ) += len; | 50 | ((char *) src ) += len; |
49 | 51 | ||
50 | len >>= 1; | 52 | len >>= 1; |
51 | while ( len-- ) | 53 | while ( len-- ) |
52 | *((short int *) dst )++ = *--((short int *) src ); | 54 | *((short int *) dst )++ = *--((short int *) src ); |
53 | } | 55 | } |
54 | 56 | ||
55 | static inline void memcpy_step ( void *dst, void *src, size_t len, size_t step ) | 57 | static inline void memcpy_step ( void *dst, void *src, size_t len, size_t step ) |
56 | { | 58 | { |
57 | len >>= 1; | 59 | len >>= 1; |
58 | while ( len-- ) { | 60 | while ( len-- ) { |
59 | *((short int *) dst )++ = *((short int *) src ); | 61 | *((short int *) dst )++ = *((short int *) src ); |
60 | ((char *) src ) += step; | 62 | ((char *) src ) += step; |
61 | } | 63 | } |
62 | } | 64 | } |
63 | 65 | ||
64 | static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t step ) | 66 | static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t step ) |
65 | { | 67 | { |
66 | len >>= 1; | 68 | len >>= 1; |
67 | 69 | ||
68 | ((char *) src ) += ( len * step ); | 70 | ((char *) src ) += ( len * step ); |
69 | 71 | ||
70 | while ( len-- ) { | 72 | while ( len-- ) { |
71 | ((char *) src ) -= step; | 73 | ((char *) src ) -= step; |
72 | *((short int *) dst )++ = *((short int *) src ); | 74 | *((short int *) dst )++ = *((short int *) src ); |
73 | } | 75 | } |
74 | } | 76 | } |
75 | 77 | ||
76 | 78 | ||
77 | XineVideoWidget::XineVideoWidget( int width, | 79 | XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name ) |
78 | int height, | ||
79 | QWidget* parent, | ||
80 | const char* name ) | ||
81 | : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase ) | 80 | : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase ) |
82 | { | 81 | { |
83 | m_image = new QImage ( width, height, qt_screen-> depth ( )); | ||
84 | m_buff = 0; | ||
85 | setBackgroundMode ( NoBackground ); | 82 | setBackgroundMode ( NoBackground ); |
86 | /* QImage image = Resource::loadImage("SoundPlayer"); | 83 | |
87 | image = image.smoothScale( width, height ); | 84 | m_image = 0; |
88 | 85 | m_buff = 0; | |
89 | m_image = new QImage( image );*/ | 86 | m_bytes_per_line_fb = qt_screen-> linestep ( ); |
87 | m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8; | ||
88 | m_rotation = 0; | ||
90 | } | 89 | } |
91 | 90 | ||
91 | |||
92 | XineVideoWidget::~XineVideoWidget ( ) | 92 | XineVideoWidget::~XineVideoWidget ( ) |
93 | { | 93 | { |
94 | delete m_image; | 94 | delete m_image; |
95 | } | 95 | } |
96 | 96 | ||
97 | void XineVideoWidget::clear ( ) | 97 | void XineVideoWidget::clear ( ) |
98 | { | 98 | { |
99 | m_buff = 0; | 99 | m_buff = 0; |
100 | repaint ( false ); | 100 | repaint ( false ); |
101 | } | 101 | } |
102 | 102 | ||
103 | void XineVideoWidget::paintEvent ( QPaintEvent * ) | 103 | void XineVideoWidget::paintEvent ( QPaintEvent * ) |
104 | { | 104 | { |
105 | //qWarning( "painting <<<" ); | 105 | //qWarning( "painting <<<" ); |
106 | if ( m_buff == 0 ) { | 106 | if ( m_buff == 0 ) { |
107 | QPainter p ( this ); | 107 | QPainter p ( this ); |
108 | p. fillRect ( rect ( ), black ); | 108 | p. fillRect ( rect ( ), black ); |
109 | p. drawImage ( 0, 0, *m_image ); | 109 | if ( m_image ) |
110 | p. drawImage ( 0, 0, *m_image ); | ||
110 | //qWarning ( "logo\n" ); | 111 | //qWarning ( "logo\n" ); |
111 | } | 112 | } |
112 | else { | 113 | else { |
113 | // qWarning ( "paintevent\n" ); | 114 | // qWarning ( "paintevent\n" ); |
114 | 115 | ||
115 | QArray <QRect> qt_bug_workaround_clip_rects; | 116 | QArray <QRect> qt_bug_workaround_clip_rects; |
116 | 117 | ||
117 | { | 118 | { |
118 | QDirectPainter dp ( this ); | 119 | QDirectPainter dp ( this ); |
119 | 120 | ||
120 | int rot = dp. transformOrientation ( ); | 121 | int rot = dp. transformOrientation ( ) + m_rotation; |
121 | 122 | ||
122 | uchar *fb = dp. frameBuffer ( ); | 123 | uchar *fb = dp. frameBuffer ( ); |
123 | uchar *frame = m_buff; // rot == 0 ? m_buff : m_buff + ( m_thisframe. height ( ) - 1 ) * m_bytes_per_line_frame; | 124 | uchar *frame = m_buff; // rot == 0 ? m_buff : m_buff + ( m_thisframe. height ( ) - 1 ) * m_bytes_per_line_frame; |
124 | 125 | ||
125 | QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); | 126 | QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); |
126 | 127 | ||
127 | qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); | 128 | qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); |
128 | 129 | ||
129 | for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { | 130 | for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { |
130 | const QRect &clip = dp. rect ( i ); | 131 | const QRect &clip = dp. rect ( i ); |
131 | 132 | ||
132 | qt_bug_workaround_clip_rects [i] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); | 133 | qt_bug_workaround_clip_rects [i] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); |
133 | 134 | ||
134 | uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); | 135 | uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); |
135 | uchar *src = frame; | 136 | uchar *src = frame; |
136 | 137 | ||
137 | switch ( rot ) { | 138 | switch ( rot ) { |
138 | case 0: src += ( (( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ) ); break; | 139 | case 0: src += ( (( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ) ); break; |
139 | 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; | 140 | 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; |
140 | 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; | 141 | 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; |
141 | case 3: src += ( (( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame ) ); break; | 142 | case 3: src += ( (( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame ) ); break; |
142 | } | 143 | } |
143 | 144 | ||
144 | uint leftfill = 0; | 145 | uint leftfill = 0; |
145 | uint framefill = 0; | 146 | uint framefill = 0; |
146 | uint rightfill = 0; | 147 | uint rightfill = 0; |
147 | uint clipwidth = clip. width ( ) * m_bytes_per_pixel; | 148 | uint clipwidth = clip. width ( ) * m_bytes_per_pixel; |
148 | 149 | ||
149 | if ( clip. left ( ) < framerect. left ( )) | 150 | if ( clip. left ( ) < framerect. left ( )) |
150 | leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth; | 151 | leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth; |
151 | if ( clip. right ( ) > framerect. right ( )) | 152 | if ( clip. right ( ) > framerect. right ( )) |
152 | rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth; | 153 | rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth; |
153 | 154 | ||
154 | framefill = clipwidth - ( leftfill + rightfill ); | 155 | framefill = clipwidth - ( leftfill + rightfill ); |
155 | 156 | ||
156 | for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) { | 157 | for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) { |
157 | if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) { | 158 | if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) { |
158 | memset ( dst, 0, clipwidth ); | 159 | memset ( dst, 0, clipwidth ); |
159 | } | 160 | } |
160 | else { | 161 | else { |
161 | if ( leftfill ) | 162 | if ( leftfill ) |
162 | memset ( dst, 0, leftfill ); | 163 | memset ( dst, 0, leftfill ); |
163 | 164 | ||
164 | if ( framefill ) { | 165 | if ( framefill ) { |
165 | switch ( rot ) { | 166 | switch ( rot ) { |
166 | case 0: memcpy ( dst + leftfill, src, framefill ); break; | 167 | case 0: memcpy ( dst + leftfill, src, framefill ); break; |
167 | case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; | 168 | case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; |
168 | case 2: memcpy_rev ( dst + leftfill, src, framefill ); break; | 169 | case 2: memcpy_rev ( dst + leftfill, src, framefill ); break; |
169 | case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; | 170 | case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; |
170 | } | 171 | } |
171 | } | 172 | } |
172 | if ( rightfill ) | 173 | if ( rightfill ) |
173 | memset ( dst + leftfill + framefill, 0, rightfill ); | 174 | memset ( dst + leftfill + framefill, 0, rightfill ); |
174 | } | 175 | } |
175 | 176 | ||
176 | dst += m_bytes_per_line_fb; | 177 | dst += m_bytes_per_line_fb; |
177 | 178 | ||
178 | switch ( rot ) { | 179 | switch ( rot ) { |
179 | case 0: src += m_bytes_per_line_frame; break; | 180 | case 0: src += m_bytes_per_line_frame; break; |
180 | case 1: src -= m_bytes_per_pixel; break; | 181 | case 1: src -= m_bytes_per_pixel; break; |
181 | case 2: src -= m_bytes_per_line_frame; break; | 182 | case 2: src -= m_bytes_per_line_frame; break; |
182 | case 3: src += m_bytes_per_pixel; break; | 183 | case 3: src += m_bytes_per_pixel; break; |
183 | } | 184 | } |
184 | } | 185 | } |
185 | } | 186 | } |
186 | } | 187 | } |
187 | //qWarning ( " ||| painting |||" ); | 188 | //qWarning ( " ||| painting |||" ); |
188 | { | 189 | { |
189 | // QVFB hack by MArtin Jones | 190 | // QVFB hack by MArtin Jones |
190 | QPainter p ( this ); | 191 | QPainter p ( this ); |
191 | 192 | ||
192 | for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) { | 193 | for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) { |
193 | p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [i]. topLeft ( )), qt_bug_workaround_clip_rects [i]. size ( )), QBrush ( NoBrush ) ); | 194 | p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [i]. topLeft ( )), qt_bug_workaround_clip_rects [i]. size ( )), QBrush ( NoBrush ) ); |
194 | } | 195 | } |
195 | } | 196 | } |
196 | } | 197 | } |
197 | //qWarning( "painting >>>" ); | 198 | //qWarning( "painting >>>" ); |
198 | } | 199 | } |
199 | 200 | ||
200 | int XineVideoWidget::height ( ) const | ||
201 | { | ||
202 | return m_image-> height ( ); | ||
203 | } | ||
204 | |||
205 | int XineVideoWidget::width ( ) const | ||
206 | { | ||
207 | return m_image-> width ( ); | ||
208 | } | ||
209 | 201 | ||
210 | void XineVideoWidget::setImage ( QImage* image ) | 202 | void XineVideoWidget::setImage ( QImage* image ) |
211 | { | 203 | { |
212 | delete m_image; | 204 | delete m_image; |
213 | m_image = image; | 205 | m_image = image; |
214 | } | 206 | } |
215 | 207 | ||
216 | void XineVideoWidget::setImage( uchar* image, int yoffsetXLine, | 208 | void XineVideoWidget::setImage ( uchar* img, int w, int h, int bpl ) |
217 | int xoffsetXBytes, int width, | ||
218 | int height, int linestep, int bytes, int bpp ) | ||
219 | { | 209 | { |
210 | bool rot90 = (( -m_rotation ) & 1 ); | ||
211 | |||
212 | if ( rot90 ) { | ||
213 | int d = w; | ||
214 | w = h; | ||
215 | h = d; | ||
216 | } | ||
220 | 217 | ||
221 | m_lastframe = m_thisframe; | 218 | m_lastframe = m_thisframe; |
222 | m_thisframe. setRect ( xoffsetXBytes, yoffsetXLine, width, height ); | 219 | m_thisframe. setRect (( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); |
223 | 220 | ||
224 | m_buff = image; | 221 | //qDebug ( "Frame: %d,%d - %dx%d", ( width ( ) - w ) / 2, ( height ( ) - h ) / 2, w , h ); |
225 | m_bytes_per_line_fb = linestep; | 222 | |
226 | m_bytes_per_line_frame = bytes; | 223 | m_buff = img; |
227 | m_bytes_per_pixel = bpp; | 224 | m_bytes_per_line_frame = bpl; |
228 | 225 | ||
229 | repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false ); | 226 | repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false ); |
230 | } | 227 | } |
228 | |||
229 | void XineVideoWidget::resizeEvent ( QResizeEvent * ) | ||
230 | { | ||
231 | QSize s = size ( ); | ||
232 | bool fs = ( s == qApp-> desktop ( )-> size ( )); | ||
233 | |||
234 | m_rotation = fs ? -qt_screen-> transformOrientation ( ) : 0; | ||
235 | |||
236 | if ( fs && qt_screen-> isTransformed ( )) { | ||
237 | s = qt_screen-> mapToDevice ( s ); | ||
238 | } | ||
239 | |||
240 | //qDebug ( "\n\nResize: %dx%d, Rot: %d", s.width(),s.height(),m_rotation ); | ||
241 | |||
242 | emit videoResized ( s ); | ||
243 | } | ||
244 | |||
245 | |||
246 | void XineVideoWidget::mousePressEvent ( QMouseEvent *me ) | ||
247 | { | ||
248 | QWidget *p = parentWidget ( ); | ||
249 | |||
250 | if ( p ) { | ||
251 | QMouseEvent pme ( QEvent::MouseButtonPress, mapToParent ( me-> pos ( )), me-> globalPos ( ), me-> button ( ), me-> state ( )); | ||
252 | |||
253 | QApplication::sendEvent ( p, &pme ); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | void XineVideoWidget::mouseReleaseEvent ( QMouseEvent *me ) | ||
258 | { | ||
259 | QWidget *p = parentWidget ( ); | ||
260 | |||
261 | if ( p ) { | ||
262 | QMouseEvent pme ( QEvent::MouseButtonRelease, mapToParent ( me-> pos ( )), me-> globalPos ( ), me-> button ( ), me-> state ( )); | ||
263 | |||
264 | QApplication::sendEvent ( p, &pme ); | ||
265 | } | ||
266 | } | ||
267 | |||