MCPcopy Create free account
hub / github.com/alibaba/MNN / MNNSamplerI420Nearest

Function MNNSamplerI420Nearest

source/backend/cpu/compute/ImageProcessFunction.cpp:879–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

877 }
878}
879void 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;
882
883 auto dstY = dest + sta;
884 auto dstUV = dest + (capacity) + (sta / 2) * 2;
885 auto stride = yStride;
886 if (yStride == 0) {
887 stride = iw;
888 }
889 auto srcU = source + stride * ih;
890 MNNSamplerC1Nearest(srcY, dstY, points, 0, count, capacity, iw, ih, stride);
891
892 MNN::CV::Point uvPoints[2];
893 uvPoints[0].fX = (points[0].fX - 0.01f) / 2.0f;
894 uvPoints[0].fY = (points[0].fY - 0.01f) / 2.0f;
895 uvPoints[1].fX = points[1].fX / 2.0f;
896 uvPoints[1].fY = points[1].fY / 2.0f;
897 if (yStride == 0) {
898 stride = ((iw + 1) / 2);
899 }
900 auto srcV = srcU + stride * ((ih + 1) / 2);
901 auto uvCount = (count + 1) / 2;
902 {
903 MNN::CV::Point curPoints;
904 curPoints.fX = uvPoints[0].fX;
905 curPoints.fY = uvPoints[0].fY;
906 float dy = uvPoints[1].fY;
907 float dx = uvPoints[1].fX;
908 float xMax = ((iw + 1) / 2) - 1;
909 float yMax = ((ih + 1) / 2) - 1;
910
911 for (int i = 0; i < uvCount; ++i) {
912 int y = (int)roundf(__clamp(curPoints.fY, 0, yMax));
913 int x = (int)roundf(__clamp(curPoints.fX, 0, xMax));
914 curPoints.fY += dy;
915 curPoints.fX += dx;
916 auto offset = y * stride + x;
917 dstUV[2 * i + 0] = srcV[offset];
918 dstUV[2 * i + 1] = srcU[offset];
919 }
920 }
921}
922
923void MNNSamplerNV21Copy(const unsigned char* source, unsigned char* dest, MNN::CV::Point* points, size_t sta,
924 size_t count, size_t capacity, size_t iw, size_t ih, size_t yStride) {

Callers

nothing calls this directly

Calls 2

MNNSamplerC1NearestFunction · 0.85
__clampFunction · 0.70

Tested by

no test coverage detected