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). Now, i was playing around a bit with CImg and learning its usage.
First Question
So, i tried CImg on this binary data using load_rgba function
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
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??
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
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. Moreover setting 4th parameter(ie depth(z)) result in segmentation fault
What am i doing wrong here?