|
1 /* $Id$ */ |
|
2 |
|
3 /** @file 8bpp_simple.cpp */ |
|
4 |
|
5 #include "../stdafx.h" |
|
6 #include "../zoom.hpp" |
|
7 #include "../gfx.h" |
|
8 #include "8bpp_simple.hpp" |
|
9 |
|
10 static FBlitter_8bppSimple iFBlitter_8bppSimple; |
|
11 |
|
12 void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) |
|
13 { |
|
14 const uint8 *src, *src_line; |
|
15 uint8 *dst, *dst_line; |
|
16 |
|
17 /* Find where to start reading in the source sprite */ |
|
18 src_line = (const uint8 *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); |
|
19 dst_line = (uint8 *)bp->dst + bp->top * bp->pitch + bp->left; |
|
20 |
|
21 for (int y = 0; y < bp->height; y++) { |
|
22 dst = dst_line; |
|
23 dst_line += bp->pitch; |
|
24 |
|
25 src = src_line; |
|
26 src_line += bp->sprite_width * ScaleByZoom(1, zoom); |
|
27 |
|
28 for (int x = 0; x < bp->width; x++) { |
|
29 uint color = 0; |
|
30 |
|
31 switch (mode) { |
|
32 case BM_COLOUR_REMAP: |
|
33 color = bp->remap[*src]; |
|
34 break; |
|
35 |
|
36 case BM_TRANSPARENT: |
|
37 if (*src != 0) color = bp->remap[*dst]; |
|
38 break; |
|
39 |
|
40 default: |
|
41 color = *src; |
|
42 break; |
|
43 } |
|
44 if (color != 0) *dst = color; |
|
45 dst++; |
|
46 src += ScaleByZoom(1, zoom); |
|
47 } |
|
48 } |
|
49 } |
|
50 |
|
51 Sprite *Blitter_8bppSimple::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) |
|
52 { |
|
53 Sprite *dest_sprite; |
|
54 dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width);; |
|
55 |
|
56 dest_sprite->height = sprite->height; |
|
57 dest_sprite->width = sprite->width; |
|
58 dest_sprite->x_offs = sprite->x_offs; |
|
59 dest_sprite->y_offs = sprite->y_offs; |
|
60 |
|
61 /* Copy over only the 'remap' channel, as that is what we care about in 8bpp */ |
|
62 for (int i = 0; i < sprite->height * sprite->width; i++) { |
|
63 dest_sprite->data[i] = sprite->data[i].m; |
|
64 } |
|
65 |
|
66 return dest_sprite; |
|
67 } |