GifEncoder icon indicating copy to clipboard operation
GifEncoder copied to clipboard

Support transparent color

Open 88aleksandr88 opened this issue 3 years ago • 14 comments

Does it use premultiplied or non-premultiplied pixel color format?

88aleksandr88 avatar Nov 03 '22 19:11 88aleksandr88

It uses premultiplied ARGB32 and just throws away alpha channel.

88aleksandr88 avatar Nov 07 '22 19:11 88aleksandr88

@88aleksandr88 In fact, gif image format do not support alpha channel.

xiaozhuai avatar Nov 08 '22 09:11 xiaozhuai

xiaozhuai, gif can have a transparent color. If format of source image is ARGB32 premultiplied, to get the real colors, except fully transparent you can throw out alpha channel and take RGB channels. If format is pure ARGB32 (most images have ARGB32 premultiplied format), you need multiply each R, G, B channel on alpha before making gif color table to get real colors of image.

88aleksandr88 avatar Nov 11 '22 09:11 88aleksandr88

Ahh, you are right! Gif can have a transparent color, but it don't have alpha channel. Which meas no translucent.

xiaozhuai avatar Nov 11 '22 10:11 xiaozhuai

Can you update your algorithm, that it could support transparent background? I think for that NewQuant algorithm must split colors to 255 classes, not to 256, leaving one class to transparent color and transparent color should be mapped from image to gif-pixel data ignoring NewQuant algorithm, because for this algorithm black (0x 00 00 00) and transparent (0x 00 00 00) colors are the same.

88aleksandr88 avatar Nov 11 '22 10:11 88aleksandr88

@88aleksandr88 Good suggestion, I'll reopen this issue.

xiaozhuai avatar Nov 13 '22 05:11 xiaozhuai

xiaozhuai, You have animation type of layers Combine. Can user change it from Combine to Replace?

88aleksandr88 avatar Nov 14 '22 08:11 88aleksandr88

In NewQuant.h exists line: #define minpicturebytes (3prime4) / minimum size for input image */ Can algorithm be changed to encode gifs of any size? May be adding somewhere pixelIdex%pixelsCount will be enough?

88aleksandr88 avatar Nov 14 '22 12:11 88aleksandr88

@88aleksandr88 I don't have time to release an update for now, feel free to make a pr if you want.

xiaozhuai avatar Nov 15 '22 10:11 xiaozhuai

Can you update your algorithm, that it could support transparent background? I think for that NewQuant algorithm must split colors to 255 classes, not to 256, leaving one class to transparent color and transparent color should be mapped from image to gif-pixel data ignoring NewQuant algorithm, because for this algorithm black (0x 00 00 00) and transparent (0x 00 00 00) colors are the same.

Sounds good, I'll try to make it happen in the next couple of days

DreamOfIce avatar Feb 17 '23 15:02 DreamOfIce

That will be great. I learned NewQuant algorhitm and make it in floats with Qt and OpenMP, but it works slower than yours, but has a little bit higher quality of result (may be this quality is result of floats use). My realization works with transparent images of any gif-compatible size, but it slow.

88aleksandr88 avatar Feb 17 '23 20:02 88aleksandr88

That will be great. I learned NewQuant algorhitm and make it in floats with Qt and OpenMP, but it works slower than yours, but has a little bit higher quality of result (may be this quality is result of floats use). My realization works with transparent images of any gif-compatible size, but it slow.

Can I take a look at your code for reference?

DreamOfIce avatar Feb 18 '23 03:02 DreamOfIce

This algorithm, realized by xiaozhuai is highly-optimized. Mine is theory-straight. Its almost impossible to compare function-by-function code sens of them. Do you really need it?

88aleksandr88 avatar Feb 21 '23 16:02 88aleksandr88

I have expanded the encoder with a bunch of fatures, like cancellation token, parallelism, out of order frame pushing, and direct framebuffer. And now I've also added transparency support. I am going to try to open a pull request, but if anyone want to experiment with with before it could get approved, here's my modified files and examples:

GifEncoder_ParallelExpansion.zip

SkrFractals avatar Feb 01 '25 00:02 SkrFractals