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