summaryrefslogtreecommitdiff
authorzecke <zecke>2004-09-18 16:43:47 (UTC)
committer zecke <zecke>2004-09-18 16:43:47 (UTC)
commitc81e90d0f6c0feec1443d711833ea382a1c10ec6 (patch) (unidiff)
tree7390346761cfbceee0abccb51a80e30898f54f3b
parentfa5c8471c3053dfc8d9742426faa569b3aa03d71 (diff)
downloadopie-c81e90d0f6c0feec1443d711833ea382a1c10ec6.zip
opie-c81e90d0f6c0feec1443d711833ea382a1c10ec6.tar.gz
opie-c81e90d0f6c0feec1443d711833ea382a1c10ec6.tar.bz2
A proposal for making the memory copy functions build with g++3.4.2.
Please review the patch, specially the casts it makes, and also the boundaries and sizes. -Shouldn't we use unsigned char* instead of char*. For arm it is already unsigned? -Check again the casts
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/xinevideowidget.cpp66
1 files changed, 47 insertions, 19 deletions
diff --git a/noncore/multimedia/opieplayer2/xinevideowidget.cpp b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
index b55750a..15c611f 100644
--- a/noncore/multimedia/opieplayer2/xinevideowidget.cpp
+++ b/noncore/multimedia/opieplayer2/xinevideowidget.cpp
@@ -1,209 +1,237 @@
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 Robert Griebl <sandman@handhelds.org> 5 Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU General Public 12:`=1 )Y*s>-.--   : the terms of the GNU General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include <qimage.h> 34#include <qimage.h>
35#include <qdirectpainter_qws.h> 35#include <qdirectpainter_qws.h>
36#include <qgfx_qws.h> 36#include <qgfx_qws.h>
37#include <qsize.h> 37#include <qsize.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <qpe/resource.h> 40#include <qpe/resource.h>
41 41
42#include "xinevideowidget.h" 42#include "xinevideowidget.h"
43 43
44 44
45// 0 deg rot: copy a line from src to dst (use libc memcpy) 45// 0 deg rot: copy a line from src to dst (use libc memcpy)
46 46
47// 180 deg rot: copy a line from src to dst reversed 47// 180 deg rot: copy a line from src to dst reversed
48 48
49static inline void memcpy_rev ( void *dst, void *src, size_t len ) 49/*
50 * This code relies the len be a multiply of 16bit
51 */
52static inline void memcpy_rev ( void *_dst, void *_src, size_t len )
50{ 53{
51 len >>= 1; 54 /*
52 55 * move the source to the end
53 ((char *) src ) += ( len << 1 ); 56 */
57 char *src_c = static_cast<char*>(_src) + len;
58
59 /*
60 * as we copy by 16bit and not 8bit
61 * devide the length by two
62 */
63 len >>= 1;
64
65 short int* dst = static_cast<short int*>( _dst );
66 short int* src = reinterpret_cast<short int*>( src_c );
67
68 /*
69 * Increment dst after assigning
70 * Decrement src before assigning becase we move backwards
71 */
72 while ( len-- )
73 *dst++ = *--src;
54 74
55 while ( len-- )
56 *((short int *) dst )++ = *--((short int *) src );
57} 75}
58 76
59// 90 deg rot: copy a column from src to dst 77// 90 deg rot: copy a column from src to dst
60 78
61static inline void memcpy_step ( void *dst, void *src, size_t len, size_t step ) 79static inline void memcpy_step ( void *_dst, void *_src, size_t len, size_t step )
62{ 80{
63 len >>= 1; 81 short int *dst = static_cast<short int*>( _dst );
64 while ( len-- ) { 82 short int *src = static_cast<short int*>( _src );
65 *((short int *) dst )++ = *((short int *) src ); 83
66 ((char *) src ) += step; 84 len >>= 1;
67 } 85
86 /*
87 * Copy 16bit from src to dst and move to the next address
88 */
89 while ( len-- ) {
90 *dst++ = *src;
91 src = reinterpret_cast<short int*>(reinterpret_cast<char*>(src)+step);
92 }
68} 93}
69 94
70// 270 deg rot: copy a column from src to dst reversed 95// 270 deg rot: copy a column from src to dst reversed
71 96
72static inline void memcpy_step_rev ( void *dst, void *src, size_t len, size_t step ) 97static inline void memcpy_step_rev ( void *_dst, void *_src, size_t len, size_t step )
73{ 98{
74 len >>= 1; 99 len >>= 1;
75 100
76 ((char *) src ) += ( len * step ); 101 char *src_c = static_cast<char*>( _src ) + (len*step);
102 short int* dst = static_cast<short int*>( _dst );
103 short int* src = reinterpret_cast<short int*>( src_c );
77 104
78 while ( len-- ) { 105 while ( len-- ) {
79 ((char *) src ) -= step; 106 src_c -= step;
80 *((short int *) dst )++ = *((short int *) src ); 107 src = reinterpret_cast<short int*>( src_c );
81 } 108 *dst++ = *src;
109 }
82} 110}
83 111
84 112
85XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name ) 113XineVideoWidget::XineVideoWidget ( QWidget* parent, const char* name )
86 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase ) 114 : QWidget ( parent, name, WRepaintNoErase | WResizeNoErase )
87{ 115{
88 setBackgroundMode ( NoBackground ); 116 setBackgroundMode ( NoBackground );
89 117
90 m_logo = 0; 118 m_logo = 0;
91 m_buff = 0; 119 m_buff = 0;
92 m_bytes_per_line_fb = qt_screen-> linestep ( ); 120 m_bytes_per_line_fb = qt_screen-> linestep ( );
93 m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8; 121 m_bytes_per_pixel = ( qt_screen->depth() + 7 ) / 8;
94 m_rotation = 0; 122 m_rotation = 0;
95} 123}
96 124
97 125
98XineVideoWidget::~XineVideoWidget ( ) 126XineVideoWidget::~XineVideoWidget ( )
99{ 127{
100 delete m_logo; 128 delete m_logo;
101} 129}
102 130
103void XineVideoWidget::clear ( ) 131void XineVideoWidget::clear ( )
104{ 132{
105 m_buff = 0; 133 m_buff = 0;
106 repaint ( false ); 134 repaint ( false );
107} 135}
108 136
109QSize XineVideoWidget::videoSize() const 137QSize XineVideoWidget::videoSize() const
110{ 138{
111 QSize s = size(); 139 QSize s = size();
112 bool fs = ( s == qApp->desktop()->size() ); 140 bool fs = ( s == qApp->desktop()->size() );
113 141
114 // if we are in fullscreen mode, do not rotate the video 142 // if we are in fullscreen mode, do not rotate the video
115 // (!! the paint routine uses m_rotation + qt_screen-> transformOrientation() !!) 143 // (!! the paint routine uses m_rotation + qt_screen-> transformOrientation() !!)
116 m_rotation = fs ? - qt_screen->transformOrientation() : 0; 144 m_rotation = fs ? - qt_screen->transformOrientation() : 0;
117 145
118 if ( fs && qt_screen->isTransformed() ) 146 if ( fs && qt_screen->isTransformed() )
119 s = qt_screen->mapToDevice( s ); 147 s = qt_screen->mapToDevice( s );
120 148
121 return s; 149 return s;
122} 150}
123 151
124void XineVideoWidget::paintEvent ( QPaintEvent * ) 152void XineVideoWidget::paintEvent ( QPaintEvent * )
125{ 153{
126 if ( m_buff == 0 ) { 154 if ( m_buff == 0 ) {
127 QPainter p ( this ); 155 QPainter p ( this );
128 p. fillRect ( rect ( ), black ); 156 p. fillRect ( rect ( ), black );
129 if ( m_logo ) 157 if ( m_logo )
130 p. drawImage ( 0, 0, *m_logo ); 158 p. drawImage ( 0, 0, *m_logo );
131 } 159 }
132 else { 160 else {
133 // Qt needs to be notified which areas were really updated .. strange 161 // Qt needs to be notified which areas were really updated .. strange
134 QArray <QRect> qt_bug_workaround_clip_rects; 162 QArray <QRect> qt_bug_workaround_clip_rects;
135 163
136 { 164 {
137 QDirectPainter dp ( this ); 165 QDirectPainter dp ( this );
138 166
139 int rot = dp. transformOrientation ( ) + m_rotation; // device rotation + custom rotation 167 int rot = dp. transformOrientation ( ) + m_rotation; // device rotation + custom rotation
140 168
141 uchar *fb = dp. frameBuffer ( ); 169 uchar *fb = dp. frameBuffer ( );
142 uchar *frame = m_buff; 170 uchar *frame = m_buff;
143 171
144 // where is the video frame in fb coordinates 172 // where is the video frame in fb coordinates
145 QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); 173 QRect framerect = qt_screen-> mapToDevice ( QRect ( mapToGlobal ( m_thisframe. topLeft ( )), m_thisframe. size ( )), QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
146 174
147 qt_bug_workaround_clip_rects. resize ( dp. numRects ( )); 175 qt_bug_workaround_clip_rects. resize ( dp. numRects ( ));
148 176
149 for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) { 177 for ( int i = dp. numRects ( ) - 1; i >= 0; i-- ) {
150 const QRect &clip = dp. rect ( i ); 178 const QRect &clip = dp. rect ( i );
151 179
152 qt_bug_workaround_clip_rects [ i ] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( ))); 180 qt_bug_workaround_clip_rects [ i ] = qt_screen-> mapFromDevice ( clip, QSize ( qt_screen-> width ( ), qt_screen-> height ( )));
153 181
154 uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); // clip x/y in the fb 182 uchar *dst = fb + ( clip. x ( ) * m_bytes_per_pixel ) + ( clip. y ( ) * m_bytes_per_line_fb ); // clip x/y in the fb
155 uchar *src = frame; 183 uchar *src = frame;
156 184
157 // Adjust the start the source data based on the rotation (xine frame) 185 // Adjust the start the source data based on the rotation (xine frame)
158 switch ( rot ) { 186 switch ( rot ) {
159 case 0: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame )); break; 187 case 0: src += ((( clip. x ( ) - framerect. x ( )) * m_bytes_per_pixel ) + (( clip. y ( ) - framerect. y ( )) * m_bytes_per_line_frame )); break;
160 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; 188 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;
161 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; 189 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;
162 case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break; 190 case 3: src += ((( clip. y ( ) - framerect. y ( )) * m_bytes_per_pixel ) + (( clip. x ( ) - framerect. x ( )) * m_bytes_per_line_frame )); break;
163 default: break; 191 default: break;
164 } 192 }
165 193
166 // all of the following widths/heights are fb relative (0deg rotation) 194 // all of the following widths/heights are fb relative (0deg rotation)
167 195
168 uint leftfill = 0; // black border on the "left" side of the video frame 196 uint leftfill = 0; // black border on the "left" side of the video frame
169 uint framefill = 0; // "width" of the video frame 197 uint framefill = 0; // "width" of the video frame
170 uint rightfill = 0; // black border on the "right" side of the video frame 198 uint rightfill = 0; // black border on the "right" side of the video frame
171 uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect 199 uint clipwidth = clip. width ( ) * m_bytes_per_pixel; // "width" of the current clip rect
172 200
173 if ( clip. left ( ) < framerect. left ( )) 201 if ( clip. left ( ) < framerect. left ( ))
174 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth; 202 leftfill = (( framerect. left ( ) - clip. left ( )) * m_bytes_per_pixel ) <? clipwidth;
175 if ( clip. right ( ) > framerect. right ( )) 203 if ( clip. right ( ) > framerect. right ( ))
176 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth; 204 rightfill = (( clip. right ( ) - framerect. right ( )) * m_bytes_per_pixel ) <? clipwidth;
177 205
178 framefill = clipwidth - ( leftfill + rightfill ); 206 framefill = clipwidth - ( leftfill + rightfill );
179 207
180 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) { 208 for ( int y = clip. top ( ); y <= clip. bottom ( ); y++ ) {
181 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) { 209 if (( y < framerect. top ( )) || ( y > framerect. bottom ( ))) {
182 // "above" or "below" the video -> black 210 // "above" or "below" the video -> black
183 memset ( dst, 0, clipwidth ); 211 memset ( dst, 0, clipwidth );
184 } 212 }
185 else { 213 else {
186 if ( leftfill ) 214 if ( leftfill )
187 memset ( dst, 0, leftfill ); // "left" border -> black 215 memset ( dst, 0, leftfill ); // "left" border -> black
188 216
189 if ( framefill ) { // blit in the video frame 217 if ( framefill ) { // blit in the video frame
190 // see above for an explanation of the different memcpys 218 // see above for an explanation of the different memcpys
191 219
192 switch ( rot ) { 220 switch ( rot ) {
193 case 0: memcpy ( dst + leftfill, src, framefill & ~1 ); break; 221 case 0: memcpy ( dst + leftfill, src, framefill & ~1 ); break;
194 case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; 222 case 1: memcpy_step ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break;
195 case 2: memcpy_rev ( dst + leftfill, src, framefill ); break; 223 case 2: memcpy_rev ( dst + leftfill, src, framefill ); break;
196 case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break; 224 case 3: memcpy_step_rev ( dst + leftfill, src, framefill, m_bytes_per_line_frame ); break;
197 default: break; 225 default: break;
198 } 226 }
199 } 227 }
200 if ( rightfill ) 228 if ( rightfill )
201 memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black 229 memset ( dst + leftfill + framefill, 0, rightfill ); // "right" border -> black
202 } 230 }
203 231
204 dst += m_bytes_per_line_fb; // advance one line in the framebuffer 232 dst += m_bytes_per_line_fb; // advance one line in the framebuffer
205 233
206 // advance one "line" in the xine frame data 234 // advance one "line" in the xine frame data
207 switch ( rot ) { 235 switch ( rot ) {
208 case 0: src += m_bytes_per_line_frame;break; 236 case 0: src += m_bytes_per_line_frame;break;
209 case 1: src -= m_bytes_per_pixel; break; 237 case 1: src -= m_bytes_per_pixel; break;