| 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 21 matching lines...) Expand all Loading... |
| 32 uint8* v, int v_stride, | 32 uint8* v, int v_stride, |
| 33 int crop_x, int crop_y, | 33 int crop_x, int crop_y, |
| 34 int src_width, int src_height, | 34 int src_width, int src_height, |
| 35 int crop_width, int crop_height, | 35 int crop_width, int crop_height, |
| 36 enum RotationMode rotation, | 36 enum RotationMode rotation, |
| 37 uint32 fourcc) { | 37 uint32 fourcc) { |
| 38 uint32 format = CanonicalFourCC(fourcc); | 38 uint32 format = CanonicalFourCC(fourcc); |
| 39 int aligned_src_width = (src_width + 1) & ~1; | 39 int aligned_src_width = (src_width + 1) & ~1; |
| 40 const uint8* src; | 40 const uint8* src; |
| 41 const uint8* src_uv; | 41 const uint8* src_uv; |
| 42 int abs_src_height = (src_height < 0) ? -src_height : src_height; | 42 const int abs_src_height = (src_height < 0) ? -src_height : src_height; |
| 43 int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height; | 43 // TODO(nisse): Why allow crop_height < 0? |
| 44 const int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; |
| 44 int r = 0; | 45 int r = 0; |
| 45 LIBYUV_BOOL need_buf = (rotation && format != FOURCC_I420 && | 46 LIBYUV_BOOL need_buf = (rotation && format != FOURCC_I420 && |
| 46 format != FOURCC_NV12 && format != FOURCC_NV21 && | 47 format != FOURCC_NV12 && format != FOURCC_NV21 && |
| 47 format != FOURCC_YU12 && format != FOURCC_YV12) || y == sample; | 48 format != FOURCC_YV12) || y == sample; |
| 48 uint8* tmp_y = y; | 49 uint8* tmp_y = y; |
| 49 uint8* tmp_u = u; | 50 uint8* tmp_u = u; |
| 50 uint8* tmp_v = v; | 51 uint8* tmp_v = v; |
| 51 int tmp_y_stride = y_stride; | 52 int tmp_y_stride = y_stride; |
| 52 int tmp_u_stride = u_stride; | 53 int tmp_u_stride = u_stride; |
| 53 int tmp_v_stride = v_stride; | 54 int tmp_v_stride = v_stride; |
| 54 uint8* rotate_buffer = NULL; | 55 uint8* rotate_buffer = NULL; |
| 55 int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; | 56 const int inv_crop_height = |
| 57 (src_height < 0) ? -abs_crop_height : abs_crop_height; |
| 56 | 58 |
| 57 if (!y || !u || !v || !sample || | 59 if (!y || !u || !v || !sample || |
| 58 src_width <= 0 || crop_width <= 0 || | 60 src_width <= 0 || crop_width <= 0 || |
| 59 src_height == 0 || crop_height == 0) { | 61 src_height == 0 || crop_height == 0) { |
| 60 return -1; | 62 return -1; |
| 61 } | 63 } |
| 62 if (src_height < 0) { | |
| 63 inv_crop_height = -inv_crop_height; | |
| 64 } | |
| 65 | 64 |
| 66 // One pass rotation is available for some formats. For the rest, convert | 65 // One pass rotation is available for some formats. For the rest, convert |
| 67 // to I420 (with optional vertical flipping) into a temporary I420 buffer, | 66 // to I420 (with optional vertical flipping) into a temporary I420 buffer, |
| 68 // and then rotate the I420 to the final destination buffer. | 67 // and then rotate the I420 to the final destination buffer. |
| 69 // For in-place conversion, if destination y is same as source sample, | 68 // For in-place conversion, if destination y is same as source sample, |
| 70 // also enable temporary buffer. | 69 // also enable temporary buffer. |
| 71 if (need_buf) { | 70 if (need_buf) { |
| 72 int y_size = crop_width * abs_crop_height; | 71 int y_size = crop_width * abs_crop_height; |
| 73 int uv_size = ((crop_width + 1) / 2) * ((abs_crop_height + 1) / 2); | 72 int uv_size = ((crop_width + 1) / 2) * ((abs_crop_height + 1) / 2); |
| 74 rotate_buffer = (uint8*)malloc(y_size + uv_size * 2); | 73 rotate_buffer = (uint8*)malloc(y_size + uv_size * 2); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 case FOURCC_M420: | 206 case FOURCC_M420: |
| 208 src = sample + (src_width * crop_y) * 12 / 8 + crop_x; | 207 src = sample + (src_width * crop_y) * 12 / 8 + crop_x; |
| 209 r = M420ToI420(src, src_width, | 208 r = M420ToI420(src, src_width, |
| 210 y, y_stride, | 209 y, y_stride, |
| 211 u, u_stride, | 210 u, u_stride, |
| 212 v, v_stride, | 211 v, v_stride, |
| 213 crop_width, inv_crop_height); | 212 crop_width, inv_crop_height); |
| 214 break; | 213 break; |
| 215 // Triplanar formats | 214 // Triplanar formats |
| 216 case FOURCC_I420: | 215 case FOURCC_I420: |
| 217 case FOURCC_YU12: | |
| 218 case FOURCC_YV12: { | 216 case FOURCC_YV12: { |
| 219 const uint8* src_y = sample + (src_width * crop_y + crop_x); | 217 const uint8* src_y = sample + (src_width * crop_y + crop_x); |
| 220 const uint8* src_u; | 218 const uint8* src_u; |
| 221 const uint8* src_v; | 219 const uint8* src_v; |
| 222 int halfwidth = (src_width + 1) / 2; | 220 int halfwidth = (src_width + 1) / 2; |
| 223 int halfheight = (abs_src_height + 1) / 2; | 221 int halfheight = (abs_src_height + 1) / 2; |
| 224 if (format == FOURCC_YV12) { | 222 if (format == FOURCC_YV12) { |
| 225 src_v = sample + src_width * abs_src_height + | 223 src_v = sample + src_width * abs_src_height + |
| 226 (halfwidth * crop_y + crop_x) / 2; | 224 (halfwidth * crop_y + crop_x) / 2; |
| 227 src_u = sample + src_width * abs_src_height + | 225 src_u = sample + src_width * abs_src_height + |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 free(rotate_buffer); | 328 free(rotate_buffer); |
| 331 } | 329 } |
| 332 | 330 |
| 333 return r; | 331 return r; |
| 334 } | 332 } |
| 335 | 333 |
| 336 #ifdef __cplusplus | 334 #ifdef __cplusplus |
| 337 } // extern "C" | 335 } // extern "C" |
| 338 } // namespace libyuv | 336 } // namespace libyuv |
| 339 #endif | 337 #endif |
| OLD | NEW |