summaryrefslogtreecommitdiff
authorsandman <sandman>2002-08-02 00:22:01 (UTC)
committer sandman <sandman>2002-08-02 00:22:01 (UTC)
commitca057e02c3bacb8226d5209fcd9aa24009cdb78e (patch) (unidiff)
tree46b4072715ec2f6fcd9affb5f5f3988dba4f3438
parentdae78cce45fb769720874562821d099d979b2c87 (diff)
downloadopie-ca057e02c3bacb8226d5209fcd9aa24009cdb78e.zip
opie-ca057e02c3bacb8226d5209fcd9aa24009cdb78e.tar.gz
opie-ca057e02c3bacb8226d5209fcd9aa24009cdb78e.tar.bz2
Video should work now in QVFB and on the iPAQ with all transformations
(0,90,180 and 270 deg)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/xinevideowidget.cpp151
1 files changed, 57 insertions, 94 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
index 8e8f139..4b69044 100644
--- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp
+++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
@@ -1,267 +1,230 @@
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 <qsize.h> 40#include <qsize.h>
40 41
41#include <qpe/resource.h> 42#include <qpe/resource.h>
42 43
43#include "xinevideowidget.h" 44#include "xinevideowidget.h"
44 45
45static inline void memcpy_rev ( void *dst, void *src, size_t len ) 46static inline void memcpy_rev ( void *dst, void *src, size_t len )
46{ 47{
47 ((char *) src ) += len; 48 ((char *) src ) += len;
48 49
49 len >>= 1; 50 len >>= 1;
50 while ( len-- ) 51 while ( len-- )
51 *((short int *) dst )++ = *--((short int *) src ); 52 *((short int *) dst )++ = *--((short int *) src );
52} 53}
53 54
54static inline void memcpy_step ( void *dst, void *src, size_t len, size_t step ) 55static inline void memcpy_step ( void *dst, void *src, size_t len, size_t step )
55{ 56{
56 len >>= 1; 57 len >>= 1;
57 while ( len-- ) { 58 while ( len-- ) {
58 // *((char *) dst ) = *((char *) src + 1);
59 // *((char *) dst + 1) = *((char *) src );
60 // ((char *) dst ) += 2;
61
62 *((short int *) dst )++ = *((short int *) src ); 59 *((short int *) dst )++ = *((short int *) src );
63 ((char *) src ) += step; 60 ((char *) src ) += step;
64 } 61 }
65} 62}
66 63
67static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t step ) 64static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t step )
68{ 65{
69 len >>= 1; 66 len >>= 1;
70 67
71 ((char *) src ) += ( len * step ); 68 ((char *) src ) += ( len * step );
72 69
73 while ( len-- ) { 70 while ( len-- ) {
74 ((char *) src ) -= step; 71 ((char *) src ) -= step;
75 *((short int *) dst )++ = *((short int *) src ); 72 *((short int *) dst )++ = *((short int *) src );
76
77 // *((char *) dst ) = *((char *) src + 1);
78 // *((char *) dst + 1) = *((char *) src );
79 // ((char *) dst ) += 2;
80 } 73 }
81} 74}
82 75
83 76
84XineVideoWidget::XineVideoWidget( int width, 77XineVideoWidget::XineVideoWidget( int width,
85 int height, 78 int height,
86 QWidget* parent, 79 QWidget* parent,
87 const char* name ) 80 const char* name )
88 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase ) 81 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase )
89{ 82{
90 m_image = new QImage ( width, height, qt_screen-> depth ( )); 83 m_image = new QImage ( width, height, qt_screen-> depth ( ));
91 m_buff = 0; 84 m_buff = 0;
92 setBackgroundMode ( NoBackground ); 85 setBackgroundMode ( NoBackground );
93 /* QImage image = Resource::loadImage("SoundPlayer"); 86 /* QImage image = Resource::loadImage("SoundPlayer");
94 image = image.smoothScale( width, height ); 87 image = image.smoothScale( width, height );
95 88
96 m_image = new QImage( image );*/ 89 m_image = new QImage( image );*/
97} 90}
98 91
99XineVideoWidget::~XineVideoWidget ( ) 92XineVideoWidget::~XineVideoWidget ( )
100{ 93{
101 delete m_image; 94 delete m_image;
102} 95}
103 96
104void XineVideoWidget::clear ( ) 97void XineVideoWidget::clear ( )
105{ 98{
106 m_buff = 0; 99 m_buff = 0;
107 repaint ( false ); 100 repaint ( false );
108} 101}
109 102
110void XineVideoWidget::paintEvent ( QPaintEvent * ) 103void XineVideoWidget::paintEvent ( QPaintEvent * )
111{ 104{
112 qWarning( "painting <<<" ); 105 //qWarning( "painting <<<" );
113 if ( m_buff == 0 ) { 106 if ( m_buff == 0 ) {
114 QPainter p ( this ); 107 QPainter p ( this );
115 p. fillRect ( rect ( ), black ); 108 p. fillRect ( rect ( ), black );
116 p. drawImage ( 0, 0, *m_image ); 109 p. drawImage ( 0, 0, *m_image );
117 qWarning ( "logo\n" ); 110 //qWarning ( "logo\n" );
118 } 111 }
119 else { 112 else {
120 // qWarning ( "paintevent\n" ); 113 // qWarning ( "paintevent\n" );
121 114
122 QArray <QRect> qt_bug_workaround_clip_rects; 115 QArray <QRect> qt_bug_workaround_clip_rects;
123 116
124 { 117 {
125 QDirectPainter dp ( this ); 118 QDirectPainter dp ( this );
126 119
127 int rot = dp. transformOrientation ( ); 120 int rot = dp. transformOrientation ( );
128 121
129 uchar *fb = dp. frameBuffer ( ); 122 uchar *fb = dp. frameBuffer ( );
130 uchar *frame = m_buff; // rot == 0 ? m_buff : m_buff + ( m_thisframe. height ( ) - 1 ) * m_bytes_per_line_frame; 123 uchar *frame = m_buff; // rot == 0 ? m_buff : m_buff + ( m_thisframe. height ( ) - 1 ) * m_bytes_per_line_frame;
131 124
132 QRect framerect = QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )); 125 QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
133 126
134 qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); 127 qt_bug_workaround_clip_rects. resize ( dp. numRects ( ));
135 128
136 for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { 129 for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) {
137 const QRect &clip = dp. rect ( i ); 130 const QRect &clip = dp. rect ( i );
138 131
139 qt_bug_workaround_clip_rects [i] = clip; 132 qt_bug_workaround_clip_rects [i] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
140 133
141 if ( rot == 0 || rot == 180 ) { 134 uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb );
142 uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); 135 uchar *src = frame;
143 uchar *src = frame + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ); 136
144 137 switch ( rot ) {
145 if ( rot == 180 ) 138 case 0: src += ( (( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ) ); break;
146 src += (( framerect. height ( ) - 1 ) * m_bytes_per_line_frame ); 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;
147 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;
148 uint leftfill = 0; 141 case 3: src += ( (( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame ) ); break;
149 uint framefill = 0;
150 uint rightfill = 0;
151 uint clipwidth = clip. width ( ) * m_bytes_per_pixel;
152
153 if ( clip. left ( ) < framerect. left ( ))
154 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth;
155 if ( clip. right ( ) > framerect. right ( ))
156 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth;
157
158 framefill = clipwidth - ( leftfill + rightfill );
159
160 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) {
161 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) {
162 memset ( dst, 0, clipwidth );
163 }
164 else {
165 if ( leftfill )
166 memset ( dst, 0, leftfill );
167
168 if ( framefill ) {
169 if ( rot == 0 )
170 memcpy ( dst + leftfill, src, framefill );
171 else
172 memcpy_rev ( dst + leftfill, src, framefill );
173 }
174 if ( rightfill )
175 memset ( dst + leftfill + framefill, 0, rightfill );
176 }
177
178 dst += m_bytes_per_line_fb;
179 src += ( rot == 0 ? m_bytes_per_line_frame : -m_bytes_per_line_frame );
180 }
181 } 142 }
182 else { // rot == 90 || rot == 270 143
183 uchar *dst = fb + ( clip. y ( ) * m_bytes_per_pixel ) + ( clip. x ( ) * m_bytes_per_line_fb ); 144 uint leftfill = 0;
184 uchar *src = frame + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame ); 145 uint framefill = 0;
185 146 uint rightfill = 0;
186 if ( rot == 270 ) 147 uint clipwidth = clip. width ( ) * m_bytes_per_pixel;
187 src += (( framerect. height ( ) - 1 ) * m_bytes_per_pixel ); 148
188 149 if ( clip. left ( ) < framerect. left ( ))
189 uint leftfill = 0; 150 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth;
190 uint framefill = 0; 151 if ( clip. right ( ) > framerect. right ( ))
191 uint rightfill = 0; 152 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth;
192 uint clipwidth = clip. height ( ) * m_bytes_per_pixel; 153
193 154 framefill = clipwidth - ( leftfill + rightfill );
194 if ( clip. bottom ( ) > framerect. bottom ( )) 155
195 leftfill = (( clip. bottom ( ) - framerect. bottom ( )) * m_bytes_per_pixel ) <? clipwidth; 156 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) {
196 if ( clip. top ( ) < framerect. top ( )) 157 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) {
197 rightfill = (( framerect. top ( ) - framerect. top ( )) * m_bytes_per_pixel ) <? clipwidth; 158 memset ( dst, 0, clipwidth );
159 }
160 else {
161 if ( leftfill )
162 memset ( dst, 0, leftfill );
163
164 if ( framefill ) {
165 switch ( rot ) {
166 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 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 }
171 }
172 if ( rightfill )
173 memset ( dst + leftfill + framefill, 0, rightfill );
174 }
198 175
199 framefill = clipwidth - ( leftfill + rightfill ); 176 dst += m_bytes_per_line_fb;
200 177
201 for ( int y = clip. left ( ); y <= clip. right ( ); y++ ) { 178 switch ( rot ) {
202 if (( y < framerect. left ( )) || ( y > framerect. right ( ))) { 179 case 0: src += m_bytes_per_line_frame; break;
203 memset ( dst, 0, clipwidth ); 180 case 1: src -= m_bytes_per_pixel; break;
204 } 181 case 2: src -= m_bytes_per_line_frame; break;
205 else { 182 case 3: src += m_bytes_per_pixel; break;
206 if ( leftfill ) 183 }
207 memset ( dst, 0, leftfill );
208
209 if ( framefill ) {
210 if ( rot == 90 )
211 memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame );
212 else
213 memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame );
214 }
215 if ( rightfill )
216 memset ( dst + leftfill + framefill, 0, rightfill );
217 }
218
219 dst += m_bytes_per_line_fb;
220 src += ( rot == 270 ? -m_bytes_per_pixel : m_bytes_per_pixel );
221 }
222 } 184 }
223 } 185 }
224 } 186 }
187 //qWarning ( " ||| painting |||" );
225 { 188 {
226 // QVFB hack by MArtin Jones 189 // QVFB hack by MArtin Jones
227 QPainter p ( this ); 190 QPainter p ( this );
228 191
229 for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) { 192 for ( int i = qt_bug_workaround_clip_rects. size ( ) - 1; i >= 0; i-- ) {
230 p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [i]. topLeft ( )), qt_bug_workaround_clip_rects [i]. size ( )), QBrush ( NoBrush ) ); 193 p. fillRect ( QRect ( mapFromGlobal ( qt_bug_workaround_clip_rects [i]. topLeft ( )), qt_bug_workaround_clip_rects [i]. size ( )), QBrush ( NoBrush ) );
231 } 194 }
232 } 195 }
233 } 196 }
234 qWarning( "painting >>>" ); 197 //qWarning( "painting >>>" );
235} 198}
236 199
237int XineVideoWidget::height ( ) const 200int XineVideoWidget::height ( ) const
238{ 201{
239 return m_image-> height ( ); 202 return m_image-> height ( );
240} 203}
241 204
242int XineVideoWidget::width ( ) const 205int XineVideoWidget::width ( ) const
243{ 206{
244 return m_image-> width ( ); 207 return m_image-> width ( );
245} 208}
246 209
247void XineVideoWidget::setImage ( QImage* image ) 210void XineVideoWidget::setImage ( QImage* image )
248{ 211{
249 delete m_image; 212 delete m_image;
250 m_image = image; 213 m_image = image;
251} 214}
252 215
253void XineVideoWidget::setImage( uchar* image, int yoffsetXLine, 216void XineVideoWidget::setImage( uchar* image, int yoffsetXLine,
254 int xoffsetXBytes, int width, 217 int xoffsetXBytes, int width,
255 int height, int linestep, int bytes, int bpp ) 218 int height, int linestep, int bytes, int bpp )
256{ 219{
257 220
258 m_lastframe = m_thisframe; 221 m_lastframe = m_thisframe;
259 m_thisframe. setRect ( xoffsetXBytes, yoffsetXLine, width, height ); 222 m_thisframe. setRect ( xoffsetXBytes, yoffsetXLine, width, height );
260 223
261 m_buff = image; 224 m_buff = image;
262 m_bytes_per_line_fb = linestep; 225 m_bytes_per_line_fb = linestep;
263 m_bytes_per_line_frame = bytes; 226 m_bytes_per_line_frame = bytes;
264 m_bytes_per_pixel = bpp; 227 m_bytes_per_pixel = bpp;
265 228
266 repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false ); 229 repaint ((( m_thisframe & m_lastframe ) != m_lastframe ) ? m_lastframe : m_thisframe, false );
267} 230}