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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 uint32 fourcc) { | 43 uint32 fourcc) { |
44 uint32 format = CanonicalFourCC(fourcc); | 44 uint32 format = CanonicalFourCC(fourcc); |
45 int aligned_src_width = (src_width + 1) & ~1; | 45 int aligned_src_width = (src_width + 1) & ~1; |
46 const uint8* src; | 46 const uint8* src; |
47 const uint8* src_uv; | 47 const uint8* src_uv; |
48 int abs_src_height = (src_height < 0) ? -src_height : src_height; | 48 int abs_src_height = (src_height < 0) ? -src_height : src_height; |
49 int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height; | 49 int inv_crop_height = (crop_height < 0) ? -crop_height : crop_height; |
50 int r = 0; | 50 int r = 0; |
51 | 51 |
52 // One pass rotation is available for some formats. For the rest, convert | 52 // One pass rotation is available for some formats. For the rest, convert |
53 // to I420 (with optional vertical flipping) into a temporary I420 buffer, | 53 // to ARGB (with optional vertical flipping) into a temporary ARGB buffer, |
54 // and then rotate the I420 to the final destination buffer. | 54 // and then rotate the ARGB to the final destination buffer. |
55 // For in-place conversion, if destination crop_argb is same as source sample, | 55 // For in-place conversion, if destination crop_argb is same as source sample, |
56 // also enable temporary buffer. | 56 // also enable temporary buffer. |
57 LIBYUV_BOOL need_buf = | 57 LIBYUV_BOOL need_buf = |
58 (rotation && format != FOURCC_ARGB) || crop_argb == sample; | 58 (rotation && format != FOURCC_ARGB) || crop_argb == sample; |
59 uint8* dest_argb = crop_argb; | 59 uint8* dest_argb = crop_argb; |
60 int dest_argb_stride = argb_stride; | 60 int dest_argb_stride = argb_stride; |
61 uint8* rotate_buffer = NULL; | 61 uint8* rotate_buffer = NULL; |
62 int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; | 62 int abs_crop_height = (crop_height < 0) ? -crop_height : crop_height; |
63 | 63 |
64 if (crop_argb == NULL || sample == NULL || src_width <= 0 || | 64 if (crop_argb == NULL || sample == NULL || src_width <= 0 || |
(...skipping 30 matching lines...) Expand all Loading... | |
95 src = sample + (src_width * crop_y + crop_x) * 3; | 95 src = sample + (src_width * crop_y + crop_x) * 3; |
96 r = RGB24ToARGB(src, src_width * 3, crop_argb, argb_stride, crop_width, | 96 r = RGB24ToARGB(src, src_width * 3, crop_argb, argb_stride, crop_width, |
97 inv_crop_height); | 97 inv_crop_height); |
98 break; | 98 break; |
99 case FOURCC_RAW: | 99 case FOURCC_RAW: |
100 src = sample + (src_width * crop_y + crop_x) * 3; | 100 src = sample + (src_width * crop_y + crop_x) * 3; |
101 r = RAWToARGB(src, src_width * 3, crop_argb, argb_stride, crop_width, | 101 r = RAWToARGB(src, src_width * 3, crop_argb, argb_stride, crop_width, |
102 inv_crop_height); | 102 inv_crop_height); |
103 break; | 103 break; |
104 case FOURCC_ARGB: | 104 case FOURCC_ARGB: |
105 src = sample + (src_width * crop_y + crop_x) * 4; | 105 if (!need_buf && !rotation) { |
fbarchard1
2017/01/11 19:42:16
FYI for I420 version the rotation is done here for
| |
106 r = ARGBToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width, | 106 src = sample + (src_width * crop_y + crop_x) * 4; |
107 inv_crop_height); | 107 r = ARGBToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width, |
108 inv_crop_height); | |
109 } | |
108 break; | 110 break; |
109 case FOURCC_BGRA: | 111 case FOURCC_BGRA: |
110 src = sample + (src_width * crop_y + crop_x) * 4; | 112 src = sample + (src_width * crop_y + crop_x) * 4; |
111 r = BGRAToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width, | 113 r = BGRAToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width, |
112 inv_crop_height); | 114 inv_crop_height); |
113 break; | 115 break; |
114 case FOURCC_ABGR: | 116 case FOURCC_ABGR: |
115 src = sample + (src_width * crop_y + crop_x) * 4; | 117 src = sample + (src_width * crop_y + crop_x) * 4; |
116 r = ABGRToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width, | 118 r = ABGRToARGB(src, src_width * 4, crop_argb, argb_stride, crop_width, |
117 inv_crop_height); | 119 inv_crop_height); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 default: | 248 default: |
247 r = -1; // unknown fourcc - return failure code. | 249 r = -1; // unknown fourcc - return failure code. |
248 } | 250 } |
249 | 251 |
250 if (need_buf) { | 252 if (need_buf) { |
251 if (!r) { | 253 if (!r) { |
252 r = ARGBRotate(crop_argb, argb_stride, dest_argb, dest_argb_stride, | 254 r = ARGBRotate(crop_argb, argb_stride, dest_argb, dest_argb_stride, |
253 crop_width, abs_crop_height, rotation); | 255 crop_width, abs_crop_height, rotation); |
254 } | 256 } |
255 free(rotate_buffer); | 257 free(rotate_buffer); |
258 } else if (rotation) { | |
259 src = sample + (src_width * crop_y + crop_x) * 4; | |
260 r = ARGBRotate(src, src_width * 4, | |
261 crop_argb, argb_stride, | |
262 crop_width, inv_crop_height, rotation); | |
256 } | 263 } |
257 | 264 |
258 return r; | 265 return r; |
259 } | 266 } |
260 | 267 |
261 #ifdef __cplusplus | 268 #ifdef __cplusplus |
262 } // extern "C" | 269 } // extern "C" |
263 } // namespace libyuv | 270 } // namespace libyuv |
264 #endif | 271 #endif |
OLD | NEW |