Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 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_y_width == 0 || src_y_height == 0 || |
| 44 src_uv_width == 0 || src_uv_height == 0) { | 44 src_uv_width == 0 || src_uv_height == 0) { |
| 45 return -1; | 45 return -1; |
| 46 } | 46 } |
| 47 // TODO(fbarchard): make Y optional. | 47 // TODO(fbarchard): support NULL for dst_y |
|
fbarchard1
2016/08/24 22:34:16
check dst_y is not null.
| |
| 48 ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, | 48 ScalePlane(src_y, src_stride_y, src_y_width, src_y_height, |
| 49 dst_y, dst_stride_y, dst_y_width, dst_y_height, | 49 dst_y, dst_stride_y, dst_y_width, dst_y_height, |
| 50 kFilterBilinear); | 50 kFilterBilinear); |
| 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 |
| 61 // TODO(fbarchard): Use Scale plane which supports mirroring, but ensure | 61 // TODO(fbarchard): Use Scale plane which supports mirroring, but ensure |
| 62 // is does row coalescing. | 62 // is does row coalescing. |
| 63 LIBYUV_API | 63 LIBYUV_API |
| 64 int I420Copy(const uint8* src_y, int src_stride_y, | 64 int I420Copy(const uint8* src_y, int src_stride_y, |
| 65 const uint8* src_u, int src_stride_u, | 65 const uint8* src_u, int src_stride_u, |
| 66 const uint8* src_v, int src_stride_v, | 66 const uint8* src_v, int src_stride_v, |
| 67 uint8* dst_y, int dst_stride_y, | 67 uint8* dst_y, int dst_stride_y, |
| 68 uint8* dst_u, int dst_stride_u, | 68 uint8* dst_u, int dst_stride_u, |
| 69 uint8* dst_v, int dst_stride_v, | 69 uint8* dst_v, int dst_stride_v, |
| 70 int width, int height) { | 70 int width, int height) { |
| 71 int halfwidth = (width + 1) >> 1; | 71 int halfwidth = (width + 1) >> 1; |
| 72 int halfheight = (height + 1) >> 1; | 72 int halfheight = (height + 1) >> 1; |
| 73 if (!src_y || !src_u || !src_v || | 73 if (!src_u || !src_v || |
| 74 !dst_y || !dst_u || !dst_v || | 74 !dst_u || !dst_v || |
| 75 width <= 0 || height == 0) { | 75 width <= 0 || height == 0) { |
| 76 return -1; | 76 return -1; |
| 77 } | 77 } |
| 78 // Negative height means invert the image. | 78 // Negative height means invert the image. |
| 79 if (height < 0) { | 79 if (height < 0) { |
| 80 height = -height; | 80 height = -height; |
| 81 halfheight = (height + 1) >> 1; | 81 halfheight = (height + 1) >> 1; |
| 82 src_y = src_y + (height - 1) * src_stride_y; | 82 src_y = src_y + (height - 1) * src_stride_y; |
| 83 src_u = src_u + (halfheight - 1) * src_stride_u; | 83 src_u = src_u + (halfheight - 1) * src_stride_u; |
| 84 src_v = src_v + (halfheight - 1) * src_stride_v; | 84 src_v = src_v + (halfheight - 1) * src_stride_v; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 // 420 chroma is 1/2 width, 1/2 height | 141 // 420 chroma is 1/2 width, 1/2 height |
| 142 LIBYUV_API | 142 LIBYUV_API |
| 143 int I411ToI420(const uint8* src_y, int src_stride_y, | 143 int I411ToI420(const uint8* src_y, int src_stride_y, |
| 144 const uint8* src_u, int src_stride_u, | 144 const uint8* src_u, int src_stride_u, |
| 145 const uint8* src_v, int src_stride_v, | 145 const uint8* src_v, int src_stride_v, |
| 146 uint8* dst_y, int dst_stride_y, | 146 uint8* dst_y, int dst_stride_y, |
| 147 uint8* dst_u, int dst_stride_u, | 147 uint8* dst_u, int dst_stride_u, |
| 148 uint8* dst_v, int dst_stride_v, | 148 uint8* dst_v, int dst_stride_v, |
| 149 int width, int height) { | 149 int width, int height) { |
| 150 const int src_uv_width = SUBSAMPLE(width, 3, 2); | 150 const int src_uv_width = SUBSAMPLE(width, 3, 2); |
| 151 return I4xxToI420(src_y, src_stride_y, | 151 return I4xxToI420(src_y, src_stride_y, |
|
fbarchard1
2016/08/24 22:34:16
consider CopyPlane here
| |
| 152 src_u, src_stride_u, | 152 src_u, src_stride_u, |
| 153 src_v, src_stride_v, | 153 src_v, src_stride_v, |
| 154 dst_y, dst_stride_y, | 154 dst_y, dst_stride_y, |
| 155 dst_u, dst_stride_u, | 155 dst_u, dst_stride_u, |
| 156 dst_v, dst_stride_v, | 156 dst_v, dst_stride_v, |
| 157 width, height, | 157 width, height, |
| 158 src_uv_width, height); | 158 src_uv_width, height); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // I400 is greyscale typically used in MJPG | 161 // I400 is greyscale typically used in MJPG |
| 162 LIBYUV_API | 162 LIBYUV_API |
| 163 int I400ToI420(const uint8* src_y, int src_stride_y, | 163 int I400ToI420(const uint8* src_y, int src_stride_y, |
| 164 uint8* dst_y, int dst_stride_y, | 164 uint8* dst_y, int dst_stride_y, |
| 165 uint8* dst_u, int dst_stride_u, | 165 uint8* dst_u, int dst_stride_u, |
| 166 uint8* dst_v, int dst_stride_v, | 166 uint8* dst_v, int dst_stride_v, |
| 167 int width, int height) { | 167 int width, int height) { |
| 168 int halfwidth = (width + 1) >> 1; | 168 int halfwidth = (width + 1) >> 1; |
| 169 int halfheight = (height + 1) >> 1; | 169 int halfheight = (height + 1) >> 1; |
| 170 if (!src_y || !dst_y || !dst_u || !dst_v || | 170 if (!dst_u || !dst_v || |
| 171 width <= 0 || height == 0) { | 171 width <= 0 || height == 0) { |
| 172 return -1; | 172 return -1; |
| 173 } | 173 } |
| 174 // Negative height means invert the image. | 174 // Negative height means invert the image. |
| 175 if (height < 0) { | 175 if (height < 0) { |
| 176 height = -height; | 176 height = -height; |
| 177 halfheight = (height + 1) >> 1; | 177 halfheight = (height + 1) >> 1; |
| 178 src_y = src_y + (height - 1) * src_stride_y; | 178 src_y = src_y + (height - 1) * src_stride_y; |
| 179 src_stride_y = -src_stride_y; | 179 src_stride_y = -src_stride_y; |
| 180 } | 180 } |
| 181 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); | 181 if (dst_y) { |
| 182 CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height); | |
| 183 } | |
| 182 SetPlane(dst_u, dst_stride_u, halfwidth, halfheight, 128); | 184 SetPlane(dst_u, dst_stride_u, halfwidth, halfheight, 128); |
| 183 SetPlane(dst_v, dst_stride_v, halfwidth, halfheight, 128); | 185 SetPlane(dst_v, dst_stride_v, halfwidth, halfheight, 128); |
| 184 return 0; | 186 return 0; |
| 185 } | 187 } |
| 186 | 188 |
| 187 static void CopyPlane2(const uint8* src, int src_stride_0, int src_stride_1, | 189 static void CopyPlane2(const uint8* src, int src_stride_0, int src_stride_1, |
| 188 uint8* dst, int dst_stride, | 190 uint8* dst, int dst_stride, |
| 189 int width, int height) { | 191 int width, int height) { |
| 190 int y; | 192 int y; |
| 191 void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; | 193 void (*CopyRow)(const uint8* src, uint8* dst, int width) = CopyRow_C; |
| (...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1428 const uint8* src_v, int src_stride_v, | 1430 const uint8* src_v, int src_stride_v, |
| 1429 int src_pixel_stride_uv, | 1431 int src_pixel_stride_uv, |
| 1430 uint8* dst_y, int dst_stride_y, | 1432 uint8* dst_y, int dst_stride_y, |
| 1431 uint8* dst_u, int dst_stride_u, | 1433 uint8* dst_u, int dst_stride_u, |
| 1432 uint8* dst_v, int dst_stride_v, | 1434 uint8* dst_v, int dst_stride_v, |
| 1433 int width, int height) { | 1435 int width, int height) { |
| 1434 int y; | 1436 int y; |
| 1435 const int vu_off = src_v - src_u; | 1437 const int vu_off = src_v - src_u; |
| 1436 int halfwidth = (width + 1) >> 1; | 1438 int halfwidth = (width + 1) >> 1; |
| 1437 int halfheight = (height + 1) >> 1; | 1439 int halfheight = (height + 1) >> 1; |
| 1438 if (!src_y || !src_u || !src_v || | 1440 if (!src_u || !src_v || |
| 1439 !dst_y || !dst_u || !dst_v || | 1441 !dst_u || !dst_v || |
| 1440 width <= 0 || height == 0) { | 1442 width <= 0 || height == 0) { |
| 1441 return -1; | 1443 return -1; |
| 1442 } | 1444 } |
| 1443 // Negative height means invert the image. | 1445 // Negative height means invert the image. |
| 1444 if (height < 0) { | 1446 if (height < 0) { |
| 1445 height = -height; | 1447 height = -height; |
| 1446 halfheight = (height + 1) >> 1; | 1448 halfheight = (height + 1) >> 1; |
| 1447 src_y = src_y + (height - 1) * src_stride_y; | 1449 src_y = src_y + (height - 1) * src_stride_y; |
| 1448 src_u = src_u + (halfheight - 1) * src_stride_u; | 1450 src_u = src_u + (halfheight - 1) * src_stride_u; |
| 1449 src_v = src_v + (halfheight - 1) * src_stride_v; | 1451 src_v = src_v + (halfheight - 1) * src_stride_v; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1483 dst_u += dst_stride_u; | 1485 dst_u += dst_stride_u; |
| 1484 dst_v += dst_stride_v; | 1486 dst_v += dst_stride_v; |
| 1485 } | 1487 } |
| 1486 return 0; | 1488 return 0; |
| 1487 } | 1489 } |
| 1488 | 1490 |
| 1489 #ifdef __cplusplus | 1491 #ifdef __cplusplus |
| 1490 } // extern "C" | 1492 } // extern "C" |
| 1491 } // namespace libyuv | 1493 } // namespace libyuv |
| 1492 #endif | 1494 #endif |
| OLD | NEW |