author | rubidium |
Wed, 09 Jan 2008 18:11:12 +0000 | |
branch | noai |
changeset 9723 | eee46cb39750 |
parent 9703 | d2a6acdbd665 |
child 9724 | b39bc69bb2f2 |
permissions | -rw-r--r-- |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9703
diff
changeset
|
1 |
/* $Id$ */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9703
diff
changeset
|
2 |
|
9703 | 3 |
#include "../stdafx.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9703
diff
changeset
|
4 |
#include "../zoom_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9703
diff
changeset
|
5 |
#include "../gfx_func.h" |
9703 | 6 |
#include "../debug.h" |
7 |
#include "../table/sprites.h" |
|
8 |
#include "32bpp_optimized.hpp" |
|
9 |
||
10 |
static FBlitter_32bppOptimized iFBlitter_32bppOptimized; |
|
11 |
||
12 |
void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) |
|
13 |
{ |
|
14 |
const SpriteLoader::CommonPixel *src, *src_line; |
|
15 |
uint32 *dst, *dst_line; |
|
16 |
||
17 |
/* Find where to start reading in the source sprite */ |
|
18 |
src_line = (const SpriteLoader::CommonPixel *)bp->sprite + (bp->skip_top * bp->sprite_width + bp->skip_left) * ScaleByZoom(1, zoom); |
|
19 |
dst_line = (uint32 *)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 |
if (src->a == 0) { |
|
30 |
/* src->r is 'misused' here to indicate how much more pixels are following with an alpha of 0 */ |
|
31 |
int skip = UnScaleByZoom(src->r, zoom); |
|
32 |
||
33 |
dst += skip; |
|
34 |
x += skip - 1; |
|
35 |
src += ScaleByZoom(1, zoom) * skip; |
|
36 |
continue; |
|
37 |
} |
|
38 |
||
39 |
switch (mode) { |
|
40 |
case BM_COLOUR_REMAP: |
|
41 |
/* In case the m-channel is zero, do not remap this pixel in any way */ |
|
42 |
if (src->m == 0) { |
|
43 |
*dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst); |
|
44 |
} else { |
|
45 |
if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->LookupColourInPalette(bp->remap[src->m]), src->a, *dst); |
|
46 |
} |
|
47 |
break; |
|
48 |
||
49 |
case BM_TRANSPARENT: |
|
50 |
/* TODO -- We make an assumption here that the remap in fact is transparency, not some color. |
|
51 |
* This is never a problem with the code we produce, but newgrfs can make it fail... or at least: |
|
52 |
* we produce a result the newgrf maker didn't expect ;) */ |
|
53 |
||
54 |
/* Make the current color a bit more black, so it looks like this image is transparent */ |
|
55 |
*dst = MakeTransparent(*dst, 192); |
|
56 |
break; |
|
57 |
||
58 |
default: |
|
59 |
*dst = ComposeColourRGBA(src->r, src->g, src->b, src->a, *dst); |
|
60 |
break; |
|
61 |
} |
|
62 |
dst++; |
|
63 |
src += ScaleByZoom(1, zoom); |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
Sprite *Blitter_32bppOptimized::Encode(SpriteLoader::Sprite *sprite, Blitter::AllocatorProc *allocator) |
|
69 |
{ |
|
70 |
Sprite *dest_sprite; |
|
71 |
SpriteLoader::CommonPixel *dst; |
|
72 |
dest_sprite = (Sprite *)allocator(sizeof(*dest_sprite) + sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel)); |
|
73 |
||
74 |
dest_sprite->height = sprite->height; |
|
75 |
dest_sprite->width = sprite->width; |
|
76 |
dest_sprite->x_offs = sprite->x_offs; |
|
77 |
dest_sprite->y_offs = sprite->y_offs; |
|
78 |
||
79 |
dst = (SpriteLoader::CommonPixel *)dest_sprite->data; |
|
80 |
||
81 |
memcpy(dst, sprite->data, sprite->height * sprite->width * sizeof(SpriteLoader::CommonPixel)); |
|
82 |
/* Skip to the end of the array, and work backwards to find transparent blocks */ |
|
83 |
dst = dst + sprite->height * sprite->width - 1; |
|
84 |
||
85 |
for (uint y = sprite->height; y > 0; y--) { |
|
86 |
int trans = 0; |
|
87 |
/* Process sprite line backwards, to compute lengths of transparent blocks */ |
|
88 |
for (uint x = sprite->width; x > 0; x--) { |
|
89 |
if (dst->a == 0) { |
|
90 |
/* Save transparent block length in red channel; max value is 255 the red channel can contain */ |
|
91 |
if (trans < 255) trans++; |
|
92 |
dst->r = trans; |
|
93 |
dst->g = 0; |
|
94 |
dst->b = 0; |
|
95 |
dst->m = 0; |
|
96 |
} else { |
|
97 |
trans = 0; |
|
98 |
if (dst->m != 0) { |
|
99 |
/* Pre-convert the mapping channel to a RGB value */ |
|
100 |
uint color = this->LookupColourInPalette(dst->m); |
|
101 |
dst->r = GB(color, 16, 8); |
|
102 |
dst->g = GB(color, 8, 8); |
|
103 |
dst->b = GB(color, 0, 8); |
|
104 |
} |
|
105 |
} |
|
106 |
dst--; |
|
107 |
} |
|
108 |
} |
|
109 |
return dest_sprite; |
|
110 |
} |