Skip to content

Commit 16b6cb7

Browse files
committed
Fix float to integer overflow
1 parent b7340db commit 16b6cb7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/mediancut.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ impl<'hist> MBox<'hist> {
109109
let chans: [f32; 4] = rgb::bytemuck::cast(a.color.0);
110110
// Only the first channel really matters. But other channels are included, because when trying median cut
111111
// many times with different histogram weights, I don't want sort randomness to influence the outcome.
112-
a.tmp.mc_sort_value = (((chans[channels[0].chan] * 65535.) as u32) << 16)
113-
| ((chans[channels[2].chan] + chans[channels[1].chan] / 2. + chans[channels[3].chan] / 4.) * 65535.) as u32; // box will be split to make color_weight of each side even
112+
a.tmp.mc_sort_value = (u32::from((chans[channels[0].chan] * 65535.) as u16) << 16)
113+
| u32::from(((chans[channels[2].chan] + chans[channels[1].chan] / 2. + chans[channels[3].chan] / 4.) * 65535.) as u16); // box will be split to make color_weight of each side even
114114
}
115115
}
116116

0 commit comments

Comments
 (0)