|
| 1 | +/* |
| 2 | + * Copyright 2022 LiveKit |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "yuv_helper.h" |
| 18 | + |
| 19 | +#include "libyuv/convert.h" |
| 20 | +#include "third_party/libyuv/include/libyuv.h" |
| 21 | +#include "video_rotation.h" |
| 22 | + |
| 23 | +namespace webrtc { |
| 24 | + |
| 25 | +int I420Rotate(const uint8_t* src_y, |
| 26 | + int src_stride_y, |
| 27 | + const uint8_t* src_u, |
| 28 | + int src_stride_u, |
| 29 | + const uint8_t* src_v, |
| 30 | + int src_stride_v, |
| 31 | + uint8_t* dst_y, |
| 32 | + int dst_stride_y, |
| 33 | + uint8_t* dst_u, |
| 34 | + int dst_stride_u, |
| 35 | + uint8_t* dst_v, |
| 36 | + int dst_stride_v, |
| 37 | + int width, |
| 38 | + int height, |
| 39 | + VideoRotation mode) { |
| 40 | + return libyuv::I420Rotate(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 41 | + src_stride_v, dst_y, dst_stride_y, dst_u, |
| 42 | + dst_stride_u, dst_v, dst_stride_v, width, height, |
| 43 | + static_cast<libyuv::RotationMode>(mode)); |
| 44 | +} |
| 45 | + |
| 46 | +int I420ToNV12(const uint8_t* src_y, |
| 47 | + int src_stride_y, |
| 48 | + const uint8_t* src_u, |
| 49 | + int src_stride_u, |
| 50 | + const uint8_t* src_v, |
| 51 | + int src_stride_v, |
| 52 | + uint8_t* dst_y, |
| 53 | + int dst_stride_y, |
| 54 | + uint8_t* dst_uv, |
| 55 | + int dst_stride_uv, |
| 56 | + int width, |
| 57 | + int height) { |
| 58 | + return libyuv::I420ToNV12(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 59 | + src_stride_v, dst_y, dst_stride_y, dst_uv, |
| 60 | + dst_stride_uv, width, height); |
| 61 | +} |
| 62 | + |
| 63 | +int NV12ToI420(const uint8_t* src_y, |
| 64 | + int src_stride_y, |
| 65 | + const uint8_t* src_uv, |
| 66 | + int src_stride_uv, |
| 67 | + uint8_t* dst_y, |
| 68 | + int dst_stride_y, |
| 69 | + uint8_t* dst_u, |
| 70 | + int dst_stride_u, |
| 71 | + uint8_t* dst_v, |
| 72 | + int dst_stride_v, |
| 73 | + int width, |
| 74 | + int height) { |
| 75 | + return libyuv::NV12ToI420(src_y, src_stride_y, src_uv, src_stride_uv, dst_y, |
| 76 | + dst_stride_y, dst_u, dst_stride_u, dst_v, |
| 77 | + dst_stride_v, width, height); |
| 78 | +} |
| 79 | + |
| 80 | +int I420ToARGB(const uint8_t* src_y, |
| 81 | + int src_stride_y, |
| 82 | + const uint8_t* src_u, |
| 83 | + int src_stride_u, |
| 84 | + const uint8_t* src_v, |
| 85 | + int src_stride_v, |
| 86 | + uint8_t* dst_argb, |
| 87 | + int dst_stride_argb, |
| 88 | + int width, |
| 89 | + int height) { |
| 90 | + return libyuv::I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 91 | + src_stride_v, dst_argb, dst_stride_argb, width, |
| 92 | + height); |
| 93 | +} |
| 94 | + |
| 95 | +int I420ToBGRA(const uint8_t* src_y, |
| 96 | + int src_stride_y, |
| 97 | + const uint8_t* src_u, |
| 98 | + int src_stride_u, |
| 99 | + const uint8_t* src_v, |
| 100 | + int src_stride_v, |
| 101 | + uint8_t* dst_bgra, |
| 102 | + int dst_stride_bgra, |
| 103 | + int width, |
| 104 | + int height) { |
| 105 | + return libyuv::I420ToBGRA(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 106 | + src_stride_v, dst_bgra, dst_stride_bgra, width, |
| 107 | + height); |
| 108 | +} |
| 109 | + |
| 110 | +int I420ToABGR(const uint8_t* src_y, |
| 111 | + int src_stride_y, |
| 112 | + const uint8_t* src_u, |
| 113 | + int src_stride_u, |
| 114 | + const uint8_t* src_v, |
| 115 | + int src_stride_v, |
| 116 | + uint8_t* dst_abgr, |
| 117 | + int dst_stride_abgr, |
| 118 | + int width, |
| 119 | + int height) { |
| 120 | + return libyuv::I420ToABGR(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 121 | + src_stride_v, dst_abgr, dst_stride_abgr, width, |
| 122 | + height); |
| 123 | +} |
| 124 | + |
| 125 | +int I420ToRGBA(const uint8_t* src_y, |
| 126 | + int src_stride_y, |
| 127 | + const uint8_t* src_u, |
| 128 | + int src_stride_u, |
| 129 | + const uint8_t* src_v, |
| 130 | + int src_stride_v, |
| 131 | + uint8_t* dst_rgba, |
| 132 | + int dst_stride_rgba, |
| 133 | + int width, |
| 134 | + int height) { |
| 135 | + return libyuv::I420ToRGBA(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 136 | + src_stride_v, dst_rgba, dst_stride_rgba, width, |
| 137 | + height); |
| 138 | +} |
| 139 | + |
| 140 | +int I420ToRGB24(const uint8_t* src_y, |
| 141 | + int src_stride_y, |
| 142 | + const uint8_t* src_u, |
| 143 | + int src_stride_u, |
| 144 | + const uint8_t* src_v, |
| 145 | + int src_stride_v, |
| 146 | + uint8_t* dst_rgb24, |
| 147 | + int dst_stride_rgb24, |
| 148 | + int width, |
| 149 | + int height) { |
| 150 | + return libyuv::I420ToRGB24(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 151 | + src_stride_v, dst_rgb24, dst_stride_rgb24, width, |
| 152 | + height); |
| 153 | +} |
| 154 | + |
| 155 | +int I420Scale(const uint8_t* src_y, |
| 156 | + int src_stride_y, |
| 157 | + const uint8_t* src_u, |
| 158 | + int src_stride_u, |
| 159 | + const uint8_t* src_v, |
| 160 | + int src_stride_v, |
| 161 | + int src_width, |
| 162 | + int src_height, |
| 163 | + uint8_t* dst_y, |
| 164 | + int dst_stride_y, |
| 165 | + uint8_t* dst_u, |
| 166 | + int dst_stride_u, |
| 167 | + uint8_t* dst_v, |
| 168 | + int dst_stride_v, |
| 169 | + int dst_width, |
| 170 | + int dst_height, |
| 171 | + libyuv::FilterMode filtering) { |
| 172 | + return libyuv::I420Scale(src_y, src_stride_y, src_u, src_stride_u, src_v, |
| 173 | + src_stride_v, src_width, src_height, dst_y, |
| 174 | + dst_stride_y, dst_u, dst_stride_u, dst_v, |
| 175 | + dst_stride_v, dst_width, dst_height, filtering); |
| 176 | +} |
| 177 | + |
| 178 | +int ARGBToI420(const uint8_t* src_argb, |
| 179 | + int src_stride_argb, |
| 180 | + uint8_t* dst_y, |
| 181 | + int dst_stride_y, |
| 182 | + uint8_t* dst_u, |
| 183 | + int dst_stride_u, |
| 184 | + uint8_t* dst_v, |
| 185 | + int dst_stride_v, |
| 186 | + int width, |
| 187 | + int height) { |
| 188 | + return libyuv::ARGBToI420(src_argb, src_stride_argb, dst_y, dst_stride_y, |
| 189 | + dst_u, dst_stride_u, dst_v, dst_stride_v, width, |
| 190 | + height); |
| 191 | +} |
| 192 | + |
| 193 | +int ABGRToI420(const uint8_t* src_abgr, |
| 194 | + int src_stride_abgr, |
| 195 | + uint8_t* dst_y, |
| 196 | + int dst_stride_y, |
| 197 | + uint8_t* dst_u, |
| 198 | + int dst_stride_u, |
| 199 | + uint8_t* dst_v, |
| 200 | + int dst_stride_v, |
| 201 | + int width, |
| 202 | + int height) { |
| 203 | + return libyuv::ABGRToI420(src_abgr, src_stride_abgr, dst_y, dst_stride_y, |
| 204 | + dst_u, dst_stride_u, dst_v, dst_stride_v, width, |
| 205 | + height); |
| 206 | +} |
| 207 | + |
| 208 | +int ARGBToRGB24(const uint8_t* src_argb, |
| 209 | + int src_stride_argb, |
| 210 | + uint8_t* dst_rgb24, |
| 211 | + int dst_stride_rgb24, |
| 212 | + int width, |
| 213 | + int height) { |
| 214 | + return libyuv::ARGBToRGB24(src_argb, src_stride_argb, dst_rgb24, |
| 215 | + dst_stride_rgb24, width, height); |
| 216 | +} |
| 217 | + |
| 218 | +} // namespace webrtc |
0 commit comments