Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1101)

Side by Side Diff: source/convert.cc

Issue 2277603004: Add SplitUVPlanes and MergeUVPlanes (Closed) Base URL: https://chromium.googlesource.com/libyuv/libyuv@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 CopyRow(src, dst, width); 222 CopyRow(src, dst, width);
223 CopyRow(src + src_stride_0, dst + dst_stride, width); 223 CopyRow(src + src_stride_0, dst + dst_stride, width);
224 src += src_stride_0 + src_stride_1; 224 src += src_stride_0 + src_stride_1;
225 dst += dst_stride * 2; 225 dst += dst_stride * 2;
226 } 226 }
227 if (height & 1) { 227 if (height & 1) {
228 CopyRow(src, dst, width); 228 CopyRow(src, dst, width);
229 } 229 }
230 } 230 }
231 231
232 // Support function for NV12 etc UV channels. 232 LIBYUV_API
233 // Width and height are plane sizes (typically half pixel width). 233 int SplitUVPlane(const uint8* src_uv, int src_stride_uv,
234 static void SplitUVPlane(const uint8* src_uv, int src_stride_uv, 234 uint8* dst_u, int dst_stride_u,
235 uint8* dst_u, int dst_stride_u, 235 uint8* dst_v, int dst_stride_v,
236 uint8* dst_v, int dst_stride_v, 236 int width, int height) {
237 int width, int height) { 237 if (!src_uv || !dst_u || !dst_v || width <= 0 || height == 0) {
238 int y; 238 return -1;
239 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, 239 }
240 int width) = SplitUVRow_C;
241 // Negative height means invert the image. 240 // Negative height means invert the image.
242 if (height < 0) { 241 if (height < 0) {
243 height = -height; 242 height = -height;
244 dst_u = dst_u + (height - 1) * dst_stride_u; 243 dst_u = dst_u + (height - 1) * dst_stride_u;
245 dst_v = dst_v + (height - 1) * dst_stride_v; 244 dst_v = dst_v + (height - 1) * dst_stride_v;
246 dst_stride_u = -dst_stride_u; 245 dst_stride_u = -dst_stride_u;
247 dst_stride_v = -dst_stride_v; 246 dst_stride_v = -dst_stride_v;
248 } 247 }
249 // Coalesce rows. 248 // Coalesce rows.
250 if (src_stride_uv == width * 2 && 249 if (src_stride_uv == width * 2 &&
251 dst_stride_u == width && 250 dst_stride_u == width &&
252 dst_stride_v == width) { 251 dst_stride_v == width) {
253 width *= height; 252 width *= height;
254 height = 1; 253 height = 1;
255 src_stride_uv = dst_stride_u = dst_stride_v = 0; 254 src_stride_uv = dst_stride_u = dst_stride_v = 0;
256 } 255 }
257 #if defined(HAS_SPLITUVROW_SSE2) 256 SplitUVRowFunction SplitUVRow = GetOptimizedSplitUVRowFunction(
258 if (TestCpuFlag(kCpuHasSSE2)) { 257 src_uv, src_stride_uv, dst_u, dst_stride_u, dst_v, dst_stride_v, width);
259 SplitUVRow = SplitUVRow_Any_SSE2;
260 if (IS_ALIGNED(width, 16)) {
261 SplitUVRow = SplitUVRow_SSE2;
262 }
263 }
264 #endif
265 #if defined(HAS_SPLITUVROW_AVX2)
266 if (TestCpuFlag(kCpuHasAVX2)) {
267 SplitUVRow = SplitUVRow_Any_AVX2;
268 if (IS_ALIGNED(width, 32)) {
269 SplitUVRow = SplitUVRow_AVX2;
270 }
271 }
272 #endif
273 #if defined(HAS_SPLITUVROW_NEON)
274 if (TestCpuFlag(kCpuHasNEON)) {
275 SplitUVRow = SplitUVRow_Any_NEON;
276 if (IS_ALIGNED(width, 16)) {
277 SplitUVRow = SplitUVRow_NEON;
278 }
279 }
280 #endif
281 #if defined(HAS_SPLITUVROW_DSPR2)
282 if (TestCpuFlag(kCpuHasDSPR2) &&
283 IS_ALIGNED(dst_u, 4) && IS_ALIGNED(dst_stride_u, 4) &&
284 IS_ALIGNED(dst_v, 4) && IS_ALIGNED(dst_stride_v, 4)) {
285 SplitUVRow = SplitUVRow_Any_DSPR2;
286 if (IS_ALIGNED(width, 16)) {
287 SplitUVRow = SplitUVRow_DSPR2;
288 }
289 }
290 #endif
291 258
292 for (y = 0; y < height; ++y) { 259 for (int y = 0; y < height; ++y) {
293 // Copy a row of UV. 260 // Copy a row of UV.
294 SplitUVRow(src_uv, dst_u, dst_v, width); 261 SplitUVRow(src_uv, dst_u, dst_v, width);
295 dst_u += dst_stride_u; 262 dst_u += dst_stride_u;
296 dst_v += dst_stride_v; 263 dst_v += dst_stride_v;
297 src_uv += src_stride_uv; 264 src_uv += src_stride_uv;
298 } 265 }
266 return 0;
299 } 267 }
300 268
301 // Support converting from FOURCC_M420 269 // Support converting from FOURCC_M420
302 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for 270 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for
303 // easy conversion to I420. 271 // easy conversion to I420.
304 // M420 format description: 272 // M420 format description:
305 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. 273 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV.
306 // Chroma is half width / half height. (420) 274 // Chroma is half width / half height. (420)
307 // src_stride_m420 is row planar. Normally this will be the width in pixels. 275 // src_stride_m420 is row planar. Normally this will be the width in pixels.
308 // The UV plane is half width, but 2 values, so src_stride_m420 applies to 276 // The UV plane is half width, but 2 values, so src_stride_m420 applies to
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 dst_u += dst_stride_u; 1453 dst_u += dst_stride_u;
1486 dst_v += dst_stride_v; 1454 dst_v += dst_stride_v;
1487 } 1455 }
1488 return 0; 1456 return 0;
1489 } 1457 }
1490 1458
1491 #ifdef __cplusplus 1459 #ifdef __cplusplus
1492 } // extern "C" 1460 } // extern "C"
1493 } // namespace libyuv 1461 } // namespace libyuv
1494 #endif 1462 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698