fragment_downloaded_cb({"url":"tutorial.html#example-3","fragment":"Example 3\nThe third example shows how to convert a planar 4:2:0 video image into a packed 4:4:4 video image with an alpha channel. The first format is often referred to as I420 and the second as AYUV.\nFor simplicity in the following discussion, we'll assume that the image dimensions are 640x480. The 4:2:0 subsampling means the input chroma planes are 320x240 (subsampled by 2 in each direction). These need to be upsampled to 640x480, then repacked with the input Y plane, with an added dummy alpha value. There are many ways to perform upsampling; the simplest is to duplicate each value horizontally and vertically. The result is low quality, but adequate for demonstration purposes.\nThere are several choices for the Orc array size and dimensionality. Iterating vertically can be done in the C code or in the Orc code. If done in the Orc code, we would need to use an array size of 240 and have two separate arrays for the even and odd Y rows. If done in the C code, there is no such limitation. Horizontally, the story is different: we can use the loadupsdb opcode to duplicate each byte in the U and V arrays, so we can iterate over 640 array elements. It is also possible to iterate over 320 elements and duplicate the U and V elements using mergebw. There is a very slight speed advantage to iterating vertically in Orc, and for demonstration purposes, we will choose to use the loadupsdb opcode, thus we will be iterating over 320x240 elements.\nThe code:\nA few things of note: The \".flags 2d\" line is used to indicate that Orc should iterate over two dimensions, and generate a prototype that includes row strides for each array and a size parameter for the second dimension.\nSince we are working on two input Y lines and two output AYUV lines at a time, we need two source and destination arrays corresponding to the even and odd lines. The row strides for these are doubled compared to the normal 2-D array.\nThe mergebw and mergewl opcodes join two 8-bit values into one 16-bit value (or 16-bit values into a 32-bit value) by concatinating them in memory order. Thus, to get AYUV in memory order, we merge AY and UV, and to get UV, we merge U and V. Since we're duplicating each U and V line, we use the same UV value for the even and odd output lines.\nThe prototype that is generated is:\nThe orcc tool unhelpfully changed the names of the parameters, however, the order is standard: first destinations, then sources, then parameters, then array sizes. Think of it like memcpy() or memset().\nCalling the function:\n"});