In the final line, the value is shifted back (scaled down by 2^14) to get back to a normal integer grayscale value. Each of RGB is an 8-bit number, and the coefficients in the grayscale calculation add up to 1, so the grayscale value is also in the range 0-256 (8 bits). The '+ (1 << ((RGB_SCALE)-1))' part is just to round to what will be the LSB after the final right shift.

In short, this algorithmj just multiplies the original RGB values by a big number so integer math can be used to compute the grayscale value. Then after the calculation, the big number is divided back out. The '+ 0.5' and the '+ (2^13)' just round results.