Skip to content

Commit

Permalink
optimize QImage comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
  • Loading branch information
Ivailo Monev committed Jul 3, 2019
1 parent ad073c1 commit e939427
Showing 1 changed file with 3 additions and 44 deletions.
47 changes: 3 additions & 44 deletions src/gui/image/qimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4328,10 +4328,8 @@ QDataStream &operator<<(QDataStream &s, const QImage &image)
if (image.isNull()) {
s << (qint32) 0; // null image marker
return s;
} else {
s << (qint32) 1;
// continue ...
}
s << (qint32) 1;
QImageWriter writer(s.device(), "png");
writer.write(image);
return s;
Expand Down Expand Up @@ -4378,51 +4376,12 @@ QDataStream &operator>>(QDataStream &s, QImage &image)
bool QImage::operator==(const QImage & i) const
{
// same object, or shared?
if (i.d == d)
if (d == i.d)
return true;
if (!i.d || !d)
return false;

// obviously different stuff?
if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format)
if (!d || !i.d || d->ser_no != i.d->ser_no || d->detach_no != i.d->detach_no)
return false;

if (d->format != Format_RGB32) {
if (d->format >= Format_ARGB32) { // all bits defined
const int n = d->width * d->depth / 8;
if (n == d->bytes_per_line && n == i.d->bytes_per_line) {
if (memcmp(bits(), i.constBits(), d->nbytes))
return false;
} else {
for (int y = 0; y < d->height; ++y) {
if (memcmp(scanLine(y), i.scanLine(y), n))
return false;
}
}
} else {
const int w = width();
const int h = height();
const QVector<QRgb> &colortable = d->colortable;
const QVector<QRgb> &icolortable = i.d->colortable;
for (int y=0; y<h; ++y) {
for (int x=0; x<w; ++x) {
if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)])
return false;
}
}
}
} else {
//alpha channel undefined, so we must mask it out
for(int l = 0; l < d->height; l++) {
int w = d->width;
const uint *p1 = reinterpret_cast<const uint*>(scanLine(l));
const uint *p2 = reinterpret_cast<const uint*>(i.scanLine(l));
while (w--) {
if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff))
return false;
}
}
}
return true;
}

Expand Down

0 comments on commit e939427

Please sign in to comment.