Commit graph

4 commits

Author SHA1 Message Date
Zaggy1024
24ae35086d LibGfx/LibVideo: Check for overreads only at end of a VPX range decode
Errors are now deferred until `finish_decode()` is finished, meaning
branches to return errors only need to occur at the end of a ranged
decode. If VPX_DEBUG is enabled, a debug message will be printed
immediately when an overread occurs.

Average decoding times for `Tests/LibGfx/test-inputs/4.webp` improve
by about 4.7% with this change, absolute decode times changing from
27.4ms±1.1ms down to 26.1ms±1.0ms.
2023-06-10 07:17:12 +02:00
Zaggy1024
873b0e9470 LibGfx/LibVideo: Read batches of multiple bytes in VPX BooleanDecoder
This does a few things:

- The decoder uses a 32- or 64-bit integer as a reservoir of the data
  being decoded, rather than one single byte as it was previously.
- `read_bool()` only refills the reservoir (value) when the size drops
  below one byte. Previously, it would read out a bit-sized range from
  the data to completely refill the 8-bit value, doing much more work
  than necessary for each individual read.
- VP9-specific code for reading the marker bit was moved to its own
  function in Context.h.
- A debug flag `VPX_DEBUG` was added to optionally enable checking of
  the final bits in a VPX ranged arithmetic decode and ensure that it
  contains all zeroes. These zeroes are a bitstream requirement for
  VP9, and are also present for all our lossy WebP test inputs
  currently. This can be useful to test whether all the data present in
  the range has been consumed.

A lot of the size of this diff comes from the removal of error handling
from all the range decoder reads in LibVideo/VP9 and LibGfx/WebP (VP8),
since it is now checked only at the end of the range.

In a benchmark decoding `Tests/LibGfx/test-inputs/4.webp`, decode times
are improved by about 22.8%, reducing average runtime from 35.5ms±1.1ms
down to 27.4±1.1ms.

This should cause no behavioral changes.
2023-06-10 07:17:12 +02:00
Nico Weber
1dfb065a9c LibGfx+LibVideo: Make BooleanDecoder usable for both VP8 and VP9
The marker bit is VP9-only, so move that into a new initialize_vp9()
function.

finish_decode() is VP9-only, so rename that to finish_decode_vp9().
2023-05-27 05:47:42 +02:00
Nico Weber
fbc53c1ec3 LibGfx+LibVideo: Move VP9/BooleanDecoder to LibGfx/ImageFormats
...and keep a forwarding header around in VP9, so we don't have to
update all references to the class there.

In time, we probably want to merge LibGfx/ImageDecoders and LibVideo
into LibMedia, but for now I need just this class for the lossy
webp decoder. So move just it over.

No behvior change.
2023-05-27 05:47:42 +02:00