value and dpi are unsigned so the delta calculations was wrong when dpi is larger than than value. Casting to int should be fine for the expected range of values in those variables.