How do you calculate your Tournament Performance Rating? How do you calculate your Tournament Performance Rating?

I can think about two different ways to answer my question:


Do you know the formula for calculating your TPR (FIDE or USCF)?
Can you link me to a FIDE TPR calculator and then a USCF TPR calculator? 


I recall that rating change calculators have this TPR function.
TPR calculators and expected rating change.

http://englishchess.org.uk/Juniors/tournament-performance-calculator/
http://www.uschess.org/content/view/13146/836/

Basically Performance rating is the average of your opponent's ratings with an adjustment based on the score of the game.  For each win, you add your opponent's rating + 400, a draw is just your opponent's rating, and a loss is your opponent's rating - 400.  There is an exception for a perfect score, then the adjustment is 800.