[FFmpeg-devel] [PATCH 2/3] avcodec: add SGA Video decoder

Carl Eugen Hoyos ceffmpeg at gmail.com
Tue Feb 23 21:39:11 EET 2021


Am Di., 23. Feb. 2021 um 20:27 Uhr schrieb Paul B Mahol <onemda at gmail.com>:
>
> On Tue, Feb 23, 2021 at 8:20 PM Carl Eugen Hoyos <ceffmpeg at gmail.com> wrote:
>
> > Am Di., 23. Feb. 2021 um 18:32 Uhr schrieb Paul B Mahol <onemda at gmail.com
> > >:
> >
> > > +static int decode_palette(GetByteContext *gb, uint32_t *pal)
> > > +{
> > > +    GetBitContext gbit;
> > > +
> > > +    if (bytestream2_get_bytes_left(gb) < 18)
> > > +        return AVERROR_INVALIDDATA;
> > > +
> > > +    memset(pal, 0, 16 * sizeof(*pal));
> > > +    init_get_bits8(&gbit, gb->buffer, 18);
> > > +
> > > +    for (int RGBIndex = 0; RGBIndex < 3; RGBIndex++) {
> > > +        for (int index = 0; index < 16; index++) {
> > > +            unsigned color = get_bits1(&gbit) << RGBIndex;
> > > +            pal[15 - index] |= color << (5 + 16);
> > > +        }
> > > +    }
> > > +
> > > +    for (int RGBIndex = 0; RGBIndex < 3; RGBIndex++) {
> > > +        for (int index = 0; index < 16; index++) {
> > > +            unsigned color = get_bits1(&gbit) << RGBIndex;
> > > +            pal[15 - index] |= color << (5 + 8);
> > > +        }
> > > +    }
> > > +
> > > +    for (int RGBIndex = 0; RGBIndex < 3; RGBIndex++) {
> > > +        for (int index = 0; index < 16; index++) {
> > > +            unsigned color = get_bits1(&gbit) << RGBIndex;
> > > +            pal[15 - index] |= color << (5 + 0);
> > > +        }
> > > +    }
> >
> > This will not allow white to look white on the screen,
> > you have to add color more often to pal.
> >
> >
> What this even means?

The value closest to white that is possible with above
code (please correct me if I am wrong) is:
0xE0E0E0
This is visually different than 0xFFFFFF

Something like the following is possible, simpler solutions
probably exist:
pal{15-index] |= color << 16+5 | color << 16+2 | (color & 6) << 16-1 ;

pal[15-index] |= color << 8+5 | color << 8+2 | (color & 6) << 8-1;

pal[15-index] |= color << 5 | color << 2 | color >> 1;


Carl Eugen


More information about the ffmpeg-devel mailing list