| OLD | NEW |
| 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 22 matching lines...) Expand all Loading... |
| 33 const uint8* src_v, int src_stride_v, | 33 const uint8* src_v, int src_stride_v, |
| 34 uint8* dst_y, int dst_stride_y, | 34 uint8* dst_y, int dst_stride_y, |
| 35 uint8* dst_u, int dst_stride_u, | 35 uint8* dst_u, int dst_stride_u, |
| 36 uint8* dst_v, int dst_stride_v, | 36 uint8* dst_v, int dst_stride_v, |
| 37 int src_y_width, int src_y_height, | 37 int src_y_width, int src_y_height, |
| 38 int src_uv_width, int src_uv_height) { | 38 int src_uv_width, int src_uv_height) { |
| 39 const int dst_y_width = Abs(src_y_width); | 39 const int dst_y_width = Abs(src_y_width); |
| 40 const int dst_y_height = Abs(src_y_height); | 40 const int dst_y_height = Abs(src_y_height); |
| 41 const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); | 41 const int dst_uv_width = SUBSAMPLE(dst_y_width, 1, 1); |
| 42 const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); | 42 const int dst_uv_height = SUBSAMPLE(dst_y_height, 1, 1); |
| 43 if (src_y_width == 0 || src_y_height == 0 || | 43 if (src_uv_width == 0 || src_uv_height == 0) { |
| 44 src_uv_width == 0 || src_uv_height == 0) { | |
| 45 return -1; | 44 return -1; |
| 46 } | 45 } |
| 47 // TODO(fbarchard): support NULL for dst_y | 46 if (dst_y) { |
| 48 ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, | 47 ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, |
| 49 dst_y, dst_stride_y, dst_y_width, dst_y_height, | 48 dst_y, dst_stride_y, dst_y_width, dst_y_height, |
| 50 kFilterBilinear); | 49 kFilterBilinear); |
| 50 } |
| 51 ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, | 51 ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, |
| 52 dst_u, dst_stride_u, dst_uv_width, dst_uv_height, | 52 dst_u, dst_stride_u, dst_uv_width, dst_uv_height, |
| 53 kFilterBilinear); | 53 kFilterBilinear); |
| 54 ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, | 54 ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, |
| 55 dst_v, dst_stride_v, dst_uv_width, dst_uv_height, | 55 dst_v, dst_stride_v, dst_uv_width, dst_uv_height, |
| 56 kFilterBilinear); | 56 kFilterBilinear); |
| 57 return 0; | 57 return 0; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Copy I420 with optional flipping | 60 // Copy I420 with optional flipping |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. | |
| 233 // Width and height are plane sizes (typically half pixel width). | |
| 234 static void SplitUVPlane(const uint8* src_uv, int src_stride_uv, | |
| 235 uint8* dst_u, int dst_stride_u, | |
| 236 uint8* dst_v, int dst_stride_v, | |
| 237 int width, int height) { | |
| 238 int y; | |
| 239 void (*SplitUVRow)(const uint8* src_uv, uint8* dst_u, uint8* dst_v, | |
| 240 int width) = SplitUVRow_C; | |
| 241 // Negative height means invert the image. | |
| 242 if (height < 0) { | |
| 243 height = -height; | |
| 244 dst_u = dst_u + (height - 1) * dst_stride_u; | |
| 245 dst_v = dst_v + (height - 1) * dst_stride_v; | |
| 246 dst_stride_u = -dst_stride_u; | |
| 247 dst_stride_v = -dst_stride_v; | |
| 248 } | |
| 249 // Coalesce rows. | |
| 250 if (src_stride_uv == width * 2 && | |
| 251 dst_stride_u == width && | |
| 252 dst_stride_v == width) { | |
| 253 width *= height; | |
| 254 height = 1; | |
| 255 src_stride_uv = dst_stride_u = dst_stride_v = 0; | |
| 256 } | |
| 257 #if defined(HAS_SPLITUVROW_SSE2) | |
| 258 if (TestCpuFlag(kCpuHasSSE2)) { | |
| 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 | |
| 292 for (y = 0; y < height; ++y) { | |
| 293 // Copy a row of UV. | |
| 294 SplitUVRow(src_uv, dst_u, dst_v, width); | |
| 295 dst_u += dst_stride_u; | |
| 296 dst_v += dst_stride_v; | |
| 297 src_uv += src_stride_uv; | |
| 298 } | |
| 299 } | |
| 300 | |
| 301 // Support converting from FOURCC_M420 | 232 // Support converting from FOURCC_M420 |
| 302 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for | 233 // Useful for bandwidth constrained transports like USB 1.0 and 2.0 and for |
| 303 // easy conversion to I420. | 234 // easy conversion to I420. |
| 304 // M420 format description: | 235 // M420 format description: |
| 305 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. | 236 // M420 is row biplanar 420: 2 rows of Y and 1 row of UV. |
| 306 // Chroma is half width / half height. (420) | 237 // Chroma is half width / half height. (420) |
| 307 // src_stride_m420 is row planar. Normally this will be the width in pixels. | 238 // 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 | 239 // The UV plane is half width, but 2 values, so src_stride_m420 applies to |
| 309 // this as well as the two Y planes. | 240 // this as well as the two Y planes. |
| 310 static int X420ToI420(const uint8* src_y, | 241 static int X420ToI420(const uint8* src_y, |
| 311 int src_stride_y0, int src_stride_y1, | 242 int src_stride_y0, int src_stride_y1, |
| 312 const uint8* src_uv, int src_stride_uv, | 243 const uint8* src_uv, int src_stride_uv, |
| 313 uint8* dst_y, int dst_stride_y, | 244 uint8* dst_y, int dst_stride_y, |
| 314 uint8* dst_u, int dst_stride_u, | 245 uint8* dst_u, int dst_stride_u, |
| 315 uint8* dst_v, int dst_stride_v, | 246 uint8* dst_v, int dst_stride_v, |
| 316 int width, int height) { | 247 int width, int height) { |
| 317 int halfwidth = (width + 1) >> 1; | 248 int halfwidth = (width + 1) >> 1; |
| 318 int halfheight = (height + 1) >> 1; | 249 int halfheight = (height + 1) >> 1; |
| 319 if (!src_uv || !dst_u || !dst_v || | 250 if (!src_uv || !dst_u || !dst_v || |
| 320 width <= 0 || height == 0) { | 251 width <= 0 || height == 0) { |
| 321 return -1; | 252 return -1; |
| 322 } | 253 } |
| 323 // Negative height means invert the image. | 254 // Negative height means invert the image. |
| 324 if (height < 0) { | 255 if (height < 0) { |
| 325 height = -height; | 256 height = -height; |
| 326 halfheight = (height + 1) >> 1; | 257 halfheight = (height + 1) >> 1; |
| 327 dst_y = dst_y + (height - 1) * dst_stride_y; | 258 if (dst_y) { |
| 259 dst_y = dst_y + (height - 1) * dst_stride_y; |
| 260 } |
| 328 dst_u = dst_u + (halfheight - 1) * dst_stride_u; | 261 dst_u = dst_u + (halfheight - 1) * dst_stride_u; |
| 329 dst_v = dst_v + (halfheight - 1) * dst_stride_v; | 262 dst_v = dst_v + (halfheight - 1) * dst_stride_v; |
| 330 dst_stride_y = -dst_stride_y; | 263 dst_stride_y = -dst_stride_y; |
| 331 dst_stride_u = -dst_stride_u; | 264 dst_stride_u = -dst_stride_u; |
| 332 dst_stride_v = -dst_stride_v; | 265 dst_stride_v = -dst_stride_v; |
| 333 } | 266 } |
| 334 // Coalesce rows. | 267 // Coalesce rows. |
| 335 if (src_stride_y0 == width && | 268 if (src_stride_y0 == width && |
| 336 src_stride_y1 == width && | 269 src_stride_y1 == width && |
| 337 dst_stride_y == width) { | 270 dst_stride_y == width) { |
| (...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 dst_u += dst_stride_u; | 1418 dst_u += dst_stride_u; |
| 1486 dst_v += dst_stride_v; | 1419 dst_v += dst_stride_v; |
| 1487 } | 1420 } |
| 1488 return 0; | 1421 return 0; |
| 1489 } | 1422 } |
| 1490 | 1423 |
| 1491 #ifdef __cplusplus | 1424 #ifdef __cplusplus |
| 1492 } // extern "C" | 1425 } // extern "C" |
| 1493 } // namespace libyuv | 1426 } // namespace libyuv |
| 1494 #endif | 1427 #endif |
| OLD | NEW |