Problems with image colortable from latin1 file
-
Hello,
I wrote some Raw-Image-Reader and most of it works. But I still cant figure out how to set the colortable correctly. So first of all here is my code example:
QFile file(":/new/1.raw"); //open file dialog
if(file.open(QIODevice::ReadOnly)){qDebug("File opened");}
else{qDebug("File not opened");}QByteArray ba=file.readAll(); //read file into bytearray
QImage image(512,256,QImage::Format_Indexed8); //setup the blank image for pixel transfer later
QVector<QRgb> colorTable; //setup the 8 bit grayscale colortable
for(int i=0;i<256;i++) colorTable.push_back(qRgb(i,i,i));
image.setColorTable(colorTable);image.fill(0); //just displaying a blank image here
QPixmap pix1(QPixmap::fromImage(image));
ui->label->setPixmap(pix1);int j=0; //image manipulation procedure
for(int y=0;y<image.height();y++){
for(int x=0;x<image.width();x++){image.setPixel(x,y,ba.at( j)+128); j++;}}
// I add +128 because the image file give me values from -128...127QPixmap pix2(QPixmap::fromImage(image)); //display the file image on second pixmap here
ui->label_4->setPixmap(pix2);So like I said most of it works, but it displays half of the image in a very dark colors and some other parts looking extremly bright. I'm pretty sure I did something wrong with the file itself, maybe it contains some special code. I thought it is just ascii, but my Geany-Editor encodes it with ISO-8859-1. So I guess I need to convert from Latin1 to ascii or something else.
Here is a example from the beginning of the file:
÷=!<qÜáßåçëçìñîîìïñîòöñöø� �ÿúùüøýüûýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ� �ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ� �ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ� �ùÿúôæêèçÜÙØ×ØÔÒÍÉÁÈÅÇËÈÃ� �ÄÂÁÂÂÅÈÍÏÑÈÇÅÇÍÑÓÓÏÒ×ÙÖÚ� �àâáâáäÜåçèíîîòóöÿÿûÿÿÿýû� �ÿÿÿÿÿÿÿÿÿÿÿÿÿ
Hope someone got a hint for me to set the display correct, so that I could finish this stuff.
Best reagrds,
Olli
-
Whats the supposed format of the image file?
[quote author="xxxOllixxx" date="1386067526"]
int j=0; //image manipulation procedure
for(int y=0;y<image.height();y++){
for(int x=0;x<image.width();x++){image.setPixel(x,y,ba.at( j)+128); j++;}}
// I add +128 because the image file give me values from -128...127
[/quote]
Whats the exact purpose of this routine?![quote author="xxxOllixxx" date="1386067526"]
So like I said most of it works, but it displays half of the image in a very dark colors and some other parts looking extremly bright. I'm pretty sure I did something wrong with the file itself, maybe it contains some special code. I thought it is just ascii, but my Geany-Editor encodes it with ISO-8859-1. So I guess I need to convert from Latin1 to ascii or something else.
[/quote]
you don't need to worry about encodings. Since you are anyway interested in the binary data. The encodings are interesting for string representation (like when you open it in an text editor like you did). -
The image file is a Raw-format, but it contains only pixels. The routine you remarked, is for setting the pixel data from the bytearray to a QImage...pixel by pixel.
Sure I'm interested in the binary data, but where is still something wrong. The contour of the image is correct, the color of the pixel dosnt match. It is much to bright or much to dark. -
and the format of the raw image data is really equivalent to QImage::Format_Indexed8 ?
-
I'm not totally sure. But the image contains only values between -128...127 and the Format_Indexed8 is the only format with 8 Bit, so I just used it.
-
f.ex. Infranviewer can read the file... 8 bit grayscale...0 header bits