okay, I have a really weird edge case for extracting pngs from avatars for the mscc thing. details below the fold.
so transparency masks in cchat don't work like true masks for colors other than white/black in the base image.
(for a given pixel, if the mask is white, the rendered pixel is the bitwise and of the base image ("fg") and background color ("bg"). if the fg is white, this is "transparent". if it's black, it's opaque black. see my earlier thread for details on this matter.)
99.9% of the time, I can export a png with an alpha channel that's going to look like how comic chat renders it. In a scant few cases though, the mask has white pixels that correspond to base image pixels that aren't white.
Since the actual render depends on the background, I don't think there's a way I can export a standalone alpha transparency png that actually matches what you'd get in the real program 100% of the time.
... So I guess I can kinda-sorta fudge it?
I could, for each white pixel in the mask, set the transparency % to the number of bits set for that pixel.
e.g. a white base image pixel would be #FFFFFF, 24/24 or 100% transparent. a black base image pixel would be #000000, 0/24 or 0% transparent, fully opaque. #808080 would be just 3/24, 12.5%. #7F7F7F would be 87.5% transparent. #FFFFFC would also be 87.5% transparent. It's not perfect.
(The other option would be to compute transparency per channel and average them, so 7F7F7F would be 7/8 but FFFFFC would be 7.3/8. I'm not sure if one is more justifiable than the other.)
It's kind of weird and counter-intuitive, but it probably matches what you'd be likely to see in the cchat renderer more often, like, statistically.
And it probably only matters on a very, very few avatars but ... I guess when you're "archiving" and "preserving", accuracy matters.
(I guess I'll just leave a little warning disclaimer in the library if you decode an avatar where this matters that says "Hey! This isn't provably accurate for extremely pedantic reasons!")

