TFPColor (avgC, c1, c2, c3, c4) is a record consisting for unsigned 16-bit elements for Red, Green, Blue and Alpha. In the code snippet that you cite, four word values are added for calculating the average Red component. The addition may overflow the range of the word data type. Therefore, I am casting to the next larger integer type (sorry, Int64 is not needed, Int32 or DWord, would be enough). I am casting only the first value because then the sum will be the casted type too, and the same with the other values. The final division by 4 brings the average value back into the word range again.