~ubuntu-branches/ubuntu/raring/scummvm/raring

« back to all changes in this revision

Viewing changes to graphics/surface.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: (21.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * along with this program; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/graphics/surface.cpp $
22
 
 * $Id: surface.cpp 52268 2010-08-21 20:14:46Z sev $
 
21
 * $URL$
 
22
 * $Id$
23
23
 */
24
24
 
25
25
#include "common/algorithm.h"
26
26
#include "common/util.h"
 
27
#include "common/rect.h"
 
28
#include "common/textconsole.h"
27
29
#include "graphics/primitives.h"
28
30
#include "graphics/surface.h"
29
31
 
179
181
        vLine(r.right-1, r.top, r.bottom-1, color);
180
182
}
181
183
 
182
 
// FIXME: LordHoto asks why is this in Surface, since this
183
 
// just supports 8bpp surfaces. Looks like someone wants
184
 
// to subclass Surface to add this or it should be extended
185
 
// to support 16bpp (or marked as just working for 8bpp
186
 
// surfaces).
187
184
void Surface::move(int dx, int dy, int height) {
188
 
        // This function currently just works with 8bpp surfaces
189
 
        assert(bytesPerPixel == 1);
190
 
 
191
185
        // Short circuit check - do we have to do anything anyway?
192
186
        if ((dx == 0 && dy == 0) || height <= 0)
193
187
                return;
194
188
 
 
189
        if (bytesPerPixel != 1 && bytesPerPixel != 2)
 
190
                error("Surface::move: bytesPerPixel must be 1 or 2");
 
191
 
195
192
        byte *src, *dst;
196
193
        int x, y;
197
194
 
198
195
        // vertical movement
199
196
        if (dy > 0) {
200
197
                // move down - copy from bottom to top
201
 
                dst = (byte *)pixels + (height - 1) * w;
202
 
                src = dst - dy * w;
 
198
                dst = (byte *)pixels + (height - 1) * pitch;
 
199
                src = dst - dy * pitch;
203
200
                for (y = dy; y < height; y++) {
204
 
                        memcpy(dst, src, w);
205
 
                        src -= w;
206
 
                        dst -= w;
 
201
                        memcpy(dst, src, pitch);
 
202
                        src -= pitch;
 
203
                        dst -= pitch;
207
204
                }
208
205
        } else if (dy < 0) {
209
206
                // move up - copy from top to bottom
210
207
                dst = (byte *)pixels;
211
 
                src = dst - dy * w;
 
208
                src = dst - dy * pitch;
212
209
                for (y = -dy; y < height; y++) {
213
 
                        memcpy(dst, src, w);
214
 
                        src += w;
215
 
                        dst += w;
 
210
                        memcpy(dst, src, pitch);
 
211
                        src += pitch;
 
212
                        dst += pitch;
216
213
                }
217
214
        }
218
215
 
219
216
        // horizontal movement
220
217
        if (dx > 0) {
221
218
                // move right - copy from right to left
222
 
                dst = (byte *)pixels + (w - 1);
223
 
                src = dst - dx;
 
219
                dst = (byte *)pixels + (pitch - bytesPerPixel);
 
220
                src = dst - (dx * bytesPerPixel);
224
221
                for (y = 0; y < height; y++) {
225
222
                        for (x = dx; x < w; x++) {
226
 
                                *dst-- = *src--;
 
223
                                if (bytesPerPixel == 1) {
 
224
                                        *dst-- = *src--;
 
225
                                } else if (bytesPerPixel == 2) {
 
226
                                        *(uint16 *)dst = *(const uint16 *)src;
 
227
                                        src -= 2;
 
228
                                        dst -= 2;
 
229
                                }
227
230
                        }
228
 
                        src += w + (w - dx);
229
 
                        dst += w + (w - dx);
 
231
                        src += pitch + (pitch - dx * bytesPerPixel);
 
232
                        dst += pitch + (pitch - dx * bytesPerPixel);
230
233
                }
231
234
        } else if (dx < 0)  {
232
235
                // move left - copy from left to right
233
236
                dst = (byte *)pixels;
234
 
                src = dst - dx;
 
237
                src = dst - (dx * bytesPerPixel);
235
238
                for (y = 0; y < height; y++) {
236
239
                        for (x = -dx; x < w; x++) {
237
 
                                *dst++ = *src++;
 
240
                                if (bytesPerPixel == 1) {
 
241
                                        *dst++ = *src++;
 
242
                                } else if (bytesPerPixel == 2) {
 
243
                                        *(uint16 *)dst = *(const uint16 *)src;
 
244
                                        src += 2;
 
245
                                        dst += 2;
 
246
                                }
238
247
                        }
239
 
                        src += w - (w + dx);
240
 
                        dst += w - (w + dx);
 
248
                        src += pitch - (pitch + dx * bytesPerPixel);
 
249
                        dst += pitch - (pitch + dx * bytesPerPixel);
241
250
                }
242
251
        }
243
252
}