From 14b065c2e3340ae4550c7e16496f95f45541a9d1 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Thu, 29 Apr 2004 16:06:59 +0000 Subject: [PATCH] Implement missing grayscale transformation. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8714 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 6 ++++++ src/frontends/qt2/QLImage.C | 38 ++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 848ae5cf9e..8e1ce5cdf4 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,9 @@ +2004-04-29 Angus Leeming + + * QLImage.C (toGray): new helper function, copied from + KImageEffect::toGray. + (setPixmap_impl): use it. + 2004-04-29 Angus Leeming * QGraphics.C (apply): Remove a #warning statement by diff --git a/src/frontends/qt2/QLImage.C b/src/frontends/qt2/QLImage.C index aaa0f4d5f7..302780d458 100644 --- a/src/frontends/qt2/QLImage.C +++ b/src/frontends/qt2/QLImage.C @@ -103,7 +103,7 @@ QLImage::QLImage() QLImage::QLImage(QLImage const & other) : Image(other), pixmap_(other.pixmap_), - xformed_pixmap_(other.xformed_pixmap_) + xformed_pixmap_(other.pixmap_) { } @@ -151,16 +151,44 @@ void QLImage::load_impl(string const & filename) } +namespace { + +// This code is taken from KImageEffect::toGray +QImage & toGray(QImage & img) +{ + if (img.width() == 0 || img.height() == 0) + return img; + + int const pixels = img.depth() > 8 ? + img.width() * img.height() : img.numColors(); + + unsigned int * const data = img.depth() > 8 ? + (unsigned int *)img.bits() : + (unsigned int *)img.colorTable(); + + for(int i = 0; i < pixels; ++i){ + int const val = qGray(data[i]); + data[i] = qRgba(val, val, val, qAlpha(data[i])); + } + return img; +} + +} // namespace anon + + bool QLImage::setPixmap_impl(Params const & params) { if (pixmap_.isNull() || params.display == NoDisplay) return false; - // FIXME: it's a fake kind of grayscale ! - switch (params.display) { - case GrayscaleDisplay: - case MonochromeDisplay: { + case GrayscaleDisplay: { + QImage i(xformed_pixmap_.convertToImage()); + xformed_pixmap_.convertFromImage(toGray(i)); + break; + } + + case MonochromeDisplay: { QImage i(xformed_pixmap_.convertToImage()); xformed_pixmap_.convertFromImage(i, QPixmap::Mono); break; -- 2.39.2