Exemplo n.º 1
0
void extractColorChannels(veci16 packedColors, vecf16 outColor[3])
{
	outColor[0] = __builtin_vp_vitof(packedColors & splati(255))
		/ splatf(255.0f);	// B
	outColor[1] = __builtin_vp_vitof((packedColors >> splati(8)) & splati(255)) 
		/ splatf(255.0f); // G
	outColor[2] = __builtin_vp_vitof((packedColors >> splati(16)) & splati(255)) 
		/ splatf(255.0f); // R
	outColor[3] = __builtin_vp_vitof((packedColors >> splati(24)) & splati(255)) 
		/ splatf(255.0f); // A
}
Exemplo n.º 2
0
void Surface::clearTile(int left, int top, unsigned int value)
{
    veci16 *ptr = (veci16*)(fBaseAddress + left * kBytesPerPixel + top * fWidth 
        * kBytesPerPixel);
    const veci16 kClearColor = splati(value);
    const int kStride = ((fWidth - kTileSize) * kBytesPerPixel / sizeof(veci16));
    
    for (int y = 0; y < kTileSize; y++)
    {
        for (int x = 0; x < kTileSize; x += 16)
            *ptr++ = kClearColor;
        
        ptr += kStride;
    }
}
Exemplo n.º 3
0
void memset(void *_dest, int value, unsigned int length)
{
	char *dest = (char*) _dest;
	value &= 0xff;

	if ((((unsigned int) dest) & 63) == 0)
	{
		// Write 64 bytes at a time.
		veci16 reallyWideValue = splati(value | (value << 8) | (value << 16) 
			| (value << 24));
		while (length > 64)
		{
			*((veci16*) dest) = reallyWideValue;
			length -= 64;
			dest += 64;
		}
	}

	if ((((unsigned int) dest) & 3) == 0)
	{
		// Write 4 bytes at a time.
		unsigned wideVal = value | (value << 8) | (value << 16) | (value << 24);
		while (length > 4)
		{
			*((unsigned int*) dest) = wideVal;
			dest += 4;
			length -= 4;
		}		
	}

	// Write one byte at a time
	while (length > 0)
	{
		*dest++ = value;
		length--;
	}
}
Exemplo n.º 4
0
//
// Note that this wraps by default
//
void TextureSampler::readPixels(vecf16 u, vecf16 v, unsigned short mask,
	vecf16 outColors[4])
{
	// Convert from texture space into raster coordinates
	vecf16 uRaster = u * splatf(fWidth);
	vecf16 vRaster = v * splatf(fWidth);
	

	if (fBilinearFilteringEnabled)
	{
		// Compute weights
		vecf16 wx = uRaster - __builtin_vp_vitof(__builtin_vp_vftoi(uRaster));
		vecf16 wy = vRaster - __builtin_vp_vitof(__builtin_vp_vftoi(vRaster));
		vecf16 w11 = wx * wy;
		vecf16 w01 = (splatf(1.0) - wx) * wy;
		vecf16 w10 = (splatf(1.0) - wy) * wx;
		vecf16 w00 = (splatf(1.0) - wy) * (splatf(1.0) - wx);

		// Load pixels	
		vecf16 p00Colors[4];
		vecf16 p10Colors[4];
		vecf16 p01Colors[4];
		vecf16 p11Colors[4];

		veci16 tx = __builtin_vp_vftoi(uRaster) & splati(fWidth - 1);
		veci16 ty = __builtin_vp_vftoi(vRaster) & splati(fHeight - 1);

		extractColorChannels(fSurface->readPixels(tx, ty, mask), p00Colors);
		extractColorChannels(fSurface->readPixels(tx, (ty + splati(1)) & splati(fWidth 
			- 1), mask), p01Colors);
		extractColorChannels(fSurface->readPixels((tx + splati(1)) & splati(fWidth - 1), 
			ty, mask), p10Colors);
		extractColorChannels(fSurface->readPixels((tx + splati(1)) & splati(fWidth - 1), 
			(ty + splati(1)) & splati(fWidth - 1), mask), 
			p11Colors);

		// Apply weights & blend
		outColors[0] = p00Colors[0] * w00 + p01Colors[0] * w01 + p10Colors[0] * w10 
			+ p11Colors[0] * w11;
		outColors[1] = p00Colors[1] * w00 + p01Colors[1] * w01 + p10Colors[1] * w10 
			+ p11Colors[1] * w11;
		outColors[2] = p00Colors[2] * w00 + p01Colors[2] * w01 + p10Colors[2] * w10 
			+ p11Colors[2] * w11;
		outColors[3] = p00Colors[3] * w00 + p01Colors[3] * w01 + p10Colors[3] * w10 
			+ p11Colors[3] * w11;
	}
	else
	{
		// Nearest neighbor
		veci16 tx = __builtin_vp_vftoi(uRaster) & splati(fWidth - 1);
		veci16 ty = __builtin_vp_vftoi(vRaster) & splati(fHeight - 1);
		extractColorChannels(fSurface->readPixels(tx, ty, mask), outColors);
	}
}