engine/EngineVideoTextureManager.c
/*	eliminate pink edges on sprites, etc.
	operates in place on 32bit data
*/
eliminate pink edges on sprites, etc.
operates in place on 32bit data
eliminate pink edges on sprites etc . operates in place on 32bit data
void TexMgr_AlphaEdgeFix(uint8_t *data, int width, int height)
{
	int i,j,n=0,
		b,
		c[3]={0,0,0},
		lastrow,thisrow,nextrow,lastpix,thispix,nextpix;
	uint8_t *dest = data;
	for (i=0; i<height; i++)
	{
		lastrow = width * 4 * ((i == 0) ? height-1 : i-1);
		thisrow = width * 4 * i;
		nextrow = width * 4 * ((i == height-1) ? 0 : i+1);
		for (j=0; j<width; j++, dest+=4)
		{
			if (dest[3]) 
				continue;
			lastpix = 4 * ((j == 0) ? width-1 : j-1);
			thispix = 4 * j;
			nextpix = 4 * ((j == width-1) ? 0 : j+1);
			b = lastrow + lastpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = thisrow + lastpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = nextrow + lastpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = lastrow + thispix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = nextrow + thispix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = lastrow + nextpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = thisrow + nextpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			b = nextrow + nextpix; if (data[b+3]) {c[0] += data[b]; c[1] += data[b+1]; c[2] += data[b+2]; n++;}
			if (n)
			{
				dest[0] = (uint8_t)(c[0] / n);
				dest[1] = (uint8_t)(c[1] / n);
				dest[2] = (uint8_t)(c[2] / n);
				n = c[0] = c[1] = c[2] = 0;
			}
		}
	}
}
void TexMgr_AlphaEdgeFix ( uint8_t * data , int width , int height ) { int i , j , n = 0 , b , c [ 3 ] = { 0 , 0 , 0 } , lastrow , thisrow , nextrow , lastpix , thispix , nextpix ; uint8_t * dest = data ; for ( i = 0 ; i < height ; i ++ ) { lastrow = width * 4 * ( ( i == 0 ) ? height - 1 : i - 1 ) ; thisrow = width * 4 * i ; nextrow = width * 4 * ( ( i == height - 1 ) ? 0 : i + 1 ) ; for ( j = 0 ; j < width ; j ++ , dest += 4 ) { if ( dest [ 3 ] ) continue ; lastpix = 4 * ( ( j == 0 ) ? width - 1 : j - 1 ) ; thispix = 4 * j ; nextpix = 4 * ( ( j == width - 1 ) ? 0 : j + 1 ) ; b = lastrow + lastpix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = thisrow + lastpix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = nextrow + lastpix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = lastrow + thispix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = nextrow + thispix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = lastrow + nextpix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = thisrow + nextpix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } b = nextrow + nextpix ; if ( data [ b + 3 ] ) { c [ 0 ] += data [ b ] ; c [ 1 ] += data [ b + 1 ] ; c [ 2 ] += data [ b + 2 ] ; n ++ ; } if ( n ) { dest [ 0 ] = ( uint8_t ) ( c [ 0 ] / n ) ; dest [ 1 ] = ( uint8_t ) ( c [ 1 ] / n ) ; dest [ 2 ] = ( uint8_t ) ( c [ 2 ] / n ) ; n = c [ 0 ] = c [ 1 ] = c [ 2 ] = 0 ; } } } }
eliminate pink edges on sprites, etc.
eliminate pink edges on sprites etc .
//not transparent //average all non-transparent neighbors