| 856 | } |
| 857 | |
| 858 | void MNNSamplerI420Copy(const unsigned char* source, unsigned char* dest, MNN::CV::Point* points, size_t sta, |
| 859 | size_t count, size_t capacity, size_t iw, size_t ih, size_t yStride) { |
| 860 | MNN::CV::Point curPoints; |
| 861 | curPoints.fX = points[0].fX; |
| 862 | curPoints.fY = points[0].fY; |
| 863 | float xMax = iw - 1; |
| 864 | float yMax = ih - 1; |
| 865 | int y = (int)roundf(__clamp(curPoints.fY, 0, yMax)); |
| 866 | int x = (int)roundf(__clamp(curPoints.fX, 0, xMax)); |
| 867 | auto uvPlane = (((int)iw + 1) / 2) * ((int(ih) + 1) / 2); |
| 868 | int sourcePosY = y * (int)iw + x; |
| 869 | auto sourcePosU = source + (int)iw * (int)ih + (y / 2) * (((int)iw + 1) / 2) + (x / 2); |
| 870 | auto sourcePosV = source + (int)iw * (int)ih + (y / 2) * (((int)iw + 1) / 2) + (x / 2) + uvPlane; |
| 871 | auto uvCount = (count + 1) / 2; |
| 872 | ::memcpy(dest + sta, source + sourcePosY, count); |
| 873 | auto uDest = dest + (capacity) + (sta / 2) * 2; |
| 874 | for (int i=0; i<uvCount; ++i) { |
| 875 | uDest[2 * i + 0] = sourcePosV[i]; |
| 876 | uDest[2 * i + 1] = sourcePosU[i]; |
| 877 | } |
| 878 | } |
| 879 | void MNNSamplerI420Nearest(const unsigned char* source, unsigned char* dest, MNN::CV::Point* points, size_t sta, |
| 880 | size_t count, size_t capacity, size_t iw, size_t ih, size_t yStride) { |
| 881 | auto srcY = source; |