Expand description
Utilities for doing the YUV -> RGB conversion The images are encoded in the YโCbCr format as detailed here: https://en.wikipedia.org/wiki/YCbCr so need to be converted to RGB to be displayed To do the YUV -> RGB conversion we need to first decide how to map the yuv values to the pixels The y buffer is the same size as the pixel buffer so that maps 1-1 but the u and v buffers are half the size of the pixel buffer so we need to scale it up The simple way to upscale is just to take each u/v value and associate it with the 4 pixels around it e.g. for a 4x4 image:
|||||| |yyyy| |yyyy| |yyyy| |yyyy| ||||||
||||||| |uu|vv| |uu|vv| |||||||
Then each of the 2x2 pixels would match the u/v from the same quadrant
However fancy upsampling is the default for libwebp which does a little more work to make the values smoother It interpolates u and v so that for e.g. the pixel 1 down and 1 from the left the u value would be (9u0 + 3u1 + 3u2 + u3 + 8) / 16 and similar for the other pixels The edges are mirrored, so for the pixel 1 down and 0 from the left it uses (9u0 + 3u2 + 3u0 + u2 + 8) / 16
Functionsยง
- clip ๐
- This function has been rewritten to encourage auto-vectorization.
- fill_
rgb_ ๐buffer_ fancy - Fills an rgb buffer with the image from the yuv buffers Size of the buffer is assumed to be correct BPP is short for bytes per pixel, allows both rgb and rgba to be decoded
- fill_
rgb_ ๐buffer_ simple - Simple conversion, not currently used but could add a config to allow for using the simple
- fill_
rgba_ ๐row_ simple - fill_
row_ ๐fancy_ with_ 1_ uv_ row - fill_
row_ ๐fancy_ with_ 2_ uv_ rows - Fills a row with the fancy interpolation as detailed
- get_
fancy_ ๐chroma_ value - mulhi ๐
_mm_mulhi_epu16
emulation- set_
pixel ๐ - yuv_
to_ ๐b - yuv_
to_ ๐g - yuv_
to_ ๐r