我需要使用PNG ++来执行相机缓冲区图像(原始单声道8数据)的优化转换为png压缩少文件的帮助。以下的作品,但它太慢了。我将在ARM中执行它。我需要一个非常快速的过程。将原始单声道8数据转换为PNG时加速PNG ++
sprintf(mBuffer, "%lu.png", pFrame->FrameCount);
try
{
//Take the image from my camera buffer and put it into vector i can
//work with
images = (const unsigned char*)pFrame->ImageBuffer;
//create the png profile to be used
png::image<png::gray_pixel> image(1024,1024);
//Take every byte from the vector and put in the determined position on
//the image matrix
for(int i=0;i<1024;i++)
{
for(int j=0;j<1024;j++)
{
png::gray_pixel pix = images[i*1024+j];
image[i][j] = pix;
}
}
image.write(mBuffer);
}
catch (std::exception const& error)
{
std::cerr << "Teste: " << error.what() << std::endl;
}
我不熟悉PNG :: gray_pixel,但我想你可能只是逐字节复制内存,并且如果可能的话,最好是以CPU数据总线的宽度(即64位或32位而不是8位块)的块来进行,所以我想使用memcpy()并有效地移动16个64位数字而不是1024个8位数字。看看这里http://www.embedded.com/design/configurable-systems/4024961/Optimizing-Memcpy-improves-speed –
建议,使用memcpy而不是自己复制。也改善了这个问题。目前尚不清楚你尝试过什么。 – auselen
“png压缩少文件”==一个不太多的压缩文件?这可能(甚至可能)您的库自动处理压缩。检查是否有影响其参数的功能 - 当然应该在“快速”和“良好”之间进行选择。另一种选择可能是自己处理整个PNG创建的东西,从而消除*所有*库开销。创建“有史以来最糟糕的压缩”zlib数据是向原始的,否则未压缩的数据流中注入几个字节的情况。您可能需要测试哪些更好:压缩内存或创建更大的文件并写入。 – usr2564301