Skip to content

Commit 23f9681

Browse files
committed
fix transparency in small palettes
1 parent 520fbc2 commit 23f9681

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/images.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,19 @@ fn convert_color(c: Rgba<u8>) -> Option<Color> {
109109
/// Pick the color to be used to represent transparency
110110
fn pick_transparent(img_pal: &[Color], sys_pal: &Palette) -> Result<u8> {
111111
assert!(img_pal.len() <= sys_pal.len());
112+
assert!(sys_pal.len() <= 16);
112113
for (color, i) in sys_pal.iter().zip(0u8..) {
113114
if !img_pal.contains(color) {
114115
return Ok(i);
115116
}
116117
}
117-
bail!("cannot use all 16 colors with transparency, remove one color");
118+
if sys_pal.len() == 16 {
119+
bail!("cannot use all 16 colors with transparency, remove one color");
120+
}
121+
// If the system palette has less than 16 colors,
122+
// any of the colors outside the palette
123+
// can be used for transparency. We use 15.
124+
Ok(0xf)
118125
}
119126

120127
#[cfg(test)]

0 commit comments

Comments
 (0)