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