• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Introduction
2
3Rotation by multiplies of 90 degrees allows mobile devices to rotate webcams from landscape to portrait.  The higher level functions ConvertToI420 and ConvertToARGB allow rotation of any format.  Optimized functionality is supported for I420, ARGB, NV12 and NV21.
4
5# ConvertToI420
6
7    int ConvertToI420(const uint8* src_frame, size_t src_size,
8                      uint8* dst_y, int dst_stride_y,
9                      uint8* dst_u, int dst_stride_u,
10                      uint8* dst_v, int dst_stride_v,
11                      int crop_x, int crop_y,
12                      int src_width, int src_height,
13                      int crop_width, int crop_height,
14                      enum RotationMode rotation,
15                      uint32 format);
16
17This function crops, converts, and rotates.  You should think of it in that order.
18  * Crops the original image, which is src_width x src_height, to crop_width x crop_height.  At this point the image is still not rotated.
19  * Converts the cropped region to I420.  Supports inverted source for src_height negative.
20  * Rotates by 90, 180 or 270 degrees.
21The buffer the caller provides should account for rotation.  Be especially important to get stride of the destination correct.
22
23e.g.
24640 x 480 NV12 captured<br>
25Crop to 640 x 360<br>
26Rotate by 90 degrees to 360 x 640.<br>
27Caller passes stride of 360 for Y and 360 / 2 for U and V.<br>
28Caller passes crop_width of 640, crop_height of 360.<br>
29
30# ConvertToARGB
31
32    int ConvertToARGB(const uint8* src_frame, size_t src_size,
33                      uint8* dst_argb, int dst_stride_argb,
34                      int crop_x, int crop_y,
35                      int src_width, int src_height,
36                      int crop_width, int crop_height,
37                      enum RotationMode rotation,
38                      uint32 format);
39
40Same as I420, but implementation is less optimized - reads columns and writes rows, 16 bytes at a time.
41
42# I420Rotate
43
44    int I420Rotate(const uint8* src_y, int src_stride_y,
45                   const uint8* src_u, int src_stride_u,
46                   const uint8* src_v, int src_stride_v,
47                   uint8* dst_y, int dst_stride_y,
48                   uint8* dst_u, int dst_stride_u,
49                   uint8* dst_v, int dst_stride_v,
50                   int src_width, int src_height, enum RotationMode mode);
51
52Destination is rotated, so pass dst_stride_y etc that consider rotation.<br>
53Rotate by 180 can be done in place, but 90 and 270 can not.
54
55Implementation (Neon/SSE2) uses 8 x 8 block transpose, so best efficiency is with sizes and pointers that are aligned to 8.
56
57Cropping can be achieved by adjusting the src_y/u/v pointers and src_width, src_height.
58
59Lower level plane functions are provided, allowing other planar formats to be rotated.  (e.g. I444)
60
61For other planar YUV formats (I444, I422, I411, I400, NV16, NV24), the planar functions are exposed and can be called directly
62
63
64    // Rotate a plane by 0, 90, 180, or 270.
65    int RotatePlane(const uint8* src, int src_stride,
66                    uint8* dst, int dst_stride,
67                    int src_width, int src_height, enum RotationMode mode);
68
69# ARGBRotate
70
71    LIBYUV_API
72    int ARGBRotate(const uint8* src_argb, int src_stride_argb,
73                   uint8* dst_argb, int dst_stride_argb,
74                   int src_width, int src_height, enum RotationMode mode);
75
76Same as I420, but implementation is less optimized - reads columns and writes rows.
77
78Rotate by 90, or any angle, can be achieved using ARGBAffine.
79
80# Mirror - Horizontal Flip
81
82Mirror functions for horizontally flipping an image, which can be useful for 'self view' of a webcam.
83
84    int I420Mirror(const uint8* src_y, int src_stride_y,
85                   const uint8* src_u, int src_stride_u,
86                   const uint8* src_v, int src_stride_v,
87                   uint8* dst_y, int dst_stride_y,
88                   uint8* dst_u, int dst_stride_u,
89                   uint8* dst_v, int dst_stride_v,
90                   int width, int height);
91    int ARGBMirror(const uint8* src_argb, int src_stride_argb,
92                   uint8* dst_argb, int dst_stride_argb,
93                   int width, int height);
94
95Mirror functionality can also be achieved with the I420Scale and ARGBScale functions by passing negative width and/or height.
96
97# Invert - Vertical Flip
98
99Inverting can be achieved with almost any libyuv function by passing a negative source height.
100
101I420Mirror and ARGBMirror can also be used to rotate by 180 degrees by passing a negative height.
102
103
104