简体   繁体   English

CImg对二进制图像数据

[英]CImg on binary image data

I created a binary file after taking a snapshot using X11 xGetImage and stored contents of data field in a binary file (The file has been zipped. Please uncompress it). 我使用X11 xGetImage拍摄快照后创建了一个二进制文件,并将数据字段的内容存储在二进制文件中 (该文件已压缩。请解压缩它)。 Now, i was playing around a bit with CImg and learning its usage. 现在,我正在与CImg一起玩耍并学习其用法。

First Question 第一个问题

So, i tried CImg on this binary data using load_rgba function 因此,我使用load_rgba函数在此二进制数据上尝试了CImg

CImgDisplay *disp;
CImg <float>img1,img2; //I don't why,it only works with float, with int it gives gray colour and with unsigned int it gives black foreground
img2 = img1.load_rgba("imagedata",1366,768);  //1366 X 768 is the dimension of my image that i got from X11
disp = new CImgDisplay(1024,768,"window");
disp->display(img2);

Now, i can see the image in the window, but there is a loss of quality. 现在,我可以在窗口中看到图像,但是质量下降了。 so i tried to have a look at the code and found that 所以我试图看一下代码,发现

at line 34318 在34318行

assign(dimw,dimh,1,4); // the depth is assigned to 1. which i believe is the culprit, however i would like confirm it

and why it only works when float is passed for template?? 以及为什么仅在为模板传递float时才起作用?

Second Question Now i thought,to use CImg by first reading the file myself and then handing over the pointer of buffer to Cimg using this code 第二个问题现在,我想使用CImg,方法是先自己读取文件,然后使用此代码将缓冲区的指针移交给Cimg。

int main() {
    char *data;
    int size = 1366*768*4;   //1366 X 768 is the dimension of my image that i got from X11 and 4 is number of bits per pixel
    ifstream file ("imagedata", ios::in|ios::binary|ios::ate);
    data = new char[size];
    file.read (data, size);

    CImgDisplay *disp;
    CImg <float>img3(data,1366,768,1,4);
    disp = new CImgDisplay(1024,768,"window");
    disp->display(img3);
    getchar();
    return 0;   
}

Running this code on same imagedata(as in first case), all i get is a black window. 在相同的imagedata上运行此代码(如第一种情况),我得到的只是一个黑色窗口。 Moreover setting 4th parameter(ie depth(z)) result in segmentation fault 此外,设置第四个参数(即depth(z))会导致分割错误

What am i doing wrong here? 我在这里做错了什么?

Second Question Now i thought,to use CImg by first reading the file myself and then handing over the pointer of buffer to Cimg using this code 第二个问题现在,我想使用CImg,方法是先自己读取文件,然后使用此代码将缓冲区的指针移交给Cimg。

CImg data format: http://cimg.eu/reference/group__cimg__storage.html CImg数据格式: http ://cimg.eu/reference/group__cimg__storage.html

If you want to init CImg object from buffer manually you should set up this arrays by yourself. 如果要手动从缓冲区初始化CImg对象,则应自行设置此数组。

This is an example for jpeg image, for other formats you can check sources (functions names: _load_png , _load_jpeg etc.): 这是jpeg图像的示例,对于其他格式,您可以检查源(函数名称: _load_png_load_jpeg等):

https://github.com/EyalAr/lwip/blob/master/src/decoder/jpeg_decoder.cpp https://github.com/EyalAr/lwip/blob/master/src/decoder/jpeg_decoder.cpp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM