File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -109,12 +109,19 @@ fn convert_color(c: Rgba<u8>) -> Option<Color> {
109109/// Pick the color to be used to represent transparency
110110fn 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) ]
You can’t perform that action at this time.
0 commit comments