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

Method run

test/speed/ImageProcessSpeedTest.cpp:716–791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

714public:
715 virtual ~ImageProcessSpeedNV12ToRGBTest() = default;
716 virtual bool run(int precision) {
717 ImageProcess::Config config;
718 config.sourceFormat = YUV_NV12;
719 config.destFormat = RGB;
720 config.filterType = NEAREST;
721 config.wrap = CLAMP_TO_EDGE;
722 std::shared_ptr<ImageProcess> process(ImageProcess::create(config));
723
724 int sw = 1920;
725 int sh = 1080;
726 Matrix tr;
727 process->setMatrix(tr);
728 std::shared_ptr<unsigned char> nv12(new unsigned char[sw * sh + (sw / 2) * (sh / 2) * 2]);
729 auto pixels = nv12.get();
730 for (int y = 0; y < sh; ++y) {
731 auto pixelY = pixels + sw * y;
732 auto pixelUV = pixels + sw * sh + (y / 2) * sw;
733 int magicY = ((sh - y) * (sh - y)) % 79;
734 for (int x = 0; x < sw; ++x) {
735 auto pixelX = pixelY + x;
736 int magicX = (x * x) % 113;
737 int magic = (magicX + magicY) % 255;
738 pixelX[0] = magic;
739 }
740 for (int x = 0; x < sw / 2; ++x) {
741 auto pixelX = pixelUV + 2 * x;
742 int magicX = ((((x % 283) * (x % 283)) % 283) * (((x % 283) * (x % 283)) % 283)) % 283;
743 int magic0 = (magicX + magicY) % 255;
744 int magic1 = (magicX + magicY * 179) % 255;
745 pixelX[0] = magic0;
746 pixelX[1] = magic1;
747 }
748 }
749
750 std::shared_ptr<Tensor> tensor(
751 Tensor::create<uint8_t>(std::vector<int>{1, sh, sw, 3}, nullptr, Tensor::TENSORFLOW));
752 process->convert(nv12.get(), sw, sh, 0, tensor.get());
753 for (int y = 0; y < sh; ++y) {
754 auto dstY = tensor->host<uint8_t>() + 3 * y * sw;
755 auto srcY_Y = nv12.get() + y * sw;
756 auto srcY_UV = nv12.get() + (y / 2) * (sw / 2) * 2 + sw * sh;
757 for (int x = 0; x < sw; ++x) {
758 auto dstX = dstY + 3 * x;
759 auto srcX_Y = srcY_Y + x;
760 auto srcX_UV = srcY_UV + (x / 2) * 2;
761 int Y = srcX_Y[0];
762 int U = (int)srcX_UV[0] - 128;
763 int V = (int)srcX_UV[1] - 128;
764
765 Y = Y << 6;
766 int r = (Y + 73 * V) >> 6;
767 int g = (Y - 25 * U - 37 * V) >> 6;
768 int b = (Y + 130 * U) >> 6;
769
770 r = r < 0 ? 0 : r;
771 r = r > 255 ? 255 : r;
772 g = g < 0 ? 0 : g;
773 g = g > 255 ? 255 : g;

Callers

nothing calls this directly

Calls 6

diffFunction · 0.85
createFunction · 0.50
absFunction · 0.50
setMatrixMethod · 0.45
getMethod · 0.45
convertMethod · 0.45

Tested by

no test coverage detected