Module yuv

Source
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 ๐Ÿ”’