Changeset - r6895:394e17c42f1f
[Not reviewed]
master
0 2 0
truelight - 17 years ago 2007-06-13 16:04:35
truelight@openttd.org
(svn r10142) -Fix r10132: do something useful with the alpha channel instead of ignoring it
2 files changed with 38 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/blitter/32bpp_simple.cpp
Show inline comments
 
@@ -14,12 +14,45 @@ static FBlitter_32bppSimple iFBlitter_32
 
static inline uint ComposeColor(uint r, uint g, uint b)
 
{
 
	return (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF) << 0;
 
}
 

	
 
/**
 
 * Compose a color based on RGBA values and the current pixel value.
 
 */
 
static inline uint ComposeColorRGBA(uint r, uint g, uint b, uint a, uint current)
 
{
 
	uint cr, cg, cb;
 
	cr = GB(current, 16, 8);
 
	cg = GB(current, 8,  8);
 
	cb = GB(current, 0,  8);
 

	
 
	return ComposeColor((r * a + cr * (255 - a)) / 255,
 
											(g * a + cg * (255 - a)) / 255,
 
											(b * a + cb * (255 - a)) / 255);
 
}
 

	
 
/**
 
 * Compose a color based on Pixel value, alpha value, and the current pixel value.
 
 */
 
static inline uint ComposeColorPA(uint color, uint a, uint current)
 
{
 
	uint r, g, b, cr, cg, cb;
 
	r  = GB(color,   16, 8);
 
	g  = GB(color,   8,  8);
 
	b  = GB(color,   0,  8);
 
	cr = GB(current, 16, 8);
 
	cg = GB(current, 8,  8);
 
	cb = GB(current, 0,  8);
 

	
 
	return ComposeColor((r * a + cr * (255 - a)) / 255,
 
											(g * a + cg * (255 - a)) / 255,
 
											(b * a + cb * (255 - a)) / 255);
 
}
 

	
 
/**
 
 * Make a pixel looks like it is transparent.
 
 * @param color the color already on the screen.
 
 * @param amount the amount of transparency, times 100.
 
 * @return the new color for the screen.
 
 */
 
static inline uint MakeTransparent(uint color, uint amount)
 
@@ -66,20 +99,19 @@ void Blitter_32bppSimple::Draw(Blitter::
 
		dst_line += bp->pitch;
 

	
 
		src = src_line;
 
		src_line += bp->sprite_width * ScaleByZoom(1, zoom);
 

	
 
		for (int x = 0; x < bp->width; x++) {
 

	
 
			switch (mode) {
 
				case BM_COLOUR_REMAP:
 
					/* In case the m-channel is zero, do not remap this pixel in any way */
 
					if (src->m == 0) {
 
						if (src->a != 0) *dst = ComposeColor(src->r, src->g, src->b);
 
						if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
 
					} else {
 
						if (bp->remap[src->m] != 0) *dst = Renderer_32bpp::LookupColourInPalette(bp->remap[src->m]);
 
						if (bp->remap[src->m] != 0) *dst = ComposeColorPA(Renderer_32bpp::LookupColourInPalette(bp->remap[src->m]), src->a, *dst);
 
					}
 
					break;
 

	
 
				case BM_TRANSPARENT:
 
					/* TODO -- We make an assumption here that the remap in fact is transparency, not some color.
 
					 *  This is never a problem with the code we produce, but newgrfs can make it fail... or at least:
 
@@ -87,13 +119,13 @@ void Blitter_32bppSimple::Draw(Blitter::
 

	
 
					/* Make the current color a bit more black, so it looks like this image is transparent */
 
					if (src->a != 0) *dst = MakeTransparent(*dst, 75);
 
					break;
 

	
 
				default:
 
					if (src->a != 0) *dst = ComposeColor(src->r, src->g, src->b);
 
					if (src->a != 0) *dst = ComposeColorRGBA(src->r, src->g, src->b, src->a, *dst);
 
					break;
 
			}
 
			dst++;
 
			src += ScaleByZoom(1, zoom);
 
		}
 
	}
src/fontcache.cpp
Show inline comments
 
@@ -416,21 +416,23 @@ const Sprite *GetGlyph(FontSize size, WC
 
	/* Draw shadow for medium size */
 
	if (size == FS_NORMAL) {
 
		for (y = 0; y < slot->bitmap.rows; y++) {
 
			for (x = 0; x < slot->bitmap.width; x++) {
 
				if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
 
					sprite.data[1 + x + (1 + y) * sprite.width].m = SHADOW_COLOUR;
 
					sprite.data[1 + x + (1 + y) * sprite.width].a = 0xFF;
 
				}
 
			}
 
		}
 
	}
 

	
 
	for (y = 0; y < slot->bitmap.rows; y++) {
 
		for (x = 0; x < slot->bitmap.width; x++) {
 
			if (HASBIT(slot->bitmap.buffer[(x / 8) + y * slot->bitmap.pitch], 7 - (x % 8))) {
 
				sprite.data[x + y * sprite.width].m = FACE_COLOUR;
 
				sprite.data[x + y * sprite.width].a = 0xFF;
 
			}
 
		}
 
	}
 

	
 
	new_glyph.sprite = BlitterFactoryBase::GetCurrentBlitter()->Encode(&sprite, AllocateFont);
 
	free(sprite.data);
0 comments (0 inline, 0 general)