2014-04-28 35 views
0

我需要使用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; 

    } 
+0

我不熟悉PNG :: gray_pixel,但我想你可能只是逐字节复制内存,并且如果可能的话,最好是以CPU数据总线的宽度(即64位或32位而不是8位块)的块来进行,所以我想使用memcpy()并有效地移动16个64位数字而不是1024个8位数字。看看这里http://www.embedded.com/design/configurable-systems/4024961/Optimizing-Memcpy-improves-speed –

+0

建议,使用memcpy而不是自己复制。也改善了这个问题。目前尚不清楚你尝试过什么。 – auselen

+1

“png压缩少文件”==一个不太多的压缩文件?这可能(甚至可能)您的库自动处理压缩。检查是否有影响其参数的功能 - 当然应该在“快速”和“良好”之间进行选择。另一种选择可能是自己处理整个PNG创建的东西,从而消除*所有*库开销。创建“有史以来最糟糕的压缩”zlib数据是向原始的,否则未压缩的数据流中注入几个字节的情况。您可能需要测试哪些更好:压缩内存或创建更大的文件并写入。 – usr2564301

回答

0

这可能会或可能不会帮助 - 它只是一个建议。如果帧缓冲区是8位无符号像素的顺序加载,则与文件号为here的P5类型的NetPBM Portable Greymap(PGM)完全相同。这可以非常快速地编写,可以在网页中直接使用,或者可以使用ImageMagick(here)很容易地转换成png这样的:

convert image.pgm image.png 

然后你的形象的写作可能是简单的像这样:

#include <stdio.h> 
#include <stdlib.h> 

#define HEIGHT 100 
#define WIDTH 256 

int main(){ 

    FILE *imageFile; 
    uint8_t image[HEIGHT][WIDTH]; 
    int x,y,pixel; 

    /* Create a greyscale ramp - you don't need this, you would use your framebuffer */ 
    for(x=0;x<HEIGHT;x++){ 
     for(y=0;y<WIDTH;y++){ 
     image[x][y]=y; 
     } 
    } 

    /* Now write to a file */ 
    imageFile=fopen("image.pgm","wb"); 
    if(imageFile==NULL){ 
     perror("ERROR: Cannot open output file"); 
     exit(EXIT_FAILURE); 
    } 

    /* You could coalesce the next 3 lines into a single fprintf() if you wanted */ 
    fprintf(imageFile,"P5\n");   // P5 filetype 
    fprintf(imageFile,"%d %d\n",WIDTH,HEIGHT); // dimensions 
    fprintf(imageFile,"255\n");   // Max pixel 

    fwrite(image,HEIGHT,WIDTH,imageFile); 

    fclose(imageFile); 
} 

根据您实际想要对图像执行什么操作,您可以在完成高速采集运行时批量转换它们,或者稍后在后台将其转换,或者在其他位置完全转换为其他位置。

在我的例子,我创建的形象,但是你已经有你的帧缓冲,让您的图像文字会变成:

imageFile=fopen("image.pgm","wb"); 
fprintf(imageFile,"P5\n%d %d\n255\n",WIDTH,HEIGHT); 
fwrite(images,HEIGHT,WIDTH,imageFile); 
close(imageFile); 
+0

Firefox和Chrome都无法很好地处理PGM(P5)图像。他们提供下载并邀请您提供查看器。所以虽然我同意写P5很简单(这是我通常所做的),但在将图像放到网页上之前,您应该完成转换为PNG。 –