Opened 10 years ago

Last modified 11 days ago

#4444 new defect

Transparency gets lost when scaling pal8

Reported by: Carl Eugen Hoyos Owned by:
Priority: normal Component: swscale
Version: git-master Keywords: pal8 alpha
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

$ ffmpeg -i alpha.png -s 168x168 out.png
ffmpeg version N-71320-gc4b2017 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl
  libavutil      54. 22.100 / 54. 22.100
  libavcodec     56. 34.100 / 56. 34.100
  libavformat    56. 29.100 / 56. 29.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 13.101 /  5. 13.101
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, png_pipe, from 'alpha.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, pal8, 21x21 [SAR 5:6 DAR 5:6], 25 tbr, 25 tbn, 25 tbc
Output #0, apng, to 'out.png':
  Metadata:
    encoder         : Lavf56.29.100
    Stream #0:0: Video: apng, pal8, 168x168 [SAR 5:6 DAR 5:6], q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc56.34.100 apng
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> apng (native))
Press [q] to stop, [?] for help
[apng @ 0x36fd040] Only a single frame so saving as a normal PNG.
frame=    1 fps=0.0 q=0.0 Lsize=       4kB time=00:00:00.04 bitrate= 823.4kbits/s
video:3kB audio:0kB subtitle:0kB other streams:0kB global headers:1kB muxing overhead: 24.418253%

The output file is opaque.

Attachments (1)

alpha.png (1.2 KB ) - added by Carl Eugen Hoyos 10 years ago.

Download all attachments as: .zip

Change History (3)

by Carl Eugen Hoyos, 10 years ago

Attachment: alpha.png added

comment:1 by Niklas Haas, 11 days ago

So, the fundamental problem here is that swscale does not support "true" PAL8 output. Instead a hack is performed by converting instead to BGR8 and then just tagging that as PAL8 (using avpriv_set_systematic_pal2).

The proper handling of paletted output would require generating a suitable palette and then dithering the image using that set of colors. (See vf_palettegen/paletteuse)

With the new graph dispatch infrastructure, it would be fairly straightforward to incorporate those filters as extra output passes, although it will require moving some code around. However, I propose simply dropping the "systematic" PAL8 output hack for now, at least in the case of inputs with an alpha channel.

Edit: That said, palettegen/paletteuse currently also do not support alpha transparent palettes.

Last edited 11 days ago by Niklas Haas (previous) (diff)
Note: See TracTickets for help on using tickets.