gif-stream icon indicating copy to clipboard operation
gif-stream copied to clipboard

Support transparent pixels

Open sfrdmn opened this issue 10 years ago • 3 comments

GIFEncoder currently doesn't seem to support transparency. pixel-stream frame meta data passed in may contain transparent index information, but this is ignored by the encoder.

Would be good to note this lack of support in the README

sfrdmn avatar May 12 '15 01:05 sfrdmn

We should support it. The decoder passes a transparentColor value per frame as decoded from the graphic control extension. This currently isn't even used in the conversion to RGB within the decoder. The encoder also ignores it.

Would be nice to have something more standard to work across formats. png-stream emits an alphaPalette on the format object but it doesn't get used anywhere else. The encoder just looks for a palette whose length is divisible by 4 (includes transparency for each color). GIFs only support a single transparent color though, so would be a waste to include transparency for every color... Thinking out loud here. Thoughts?

devongovett avatar May 13 '15 17:05 devongovett

Can't say I know enough about image encodings to say much about a "lowest common denominator" format for transparency meta data

But since this is transparency information regarding an indexed pixel stream, it might make sense to restrict the format to be common among only those such streams. Idea being, there may not necessarily be a clean way to reconcile it with other transparency representations, whatever they may be. GIF only has one transparency index, with a single alpha value (0). A flexible abstraction of this might be to have a standard transparencyIndices or alphaPalette property for indexed streams represented with an object whose keys enumerate palette indices and whose values give the corresponding opacity

In the PNGEncoder case, this can function the same as alphaPalette currently does, and for the GIFEncoder, it can just decide to take the first key as the index, or do something weird and fancy like approximate complex transparency with dithering.

sfrdmn avatar May 13 '15 23:05 sfrdmn

Er... actually probably just misunderstood how indexing works in the PNG case. Anyway, maybe food or thought still ^

sfrdmn avatar May 13 '15 23:05 sfrdmn