author | sandman <sandman> | 2002-08-01 19:36:14 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-08-01 19:36:14 (UTC) |
commit | c80b2060a6f051f16690db4b8f0ccbc7dde84ec5 (patch) (unidiff) | |
tree | 42ac3e7339c4a2a1b8c248b0dc6e0107e2e25aed | |
parent | df93f330693ed3baeeb43a8e4a57cdcc011f571e (diff) | |
download | opie-c80b2060a6f051f16690db4b8f0ccbc7dde84ec5.zip opie-c80b2060a6f051f16690db4b8f0ccbc7dde84ec5.tar.gz opie-c80b2060a6f051f16690db4b8f0ccbc7dde84ec5.tar.bz2 |
Optimized video repaint for 0 and 180 deg rotation - 90 and 270 are there
but untested
-rw-r--r-- | noncore/multimedia/opieplayer2/xinevideowidget.cpp | 181 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/xinevideowidget.h | 7 |
2 files changed, 159 insertions, 29 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 | |||
@@ -21,105 +21,238 @@ | |||
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 <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 ) | ||
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 | |
91 | XineVideoWidget::~XineVideoWidget ( ) | ||
92 | { | ||
60 | delete m_image; | 93 | delete m_image; |
61 | } | 94 | } |
62 | void XineVideoWidget::clear() { | 95 | |
96 | void XineVideoWidget::clear ( ) | ||
97 | { | ||
63 | m_buff = 0; | 98 | m_buff = 0; |
64 | repaint(false); | 99 | repaint(false); |
65 | } | 100 | } |
66 | void XineVideoWidget::paintEvent( QPaintEvent* e ) { | 101 | |
102 | void XineVideoWidget::paintEvent ( QPaintEvent * ) | ||
103 | { | ||
67 | qWarning("painting"); | 104 | qWarning("painting"); |
68 | if (m_buff == 0 ) { | 105 | if (m_buff == 0 ) { |
69 | QPainter p(this ); | 106 | QPainter p(this ); |
70 | p.fillRect( rect(), black ); | 107 | p.fillRect( rect(), black ); |
71 | p.drawImage( 0, 0, *m_image ); | 108 | p.drawImage( 0, 0, *m_image ); |
72 | qWarning ( "logo\n" ); | 109 | qWarning ( "logo\n" ); |
73 | } | 110 | } |
74 | else { | 111 | else { |
75 | qWarning("paitnevent\n"); | 112 | qWarning ( "paintevent\n" ); |
113 | |||
114 | QArray <QRect> qt_bug_workaround_clip_rects; | ||
115 | |||
76 | { | 116 | { |
117 | QDirectPainter dp ( this ); | ||
77 | 118 | ||
78 | if (( m_thisframe & m_lastframe ) != m_lastframe ) { | 119 | uchar *fb = dp. frameBuffer ( ); |
79 | QPainter p ( this ); | 120 | uchar *frame = m_buff; // rot == 0 ? m_buff : m_buff + ( m_thisframe. height ( ) - 1 ) * m_bytes_per_line_frame; |
80 | p. fillRect ( m_lastframe, black ); | 121 | |
122 | QRect framerect = QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )); | ||
123 | |||
124 | qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); | ||
125 | |||
126 | for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { | ||
127 | const QRect &clip = dp. rect ( i ); | ||
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 ); | ||
81 | } | 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 ); | ||
82 | } | 165 | } |
83 | { | 166 | if ( rightfill ) |
84 | QDirectPainter dp ( this ); | 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 ); | ||
85 | 200 | ||
86 | uchar* dst = dp.frameBuffer() + (m_thisframe. y ( ) + dp.yOffset() ) * linestep + | 201 | if ( framefill ) { |
87 | (m_thisframe. x ( ) + dp.xOffset() ) * m_bytes_per_pixel; | 202 | if ( rot == 90 ) |
88 | uchar* frame = m_buff; | 203 | memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); |
89 | for(int y = 0; y < m_thisframe. height ( ); y++ ) { | 204 | else |
90 | memcpy( dst, frame, m_bytes ); | 205 | memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); |
91 | frame += m_bytes; | 206 | } |
92 | dst += linestep; | 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 ) ); | ||
99 | } | 223 | } |
100 | } | 224 | } |
101 | } | 225 | } |
102 | int XineVideoWidget::height() const{ | 226 | } |
227 | |||
228 | int XineVideoWidget::height ( ) const | ||
229 | { | ||
103 | return m_image->height(); | 230 | return m_image->height(); |
104 | } | 231 | } |
105 | int XineVideoWidget::width() const{ | 232 | |
233 | int XineVideoWidget::width ( ) const | ||
234 | { | ||
106 | return m_image->width(); | 235 | return m_image->width(); |
107 | } | 236 | } |
108 | void XineVideoWidget::setImage( QImage* image ) { | 237 | |
238 | void XineVideoWidget::setImage ( QImage* image ) | ||
239 | { | ||
109 | delete m_image; | 240 | delete m_image; |
110 | m_image = 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 ) |
247 | { | ||
115 | 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 | |||
@@ -33,35 +33,32 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | 35 | ||
36 | #include <qwidget.h> | 36 | #include <qwidget.h> |
37 | 37 | ||
38 | class QImage; | 38 | class QImage; |
39 | class XineVideoWidget : public QWidget { | 39 | class XineVideoWidget : public QWidget { |
40 | Q_OBJECT | 40 | Q_OBJECT |
41 | public: | 41 | public: |
42 | XineVideoWidget( int width, int height, QWidget* parent, const char* name ); | 42 | XineVideoWidget( int width, int height, QWidget* parent, const char* name ); |
43 | ~XineVideoWidget(); | 43 | ~XineVideoWidget(); |
44 | QImage *image() { return m_image; }; | 44 | QImage *image() { return m_image; }; |
45 | void setImage( QImage* image ); | 45 | void setImage( QImage* image ); |
46 | void setImage( uchar* image, int yoffsetXLine, int xoffsetXBytes, | 46 | void setImage( uchar* image, int yoffsetXLine, int xoffsetXBytes, |
47 | int width, int height, int linestep, int bytes, int bpp); | 47 | int width, int height, int linestep, int bytes, int bpp); |
48 | int width() const; | 48 | int width() const; |
49 | int height() const; | 49 | int height() const; |
50 | void clear() ; | 50 | void clear() ; |
51 | protected: | 51 | protected: |
52 | void paintEvent( QPaintEvent* p ); | 52 | void paintEvent( QPaintEvent* p ); |
53 | private: | 53 | 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 | ||
66 | }; | 63 | }; |
67 | 64 | ||