libdragon icon indicating copy to clipboard operation
libdragon copied to clipboard

mksprite: add bleedfix option to mitigate halos for transparent sprites WIP

Open phoboslab opened this issue 1 month ago • 6 comments

This adds an optional switch to mksprite to mitigate halos around sprites with transparency.

The idea is to "radiate" the sprite outwards. These newly filled pixels will have the r,g,b values of the edges of the sprite, while still maintaining full transparency (a = 0). Only fully transparent pixels are modified; all pixels with partial transparency are left as is.

One complication arises with paletted sprites: in most cases the palette is already completely filled (with either 16 or 256 colors), so we can't create any new colors. The only option is to modify the existing palette entry with the transparent color to a single "background" color. This background color is simply computed as the average of all colors of the sprite's edges.

For now, all paletted images are filled with a single "background" color. We could be smarter about this if we have some free palette entries to use: create k-means of each of the edge colors and use those to "radiate" outwards, same as with rgba16/32. I'm not yet sure if it's worth to implement this...

I'm still doing some testing, to make sure it works as intended. I just wanted some early feedback if

  • this is wanted in libdragon and
  • this PR is going in the right direction.

Also, I'm open for suggestions for a better name. -bleedfix is not that descriptive :]

Examples (alpha value set to 255 for illustrative purposes):

Source

image

RGBA16

image

CI4

image

IA8

image

phoboslab avatar Dec 11 '25 21:12 phoboslab