File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,18 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
169
169
int i ;
170
170
Uint8 * palette_bytes = (Uint8 * )palette_colors ;
171
171
172
+ /* Reduce palette->ncolors to minimum possible value */
173
+ int palette_ncolors = 1 ;
174
+ for (i = 0 ; i < w * h ; i ++ ) {
175
+ int cur_best = pixels [i ] + 1 ;
176
+ if (palette_ncolors < cur_best ) {
177
+ palette_ncolors = cur_best ;
178
+ }
179
+ }
180
+ if (palette_ncolors < palette -> ncolors ) {
181
+ palette -> ncolors = palette_ncolors ;
182
+ }
183
+
172
184
for (i = 0 ; i < palette -> ncolors ; i ++ ) {
173
185
palette -> colors [i ].r = * palette_bytes ++ ;
174
186
palette -> colors [i ].g = * palette_bytes ++ ;
@@ -191,6 +203,8 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
191
203
SDL_FreeSurface (surface );
192
204
surface = converted ;
193
205
} else if (has_colorkey ) {
206
+ /* remove redundant pixel alpha before setting colorkey */
207
+ palette -> colors [colorkey_index ].a = SDL_ALPHA_OPAQUE ;
194
208
SDL_SetColorKey (surface , SDL_TRUE , colorkey_index );
195
209
}
196
210
}
You can’t perform that action at this time.
0 commit comments