缩放像素缓冲区

时间:2015-08-04 17:01:37

标签: c++ vector copy zoom yuv

我有一组包含图像的Y / U / V分量的矢量。我想基于整数缩放倍数来缩放这些向量。我可以想到一个明显的解决方案,就是这样:

void zoomBuffer(std::vector<unsigned char>& zoomedBuffer, std::vector<unsigned char>& srcBuffer, const unsigned int width, const unsigned height, const unsigned int zoom)
{
    zoomedBuffer.reserve(width * zoom * height * zoom);
    for (unsigned int y = 0; y < height; ++y)
    {
        unsigned int yBufferOffset = y * width;
        unsigned int zoomYBufferOffset = y * width * zoom * zoom;
        for (unsigned int x = 0; x < width; ++x)
        {
            unsigned int offset = yBufferOffset + x;
            unsigned int zoomOffset = yBufferOffset + x * zoom;
            for (unsigned int xCopy = 0; xCopy < zoom; ++xCopy)
            {
                zoomedBuffer.push_back(srcBuffer[offset]);
            }
        }
        for (unsigned int yCopy = 1; yCopy < zoom; ++yCopy)
        {
            std::copy_n(zoomedBuffer.begin() + zoomYBufferOffset, zoom * width, std::back_inserter(zoomedBuffer));
        }
    }
}

然后这样称呼它:

zoomBuffer(zoomedY, refBlock.m_yData, refBlock.m_YWidth, refBlock.m_YHeight, 2);
zoomBuffer(zoomedU, refBlock.m_yData, refBlock.m_UWidth, refBlock.m_UHeight, 2);
zoomBuffer(zoomedV, refBlock.m_yData, refBlock.m_VWidth, refBlock.m_VHeight, 2);

这应该有用,但我想知道是否有更高效/更快的方法来做到这一点?感觉很笨重。

0 个答案:

没有答案