OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 sum += a[k * 4 + j] * b[i * 4 + k]; | 68 sum += a[k * 4 + j] * b[i * 4 + k]; |
69 } | 69 } |
70 result[i * 4 + j] = sum; | 70 result[i * 4 + j] = sum; |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 // Center crop by keeping xFraction of the width and yFraction of the height, | 75 // Center crop by keeping xFraction of the width and yFraction of the height, |
76 // so e.g. cropping from 640x480 to 640x360 would use | 76 // so e.g. cropping from 640x480 to 640x360 would use |
77 // xFraction=1, yFraction=360/480. | 77 // xFraction=1, yFraction=360/480. |
78 void CropMatrix(float a[16], float xFraction, float yFraction) { | 78 void CropMatrix(float a[16], |
79 // Move cropped area to the center of the frame by offsetting half the | 79 float xFraction, |
80 // removed area. | 80 float yFraction, |
81 const float xOffset = (1 - xFraction) / 2; | 81 float xOffset, |
82 const float yOffset = (1 - yFraction) / 2; | 82 float yOffset) { |
83 const float crop_matrix[16] = { | 83 const float crop_matrix[16] = { |
84 xFraction, 0, 0, 0, | 84 xFraction, 0, 0, 0, |
85 0, yFraction, 0, 0, | 85 0, yFraction, 0, 0, |
86 0, 0, 1, 0, | 86 0, 0, 1, 0, |
87 xOffset, yOffset, 0, 1}; | 87 xOffset, yOffset, 0, 1}; |
88 float mul_result[16]; | 88 float mul_result[16]; |
89 MultiplyMatrix(crop_matrix, a, mul_result); | 89 MultiplyMatrix(crop_matrix, a, mul_result); |
90 memcpy(a, mul_result, sizeof(mul_result)); | 90 memcpy(a, mul_result, sizeof(mul_result)); |
91 } | 91 } |
92 | 92 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 byte_buffer, width(), height(), stride, | 172 byte_buffer, width(), height(), stride, |
173 native_handle_.oes_texture_id, sampling_matrix); | 173 native_handle_.oes_texture_id, sampling_matrix); |
174 CHECK_EXCEPTION(jni) << "textureToYUV throwed an exception"; | 174 CHECK_EXCEPTION(jni) << "textureToYUV throwed an exception"; |
175 | 175 |
176 return copy; | 176 return copy; |
177 } | 177 } |
178 | 178 |
179 rtc::scoped_refptr<AndroidTextureBuffer> | 179 rtc::scoped_refptr<AndroidTextureBuffer> |
180 AndroidTextureBuffer::CropScaleAndRotate(int cropped_width, | 180 AndroidTextureBuffer::CropScaleAndRotate(int cropped_width, |
181 int cropped_height, | 181 int cropped_height, |
| 182 int crop_x, |
| 183 int crop_y, |
182 int dst_width, | 184 int dst_width, |
183 int dst_height, | 185 int dst_height, |
184 webrtc::VideoRotation rotation) { | 186 webrtc::VideoRotation rotation) { |
185 if (cropped_width == dst_width && cropped_height == dst_height && | 187 if (cropped_width == dst_width && cropped_height == dst_height && |
186 width() == dst_width && height() == dst_height && | 188 width() == dst_width && height() == dst_height && |
187 rotation == webrtc::kVideoRotation_0) { | 189 rotation == webrtc::kVideoRotation_0) { |
188 return this; | 190 return this; |
189 } | 191 } |
190 int rotated_width = (rotation % 180 == 0) ? dst_width : dst_height; | 192 int rotated_width = (rotation % 180 == 0) ? dst_width : dst_height; |
191 int rotated_height = (rotation % 180 == 0) ? dst_height : dst_width; | 193 int rotated_height = (rotation % 180 == 0) ? dst_height : dst_width; |
192 | 194 |
193 // Here we use Bind magic to add a reference count to |this| until the newly | 195 // Here we use Bind magic to add a reference count to |this| until the newly |
194 // created AndroidTextureBuffer is destructed | 196 // created AndroidTextureBuffer is destructed |
195 rtc::scoped_refptr<AndroidTextureBuffer> buffer( | 197 rtc::scoped_refptr<AndroidTextureBuffer> buffer( |
196 new rtc::RefCountedObject<AndroidTextureBuffer>( | 198 new rtc::RefCountedObject<AndroidTextureBuffer>( |
197 rotated_width, rotated_height, native_handle_, | 199 rotated_width, rotated_height, native_handle_, |
198 surface_texture_helper_, rtc::KeepRefUntilDone(this))); | 200 surface_texture_helper_, rtc::KeepRefUntilDone(this))); |
199 | 201 |
200 if (cropped_width != width() || cropped_height != height()) { | 202 if (cropped_width != width() || cropped_height != height()) { |
201 CropMatrix(buffer->native_handle_.sampling_matrix, | 203 CropMatrix(buffer->native_handle_.sampling_matrix, |
202 cropped_width / static_cast<float>(width()), | 204 cropped_width / static_cast<float>(width()), |
203 cropped_height / static_cast<float>(height())); | 205 cropped_height / static_cast<float>(height()), |
| 206 crop_x / static_cast<float>(width()), |
| 207 crop_y / static_cast<float>(height())); |
204 } | 208 } |
205 RotateMatrix(buffer->native_handle_.sampling_matrix, rotation); | 209 RotateMatrix(buffer->native_handle_.sampling_matrix, rotation); |
206 return buffer; | 210 return buffer; |
207 } | 211 } |
208 | 212 |
209 } // namespace webrtc_jni | 213 } // namespace webrtc_jni |
OLD | NEW |