- /* since we're updating in-place, we have to go from right to left */
- for (x = s->width; x > 0; --x) {
- uint8_t *pixel = &row[s->bpp * (x - 1)];
- memmove(pixel, &row[raw_bpp * (x - 1)], raw_bpp);
+ if (s->bpp == 2 && byte_depth == 1) {
+ uint8_t *pixel = &row[2 * s->width - 1];
+ uint8_t *rowp = &row[1 * s->width - 1];
+ int tcolor = s->transparent_color_be[0];
+ for (x = s->width; x > 0; --x) {
+ *pixel-- = *rowp == tcolor ? 0 : 0xff;
+ *pixel-- = *rowp--;
+ }
+ } else if (s->bpp == 4 && byte_depth == 1) {
+ uint8_t *pixel = &row[4 * s->width - 1];
+ uint8_t *rowp = &row[3 * s->width - 1];
+ int tcolor = AV_RL24(s->transparent_color_be);
+ for (x = s->width; x > 0; --x) {
+ *pixel-- = AV_RL24(rowp-2) == tcolor ? 0 : 0xff;
+ *pixel-- = *rowp--;
+ *pixel-- = *rowp--;
+ *pixel-- = *rowp--;
+ }
+ } else {
+ /* since we're updating in-place, we have to go from right to left */
+ for (x = s->width; x > 0; --x) {
+ uint8_t *pixel = &row[s->bpp * (x - 1)];
+ memmove(pixel, &row[raw_bpp * (x - 1)], raw_bpp);