I have an unsigned char array that is defined like so:
unsigned char **chars = new unsigned char *[H];
for(int i = 0; i < H; i++)
{
chars[i] = new unsigned char[W*3];
}
Where H is the height of the image, and W is the width, and chars is populated in the rest of that function looping over rows x columns of the input image. Chars is populated in the order Red Green Blue
I am trying to read it with something like this:
QImage *qi = new QImage(imwidth, imheight, QImage::Format_RGB888);
for (int i = 0 ; i < imheight ; i++)
for (int j = 0 ; j < imwidth ; j++)
{ //not sure why, but have to flip j and i in the index for setPixel
qi->setPixel(j,i,qRgb(imageData[i][j],imageData[i][j+1],imageData[i][j+2]));
j+=3;
}
QPixmap p(QPixmap::fromImage(*qi,Qt::AutoColor));
QPixmap p1(p.scaled(ui->menuBar->width(),ui->menuBar->width(), Qt::KeepAspectRatio, Qt::SmoothTransformation ));
ui->viewLabel->setPixmap(p1);
ui->viewLabel->setFixedHeight(p1.height());
ui->viewLabel->setFixedWidth(p1.width());
where chars was returned to this calling function in the imageData array.
What am I doing wrong? Should I use a different format, even though I am clearly allocating 3 unsigned chars per pixel (which is why I chose the RGB888 format). This code as posted returns an image, but it is displaying incorrectly - partially scrambled, washed out, etc
Thanks