Add casts when converting from int64_t or double to int32_t

This fixes warnings when building with MSVC.
Merge pull request #1597 from mstorsjo/msvc-casts

Add casts when converting from int64_t or double to int32_t