Optimized the alpha masking loop.