[FFmpeg-devel] Scaling PAL8 images with alpha

Michael Niedermayer michael at niedermayer.cc
Sat Sep 25 17:30:19 EEST 2021


On Sat, Sep 25, 2021 at 10:23:56AM +0200, Hendrik Leppkes wrote:
> On Sat, Sep 25, 2021 at 5:00 AM Soft Works <softworkz at hotmail.com> wrote:
> >
> >
> >
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of
> > > Soft Works
> > > Sent: Friday, 24 September 2021 19:03
> > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel at ffmpeg.org>
> > > Subject: Re: [FFmpeg-devel] Scaling PAL8 images with alpha
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of
> > > Michael
> > > > Niedermayer
> > > > Sent: Friday, 24 September 2021 17:40
> > > > To: FFmpeg development discussions and patches <ffmpeg-
> > > devel at ffmpeg.org>
> > > > Subject: Re: [FFmpeg-devel] Scaling PAL8 images with alpha
> > > >
> > > > On Fri, Sep 24, 2021 at 10:30:31AM +0000, Soft Works wrote:
> > > > > Hi,
> > > > >
> > > > > for a new filter, I want to rescale PAL8 subtitle bitmaps where
> > > the palette
> > > > includes
> > > > > colors with alpha.
> > > > >
> > > > > From what I’ve seen, swscale doesn’t support PAL8-to-PAL8, only
> > > PAL8-to-
> > > > BGR8
> > > > > which doesn’t support alpha and the palette is fixed with 256
> > > entries
> > > > defined by
> > > > > convention, while I would ideally like to be able to allow the
> > > following:
> > > > >
> > > > > - constrain the output to use the same palette as the input
> > > > > - adaptively quantize it to a palette with a configurable number
> > > of colors
> > > > >
> > > > > Thus it's about the palette quantization (with or without
> > > dithering) after
> > > > > scaling in RGBA. (or some cool algorithmic trick I'm not aware
> > > of)
> > > > >
> > > > > Is there any existing code that I could reuse? The closest I
> > > could find
> > > > > is pngenc, but I'm wondering whether there's something
> > > else/better
> > > > > somewhere in the ffmpeg libs that I haven't seen?
> > > >
> > > > There are some non linear scaling filters which may make sense when
> > > you do
> > > > not have the full linear space available see:
> > > > hqx, epx, xbr
> > > > you could also try some neural net stuff
> > >
> > > Photoshop can perfectly do what is needed, but their algorithms are
> > > not
> > > public.
> >
> > I've put a few thing together to illustrate what I'm talking about:
> >
> > https://gist.github.com/softworkz/deef5c2a43d3d629c3e17f9e21544a8f
> >
> >
> > Meanwhile I found what I need: https://github.com/ImageOptim/libimagequant
> >
> > Interestingly, they are comparing their lib specifically to the
> > Photoshop feature that I mentioned: https://pngquant.org/vsphotoshop.html
> > In the 2000's, the PS implementation for image quantization, optimization
> > and compression (profanely named "Save for Web") had remained
> > unparalleled for years, that's why it was one of my first thoughts.
> >
> > I hadn't heard about libimagequant before, but it seems to do exactly
> > what is needed for rescaling PAL8 to PAL8 at a high quality.
> >
> > Before spending any time on it, I wanted ask whether that library
> > would be acceptable for adding it as a (GPLv3) reference to the
> > project and as a dependency to my filter?
> >
> 
> External dependencies for what is supposed to be a rather base feature
> are not ideal.

+1

i see no reason why this would need an external dependancy
we have filters implementing much more complex things than scaling a pal8
image

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20210925/ed8f7521/attachment.sig>


More information about the ffmpeg-devel mailing list