- num_pix = pixsize * (m_value - m_start) / (m_max - m_min);
- start_pix = pixsize * m_start / (m_max - m_min);
+ int val_range = m_max - m_min;
+ num_pix = (pixsize * (m_value - m_start) + val_range - 1) / val_range; /* properly round up */
+ start_pix = (pixsize * m_start + val_range - 1) / val_range;
+
+ if (m_orientation_swapped)
+ start_pix = pixsize - num_pix - start_pix;