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