|
1 #include "../stdafx.h" |
|
2 #include "../zoom.hpp" |
|
3 #include "../gfx.h" |
|
4 #include "../functions.h" |
|
5 #include "8bpp_debug.hpp" |
|
6 |
|
7 static FBlitter_8bppDebug iFBlitter_8bppDebug; |
|
8 |
|
9 void Blitter_8bppDebug::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) |
|
10 { |
|
11 const byte *src, *src_line; |
|
12 Pixel8 *dst, *dst_line; |
|
13 |
|
14 /* Find where to start reading in the source sprite */ |
|
15 src_line = (const byte *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); |
|
16 dst_line = (Pixel8 *)bp->dst + bp->top * bp->pitch + bp->left; |
|
17 |
|
18 for (int y = 0; y < bp->height; y++) { |
|
19 dst = dst_line; |
|
20 dst_line += bp->pitch; |
|
21 |
|
22 src = src_line; |
|
23 src_line += bp->sprite_width * ScaleByZoom(1, zoom); |
|
24 |
|
25 for (int x = 0; x < bp->width; x++) { |
|
26 if (*src != 0) *dst = *src; |
|
27 dst++; |
|
28 src += ScaleByZoom(1, zoom); |
|
29 } |
|
30 assert(src <= src_line); |
|
31 } |
|
32 } |
|
33 |
|
34 Sprite *Blitter_8bppDebug::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) |
|
35 { |
|
36 Sprite *dest_sprite; |
|
37 dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width); |
|
38 |
|
39 dest_sprite->height = sprite->height; |
|
40 dest_sprite->width = sprite->width; |
|
41 dest_sprite->x_offs = sprite->x_offs; |
|
42 dest_sprite->y_offs = sprite->y_offs; |
|
43 |
|
44 /* Write a random color as sprite; this makes debugging really easy */ |
|
45 uint color = InteractiveRandom() % 150 + 2; |
|
46 for (int i = 0; i < sprite->height * sprite->width; i++) { |
|
47 dest_sprite->data[i] = (sprite->data[i].m == 0) ? 0 : color; |
|
48 } |
|
49 |
|
50 return dest_sprite; |
|
51 } |