optimized pixel locationfunction