I have developed a small GUI in C++/Qt, I would like to know a fast way to test if image loaded is grayscale. In practise, when I load a grayscale image of gif format, I want it to be recognized as a grayscale image with depth()=8, and when I load a colored gif image, the depth of QImage would be 32.
Here's my open method :
void ImageViewer::open()
{
int status_off = 0;
fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
if (!fileName.isEmpty()) {
current_qimage = QImage(fileName);
if (current_qimage.isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
updateStatus(status_off);
// Image is colored with depth=8
if (current_qimage.depth()/8 != 4)
{rgblum_status = 0;}
else // Image is grayscale with depth=32
{rgblum_status = 1;}
loadImage();
}
}
From my first test, it seems that current_qimage, in current_qimage = QImage(fileName);
inherits firstly from the format (gif here) before the contents of the image. Therefore, QImage has in two cases a depth() equal to 32.
How to make the difference between these two gif images (one grayscale and the other colored) ?