| 632 | public: |
| 633 | virtual ~ImageProcessSpeedNV21ToRGBTest() = default; |
| 634 | virtual bool run(int precision) { |
| 635 | ImageProcess::Config config; |
| 636 | config.sourceFormat = YUV_NV21; |
| 637 | config.destFormat = RGB; |
| 638 | config.filterType = NEAREST; |
| 639 | config.wrap = CLAMP_TO_EDGE; |
| 640 | std::shared_ptr<ImageProcess> process(ImageProcess::create(config)); |
| 641 | |
| 642 | int sw = 1920; |
| 643 | int sh = 1080; |
| 644 | Matrix tr; |
| 645 | process->setMatrix(tr); |
| 646 | std::shared_ptr<unsigned char> nv12(new unsigned char[sw * sh + (sw / 2) * (sh / 2) * 2]); |
| 647 | auto pixels = nv12.get(); |
| 648 | for (int y = 0; y < sh; ++y) { |
| 649 | auto pixelY = pixels + sw * y; |
| 650 | auto pixelUV = pixels + sw * sh + (y / 2) * sw; |
| 651 | int magicY = ((sh - y) * (sh - y)) % 79; |
| 652 | for (int x = 0; x < sw; ++x) { |
| 653 | auto pixelX = pixelY + x; |
| 654 | int magicX = (x * x) % 113; |
| 655 | int magic = (magicX + magicY) % 255; |
| 656 | pixelX[0] = magic; |
| 657 | } |
| 658 | for (int x = 0; x < sw / 2; ++x) { |
| 659 | auto pixelX = pixelUV + 2 * x; |
| 660 | int magicX = ((((x % 283) * (x % 283)) % 283) * (((x % 283) * (x % 283)) % 283)) % 283; |
| 661 | int magic0 = (magicX + magicY) % 255; |
| 662 | int magic1 = (magicX + magicY * 179) % 255; |
| 663 | pixelX[0] = magic0; |
| 664 | pixelX[1] = magic1; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | std::shared_ptr<Tensor> tensor( |
| 669 | Tensor::create<uint8_t>(std::vector<int>{1, sh, sw, 3}, nullptr, Tensor::TENSORFLOW)); |
| 670 | process->convert(nv12.get(), sw, sh, 0, tensor.get()); |
| 671 | for (int y = 0; y < sh; ++y) { |
| 672 | auto dstY = tensor->host<uint8_t>() + 3 * y * sw; |
| 673 | auto srcY_Y = nv12.get() + y * sw; |
| 674 | auto srcY_UV = nv12.get() + (y / 2) * (sw / 2) * 2 + sw * sh; |
| 675 | for (int x = 0; x < sw; ++x) { |
| 676 | auto dstX = dstY + 3 * x; |
| 677 | auto srcX_Y = srcY_Y + x; |
| 678 | auto srcX_UV = srcY_UV + (x / 2) * 2; |
| 679 | int Y = srcX_Y[0]; |
| 680 | int U = (int)srcX_UV[1] - 128; |
| 681 | int V = (int)srcX_UV[0] - 128; |
| 682 | |
| 683 | Y = Y << 6; |
| 684 | int r = (Y + 73 * V) >> 6; |
| 685 | int g = (Y - 25 * U - 37 * V) >> 6; |
| 686 | int b = (Y + 130 * U) >> 6; |
| 687 | |
| 688 | r = r < 0 ? 0 : r; |
| 689 | r = r > 255 ? 255 : r; |
| 690 | g = g < 0 ? 0 : g; |
| 691 | g = g > 255 ? 255 : g; |