diff options
| author | James Brown | 2002-07-09 12:33:09 +0000 | 
|---|---|---|
| committer | James Brown | 2002-07-09 12:33:09 +0000 | 
| commit | 78be33795847ffe864338ea2a8296db223e69579 (patch) | |
| tree | 140407b52cd55774edf765ec68730aef19c31fce | |
| parent | 0a9baabbdc173f772c4278b1f5c90f59121d4ee9 (diff) | |
| download | scummvm-rg350-78be33795847ffe864338ea2a8296db223e69579.tar.gz scummvm-rg350-78be33795847ffe864338ea2a8296db223e69579.tar.bz2 scummvm-rg350-78be33795847ffe864338ea2a8296db223e69579.zip | |
Add in alpha-blending code. Why? Because I can! :)
svn-id: r4501
| -rw-r--r-- | newgui.cpp | 64 | 
1 files changed, 61 insertions, 3 deletions
| diff --git a/newgui.cpp b/newgui.cpp index be0e706823..c0826cff91 100644 --- a/newgui.cpp +++ b/newgui.cpp @@ -27,6 +27,60 @@  #define hline(x, y, x2, color) line(x, y, x2, y, color);  #define vline(x, y, y2, color) line(x, y, x, y2, color); +// 8-bit alpha blending routines +int BlendCache[256][256]; + +int RGBMatch(byte *palette, int r, int g, int b) { +	int i, bestidx = 0, besterr = 0xFFFFFF; +	int error = 0; + +	for (i = 0;i < 256;i++) { +		byte *pal = palette + (i * 3); +		int r_diff = r - (int)*pal++;  +		int g_diff = g - (int)*pal++;  +		int b_diff = b - (int)*pal++;  +		r_diff *= r_diff; g_diff *= g_diff; b_diff *= b_diff; + +		error = r_diff + g_diff + b_diff; +		if (error < besterr) { +			besterr = error; +			bestidx = i; +		} +	} +	return bestidx; +} + +int Blend(int src, int dst, byte *palette) { +	int r, g, b, idx; +	int alpha = 128;	// Level of transparency [0-256] +	byte *srcpal = palette + (dst  * 3); +	byte *dstpal = palette + (src * 3); + +	if (BlendCache[dst][src] > -1) +		return BlendCache[dst][src]; + +	r =  (*srcpal++ * alpha); +    r += (*dstpal++ * (256-alpha)); +    r /= 256; + +    g =  (*srcpal++ * alpha); +    g += (*dstpal++ * (256-alpha)); +    g /= 256; + +    b =  (*srcpal++ * alpha); +    b += (*dstpal++  * (256-alpha)); +    b /= 256; +        +	return (BlendCache[dst][src] = RGBMatch(palette, r , g , b )); +} + +void ClearBlendCache(byte *palette, int weight) { +	for (int i = 0; i < 256; i++) +		for (int j = 0 ; j < 256 ; j++)			 +//			BlendCache[i][j] = i;	// No alphablending +//			BlendCache[i][j] = j;	// 100% translucent +			BlendCache[i][j] = -1;	// Enable alphablending +}  /*   * TODO list @@ -42,7 +96,7 @@  NewGui::NewGui(Scumm *s) : _s(s), _need_redraw(false), _pauseDialog(0),  	_saveLoadDialog(0), _aboutDialog(0), _optionsDialog(0) -{ +{	  }  void NewGui::pauseDialog() @@ -54,6 +108,7 @@ void NewGui::pauseDialog()  void NewGui::saveloadDialog()  { +	ClearBlendCache(_s->_currentPalette, 128);  	if (!_saveLoadDialog)  		_saveLoadDialog = new SaveLoadDialog(this);  	openDialog(_saveLoadDialog); @@ -249,8 +304,11 @@ void NewGui::fillArea(int x, int y, int w, int h, byte color)  		return;  	while (h--) { -		for (int i = 0; i < w; i++) -			ptr[i] = color; +		for (int i = 0; i < w; i++) { +			int srcc = ptr[i]; +			ptr[i] = Blend(srcc, color, _s->_currentPalette); +		} +			//ptr[i] = color;  		ptr += 320;  	}  } | 
