From kde-accessibility Thu Nov 25 13:57:10 2004 From: Gunnar Schmi Dt Date: Thu, 25 Nov 2004 13:57:10 +0000 To: kde-accessibility Subject: [Kde-accessibility] Icon effect for monochrome icons Message-Id: <200411251457.17404.gunnar () schmi-dt ! de> X-MARC-Message: https://marc.info/?l=kde-accessibility&m=110139114916174 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1242492786==" --===============1242492786== Content-Type: multipart/signed; boundary="nextPart50069197.xvE1eZBuZY"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart50069197.xvE1eZBuZY Content-Type: multipart/mixed; boundary="Boundary-01=_2SepBWLeBee9S0i" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_2SepBWLeBee9S0i Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, During akademy I have experimented with some algorithms that produce=20 monochrome icons from standard (colored) icons. One of the algorithms=20 produces quite acceptable results, and so I have now produced patches for=20 kdelibs and kdebase that add this icon effect to the list of standard icon= =20 sets. Basically the algorithm works as follows: It first calculates an average=20 brightness of the icon. In a second step everything darker than the=20 average gets painted in the foreground color and everything lighter than=20 the average gets painted in the background color. In order to define the foreground and background color I have decided to=20 produce two versions of the patch (and I would like to hear some feedback=20 about which version is better suited for the inclusion in KDE 3.4): The first version (kdelibs.diff and kdebase.diff) uses the color defined=20 with the icon effect as the foreground color and the standard background=20 color from the color scheme as the background color. This has the=20 disadvantage that it adds a dependency between the color scheme and the=20 icon theme (everytime when the color scheme changes the icons need to be=20 re-loaded). The current version of this patch does simply ignore this=20 additional dependency. The second version (kdelibs2.diff and kdebase2.diff) adds an additional=20 second color to the icon effect, so that both colors are defined with the=20 icon effect. This has the advantage that it does not add a dependency=20 between the color scheme and the icon theme, but it also requires some=20 more changes to the API (i.e., the second color needs to be added). A problem that remains with both versions is that the selected icons are=20 calculated by applying some standard icon effect to the icon (The icon is=20 overlaid with the color for the selected background). While this is ok in=20 most situations it is not ideal for high contrast icons (where you might=20 want to have full control of the resulting colors). However, in order to=20 change this we would need to apply some big changes to both the algorithms= =20 that load the icons and to the kdecore API, so that this is not feasible=20 for KDE 3.4. In either case this icon effect does not replace the need for a high=20 contrast icon theme that is useable for low-vision users. It rather is=20 intended to both colorize such a high contrast icon theme in colors that=20 match the color theme and for "incorporating" icons that are missing in=20 the high contrast icon theme (and otherwise would be painted as they are=20 with all colors). Gunnar Schmi Dt =2D-=20 Co-maintainer of the KDE Accessibility Project Maintainer of the kdeaccessibility package http://accessibility.kde.org/ --Boundary-01=_2SepBWLeBee9S0i Content-Type: text/x-diff; charset="us-ascii"; name="kdebase2.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="kdebase2.diff" Index: kcontrol/icons/icons.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/kcontrol/icons/icons.cpp,v retrieving revision 1.37 diff -u -p -r1.37 icons.cpp =2D-- kcontrol/icons/icons.cpp 22 Oct 2004 19:11:15 -0000 1.37 +++ kcontrol/icons/icons.cpp 25 Nov 2004 13:18:55 -0000 @@ -163,6 +163,9 @@ void KIconConfig::initDefaults() mDefaultEffect[0].color =3D QColor(144,128,248); mDefaultEffect[1].color =3D QColor(169,156,255); mDefaultEffect[2].color =3D QColor(34,202,0); + mDefaultEffect[0].color2 =3D QColor(0,0,0); + mDefaultEffect[1].color2 =3D QColor(0,0,0); + mDefaultEffect[2].color2 =3D QColor(0,0,0); =20 const int defDefSizes[] =3D { 32, 22, 22, 16, 32 }; =20 @@ -250,12 +253,15 @@ void KIconConfig::read() effect =3D KIconEffect::ToGamma; else if (tmp =3D=3D "desaturate") effect =3D KIconEffect::DeSaturate; + else if (tmp =3D=3D "tomonochrome") + effect =3D KIconEffect::ToMonochrome; else if (tmp =3D=3D "none") effect =3D KIconEffect::NoEffect; else continue; mEffects[i][j].type =3D effect; mEffects[i][j].value =3D mpConfig->readDoubleNumEntry(*it2 + "Value"); mEffects[i][j].color =3D mpConfig->readColorEntry(*it2 + "Color"); + mEffects[i][j].color2 =3D mpConfig->readColorEntry(*it2 + "Color2"); mEffects[i][j].transparant =3D mpConfig->readBoolEntry(*it2 + "SemiTr= ansparent"); } } @@ -309,7 +315,7 @@ void KIconConfig::preview(int i) Effect &effect =3D mEffects[viewedGroup][i]; =20 img =3D mpEffect->apply(img, effect.type, =2D effect.value, effect.color, effect.transparant); + effect.value, effect.color, effect.color2, effect.transparant); pm.convertFromImage(img); mpPreview[i]->setPixmap(pm); } @@ -359,6 +365,9 @@ void KIconConfig::save() case KIconEffect::DeSaturate: tmp =3D "desaturate"; break; + case KIconEffect::ToMonochrome: + tmp =3D "tomonochrome"; + break; default: tmp =3D "none"; break; @@ -366,6 +375,7 @@ void KIconConfig::save() mpConfig->writeEntry(*it2 + "Effect", tmp, true, true); mpConfig->writeEntry(*it2 + "Value", mEffects[i][j].value, true, true= ); mpConfig->writeEntry(*it2 + "Color", mEffects[i][j].color, tru= e, true); + mpConfig->writeEntry(*it2 + "Color2", mEffects[i][j].color2, t= rue, true); mpConfig->writeEntry(*it2 + "SemiTransparent", mEffects[i][j].= transparant, true, true); } } @@ -526,6 +536,7 @@ KIconEffectSetupDialog::KIconEffectSetup mpEffectBox->insertItem(i18n("Colorize")); mpEffectBox->insertItem(i18n("Gamma")); mpEffectBox->insertItem(i18n("Desaturate")); + mpEffectBox->insertItem(i18n("To Monochrome")); mpEffectBox->setMinimumWidth( 100 ); connect(mpEffectBox, SIGNAL(highlighted(int)), SLOT(slotEffectType(int= ))); top->addMultiCellWidget(mpEffectBox, 1, 2, 0, 0, Qt::AlignLeft); @@ -566,6 +577,14 @@ KIconEffectSetupDialog::KIconEffectSetup SLOT(slotEffectColor(const QColor &))); grid->addWidget(mpEColButton, 2, 1); =20 + mpEffectColor2 =3D new QLabel(i18n("&Second color:"), mpEffectGroup); + grid->addWidget(mpEffectColor2, 3, 0); + mpECol2Button =3D new KColorButton(mpEffectGroup); + mpEffectColor->setBuddy( mpECol2Button ); + connect(mpECol2Button, SIGNAL(changed(const QColor &)), + SLOT(slotEffectColor2(const QColor &))); + grid->addWidget(mpECol2Button, 3, 1); + init(); preview(); } @@ -579,9 +598,11 @@ void KIconEffectSetupDialog::init() { mpEffectBox->setCurrentItem(mEffect.type); mpEffectSlider->setEnabled(mEffect.type !=3D KIconEffect::NoEffect); =2D mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize); + mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize || = mEffect.type =3D=3D KIconEffect::ToMonochrome); + mpECol2Button->setEnabled(mEffect.type =3D=3D KIconEffect::ToMonochrom= e); mpEffectSlider->setValue((int) (100.0 * mEffect.value + 0.5)); mpEColButton->setColor(mEffect.color); + mpECol2Button->setColor(mEffect.color2); mpSTCheck->setChecked(mEffect.transparant); } =20 @@ -597,13 +618,21 @@ void KIconEffectSetupDialog::slotEffectC preview(); } =20 +void KIconEffectSetupDialog::slotEffectColor2(const QColor &col) +{ + mEffect.color2 =3D col; + preview(); +} + void KIconEffectSetupDialog::slotEffectType(int type) { mEffect.type =3D type; mpEffectGroup->setEnabled(mEffect.type !=3D KIconEffect::NoEffect); mpEffectSlider->setEnabled(mEffect.type !=3D KIconEffect::NoEffect); =2D mpEffectColor->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize); =2D mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize); + mpEffectColor->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize ||= mEffect.type =3D=3D KIconEffect::ToMonochrome); + mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize || = mEffect.type =3D=3D KIconEffect::ToMonochrome); + mpEffectColor2->setEnabled(mEffect.type =3D=3D KIconEffect::ToMonochro= me); + mpECol2Button->setEnabled(mEffect.type =3D=3D KIconEffect::ToMonochrom= e); preview(); } =20 @@ -625,7 +654,7 @@ void KIconEffectSetupDialog::preview() QPixmap pm; QImage img =3D mExample.copy(); img =3D mpEffect->apply(img, mEffect.type, =2D mEffect.value, mEffect.color, mEffect.transparant); + mEffect.value, mEffect.color, mEffect.color2, mEffect.transparan= t); pm.convertFromImage(img); mpPreview->setPixmap(pm); } Index: kcontrol/icons/icons.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/kcontrol/icons/icons.h,v retrieving revision 1.13 diff -u -p -r1.13 icons.h =2D-- kcontrol/icons/icons.h 22 Oct 2004 19:11:15 -0000 1.13 +++ kcontrol/icons/icons.h 25 Nov 2004 13:18:55 -0000 @@ -44,6 +44,7 @@ struct Effect=20 int type; float value; QColor color; + QColor color2; bool transparant; }; =20 @@ -128,6 +129,7 @@ protected: protected slots: void slotEffectValue(int value); void slotEffectColor(const QColor &col); + void slotEffectColor2(const QColor &col); void slotEffectType(int type); void slotSTCheck(bool b); void slotDefault(); @@ -138,11 +140,12 @@ private: QCheckBox *mpSTCheck; QSlider *mpEffectSlider; KColorButton *mpEColButton; + KColorButton *mpECol2Button; Effect mEffect; Effect mDefaultEffect; QImage mExample; QGroupBox *mpEffectGroup; =2D QLabel *mpPreview, *mpEffectLabel, *mpEffectColor; + QLabel *mpPreview, *mpEffectLabel, *mpEffectColor, *mpEffectColor2; }; =20 =20 #endif --Boundary-01=_2SepBWLeBee9S0i Content-Type: text/x-diff; charset="us-ascii"; name="kdebase.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="kdebase.diff" Index: kcontrol/icons/icons.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdebase/kcontrol/icons/icons.cpp,v retrieving revision 1.37 diff -u -p -r1.37 icons.cpp =2D-- kcontrol/icons/icons.cpp 22 Oct 2004 19:11:15 -0000 1.37 +++ kcontrol/icons/icons.cpp 21 Nov 2004 16:20:34 -0000 @@ -250,6 +250,8 @@ void KIconConfig::read() effect =3D KIconEffect::ToGamma; else if (tmp =3D=3D "desaturate") effect =3D KIconEffect::DeSaturate; + else if (tmp =3D=3D "tomonochrome") + effect =3D KIconEffect::ToMonochrome; else if (tmp =3D=3D "none") effect =3D KIconEffect::NoEffect; else continue; @@ -359,6 +361,9 @@ void KIconConfig::save() case KIconEffect::DeSaturate: tmp =3D "desaturate"; break; + case KIconEffect::ToMonochrome: + tmp =3D "tomonochrome"; + break; default: tmp =3D "none"; break; @@ -526,6 +531,7 @@ KIconEffectSetupDialog::KIconEffectSetup mpEffectBox->insertItem(i18n("Colorize")); mpEffectBox->insertItem(i18n("Gamma")); mpEffectBox->insertItem(i18n("Desaturate")); + mpEffectBox->insertItem(i18n("To Monochrome")); mpEffectBox->setMinimumWidth( 100 ); connect(mpEffectBox, SIGNAL(highlighted(int)), SLOT(slotEffectType(int= ))); top->addMultiCellWidget(mpEffectBox, 1, 2, 0, 0, Qt::AlignLeft); @@ -579,7 +585,7 @@ void KIconEffectSetupDialog::init() { mpEffectBox->setCurrentItem(mEffect.type); mpEffectSlider->setEnabled(mEffect.type !=3D KIconEffect::NoEffect); =2D mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize); + mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize || = mEffect.type =3D=3D KIconEffect::ToMonochrome); mpEffectSlider->setValue((int) (100.0 * mEffect.value + 0.5)); mpEColButton->setColor(mEffect.color); mpSTCheck->setChecked(mEffect.transparant); @@ -602,8 +608,8 @@ void KIconEffectSetupDialog::slotEffectT mEffect.type =3D type; mpEffectGroup->setEnabled(mEffect.type !=3D KIconEffect::NoEffect); mpEffectSlider->setEnabled(mEffect.type !=3D KIconEffect::NoEffect); =2D mpEffectColor->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize); =2D mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize); + mpEffectColor->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize ||= mEffect.type =3D=3D KIconEffect::ToMonochrome); + mpEColButton->setEnabled(mEffect.type =3D=3D KIconEffect::Colorize || = mEffect.type =3D=3D KIconEffect::ToMonochrome); preview(); } =20 --Boundary-01=_2SepBWLeBee9S0i Content-Type: text/x-diff; charset="us-ascii"; name="kdelibs2.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="kdelibs2.diff" Index: kdecore/kiconeffect.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdelibs/kdecore/kiconeffect.cpp,v retrieving revision 1.47 diff -u -p -r1.47 kiconeffect.cpp =2D-- kdecore/kiconeffect.cpp 7 Sep 2004 11:42:17 -0000 1.47 +++ kdecore/kiconeffect.cpp 25 Nov 2004 13:19:49 -0000 @@ -80,6 +80,7 @@ void KIconEffect::init() QString _desaturate("desaturate"); QString _togamma("togamma"); QString _none("none"); + QString _tomonochrome("tomonochrome"); =20 KConfigGroupSaver cs(config, "default"); =20 @@ -99,6 +100,9 @@ void KIconEffect::init() mColor[i][0] =3D QColor(144,128,248); mColor[i][1] =3D QColor(169,156,255); mColor[i][2] =3D QColor(34,202,0); + mColor2[i][0] =3D QColor(0,0,0); + mColor2[i][1] =3D QColor(0,0,0); + mColor2[i][2] =3D QColor(0,0,0); =20 config->setGroup(*it + "Icons"); for (it2=3Dstates.begin(), j=3D0; it2!=3Dstates.end(); it2++, j++) @@ -112,6 +116,8 @@ void KIconEffect::init() effect =3D DeSaturate; else if (tmp =3D=3D _togamma) effect =3D ToGamma; + else if (tmp =3D=3D _tomonochrome) + effect =3D ToMonochrome; else if (tmp =3D=3D _none) effect =3D NoEffect; else @@ -120,6 +126,7 @@ void KIconEffect::init() mEffect[i][j] =3D effect; mValue[i][j] =3D config->readDoubleNumEntry(*it2 + "Value"); mColor[i][j] =3D config->readColorEntry(*it2 + "Color"); + mColor2[i][j] =3D config->readColorEntry(*it2 + "Color2"); mTrans[i][j] =3D config->readBoolEntry(*it2 + "SemiTransparent"); =20 } @@ -150,11 +157,16 @@ QString KIconEffect::fingerprint(int gro cached +=3D ':'; cached +=3D mTrans[group][state] ? QString::fromLatin1("trans") : QString::fromLatin1("notrans"); =2D if (mEffect[group][state] =3D=3D Colorize) + if (mEffect[group][state] =3D=3D Colorize || mEffect[group][state]= =3D=3D ToMonochrome) { cached +=3D ':'; cached +=3D mColor[group][state].name(); } + if (mEffect[group][state] =3D=3D ToMonochrome) + { + cached +=3D ':'; + cached +=3D mColor2[group][state].name(); + } =20 d->mKey[group][state] =3D cached; =20 } @@ -175,11 +187,16 @@ QImage KIconEffect::apply(QImage image,=20 return image; } return apply(image, mEffect[group][state], mValue[group][state], =2D mColor[group][state], mTrans[group][state]); + mColor[group][state], mColor2[group][state], mTrans[group][state]); } =20 QImage KIconEffect::apply(QImage image, int effect, float value, const QCo= lor col, bool trans) const { + apply (image, effect, value, col, KGlobalSettings::baseColor(), trans); +} + +QImage KIconEffect::apply(QImage image, int effect, float value, const QCo= lor col, const QColor col2, bool trans) const +{ if (effect >=3D LastEffect ) { kdDebug(265) << "Illegal icon effect: " << effect << "\n"; @@ -203,6 +220,9 @@ QImage KIconEffect::apply(QImage image,=20 case ToGamma: toGamma(image, value); break; + case ToMonochrome: + toMonochrome(image, col, col2, value); + break; } if (trans =3D=3D true) { @@ -224,12 +244,18 @@ QPixmap KIconEffect::apply(QPixmap pixma return pixmap; } return apply(pixmap, mEffect[group][state], mValue[group][state], =2D mColor[group][state], mTrans[group][state]); + mColor[group][state], mColor2[group][state], mTrans[group][state]); } =20 QPixmap KIconEffect::apply(QPixmap pixmap, int effect, float value, const QColor col, bool trans) const { + apply (pixmap, effect, value, col, KGlobalSettings::baseColor(), trans= ); +} + +QPixmap KIconEffect::apply(QPixmap pixmap, int effect, float value, + const QColor col, const QColor col2, bool trans) const +{ QPixmap result; =20 if (effect >=3D LastEffect ) @@ -246,7 +272,7 @@ QPixmap KIconEffect::apply(QPixmap pixma else if ( effect !=3D NoEffect ) { QImage tmpImg =3D pixmap.convertToImage(); =2D tmpImg =3D apply(tmpImg, effect, value, col, trans); + tmpImg =3D apply(tmpImg, effect, value, col, col2, trans); result.convertFromImage(tmpImg); } else @@ -321,6 +347,40 @@ void KIconEffect::colorize(QImage &img,=20 } } =20 +void KIconEffect::toMonochrome(QImage &img, const QColor &black, const QCo= lor &white, float value) { + int pixels =3D (img.depth() > 8) ? img.width()*img.height() : img.numCo= lors(); + unsigned int *data =3D img.depth() > 8 ? (unsigned int *) img.bits() + : (unsigned int *) img.colorTable(); + int rval, gval, bval, alpha, i; + int rw =3D white.red(), gw =3D white.green(), bw =3D white.blue(); + int rb =3D black.red(), gb =3D black.green(), bb =3D black.blue(); + =20 + double values =3D 0, sum =3D 0; + // Step 1: determine the average brightness + for (i=3D0; i(value*rb+(1.0-value)*qRed(data[i])); + gval =3D static_cast(value*gb+(1.0-value)*qGreen(data[i])); + bval =3D static_cast(value*bb+(1.0-value)*qBlue(data[i])); + } + else { + rval =3D static_cast(value*rw+(1.0-value)*qRed(data[i])); + gval =3D static_cast(value*gw+(1.0-value)*qGreen(data[i])); + bval =3D static_cast(value*bw+(1.0-value)*qBlue(data[i])); + } + =20 + alpha =3D qAlpha(data[i]); + data[i] =3D qRgba(rval, gval, bval, alpha); + } +} + void KIconEffect::deSaturate(QImage &img, float value) { int pixels =3D (img.depth() > 8) ? img.width()*img.height() Index: kdecore/kiconeffect.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdelibs/kdecore/kiconeffect.h,v retrieving revision 1.25 diff -u -p -r1.25 kiconeffect.h =2D-- kdecore/kiconeffect.h 9 Sep 2004 15:23:51 -0000 1.25 +++ kdecore/kiconeffect.h 25 Nov 2004 13:19:49 -0000 @@ -52,8 +52,9 @@ public: * @li Colorize: Tints the icon with an other color * @li ToGamma: Change the gamma value of the icon * @li DeSaturate: Reduce the saturation of the icon + * @li ToMonochrome: Produces a monochrome icon */ =2D enum Effects { NoEffect, ToGray, Colorize, ToGamma, DeSaturate, Last= Effect }; + enum Effects { NoEffect, ToGray, Colorize, ToGamma, DeSaturate, ToMono= chrome, LastEffect }; =20 /** * Rereads configuration. @@ -102,6 +103,7 @@ public: */ // KDE4: make them references QImage apply(QImage src, int effect, float value, const QColor rgb, bo= ol trans) const; + QImage apply(QImage src, int effect, float value, const QColor rgb, co= nst QColor rgb2, bool trans) const; =20 /** * Applies an effect to a pixmap. @@ -122,6 +124,7 @@ public: * @return A pixmap with the effect applied. */ QPixmap apply(QPixmap src, int effect, float value, const QColor rgb, = bool trans) const; + QPixmap apply(QPixmap src, int effect, float value, const QColor rgb, = const QColor rgb2, bool trans) const; =20 /** * Returns an image twice as large, consisting of 2x2 pixels. @@ -162,6 +165,16 @@ public: static void colorize(QImage &image, const QColor &col, float value); =20 /** + * Produces a monochrome icon with a given foreground and background c= olor + * + * @param image The image + * @param white The color with which the white parts of @p image are p= ainted + * @param black The color with which the black parts of @p image are p= ainted + * @param value Strength of the effect. 0 <=3D @p value <=3D 1 + */ + static void toMonochrome(QImage &image, const QColor &black, const QCo= lor &white, float value); + + /** * Desaturates an image. * * @param image The image @@ -203,6 +216,7 @@ private: int mEffect[6][3]; float mValue[6][3]; QColor mColor[6][3]; + QColor mColor2[6][3]; bool mTrans[6][3]; KIconEffectPrivate *d; }; --Boundary-01=_2SepBWLeBee9S0i Content-Type: text/x-diff; charset="us-ascii"; name="kdelibs.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="kdelibs.diff" ? kdelibs.diff Index: kdecore/kiconeffect.cpp =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdelibs/kdecore/kiconeffect.cpp,v retrieving revision 1.47 diff -u -p -r1.47 kiconeffect.cpp =2D-- kdecore/kiconeffect.cpp 7 Sep 2004 11:42:17 -0000 1.47 +++ kdecore/kiconeffect.cpp 21 Nov 2004 16:21:03 -0000 @@ -80,6 +80,7 @@ void KIconEffect::init() QString _desaturate("desaturate"); QString _togamma("togamma"); QString _none("none"); + QString _tomonochrome("tomonochrome"); =20 KConfigGroupSaver cs(config, "default"); =20 @@ -112,6 +113,8 @@ void KIconEffect::init() effect =3D DeSaturate; else if (tmp =3D=3D _togamma) effect =3D ToGamma; + else if (tmp =3D=3D _tomonochrome) + effect =3D ToMonochrome; else if (tmp =3D=3D _none) effect =3D NoEffect; else @@ -150,7 +153,7 @@ QString KIconEffect::fingerprint(int gro cached +=3D ':'; cached +=3D mTrans[group][state] ? QString::fromLatin1("trans") : QString::fromLatin1("notrans"); =2D if (mEffect[group][state] =3D=3D Colorize) + if (mEffect[group][state] =3D=3D Colorize || mEffect[group][state]= =3D=3D ToMonochrome) { cached +=3D ':'; cached +=3D mColor[group][state].name(); @@ -203,6 +206,9 @@ QImage KIconEffect::apply(QImage image,=20 case ToGamma: toGamma(image, value); break; + case ToMonochrome: + toMonochrome(image, col, KGlobalSettings::baseColor(), value); + break; } if (trans =3D=3D true) { @@ -321,6 +327,40 @@ void KIconEffect::colorize(QImage &img,=20 } } =20 +void KIconEffect::toMonochrome(QImage &img, const QColor &black, const QCo= lor &white, float value) { + int pixels =3D (img.depth() > 8) ? img.width()*img.height() : img.numCo= lors(); + unsigned int *data =3D img.depth() > 8 ? (unsigned int *) img.bits() + : (unsigned int *) img.colorTable(); + int rval, gval, bval, alpha, i; + int rw =3D white.red(), gw =3D white.green(), bw =3D white.blue(); + int rb =3D black.red(), gb =3D black.green(), bb =3D black.blue(); + =20 + double values =3D 0, sum =3D 0; + // Step 1: determine the average brightness + for (i=3D0; i(value*rb+(1.0-value)*qRed(data[i])); + gval =3D static_cast(value*gb+(1.0-value)*qGreen(data[i])); + bval =3D static_cast(value*bb+(1.0-value)*qBlue(data[i])); + } + else { + rval =3D static_cast(value*rw+(1.0-value)*qRed(data[i])); + gval =3D static_cast(value*gw+(1.0-value)*qGreen(data[i])); + bval =3D static_cast(value*bw+(1.0-value)*qBlue(data[i])); + } + =20 + alpha =3D qAlpha(data[i]); + data[i] =3D qRgba(rval, gval, bval, alpha); + } +} + void KIconEffect::deSaturate(QImage &img, float value) { int pixels =3D (img.depth() > 8) ? img.width()*img.height() Index: kdecore/kiconeffect.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/kde/kdelibs/kdecore/kiconeffect.h,v retrieving revision 1.25 diff -u -p -r1.25 kiconeffect.h =2D-- kdecore/kiconeffect.h 9 Sep 2004 15:23:51 -0000 1.25 +++ kdecore/kiconeffect.h 21 Nov 2004 16:21:03 -0000 @@ -52,8 +52,9 @@ public: * @li Colorize: Tints the icon with an other color * @li ToGamma: Change the gamma value of the icon * @li DeSaturate: Reduce the saturation of the icon + * @li ToMonochrome: Produces a monochrome icon */ =2D enum Effects { NoEffect, ToGray, Colorize, ToGamma, DeSaturate, Last= Effect }; + enum Effects { NoEffect, ToGray, Colorize, ToGamma, DeSaturate, ToMono= chrome, LastEffect }; =20 /** * Rereads configuration. @@ -162,6 +163,16 @@ public: static void colorize(QImage &image, const QColor &col, float value); =20 /** + * Produces a monochrome icon with a given foreground and background c= olor + * + * @param image The image + * @param white The color with which the white parts of @p image are p= ainted + * @param black The color with which the black parts of @p image are p= ainted + * @param value Strength of the effect. 0 <=3D @p value <=3D 1 + */ + static void toMonochrome(QImage &image, const QColor &black, const QCo= lor &white, float value); + + /** * Desaturates an image. * * @param image The image --Boundary-01=_2SepBWLeBee9S0i-- --nextPart50069197.xvE1eZBuZY Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBBpeS9sxZ93p+gHn4RAvEHAJ9WvEDAUqyXb8+kVHBMtrIbtQbg+gCfUpdC 1oXMLR8NRZ81pd8SE/vrXfI= =yX2Z -----END PGP SIGNATURE----- --nextPart50069197.xvE1eZBuZY-- --===============1242492786== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kde-accessibility mailing list kde-accessibility@kde.org https://mail.kde.org/mailman/listinfo/kde-accessibility --===============1242492786==--