-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 | |||
@@ -42,6 +42,37 @@ | |||
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, |
@@ -56,14 +87,20 @@ XineVideoWidget::XineVideoWidget( int width, | |||
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 ); |
@@ -72,54 +109,150 @@ void XineVideoWidget::paintEvent( QPaintEvent* e ) { | |||
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 | |||
@@ -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 | ||