Hello,
below a piece of code, which consists in loading image data in false color mode (or at least this is what I expected to do!) and retrieving them immediatly. I have deleted additionnal code, which includes a color table construction, to be attached to the image.
I obviously make a mistake somewhere or more likely I have not understood the way QImage interprets the raw data. I have not found any response to this specific problem in reading the various posts on loadFromData method, including http://www.qtcentre.org/forum/f-qt-p...t=loadFromData so this is the reason I create a new topic.
Thanks in advance for your help.
Code:
this->Print("size is (%u,%u)", size[0], size[1]);
uchar *data;
if ((data = (uchar *)malloc(size[0]*size[1]*sizeof(uchar))) == NULL) {
this->Error("memory allocation error (%d)", size[0]*size[1]*sizeof(uchar));
return;
}
for (int j=0 ; j<size[1] ; j++)
for (int i=0 ; i<size[0] ; i++)
data[j*size[0]+i] = i==0 && j==0 ? 255 : 0;
for (int j=0 ; j<size[1] ; j++) {
for (int i=0 ; i<size[0] ; i++) {
this->Print(" %u\r", data[j*size[0]+i]);
}
this->Print("\n");
}
image->loadFromData(data, field.size());
for (int j=0 ; j<size[1] ; j++) {
for (int i=0 ; i<size[0] ; i++) {
QRgb rgb = image->pixel(i, j);
this->Print(" %u\r", image->bits()[j*size[0]+i]);
}
this->Print("\n");
}
this->Print("size is (%u,%u)", size[0], size[1]);
uchar *data;
if ((data = (uchar *)malloc(size[0]*size[1]*sizeof(uchar))) == NULL) {
this->Error("memory allocation error (%d)", size[0]*size[1]*sizeof(uchar));
return;
}
QImage *image = new QImage(QSize(size[0], size[1]), QImage::Format_Indexed8);
for (int j=0 ; j<size[1] ; j++)
for (int i=0 ; i<size[0] ; i++)
data[j*size[0]+i] = i==0 && j==0 ? 255 : 0;
for (int j=0 ; j<size[1] ; j++) {
for (int i=0 ; i<size[0] ; i++) {
this->Print(" %u\r", data[j*size[0]+i]);
}
this->Print("\n");
}
image->loadFromData(data, field.size());
for (int j=0 ; j<size[1] ; j++) {
for (int i=0 ; i<size[0] ; i++) {
QRgb rgb = image->pixel(i, j);
this->Print(" %u\r", image->bits()[j*size[0]+i]);
}
this->Print("\n");
}
To copy to clipboard, switch view to plain text mode
Output:
wlFieldImage: size is (4,4)
wlFieldImage: Original values:
wlFieldImage: 255 0 0 0
wlFieldImage: 0 0 0 0
wlFieldImage: 0 0 0 0
wlFieldImage: 0 0 0 0
wlFieldImage: Extracted values:
wlFieldImage: 40 59 19 8
wlFieldImage: 0 0 0 0
wlFieldImage: 216 103 12 8
wlFieldImage: 184 193 9 8
wlFieldImage: size is (4,4)
wlFieldImage: Original values:
wlFieldImage: 255 0 0 0
wlFieldImage: 0 0 0 0
wlFieldImage: 0 0 0 0
wlFieldImage: 0 0 0 0
wlFieldImage: Extracted values:
wlFieldImage: 40 59 19 8
wlFieldImage: 0 0 0 0
wlFieldImage: 216 103 12 8
wlFieldImage: 184 193 9 8
To copy to clipboard, switch view to plain text mode
Bookmarks