Exemplo n.º 1
0
void MapPalette( UINT8 *pDest, UINT8 *pSrc, INT16 sWidth, INT16 sHeight, INT16 sNumColors, SGPPaletteEntry *pTable )
{
	INT32 cX, cY, cnt, bBest;
	real					dLowestDist;
	real					dCubeDist;
	vector_3			vTableVal, vSrcVal, vDiffVal;
	UINT8					*pData;
	RGBValues			*pRGBData;

	pRGBData = (RGBValues*)pSrc;

	for ( cX = 0; cX < sWidth; cX++ )
	{
		for ( cY = 0; cY < sHeight; cY++ )
		{
				// OK, FOR EACH PALETTE ENTRY, FIND CLOSEST
				bBest					= 0;
				dLowestDist		= (float)9999999;
				pData					= &(pSrc[ ( cY * sWidth ) + cX ]);

				for ( cnt = 0; cnt < sNumColors; cnt++ )
				{
					vSrcVal.x		= pRGBData[ ( cY * sWidth ) + cX ].r;
					vSrcVal.y		= pRGBData[ ( cY * sWidth ) + cX ].g;
					vSrcVal.z		= pRGBData[ ( cY * sWidth ) + cX ].b;

					vTableVal.x = pTable[ cnt ].peRed;
					vTableVal.y = pTable[ cnt ].peGreen;
					vTableVal.z = pTable[ cnt ].peBlue;

					// Get Dist
					vDiffVal = VSubtract( &vSrcVal, &vTableVal );

					// Get mag dist
					dCubeDist = VGetLength( &(vDiffVal) );

					if ( dCubeDist < dLowestDist )
					{
						dLowestDist = dCubeDist;
						bBest = cnt;
					}
				}

				// Now we have the lowest value
				// Set into dest
				pData = &(pDest[ ( cY * sWidth ) + cX ]);

				//Set!
				*pData = (UINT8)bBest;
		}
	}

}
Exemplo n.º 2
0
vector_3 VGetNormal( vector_3 *a )
{
	vector_3	c;
	real OneOverLength, Length;

	Length = VGetLength( a );

	if ( Length == 0 )	
	{
		c.x = 0;
		c.y = 0;
		c.z = 0;
	}
	else
	{
		OneOverLength = 1/Length;

		c.x = OneOverLength * a->x;
		c.y = OneOverLength * a->y;
		c.z = OneOverLength * a->z;
	}
	return ( c );
}