author | mickeyl <mickeyl> | 2003-12-20 17:47:08 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-12-20 17:47:08 (UTC) |
commit | d552ce3a94b53ae0fdb226411bd8f9e5bab6596a (patch) (unidiff) | |
tree | ca9f1edd3ed945c98a6cd4587a5094fe9b2b3d36 | |
parent | 8e96eec63c67cfcd1fb202fe7346e5408a142f2e (diff) | |
download | opie-d552ce3a94b53ae0fdb226411bd8f9e5bab6596a.zip opie-d552ce3a94b53ae0fdb226411bd8f9e5bab6596a.tar.gz opie-d552ce3a94b53ae0fdb226411bd8f9e5bab6596a.tar.bz2 |
- start cleaning up (lot of stuff left)
- use odebug classes
-rw-r--r-- | libopie2/opieui/odialog.cpp | 16 | ||||
-rw-r--r-- | libopie2/opieui/odialog.h | 10 | ||||
-rw-r--r-- | libopie2/opieui/oimageeffect.cpp | 41 | ||||
-rw-r--r-- | libopie2/opieui/olistview.cpp | 20 | ||||
-rw-r--r-- | libopie2/opieui/opieui.pro | 22 | ||||
-rw-r--r-- | libopie2/opieui/oseparator.cpp | 12 | ||||
-rw-r--r-- | libopie2/opieui/oversatileview.cpp | 25 |
7 files changed, 75 insertions, 71 deletions
diff --git a/libopie2/opieui/odialog.cpp b/libopie2/opieui/odialog.cpp index 00a7a7e..4d269d4 100644 --- a/libopie2/opieui/odialog.cpp +++ b/libopie2/opieui/odialog.cpp | |||
@@ -1,53 +1,55 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | |
4 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | =. | 4 | =. |
6 | .=l. | 5 | .=l. |
7 | .>+-= | 6 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 13 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 21 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
29 | 28 | ||
30 | */ | 29 | */ |
31 | 30 | ||
32 | #include <opie2/odialog.h> | 31 | #include <opie2/odialog.h> |
33 | 32 | ||
34 | int ODialog::mMarginSize = 5; // 11 like in KDialog is probably too much for PDA | 33 | #warning Make Margin and Spacing device dependend and configurable! |
35 | int ODialog::mSpacingSize = 2; // 6 like in KDialog is probably too much for PDA | 34 | |
35 | int ODialog::mMarginSize = 5; | ||
36 | int ODialog::mSpacingSize = 2; | ||
36 | 37 | ||
37 | ODialog::ODialog(QWidget *parent, const char *name, bool modal, WFlags f) | 38 | ODialog::ODialog(QWidget *parent, const char *name, bool modal, WFlags f) |
38 | : QDialog(parent, name, modal, f) | 39 | :QDialog(parent, name, modal, f) |
39 | { | 40 | { |
41 | // d = new ODialogPrivate(); | ||
40 | } | 42 | } |
41 | 43 | ||
42 | int ODialog::marginHint() | 44 | int ODialog::marginHint() |
43 | { | 45 | { |
44 | return( mMarginSize ); | 46 | return( mMarginSize ); |
45 | } | 47 | } |
46 | 48 | ||
47 | 49 | ||
48 | int ODialog::spacingHint() | 50 | int ODialog::spacingHint() |
49 | { | 51 | { |
50 | return( mSpacingSize ); | 52 | return( mSpacingSize ); |
51 | } | 53 | } |
52 | 54 | ||
53 | // Placeholder for even more sophisticed things | 55 | // Placeholder for even more sophisticed things |
diff --git a/libopie2/opieui/odialog.h b/libopie2/opieui/odialog.h index 4116ed7..ceff612 100644 --- a/libopie2/opieui/odialog.h +++ b/libopie2/opieui/odialog.h | |||
@@ -1,89 +1,91 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | |
4 | (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | =. | 4 | =. |
6 | .=l. | 5 | .=l. |
7 | .>+-= | 6 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 13 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 21 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
29 | 28 | ||
30 | */ | 29 | */ |
31 | 30 | ||
32 | #ifndef ODIALOG_H | 31 | #ifndef ODIALOG_H |
33 | #define ODIALOG_H | 32 | #define ODIALOG_H |
34 | 33 | ||
35 | class QLayoutItem; | 34 | class QLayoutItem; |
36 | 35 | ||
37 | #include <qdialog.h> | 36 | #include <qdialog.h> |
38 | 37 | ||
39 | /** | 38 | /** |
40 | * Dialog with extended nonmodal support and methods for OPIE standard | 39 | * Dialog with extended nonmodal support and methods for OPIE standard |
41 | * compliance. | 40 | * compliance. |
42 | * | 41 | * |
43 | * The @ref marginHint() and @ref spacingHint() sizes shall be used | 42 | * The @ref marginHint() and @ref spacingHint() sizes shall be used |
44 | * whenever you layout the interior of a dialog. One special note. If | 43 | * whenever you layout the interior of a dialog. One special note. If |
45 | * you make your own action buttons (OK, Cancel etc), the space | 44 | * you make your own action buttons (OK, Cancel etc), the space |
46 | * beteween the buttons shall be @ref spacingHint(), whereas the space | 45 | * beteween the buttons shall be @ref spacingHint(), whereas the space |
47 | * above, below, to the right and to the left shall be @ref marginHint(). | 46 | * above, below, to the right and to the left shall be @ref marginHint(). |
48 | * If you add a separator line above the buttons, there shall be a | 47 | * If you add a separator line above the buttons, there shall be a |
49 | * @ref marginHint() between the buttons and the separator and a | 48 | * @ref marginHint() between the buttons and the separator and a |
50 | * @ref marginHint() above the separator as well. | 49 | * @ref marginHint() above the separator as well. |
51 | * | 50 | * |
52 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 51 | * @author Michael 'Mickey' Lauer <mickey@Vanille.de> |
53 | */ | 52 | */ |
53 | |||
54 | // lets fix up Qt instead! Size does matter. -zecke | 54 | // lets fix up Qt instead! Size does matter. -zecke |
55 | // while that may be true, reducing maintainance effort for the future does also matter - | ||
56 | // and I believe that maintaining a patch against QtE is more work than our classes -mml | ||
55 | 57 | ||
56 | class ODialog : public QDialog | 58 | class ODialog : public QDialog |
57 | { | 59 | { |
58 | Q_OBJECT | 60 | Q_OBJECT |
59 | 61 | ||
60 | public: | 62 | public: |
61 | 63 | ||
62 | /** | 64 | /** |
63 | * Constructor. | 65 | * Constructor. |
64 | * | 66 | * |
65 | * Takes the same arguments as @ref QDialog. | 67 | * Takes the same arguments as @ref QDialog. |
66 | */ | 68 | */ |
67 | ODialog(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0); | 69 | ODialog(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0); |
68 | 70 | ||
69 | /** | 71 | /** |
70 | * Return the number of pixels you shall use between a | 72 | * Return the number of pixels you shall use between a |
71 | * dialog edge and the outermost widget(s) according to the KDE standard. | 73 | * dialog edge and the outermost widget(s) according to the KDE standard. |
72 | **/ | 74 | **/ |
73 | static int marginHint(); | 75 | static int marginHint(); |
74 | 76 | ||
75 | /** | 77 | /** |
76 | * Return the number of pixels you shall use between | 78 | * Return the number of pixels you shall use between |
77 | * widgets inside a dialog according to the KDE standard. | 79 | * widgets inside a dialog according to the KDE standard. |
78 | */ | 80 | */ |
79 | static int spacingHint(); | 81 | static int spacingHint(); |
80 | 82 | ||
81 | private: | 83 | private: |
82 | static int mMarginSize; | 84 | static int mMarginSize; |
83 | static int mSpacingSize; | 85 | static int mSpacingSize; |
84 | 86 | ||
85 | class ODialogPrivate; | 87 | class ODialogPrivate; |
86 | ODialogPrivate *d; // d pointer always needed! -zecke | 88 | ODialogPrivate *d; |
87 | 89 | ||
88 | }; | 90 | }; |
89 | #endif // ODIALOG_H | 91 | #endif // ODIALOG_H |
diff --git a/libopie2/opieui/oimageeffect.cpp b/libopie2/opieui/oimageeffect.cpp index 01e7c6f..9a58bb9 100644 --- a/libopie2/opieui/oimageeffect.cpp +++ b/libopie2/opieui/oimageeffect.cpp | |||
@@ -1,3767 +1,3768 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@kde.org> | 2 | Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@kde.org> |
3 | (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> | 3 | (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> |
4 | (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> | 4 | (C) 1998, 1999 Dirk A. Mueller <mueller@kde.org> |
5 | (C) 2000 Josef Weidendorfer <weidendo@in.tum.de> | 5 | (C) 2000 Josef Weidendorfer <weidendo@in.tum.de> |
6 | 6 | ||
7 | Redistribution and use in source and binary forms, with or without | 7 | Redistribution and use in source and binary forms, with or without |
8 | modification, are permitted provided that the following conditions | 8 | modification, are permitted provided that the following conditions |
9 | are met: | 9 | are met: |
10 | 10 | ||
11 | 1. Redistributions of source code must retain the above copyright | 11 | 1. Redistributions of source code must retain the above copyright |
12 | notice, this list of conditions and the following disclaimer. | 12 | notice, this list of conditions and the following disclaimer. |
13 | 2. Redistributions in binary form must reproduce the above copyright | 13 | 2. Redistributions in binary form must reproduce the above copyright |
14 | notice, this list of conditions and the following disclaimer in the | 14 | notice, this list of conditions and the following disclaimer in the |
15 | documentation and/or other materials provided with the distribution. | 15 | documentation and/or other materials provided with the distribution. |
16 | 16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | // $Id$ | 30 | // $Id$ |
31 | 31 | ||
32 | #include <math.h> | 32 | #include <math.h> |
33 | 33 | ||
34 | #include <qimage.h> | 34 | #include <qimage.h> |
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | 36 | ||
37 | #include "oimageeffect.h" | 37 | #include <opie2/oimageeffect.h> |
38 | #include <opie2/odebug.h> | ||
38 | 39 | ||
39 | #define MaxRGB 255L | 40 | #define MaxRGB 255L |
40 | #define DegreesToRadians(x) ((x)*M_PI/180.0) | 41 | #define DegreesToRadians(x) ((x)*M_PI/180.0) |
41 | 42 | ||
42 | using namespace std; | 43 | using namespace std; |
43 | 44 | ||
44 | inline unsigned int intensityValue(unsigned int color) | 45 | inline unsigned int intensityValue(unsigned int color) |
45 | { | 46 | { |
46 | return((unsigned int)((0.299*qRed(color) + | 47 | return((unsigned int)((0.299*qRed(color) + |
47 | 0.587*qGreen(color) + | 48 | 0.587*qGreen(color) + |
48 | 0.1140000000000001*qBlue(color)))); | 49 | 0.1140000000000001*qBlue(color)))); |
49 | } | 50 | } |
50 | 51 | ||
51 | //====================================================================== | 52 | //====================================================================== |
52 | // | 53 | // |
53 | // Gradient effects | 54 | // Gradient effects |
54 | // | 55 | // |
55 | //====================================================================== | 56 | //====================================================================== |
56 | 57 | ||
57 | QImage OImageEffect::gradient(const QSize &size, const QColor &ca, | 58 | QImage OImageEffect::gradient(const QSize &size, const QColor &ca, |
58 | const QColor &cb, GradientType eff, int ncols) | 59 | const QColor &cb, GradientType eff, int ncols) |
59 | { | 60 | { |
60 | int rDiff, gDiff, bDiff; | 61 | int rDiff, gDiff, bDiff; |
61 | int rca, gca, bca, rcb, gcb, bcb; | 62 | int rca, gca, bca, rcb, gcb, bcb; |
62 | 63 | ||
63 | QImage image(size, 32); | 64 | QImage image(size, 32); |
64 | 65 | ||
65 | if (size.width() == 0 || size.height() == 0) { | 66 | if (size.width() == 0 || size.height() == 0) { |
66 | qDebug( "WARNING: OImageEffect::gradient: invalid image" ); | 67 | odebug << "WARNING: OImageEffect::gradient: invalid image" << oendl; |
67 | return image; | 68 | return image; |
68 | } | 69 | } |
69 | 70 | ||
70 | register int x, y; | 71 | register int x, y; |
71 | 72 | ||
72 | rDiff = (rcb = cb.red()) - (rca = ca.red()); | 73 | rDiff = (rcb = cb.red()) - (rca = ca.red()); |
73 | gDiff = (gcb = cb.green()) - (gca = ca.green()); | 74 | gDiff = (gcb = cb.green()) - (gca = ca.green()); |
74 | bDiff = (bcb = cb.blue()) - (bca = ca.blue()); | 75 | bDiff = (bcb = cb.blue()) - (bca = ca.blue()); |
75 | 76 | ||
76 | if( eff == VerticalGradient || eff == HorizontalGradient ){ | 77 | if( eff == VerticalGradient || eff == HorizontalGradient ){ |
77 | 78 | ||
78 | uint *p; | 79 | uint *p; |
79 | uint rgb; | 80 | uint rgb; |
80 | 81 | ||
81 | register int rl = rca << 16; | 82 | register int rl = rca << 16; |
82 | register int gl = gca << 16; | 83 | register int gl = gca << 16; |
83 | register int bl = bca << 16; | 84 | register int bl = bca << 16; |
84 | 85 | ||
85 | if( eff == VerticalGradient ) { | 86 | if( eff == VerticalGradient ) { |
86 | 87 | ||
87 | int rcdelta = ((1<<16) / size.height()) * rDiff; | 88 | int rcdelta = ((1<<16) / size.height()) * rDiff; |
88 | int gcdelta = ((1<<16) / size.height()) * gDiff; | 89 | int gcdelta = ((1<<16) / size.height()) * gDiff; |
89 | int bcdelta = ((1<<16) / size.height()) * bDiff; | 90 | int bcdelta = ((1<<16) / size.height()) * bDiff; |
90 | 91 | ||
91 | for ( y = 0; y < size.height(); y++ ) { | 92 | for ( y = 0; y < size.height(); y++ ) { |
92 | p = (uint *) image.scanLine(y); | 93 | p = (uint *) image.scanLine(y); |
93 | 94 | ||
94 | rl += rcdelta; | 95 | rl += rcdelta; |
95 | gl += gcdelta; | 96 | gl += gcdelta; |
96 | bl += bcdelta; | 97 | bl += bcdelta; |
97 | 98 | ||
98 | rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) ); | 99 | rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) ); |
99 | 100 | ||
100 | for( x = 0; x < size.width(); x++ ) { | 101 | for( x = 0; x < size.width(); x++ ) { |
101 | *p = rgb; | 102 | *p = rgb; |
102 | p++; | 103 | p++; |
103 | } | 104 | } |
104 | } | 105 | } |
105 | 106 | ||
106 | } | 107 | } |
107 | else { // must be HorizontalGradient | 108 | else { // must be HorizontalGradient |
108 | 109 | ||
109 | unsigned int *o_src = (unsigned int *)image.scanLine(0); | 110 | unsigned int *o_src = (unsigned int *)image.scanLine(0); |
110 | unsigned int *src = o_src; | 111 | unsigned int *src = o_src; |
111 | 112 | ||
112 | int rcdelta = ((1<<16) / size.width()) * rDiff; | 113 | int rcdelta = ((1<<16) / size.width()) * rDiff; |
113 | int gcdelta = ((1<<16) / size.width()) * gDiff; | 114 | int gcdelta = ((1<<16) / size.width()) * gDiff; |
114 | int bcdelta = ((1<<16) / size.width()) * bDiff; | 115 | int bcdelta = ((1<<16) / size.width()) * bDiff; |
115 | 116 | ||
116 | for( x = 0; x < size.width(); x++) { | 117 | for( x = 0; x < size.width(); x++) { |
117 | 118 | ||
118 | rl += rcdelta; | 119 | rl += rcdelta; |
119 | gl += gcdelta; | 120 | gl += gcdelta; |
120 | bl += bcdelta; | 121 | bl += bcdelta; |
121 | 122 | ||
122 | *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16)); | 123 | *src++ = qRgb( (rl>>16), (gl>>16), (bl>>16)); |
123 | } | 124 | } |
124 | 125 | ||
125 | src = o_src; | 126 | src = o_src; |
126 | 127 | ||
127 | // Believe it or not, manually copying in a for loop is faster | 128 | // Believe it or not, manually copying in a for loop is faster |
128 | // than calling memcpy for each scanline (on the order of ms...). | 129 | // than calling memcpy for each scanline (on the order of ms...). |
129 | // I think this is due to the function call overhead (mosfet). | 130 | // I think this is due to the function call overhead (mosfet). |
130 | 131 | ||
131 | for (y = 1; y < size.height(); ++y) { | 132 | for (y = 1; y < size.height(); ++y) { |
132 | 133 | ||
133 | p = (unsigned int *)image.scanLine(y); | 134 | p = (unsigned int *)image.scanLine(y); |
134 | src = o_src; | 135 | src = o_src; |
135 | for(x=0; x < size.width(); ++x) | 136 | for(x=0; x < size.width(); ++x) |
136 | *p++ = *src++; | 137 | *p++ = *src++; |
137 | } | 138 | } |
138 | } | 139 | } |
139 | } | 140 | } |
140 | 141 | ||
141 | else { | 142 | else { |
142 | 143 | ||
143 | float rfd, gfd, bfd; | 144 | float rfd, gfd, bfd; |
144 | float rd = rca, gd = gca, bd = bca; | 145 | float rd = rca, gd = gca, bd = bca; |
145 | 146 | ||
146 | unsigned char *xtable[3]; | 147 | unsigned char *xtable[3]; |
147 | unsigned char *ytable[3]; | 148 | unsigned char *ytable[3]; |
148 | 149 | ||
149 | unsigned int w = size.width(), h = size.height(); | 150 | unsigned int w = size.width(), h = size.height(); |
150 | xtable[0] = new unsigned char[w]; | 151 | xtable[0] = new unsigned char[w]; |
151 | xtable[1] = new unsigned char[w]; | 152 | xtable[1] = new unsigned char[w]; |
152 | xtable[2] = new unsigned char[w]; | 153 | xtable[2] = new unsigned char[w]; |
153 | ytable[0] = new unsigned char[h]; | 154 | ytable[0] = new unsigned char[h]; |
154 | ytable[1] = new unsigned char[h]; | 155 | ytable[1] = new unsigned char[h]; |
155 | ytable[2] = new unsigned char[h]; | 156 | ytable[2] = new unsigned char[h]; |
156 | w*=2, h*=2; | 157 | w*=2, h*=2; |
157 | 158 | ||
158 | if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) { | 159 | if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) { |
159 | // Diagonal dgradient code inspired by BlackBox (mosfet) | 160 | // Diagonal dgradient code inspired by BlackBox (mosfet) |
160 | // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and | 161 | // BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and |
161 | // Mike Cole <mike@mydot.com>. | 162 | // Mike Cole <mike@mydot.com>. |
162 | 163 | ||
163 | rfd = (float)rDiff/w; | 164 | rfd = (float)rDiff/w; |
164 | gfd = (float)gDiff/w; | 165 | gfd = (float)gDiff/w; |
165 | bfd = (float)bDiff/w; | 166 | bfd = (float)bDiff/w; |
166 | 167 | ||
167 | int dir; | 168 | int dir; |
168 | for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) { | 169 | for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) { |
169 | dir = eff == DiagonalGradient? x : size.width() - x - 1; | 170 | dir = eff == DiagonalGradient? x : size.width() - x - 1; |
170 | xtable[0][dir] = (unsigned char) rd; | 171 | xtable[0][dir] = (unsigned char) rd; |
171 | xtable[1][dir] = (unsigned char) gd; | 172 | xtable[1][dir] = (unsigned char) gd; |
172 | xtable[2][dir] = (unsigned char) bd; | 173 | xtable[2][dir] = (unsigned char) bd; |
173 | } | 174 | } |
174 | rfd = (float)rDiff/h; | 175 | rfd = (float)rDiff/h; |
175 | gfd = (float)gDiff/h; | 176 | gfd = (float)gDiff/h; |
176 | bfd = (float)bDiff/h; | 177 | bfd = (float)bDiff/h; |
177 | rd = gd = bd = 0; | 178 | rd = gd = bd = 0; |
178 | for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) { | 179 | for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) { |
179 | ytable[0][y] = (unsigned char) rd; | 180 | ytable[0][y] = (unsigned char) rd; |
180 | ytable[1][y] = (unsigned char) gd; | 181 | ytable[1][y] = (unsigned char) gd; |
181 | ytable[2][y] = (unsigned char) bd; | 182 | ytable[2][y] = (unsigned char) bd; |
182 | } | 183 | } |
183 | 184 | ||
184 | for (y = 0; y < size.height(); y++) { | 185 | for (y = 0; y < size.height(); y++) { |
185 | unsigned int *scanline = (unsigned int *)image.scanLine(y); | 186 | unsigned int *scanline = (unsigned int *)image.scanLine(y); |
186 | for (x = 0; x < size.width(); x++) { | 187 | for (x = 0; x < size.width(); x++) { |
187 | scanline[x] = qRgb(xtable[0][x] + ytable[0][y], | 188 | scanline[x] = qRgb(xtable[0][x] + ytable[0][y], |
188 | xtable[1][x] + ytable[1][y], | 189 | xtable[1][x] + ytable[1][y], |
189 | xtable[2][x] + ytable[2][y]); | 190 | xtable[2][x] + ytable[2][y]); |
190 | } | 191 | } |
191 | } | 192 | } |
192 | } | 193 | } |
193 | 194 | ||
194 | else if (eff == RectangleGradient || | 195 | else if (eff == RectangleGradient || |
195 | eff == PyramidGradient || | 196 | eff == PyramidGradient || |
196 | eff == PipeCrossGradient || | 197 | eff == PipeCrossGradient || |
197 | eff == EllipticGradient) | 198 | eff == EllipticGradient) |
198 | { | 199 | { |
199 | int rSign = rDiff>0? 1: -1; | 200 | int rSign = rDiff>0? 1: -1; |
200 | int gSign = gDiff>0? 1: -1; | 201 | int gSign = gDiff>0? 1: -1; |
201 | int bSign = bDiff>0? 1: -1; | 202 | int bSign = bDiff>0? 1: -1; |
202 | 203 | ||
203 | rfd = (float)rDiff / size.width(); | 204 | rfd = (float)rDiff / size.width(); |
204 | gfd = (float)gDiff / size.width(); | 205 | gfd = (float)gDiff / size.width(); |
205 | bfd = (float)bDiff / size.width(); | 206 | bfd = (float)bDiff / size.width(); |
206 | 207 | ||
207 | rd = (float)rDiff/2; | 208 | rd = (float)rDiff/2; |
208 | gd = (float)gDiff/2; | 209 | gd = (float)gDiff/2; |
209 | bd = (float)bDiff/2; | 210 | bd = (float)bDiff/2; |
210 | 211 | ||
211 | for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd) | 212 | for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd) |
212 | { | 213 | { |
213 | xtable[0][x] = (unsigned char) abs((int)rd); | 214 | xtable[0][x] = (unsigned char) abs((int)rd); |
214 | xtable[1][x] = (unsigned char) abs((int)gd); | 215 | xtable[1][x] = (unsigned char) abs((int)gd); |
215 | xtable[2][x] = (unsigned char) abs((int)bd); | 216 | xtable[2][x] = (unsigned char) abs((int)bd); |
216 | } | 217 | } |
217 | 218 | ||
218 | rfd = (float)rDiff/size.height(); | 219 | rfd = (float)rDiff/size.height(); |
219 | gfd = (float)gDiff/size.height(); | 220 | gfd = (float)gDiff/size.height(); |
220 | bfd = (float)bDiff/size.height(); | 221 | bfd = (float)bDiff/size.height(); |
221 | 222 | ||
222 | rd = (float)rDiff/2; | 223 | rd = (float)rDiff/2; |
223 | gd = (float)gDiff/2; | 224 | gd = (float)gDiff/2; |
224 | bd = (float)bDiff/2; | 225 | bd = (float)bDiff/2; |
225 | 226 | ||
226 | for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd) | 227 | for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd) |
227 | { | 228 | { |
228 | ytable[0][y] = (unsigned char) abs((int)rd); | 229 | ytable[0][y] = (unsigned char) abs((int)rd); |
229 | ytable[1][y] = (unsigned char) abs((int)gd); | 230 | ytable[1][y] = (unsigned char) abs((int)gd); |
230 | ytable[2][y] = (unsigned char) abs((int)bd); | 231 | ytable[2][y] = (unsigned char) abs((int)bd); |
231 | } | 232 | } |
232 | unsigned int rgb; | 233 | unsigned int rgb; |
233 | int h = (size.height()+1)>>1; | 234 | int h = (size.height()+1)>>1; |
234 | for (y = 0; y < h; y++) { | 235 | for (y = 0; y < h; y++) { |
235 | unsigned int *sl1 = (unsigned int *)image.scanLine(y); | 236 | unsigned int *sl1 = (unsigned int *)image.scanLine(y); |
236 | unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y)); | 237 | unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y)); |
237 | 238 | ||
238 | int w = (size.width()+1)>>1; | 239 | int w = (size.width()+1)>>1; |
239 | int x2 = size.width()-1; | 240 | int x2 = size.width()-1; |
240 | 241 | ||
241 | for (x = 0; x < w; x++, x2--) { | 242 | for (x = 0; x < w; x++, x2--) { |
242 | rgb = 0; | 243 | rgb = 0; |
243 | if (eff == PyramidGradient) { | 244 | if (eff == PyramidGradient) { |
244 | rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), | 245 | rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), |
245 | gcb-gSign*(xtable[1][x]+ytable[1][y]), | 246 | gcb-gSign*(xtable[1][x]+ytable[1][y]), |
246 | bcb-bSign*(xtable[2][x]+ytable[2][y])); | 247 | bcb-bSign*(xtable[2][x]+ytable[2][y])); |
247 | } | 248 | } |
248 | if (eff == RectangleGradient) { | 249 | if (eff == RectangleGradient) { |
249 | rgb = qRgb(rcb - rSign * | 250 | rgb = qRgb(rcb - rSign * |
250 | QMAX(xtable[0][x], ytable[0][y]) * 2, | 251 | QMAX(xtable[0][x], ytable[0][y]) * 2, |
251 | gcb - gSign * | 252 | gcb - gSign * |
252 | QMAX(xtable[1][x], ytable[1][y]) * 2, | 253 | QMAX(xtable[1][x], ytable[1][y]) * 2, |
253 | bcb - bSign * | 254 | bcb - bSign * |
254 | QMAX(xtable[2][x], ytable[2][y]) * 2); | 255 | QMAX(xtable[2][x], ytable[2][y]) * 2); |
255 | } | 256 | } |
256 | if (eff == PipeCrossGradient) { | 257 | if (eff == PipeCrossGradient) { |
257 | rgb = qRgb(rcb - rSign * | 258 | rgb = qRgb(rcb - rSign * |
258 | QMIN(xtable[0][x], ytable[0][y]) * 2, | 259 | QMIN(xtable[0][x], ytable[0][y]) * 2, |
259 | gcb - gSign * | 260 | gcb - gSign * |
260 | QMIN(xtable[1][x], ytable[1][y]) * 2, | 261 | QMIN(xtable[1][x], ytable[1][y]) * 2, |
261 | bcb - bSign * | 262 | bcb - bSign * |
262 | QMIN(xtable[2][x], ytable[2][y]) * 2); | 263 | QMIN(xtable[2][x], ytable[2][y]) * 2); |
263 | } | 264 | } |
264 | if (eff == EllipticGradient) { | 265 | if (eff == EllipticGradient) { |
265 | rgb = qRgb(rcb - rSign * | 266 | rgb = qRgb(rcb - rSign * |
266 | (int)sqrt((xtable[0][x]*xtable[0][x] + | 267 | (int)sqrt((xtable[0][x]*xtable[0][x] + |
267 | ytable[0][y]*ytable[0][y])*2.0), | 268 | ytable[0][y]*ytable[0][y])*2.0), |
268 | gcb - gSign * | 269 | gcb - gSign * |
269 | (int)sqrt((xtable[1][x]*xtable[1][x] + | 270 | (int)sqrt((xtable[1][x]*xtable[1][x] + |
270 | ytable[1][y]*ytable[1][y])*2.0), | 271 | ytable[1][y]*ytable[1][y])*2.0), |
271 | bcb - bSign * | 272 | bcb - bSign * |
272 | (int)sqrt((xtable[2][x]*xtable[2][x] + | 273 | (int)sqrt((xtable[2][x]*xtable[2][x] + |
273 | ytable[2][y]*ytable[2][y])*2.0)); | 274 | ytable[2][y]*ytable[2][y])*2.0)); |
274 | } | 275 | } |
275 | 276 | ||
276 | sl1[x] = sl2[x] = rgb; | 277 | sl1[x] = sl2[x] = rgb; |
277 | sl1[x2] = sl2[x2] = rgb; | 278 | sl1[x2] = sl2[x2] = rgb; |
278 | } | 279 | } |
279 | } | 280 | } |
280 | } | 281 | } |
281 | 282 | ||
282 | delete [] xtable[0]; | 283 | delete [] xtable[0]; |
283 | delete [] xtable[1]; | 284 | delete [] xtable[1]; |
284 | delete [] xtable[2]; | 285 | delete [] xtable[2]; |
285 | delete [] ytable[0]; | 286 | delete [] ytable[0]; |
286 | delete [] ytable[1]; | 287 | delete [] ytable[1]; |
287 | delete [] ytable[2]; | 288 | delete [] ytable[2]; |
288 | } | 289 | } |
289 | 290 | ||
290 | // dither if necessary | 291 | // dither if necessary |
291 | if (ncols && (QPixmap::defaultDepth() < 15 )) { | 292 | if (ncols && (QPixmap::defaultDepth() < 15 )) { |
292 | if ( ncols < 2 || ncols > 256 ) | 293 | if ( ncols < 2 || ncols > 256 ) |
293 | ncols = 3; | 294 | ncols = 3; |
294 | QColor *dPal = new QColor[ncols]; | 295 | QColor *dPal = new QColor[ncols]; |
295 | for (int i=0; i<ncols; i++) { | 296 | for (int i=0; i<ncols; i++) { |
296 | dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ), | 297 | dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ), |
297 | gca + gDiff * i / ( ncols - 1 ), | 298 | gca + gDiff * i / ( ncols - 1 ), |
298 | bca + bDiff * i / ( ncols - 1 ) ); | 299 | bca + bDiff * i / ( ncols - 1 ) ); |
299 | } | 300 | } |
300 | dither(image, dPal, ncols); | 301 | dither(image, dPal, ncols); |
301 | delete [] dPal; | 302 | delete [] dPal; |
302 | } | 303 | } |
303 | 304 | ||
304 | return image; | 305 | return image; |
305 | } | 306 | } |
306 | 307 | ||
307 | 308 | ||
308 | // ----------------------------------------------------------------------------- | 309 | // ----------------------------------------------------------------------------- |
309 | 310 | ||
310 | //CT this was (before Dirk A. Mueller's speedup changes) | 311 | //CT this was (before Dirk A. Mueller's speedup changes) |
311 | // merely the same code as in the above method, but it's supposedly | 312 | // merely the same code as in the above method, but it's supposedly |
312 | // way less performant since it introduces a lot of supplementary tests | 313 | // way less performant since it introduces a lot of supplementary tests |
313 | // and simple math operations for the calculus of the balance. | 314 | // and simple math operations for the calculus of the balance. |
314 | // (surprizingly, it isn't less performant, in the contrary :-) | 315 | // (surprizingly, it isn't less performant, in the contrary :-) |
315 | // Yes, I could have merged them, but then the excellent performance of | 316 | // Yes, I could have merged them, but then the excellent performance of |
316 | // the balanced code would suffer with no other gain than a mere | 317 | // the balanced code would suffer with no other gain than a mere |
317 | // source code and byte code size economy. | 318 | // source code and byte code size economy. |
318 | 319 | ||
319 | QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca, | 320 | QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca, |
320 | const QColor &cb, GradientType eff, int xfactor, int yfactor, | 321 | const QColor &cb, GradientType eff, int xfactor, int yfactor, |
321 | int ncols) | 322 | int ncols) |
322 | { | 323 | { |
323 | int dir; // general parameter used for direction switches | 324 | int dir; // general parameter used for direction switches |
324 | 325 | ||
325 | bool _xanti = false , _yanti = false; | 326 | bool _xanti = false , _yanti = false; |
326 | 327 | ||
327 | if (xfactor < 0) _xanti = true; // negative on X direction | 328 | if (xfactor < 0) _xanti = true; // negative on X direction |
328 | if (yfactor < 0) _yanti = true; // negative on Y direction | 329 | if (yfactor < 0) _yanti = true; // negative on Y direction |
329 | 330 | ||
330 | xfactor = abs(xfactor); | 331 | xfactor = abs(xfactor); |
331 | yfactor = abs(yfactor); | 332 | yfactor = abs(yfactor); |
332 | 333 | ||
333 | if (!xfactor) xfactor = 1; | 334 | if (!xfactor) xfactor = 1; |
334 | if (!yfactor) yfactor = 1; | 335 | if (!yfactor) yfactor = 1; |
335 | 336 | ||
336 | if (xfactor > 200 ) xfactor = 200; | 337 | if (xfactor > 200 ) xfactor = 200; |
337 | if (yfactor > 200 ) yfactor = 200; | 338 | if (yfactor > 200 ) yfactor = 200; |
338 | 339 | ||
339 | 340 | ||
340 | // float xbal = xfactor/5000.; | 341 | // float xbal = xfactor/5000.; |
341 | // float ybal = yfactor/5000.; | 342 | // float ybal = yfactor/5000.; |
342 | float xbal = xfactor/30./size.width(); | 343 | float xbal = xfactor/30./size.width(); |
343 | float ybal = yfactor/30./size.height(); | 344 | float ybal = yfactor/30./size.height(); |
344 | float rat; | 345 | float rat; |
345 | 346 | ||
346 | int rDiff, gDiff, bDiff; | 347 | int rDiff, gDiff, bDiff; |
347 | int rca, gca, bca, rcb, gcb, bcb; | 348 | int rca, gca, bca, rcb, gcb, bcb; |
348 | 349 | ||
349 | QImage image(size, 32); | 350 | QImage image(size, 32); |
350 | 351 | ||
351 | if (size.width() == 0 || size.height() == 0) { | 352 | if (size.width() == 0 || size.height() == 0) { |
352 | qDebug( "WARNING: OImageEffect::unbalancedGradient : invalid image" ); | 353 | odebug << "WARNING: OImageEffect::unbalancedGradient : invalid image" << oendl; |
353 | return image; | 354 | return image; |
354 | } | 355 | } |
355 | 356 | ||
356 | register int x, y; | 357 | register int x, y; |
357 | unsigned int *scanline; | 358 | unsigned int *scanline; |
358 | 359 | ||
359 | rDiff = (rcb = cb.red()) - (rca = ca.red()); | 360 | rDiff = (rcb = cb.red()) - (rca = ca.red()); |
360 | gDiff = (gcb = cb.green()) - (gca = ca.green()); | 361 | gDiff = (gcb = cb.green()) - (gca = ca.green()); |
361 | bDiff = (bcb = cb.blue()) - (bca = ca.blue()); | 362 | bDiff = (bcb = cb.blue()) - (bca = ca.blue()); |
362 | 363 | ||
363 | if( eff == VerticalGradient || eff == HorizontalGradient){ | 364 | if( eff == VerticalGradient || eff == HorizontalGradient){ |
364 | QColor cRow; | 365 | QColor cRow; |
365 | 366 | ||
366 | uint *p; | 367 | uint *p; |
367 | uint rgbRow; | 368 | uint rgbRow; |
368 | 369 | ||
369 | if( eff == VerticalGradient) { | 370 | if( eff == VerticalGradient) { |
370 | for ( y = 0; y < size.height(); y++ ) { | 371 | for ( y = 0; y < size.height(); y++ ) { |
371 | dir = _yanti ? y : size.height() - 1 - y; | 372 | dir = _yanti ? y : size.height() - 1 - y; |
372 | p = (uint *) image.scanLine(dir); | 373 | p = (uint *) image.scanLine(dir); |
373 | rat = 1 - exp( - (float)y * ybal ); | 374 | rat = 1 - exp( - (float)y * ybal ); |
374 | 375 | ||
375 | cRow.setRgb( rcb - (int) ( rDiff * rat ), | 376 | cRow.setRgb( rcb - (int) ( rDiff * rat ), |
376 | gcb - (int) ( gDiff * rat ), | 377 | gcb - (int) ( gDiff * rat ), |
377 | bcb - (int) ( bDiff * rat ) ); | 378 | bcb - (int) ( bDiff * rat ) ); |
378 | 379 | ||
379 | rgbRow = cRow.rgb(); | 380 | rgbRow = cRow.rgb(); |
380 | 381 | ||
381 | for( x = 0; x < size.width(); x++ ) { | 382 | for( x = 0; x < size.width(); x++ ) { |
382 | *p = rgbRow; | 383 | *p = rgbRow; |
383 | p++; | 384 | p++; |
384 | } | 385 | } |
385 | } | 386 | } |
386 | } | 387 | } |
387 | else { | 388 | else { |
388 | 389 | ||
389 | unsigned int *src = (unsigned int *)image.scanLine(0); | 390 | unsigned int *src = (unsigned int *)image.scanLine(0); |
390 | for(x = 0; x < size.width(); x++ ) | 391 | for(x = 0; x < size.width(); x++ ) |
391 | { | 392 | { |
392 | dir = _xanti ? x : size.width() - 1 - x; | 393 | dir = _xanti ? x : size.width() - 1 - x; |
393 | rat = 1 - exp( - (float)x * xbal ); | 394 | rat = 1 - exp( - (float)x * xbal ); |
394 | 395 | ||
395 | src[dir] = qRgb(rcb - (int) ( rDiff * rat ), | 396 | src[dir] = qRgb(rcb - (int) ( rDiff * rat ), |
396 | gcb - (int) ( gDiff * rat ), | 397 | gcb - (int) ( gDiff * rat ), |
397 | bcb - (int) ( bDiff * rat )); | 398 | bcb - (int) ( bDiff * rat )); |
398 | } | 399 | } |
399 | 400 | ||
400 | // Believe it or not, manually copying in a for loop is faster | 401 | // Believe it or not, manually copying in a for loop is faster |
401 | // than calling memcpy for each scanline (on the order of ms...). | 402 | // than calling memcpy for each scanline (on the order of ms...). |
402 | // I think this is due to the function call overhead (mosfet). | 403 | // I think this is due to the function call overhead (mosfet). |
403 | 404 | ||
404 | for(y = 1; y < size.height(); ++y) | 405 | for(y = 1; y < size.height(); ++y) |
405 | { | 406 | { |
406 | scanline = (unsigned int *)image.scanLine(y); | 407 | scanline = (unsigned int *)image.scanLine(y); |
407 | for(x=0; x < size.width(); ++x) | 408 | for(x=0; x < size.width(); ++x) |
408 | scanline[x] = src[x]; | 409 | scanline[x] = src[x]; |
409 | } | 410 | } |
410 | } | 411 | } |
411 | } | 412 | } |
412 | 413 | ||
413 | else { | 414 | else { |
414 | int w=size.width(), h=size.height(); | 415 | int w=size.width(), h=size.height(); |
415 | 416 | ||
416 | unsigned char *xtable[3]; | 417 | unsigned char *xtable[3]; |
417 | unsigned char *ytable[3]; | 418 | unsigned char *ytable[3]; |
418 | xtable[0] = new unsigned char[w]; | 419 | xtable[0] = new unsigned char[w]; |
419 | xtable[1] = new unsigned char[w]; | 420 | xtable[1] = new unsigned char[w]; |
420 | xtable[2] = new unsigned char[w]; | 421 | xtable[2] = new unsigned char[w]; |
421 | ytable[0] = new unsigned char[h]; | 422 | ytable[0] = new unsigned char[h]; |
422 | ytable[1] = new unsigned char[h]; | 423 | ytable[1] = new unsigned char[h]; |
423 | ytable[2] = new unsigned char[h]; | 424 | ytable[2] = new unsigned char[h]; |
424 | 425 | ||
425 | if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) | 426 | if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) |
426 | { | 427 | { |
427 | for (x = 0; x < w; x++) { | 428 | for (x = 0; x < w; x++) { |
428 | dir = _xanti ? x : w - 1 - x; | 429 | dir = _xanti ? x : w - 1 - x; |
429 | rat = 1 - exp( - (float)x * xbal ); | 430 | rat = 1 - exp( - (float)x * xbal ); |
430 | 431 | ||
431 | xtable[0][dir] = (unsigned char) ( rDiff/2 * rat ); | 432 | xtable[0][dir] = (unsigned char) ( rDiff/2 * rat ); |
432 | xtable[1][dir] = (unsigned char) ( gDiff/2 * rat ); | 433 | xtable[1][dir] = (unsigned char) ( gDiff/2 * rat ); |
433 | xtable[2][dir] = (unsigned char) ( bDiff/2 * rat ); | 434 | xtable[2][dir] = (unsigned char) ( bDiff/2 * rat ); |
434 | } | 435 | } |
435 | 436 | ||
436 | for (y = 0; y < h; y++) { | 437 | for (y = 0; y < h; y++) { |
437 | dir = _yanti ? y : h - 1 - y; | 438 | dir = _yanti ? y : h - 1 - y; |
438 | rat = 1 - exp( - (float)y * ybal ); | 439 | rat = 1 - exp( - (float)y * ybal ); |
439 | 440 | ||
440 | ytable[0][dir] = (unsigned char) ( rDiff/2 * rat ); | 441 | ytable[0][dir] = (unsigned char) ( rDiff/2 * rat ); |
441 | ytable[1][dir] = (unsigned char) ( gDiff/2 * rat ); | 442 | ytable[1][dir] = (unsigned char) ( gDiff/2 * rat ); |
442 | ytable[2][dir] = (unsigned char) ( bDiff/2 * rat ); | 443 | ytable[2][dir] = (unsigned char) ( bDiff/2 * rat ); |
443 | } | 444 | } |
444 | 445 | ||
445 | for (y = 0; y < h; y++) { | 446 | for (y = 0; y < h; y++) { |
446 | unsigned int *scanline = (unsigned int *)image.scanLine(y); | 447 | unsigned int *scanline = (unsigned int *)image.scanLine(y); |
447 | for (x = 0; x < w; x++) { | 448 | for (x = 0; x < w; x++) { |
448 | scanline[x] = qRgb(rcb - (xtable[0][x] + ytable[0][y]), | 449 | scanline[x] = qRgb(rcb - (xtable[0][x] + ytable[0][y]), |
449 | gcb - (xtable[1][x] + ytable[1][y]), | 450 | gcb - (xtable[1][x] + ytable[1][y]), |
450 | bcb - (xtable[2][x] + ytable[2][y])); | 451 | bcb - (xtable[2][x] + ytable[2][y])); |
451 | } | 452 | } |
452 | } | 453 | } |
453 | } | 454 | } |
454 | 455 | ||
455 | else if (eff == RectangleGradient || | 456 | else if (eff == RectangleGradient || |
456 | eff == PyramidGradient || | 457 | eff == PyramidGradient || |
457 | eff == PipeCrossGradient || | 458 | eff == PipeCrossGradient || |
458 | eff == EllipticGradient) | 459 | eff == EllipticGradient) |
459 | { | 460 | { |
460 | int rSign = rDiff>0? 1: -1; | 461 | int rSign = rDiff>0? 1: -1; |
461 | int gSign = gDiff>0? 1: -1; | 462 | int gSign = gDiff>0? 1: -1; |
462 | int bSign = bDiff>0? 1: -1; | 463 | int bSign = bDiff>0? 1: -1; |
463 | 464 | ||
464 | for (x = 0; x < w; x++) | 465 | for (x = 0; x < w; x++) |
465 | { | 466 | { |
466 | dir = _xanti ? x : w - 1 - x; | 467 | dir = _xanti ? x : w - 1 - x; |
467 | rat = 1 - exp( - (float)x * xbal ); | 468 | rat = 1 - exp( - (float)x * xbal ); |
468 | 469 | ||
469 | xtable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat))); | 470 | xtable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat))); |
470 | xtable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat))); | 471 | xtable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat))); |
471 | xtable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat))); | 472 | xtable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat))); |
472 | } | 473 | } |
473 | 474 | ||
474 | for (y = 0; y < h; y++) | 475 | for (y = 0; y < h; y++) |
475 | { | 476 | { |
476 | dir = _yanti ? y : h - 1 - y; | 477 | dir = _yanti ? y : h - 1 - y; |
477 | 478 | ||
478 | rat = 1 - exp( - (float)y * ybal ); | 479 | rat = 1 - exp( - (float)y * ybal ); |
479 | 480 | ||
480 | ytable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat))); | 481 | ytable[0][dir] = (unsigned char) abs((int)(rDiff*(0.5-rat))); |
481 | ytable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat))); | 482 | ytable[1][dir] = (unsigned char) abs((int)(gDiff*(0.5-rat))); |
482 | ytable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat))); | 483 | ytable[2][dir] = (unsigned char) abs((int)(bDiff*(0.5-rat))); |
483 | } | 484 | } |
484 | 485 | ||
485 | for (y = 0; y < h; y++) { | 486 | for (y = 0; y < h; y++) { |
486 | unsigned int *scanline = (unsigned int *)image.scanLine(y); | 487 | unsigned int *scanline = (unsigned int *)image.scanLine(y); |
487 | for (x = 0; x < w; x++) { | 488 | for (x = 0; x < w; x++) { |
488 | if (eff == PyramidGradient) | 489 | if (eff == PyramidGradient) |
489 | { | 490 | { |
490 | scanline[x] = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), | 491 | scanline[x] = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]), |
491 | gcb-gSign*(xtable[1][x]+ytable[1][y]), | 492 | gcb-gSign*(xtable[1][x]+ytable[1][y]), |
492 | bcb-bSign*(xtable[2][x]+ytable[2][y])); | 493 | bcb-bSign*(xtable[2][x]+ytable[2][y])); |
493 | } | 494 | } |
494 | if (eff == RectangleGradient) | 495 | if (eff == RectangleGradient) |
495 | { | 496 | { |
496 | scanline[x] = qRgb(rcb - rSign * | 497 | scanline[x] = qRgb(rcb - rSign * |
497 | QMAX(xtable[0][x], ytable[0][y]) * 2, | 498 | QMAX(xtable[0][x], ytable[0][y]) * 2, |
498 | gcb - gSign * | 499 | gcb - gSign * |
499 | QMAX(xtable[1][x], ytable[1][y]) * 2, | 500 | QMAX(xtable[1][x], ytable[1][y]) * 2, |
500 | bcb - bSign * | 501 | bcb - bSign * |
501 | QMAX(xtable[2][x], ytable[2][y]) * 2); | 502 | QMAX(xtable[2][x], ytable[2][y]) * 2); |
502 | } | 503 | } |
503 | if (eff == PipeCrossGradient) | 504 | if (eff == PipeCrossGradient) |
504 | { | 505 | { |
505 | scanline[x] = qRgb(rcb - rSign * | 506 | scanline[x] = qRgb(rcb - rSign * |
506 | QMIN(xtable[0][x], ytable[0][y]) * 2, | 507 | QMIN(xtable[0][x], ytable[0][y]) * 2, |
507 | gcb - gSign * | 508 | gcb - gSign * |
508 | QMIN(xtable[1][x], ytable[1][y]) * 2, | 509 | QMIN(xtable[1][x], ytable[1][y]) * 2, |
509 | bcb - bSign * | 510 | bcb - bSign * |
510 | QMIN(xtable[2][x], ytable[2][y]) * 2); | 511 | QMIN(xtable[2][x], ytable[2][y]) * 2); |
511 | } | 512 | } |
512 | if (eff == EllipticGradient) | 513 | if (eff == EllipticGradient) |
513 | { | 514 | { |
514 | scanline[x] = qRgb(rcb - rSign * | 515 | scanline[x] = qRgb(rcb - rSign * |
515 | (int)sqrt((xtable[0][x]*xtable[0][x] + | 516 | (int)sqrt((xtable[0][x]*xtable[0][x] + |
516 | ytable[0][y]*ytable[0][y])*2.0), | 517 | ytable[0][y]*ytable[0][y])*2.0), |
517 | gcb - gSign * | 518 | gcb - gSign * |
518 | (int)sqrt((xtable[1][x]*xtable[1][x] + | 519 | (int)sqrt((xtable[1][x]*xtable[1][x] + |
519 | ytable[1][y]*ytable[1][y])*2.0), | 520 | ytable[1][y]*ytable[1][y])*2.0), |
520 | bcb - bSign * | 521 | bcb - bSign * |
521 | (int)sqrt((xtable[2][x]*xtable[2][x] + | 522 | (int)sqrt((xtable[2][x]*xtable[2][x] + |
522 | ytable[2][y]*ytable[2][y])*2.0)); | 523 | ytable[2][y]*ytable[2][y])*2.0)); |
523 | } | 524 | } |
524 | } | 525 | } |
525 | } | 526 | } |
526 | } | 527 | } |
527 | 528 | ||
528 | if (ncols && (QPixmap::defaultDepth() < 15 )) { | 529 | if (ncols && (QPixmap::defaultDepth() < 15 )) { |
529 | if ( ncols < 2 || ncols > 256 ) | 530 | if ( ncols < 2 || ncols > 256 ) |
530 | ncols = 3; | 531 | ncols = 3; |
531 | QColor *dPal = new QColor[ncols]; | 532 | QColor *dPal = new QColor[ncols]; |
532 | for (int i=0; i<ncols; i++) { | 533 | for (int i=0; i<ncols; i++) { |
533 | dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ), | 534 | dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ), |
534 | gca + gDiff * i / ( ncols - 1 ), | 535 | gca + gDiff * i / ( ncols - 1 ), |
535 | bca + bDiff * i / ( ncols - 1 ) ); | 536 | bca + bDiff * i / ( ncols - 1 ) ); |
536 | } | 537 | } |
537 | dither(image, dPal, ncols); | 538 | dither(image, dPal, ncols); |
538 | delete [] dPal; | 539 | delete [] dPal; |
539 | } | 540 | } |
540 | 541 | ||
541 | delete [] xtable[0]; | 542 | delete [] xtable[0]; |
542 | delete [] xtable[1]; | 543 | delete [] xtable[1]; |
543 | delete [] xtable[2]; | 544 | delete [] xtable[2]; |
544 | delete [] ytable[0]; | 545 | delete [] ytable[0]; |
545 | delete [] ytable[1]; | 546 | delete [] ytable[1]; |
546 | delete [] ytable[2]; | 547 | delete [] ytable[2]; |
547 | 548 | ||
548 | } | 549 | } |
549 | 550 | ||
550 | return image; | 551 | return image; |
551 | } | 552 | } |
552 | 553 | ||
553 | 554 | ||
554 | //====================================================================== | 555 | //====================================================================== |
555 | // | 556 | // |
556 | // Intensity effects | 557 | // Intensity effects |
557 | // | 558 | // |
558 | //====================================================================== | 559 | //====================================================================== |
559 | 560 | ||
560 | 561 | ||
561 | /* This builds a 256 byte unsigned char lookup table with all | 562 | /* This builds a 256 byte unsigned char lookup table with all |
562 | * the possible percent values prior to applying the effect, then uses | 563 | * the possible percent values prior to applying the effect, then uses |
563 | * integer math for the pixels. For any image larger than 9x9 this will be | 564 | * integer math for the pixels. For any image larger than 9x9 this will be |
564 | * less expensive than doing a float operation on the 3 color components of | 565 | * less expensive than doing a float operation on the 3 color components of |
565 | * each pixel. (mosfet) | 566 | * each pixel. (mosfet) |
566 | */ | 567 | */ |
567 | 568 | ||
568 | QImage& OImageEffect::intensity(QImage &image, float percent) | 569 | QImage& OImageEffect::intensity(QImage &image, float percent) |
569 | { | 570 | { |
570 | if (image.width() == 0 || image.height() == 0) { | 571 | if (image.width() == 0 || image.height() == 0) { |
571 | qDebug( "WARNING: OImageEffect::intensity : invalid image" ); | 572 | odebug << "WARNING: OImageEffect::intensity : invalid image" << oendl; |
572 | return image; | 573 | return image; |
573 | } | 574 | } |
574 | 575 | ||
575 | int segColors = image.depth() > 8 ? 256 : image.numColors(); | 576 | int segColors = image.depth() > 8 ? 256 : image.numColors(); |
576 | unsigned char *segTbl = new unsigned char[segColors]; | 577 | unsigned char *segTbl = new unsigned char[segColors]; |
577 | int pixels = image.depth() > 8 ? image.width()*image.height() : | 578 | int pixels = image.depth() > 8 ? image.width()*image.height() : |
578 | image.numColors(); | 579 | image.numColors(); |
579 | unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : | 580 | unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : |
580 | (unsigned int *)image.colorTable(); | 581 | (unsigned int *)image.colorTable(); |
581 | 582 | ||
582 | bool brighten = (percent >= 0); | 583 | bool brighten = (percent >= 0); |
583 | if(percent < 0) | 584 | if(percent < 0) |
584 | percent = -percent; | 585 | percent = -percent; |
585 | 586 | ||
586 | if(brighten){ // keep overflow check out of loops | 587 | if(brighten){ // keep overflow check out of loops |
587 | for(int i=0; i < segColors; ++i){ | 588 | for(int i=0; i < segColors; ++i){ |
588 | int tmp = (int)(i*percent); | 589 | int tmp = (int)(i*percent); |
589 | if(tmp > 255) | 590 | if(tmp > 255) |
590 | tmp = 255; | 591 | tmp = 255; |
591 | segTbl[i] = tmp; | 592 | segTbl[i] = tmp; |
592 | } | 593 | } |
593 | } | 594 | } |
594 | else{ | 595 | else{ |
595 | for(int i=0; i < segColors; ++i){ | 596 | for(int i=0; i < segColors; ++i){ |
596 | int tmp = (int)(i*percent); | 597 | int tmp = (int)(i*percent); |
597 | if(tmp < 0) | 598 | if(tmp < 0) |
598 | tmp = 0; | 599 | tmp = 0; |
599 | segTbl[i] = tmp; | 600 | segTbl[i] = tmp; |
600 | } | 601 | } |
601 | } | 602 | } |
602 | 603 | ||
603 | if(brighten){ // same here | 604 | if(brighten){ // same here |
604 | for(int i=0; i < pixels; ++i){ | 605 | for(int i=0; i < pixels; ++i){ |
605 | int r = qRed(data[i]); | 606 | int r = qRed(data[i]); |
606 | int g = qGreen(data[i]); | 607 | int g = qGreen(data[i]); |
607 | int b = qBlue(data[i]); | 608 | int b = qBlue(data[i]); |
608 | int a = qAlpha(data[i]); | 609 | int a = qAlpha(data[i]); |
609 | r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; | 610 | r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; |
610 | g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; | 611 | g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; |
611 | b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; | 612 | b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; |
612 | data[i] = qRgba(r, g, b,a); | 613 | data[i] = qRgba(r, g, b,a); |
613 | } | 614 | } |
614 | } | 615 | } |
615 | else{ | 616 | else{ |
616 | for(int i=0; i < pixels; ++i){ | 617 | for(int i=0; i < pixels; ++i){ |
617 | int r = qRed(data[i]); | 618 | int r = qRed(data[i]); |
618 | int g = qGreen(data[i]); | 619 | int g = qGreen(data[i]); |
619 | int b = qBlue(data[i]); | 620 | int b = qBlue(data[i]); |
620 | int a = qAlpha(data[i]); | 621 | int a = qAlpha(data[i]); |
621 | r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; | 622 | r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; |
622 | g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; | 623 | g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; |
623 | b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; | 624 | b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; |
624 | data[i] = qRgba(r, g, b, a); | 625 | data[i] = qRgba(r, g, b, a); |
625 | } | 626 | } |
626 | } | 627 | } |
627 | delete [] segTbl; | 628 | delete [] segTbl; |
628 | 629 | ||
629 | return image; | 630 | return image; |
630 | } | 631 | } |
631 | 632 | ||
632 | QImage& OImageEffect::channelIntensity(QImage &image, float percent, | 633 | QImage& OImageEffect::channelIntensity(QImage &image, float percent, |
633 | RGBComponent channel) | 634 | RGBComponent channel) |
634 | { | 635 | { |
635 | if (image.width() == 0 || image.height() == 0) { | 636 | if (image.width() == 0 || image.height() == 0) { |
636 | qDebug( "WARNING: OImageEffect::channelIntensity : invalid image" ); | 637 | odebug << "WARNING: OImageEffect::channelIntensity : invalid image" << oendl; |
637 | return image; | 638 | return image; |
638 | } | 639 | } |
639 | 640 | ||
640 | int segColors = image.depth() > 8 ? 256 : image.numColors(); | 641 | int segColors = image.depth() > 8 ? 256 : image.numColors(); |
641 | unsigned char *segTbl = new unsigned char[segColors]; | 642 | unsigned char *segTbl = new unsigned char[segColors]; |
642 | int pixels = image.depth() > 8 ? image.width()*image.height() : | 643 | int pixels = image.depth() > 8 ? image.width()*image.height() : |
643 | image.numColors(); | 644 | image.numColors(); |
644 | unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : | 645 | unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : |
645 | (unsigned int *)image.colorTable(); | 646 | (unsigned int *)image.colorTable(); |
646 | bool brighten = (percent >= 0); | 647 | bool brighten = (percent >= 0); |
647 | if(percent < 0) | 648 | if(percent < 0) |
648 | percent = -percent; | 649 | percent = -percent; |
649 | 650 | ||
650 | if(brighten){ // keep overflow check out of loops | 651 | if(brighten){ // keep overflow check out of loops |
651 | for(int i=0; i < segColors; ++i){ | 652 | for(int i=0; i < segColors; ++i){ |
652 | int tmp = (int)(i*percent); | 653 | int tmp = (int)(i*percent); |
653 | if(tmp > 255) | 654 | if(tmp > 255) |
654 | tmp = 255; | 655 | tmp = 255; |
655 | segTbl[i] = tmp; | 656 | segTbl[i] = tmp; |
656 | } | 657 | } |
657 | } | 658 | } |
658 | else{ | 659 | else{ |
659 | for(int i=0; i < segColors; ++i){ | 660 | for(int i=0; i < segColors; ++i){ |
660 | int tmp = (int)(i*percent); | 661 | int tmp = (int)(i*percent); |
661 | if(tmp < 0) | 662 | if(tmp < 0) |
662 | tmp = 0; | 663 | tmp = 0; |
663 | segTbl[i] = tmp; | 664 | segTbl[i] = tmp; |
664 | } | 665 | } |
665 | } | 666 | } |
666 | 667 | ||
667 | if(brighten){ // same here | 668 | if(brighten){ // same here |
668 | if(channel == Red){ // and here ;-) | 669 | if(channel == Red){ // and here ;-) |
669 | for(int i=0; i < pixels; ++i){ | 670 | for(int i=0; i < pixels; ++i){ |
670 | int c = qRed(data[i]); | 671 | int c = qRed(data[i]); |
671 | c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; | 672 | c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; |
672 | data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i])); | 673 | data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i])); |
673 | } | 674 | } |
674 | } | 675 | } |
675 | if(channel == Green){ | 676 | if(channel == Green){ |
676 | for(int i=0; i < pixels; ++i){ | 677 | for(int i=0; i < pixels; ++i){ |
677 | int c = qGreen(data[i]); | 678 | int c = qGreen(data[i]); |
678 | c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; | 679 | c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; |
679 | data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i])); | 680 | data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i])); |
680 | } | 681 | } |
681 | } | 682 | } |
682 | else{ | 683 | else{ |
683 | for(int i=0; i < pixels; ++i){ | 684 | for(int i=0; i < pixels; ++i){ |
684 | int c = qBlue(data[i]); | 685 | int c = qBlue(data[i]); |
685 | c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; | 686 | c = c + segTbl[c] > 255 ? 255 : c + segTbl[c]; |
686 | data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i])); | 687 | data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i])); |
687 | } | 688 | } |
688 | } | 689 | } |
689 | 690 | ||
690 | } | 691 | } |
691 | else{ | 692 | else{ |
692 | if(channel == Red){ | 693 | if(channel == Red){ |
693 | for(int i=0; i < pixels; ++i){ | 694 | for(int i=0; i < pixels; ++i){ |
694 | int c = qRed(data[i]); | 695 | int c = qRed(data[i]); |
695 | c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; | 696 | c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; |
696 | data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i])); | 697 | data[i] = qRgba(c, qGreen(data[i]), qBlue(data[i]), qAlpha(data[i])); |
697 | } | 698 | } |
698 | } | 699 | } |
699 | if(channel == Green){ | 700 | if(channel == Green){ |
700 | for(int i=0; i < pixels; ++i){ | 701 | for(int i=0; i < pixels; ++i){ |
701 | int c = qGreen(data[i]); | 702 | int c = qGreen(data[i]); |
702 | c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; | 703 | c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; |
703 | data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i])); | 704 | data[i] = qRgba(qRed(data[i]), c, qBlue(data[i]), qAlpha(data[i])); |
704 | } | 705 | } |
705 | } | 706 | } |
706 | else{ | 707 | else{ |
707 | for(int i=0; i < pixels; ++i){ | 708 | for(int i=0; i < pixels; ++i){ |
708 | int c = qBlue(data[i]); | 709 | int c = qBlue(data[i]); |
709 | c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; | 710 | c = c - segTbl[c] < 0 ? 0 : c - segTbl[c]; |
710 | data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i])); | 711 | data[i] = qRgba(qRed(data[i]), qGreen(data[i]), c, qAlpha(data[i])); |
711 | } | 712 | } |
712 | } | 713 | } |
713 | } | 714 | } |
714 | delete [] segTbl; | 715 | delete [] segTbl; |
715 | 716 | ||
716 | return image; | 717 | return image; |
717 | } | 718 | } |
718 | 719 | ||
719 | // Modulate an image with an RBG channel of another image | 720 | // Modulate an image with an RBG channel of another image |
720 | // | 721 | // |
721 | QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse, | 722 | QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse, |
722 | ModulationType type, int factor, RGBComponent channel) | 723 | ModulationType type, int factor, RGBComponent channel) |
723 | { | 724 | { |
724 | if (image.width() == 0 || image.height() == 0 || | 725 | if (image.width() == 0 || image.height() == 0 || |
725 | modImage.width() == 0 || modImage.height() == 0) { | 726 | modImage.width() == 0 || modImage.height() == 0) { |
726 | qDebug( "WARNING: OImageEffect::modulate : invalid image" ); | 727 | odebug << "WARNING: OImageEffect::modulate : invalid image" << oendl; |
727 | return image; | 728 | return image; |
728 | } | 729 | } |
729 | 730 | ||
730 | int r, g, b, h, s, v, a; | 731 | int r, g, b, h, s, v, a; |
731 | QColor clr; | 732 | QColor clr; |
732 | int mod=0; | 733 | int mod=0; |
733 | unsigned int x1, x2, y1, y2; | 734 | unsigned int x1, x2, y1, y2; |
734 | register int x, y; | 735 | register int x, y; |
735 | 736 | ||
736 | // for image, we handle only depth 32 | 737 | // for image, we handle only depth 32 |
737 | if (image.depth()<32) image = image.convertDepth(32); | 738 | if (image.depth()<32) image = image.convertDepth(32); |
738 | 739 | ||
739 | // for modImage, we handle depth 8 and 32 | 740 | // for modImage, we handle depth 8 and 32 |
740 | if (modImage.depth()<8) modImage = modImage.convertDepth(8); | 741 | if (modImage.depth()<8) modImage = modImage.convertDepth(8); |
741 | 742 | ||
742 | unsigned int *colorTable2 = (modImage.depth()==8) ? | 743 | unsigned int *colorTable2 = (modImage.depth()==8) ? |
743 | modImage.colorTable():0; | 744 | modImage.colorTable():0; |
744 | unsigned int *data1, *data2; | 745 | unsigned int *data1, *data2; |
745 | unsigned char *data2b; | 746 | unsigned char *data2b; |
746 | unsigned int color1, color2; | 747 | unsigned int color1, color2; |
747 | 748 | ||
748 | x1 = image.width(); y1 = image.height(); | 749 | x1 = image.width(); y1 = image.height(); |
749 | x2 = modImage.width(); y2 = modImage.height(); | 750 | x2 = modImage.width(); y2 = modImage.height(); |
750 | 751 | ||
751 | for (y = 0; y < (int)y1; y++) { | 752 | for (y = 0; y < (int)y1; y++) { |
752 | data1 = (unsigned int *) image.scanLine(y); | 753 | data1 = (unsigned int *) image.scanLine(y); |
753 | data2 = (unsigned int *) modImage.scanLine( y%y2 ); | 754 | data2 = (unsigned int *) modImage.scanLine( y%y2 ); |
754 | data2b = (unsigned char *) modImage.scanLine( y%y2 ); | 755 | data2b = (unsigned char *) modImage.scanLine( y%y2 ); |
755 | 756 | ||
756 | x=0; | 757 | x=0; |
757 | while(x < (int)x1) { | 758 | while(x < (int)x1) { |
758 | color2 = (colorTable2) ? colorTable2[*data2b] : *data2; | 759 | color2 = (colorTable2) ? colorTable2[*data2b] : *data2; |
759 | if (reverse) { | 760 | if (reverse) { |
760 | color1 = color2; | 761 | color1 = color2; |
761 | color2 = *data1; | 762 | color2 = *data1; |
762 | } | 763 | } |
763 | else | 764 | else |
764 | color1 = *data1; | 765 | color1 = *data1; |
765 | 766 | ||
766 | if (type == Intensity || type == Contrast) { | 767 | if (type == Intensity || type == Contrast) { |
767 | r = qRed(color1); | 768 | r = qRed(color1); |
768 | g = qGreen(color1); | 769 | g = qGreen(color1); |
769 | b = qBlue(color1); | 770 | b = qBlue(color1); |
770 | if (channel != All) { | 771 | if (channel != All) { |
771 | mod = (channel == Red) ? qRed(color2) : | 772 | mod = (channel == Red) ? qRed(color2) : |
772 | (channel == Green) ? qGreen(color2) : | 773 | (channel == Green) ? qGreen(color2) : |
773 | (channel == Blue) ? qBlue(color2) : | 774 | (channel == Blue) ? qBlue(color2) : |
774 | (channel == Gray) ? qGray(color2) : 0; | 775 | (channel == Gray) ? qGray(color2) : 0; |
775 | mod = mod*factor/50; | 776 | mod = mod*factor/50; |
776 | } | 777 | } |
777 | 778 | ||
778 | if (type == Intensity) { | 779 | if (type == Intensity) { |
779 | if (channel == All) { | 780 | if (channel == All) { |
780 | r += r * factor/50 * qRed(color2)/256; | 781 | r += r * factor/50 * qRed(color2)/256; |
781 | g += g * factor/50 * qGreen(color2)/256; | 782 | g += g * factor/50 * qGreen(color2)/256; |
782 | b += b * factor/50 * qBlue(color2)/256; | 783 | b += b * factor/50 * qBlue(color2)/256; |
783 | } | 784 | } |
784 | else { | 785 | else { |
785 | r += r * mod/256; | 786 | r += r * mod/256; |
786 | g += g * mod/256; | 787 | g += g * mod/256; |
787 | b += b * mod/256; | 788 | b += b * mod/256; |
788 | } | 789 | } |
789 | } | 790 | } |
790 | else { // Contrast | 791 | else { // Contrast |
791 | if (channel == All) { | 792 | if (channel == All) { |
792 | r += (r-128) * factor/50 * qRed(color2)/128; | 793 | r += (r-128) * factor/50 * qRed(color2)/128; |
793 | g += (g-128) * factor/50 * qGreen(color2)/128; | 794 | g += (g-128) * factor/50 * qGreen(color2)/128; |
794 | b += (b-128) * factor/50 * qBlue(color2)/128; | 795 | b += (b-128) * factor/50 * qBlue(color2)/128; |
795 | } | 796 | } |
796 | else { | 797 | else { |
797 | r += (r-128) * mod/128; | 798 | r += (r-128) * mod/128; |
798 | g += (g-128) * mod/128; | 799 | g += (g-128) * mod/128; |
799 | b += (b-128) * mod/128; | 800 | b += (b-128) * mod/128; |
800 | } | 801 | } |
801 | } | 802 | } |
802 | 803 | ||
803 | if (r<0) r=0; if (r>255) r=255; | 804 | if (r<0) r=0; if (r>255) r=255; |
804 | if (g<0) g=0; if (g>255) g=255; | 805 | if (g<0) g=0; if (g>255) g=255; |
805 | if (b<0) b=0; if (b>255) b=255; | 806 | if (b<0) b=0; if (b>255) b=255; |
806 | a = qAlpha(*data1); | 807 | a = qAlpha(*data1); |
807 | *data1 = qRgba(r, g, b, a); | 808 | *data1 = qRgba(r, g, b, a); |
808 | } | 809 | } |
809 | else if (type == Saturation || type == HueShift) { | 810 | else if (type == Saturation || type == HueShift) { |
810 | clr.setRgb(color1); | 811 | clr.setRgb(color1); |
811 | clr.hsv(&h, &s, &v); | 812 | clr.hsv(&h, &s, &v); |
812 | mod = (channel == Red) ? qRed(color2) : | 813 | mod = (channel == Red) ? qRed(color2) : |
813 | (channel == Green) ? qGreen(color2) : | 814 | (channel == Green) ? qGreen(color2) : |
814 | (channel == Blue) ? qBlue(color2) : | 815 | (channel == Blue) ? qBlue(color2) : |
815 | (channel == Gray) ? qGray(color2) : 0; | 816 | (channel == Gray) ? qGray(color2) : 0; |
816 | mod = mod*factor/50; | 817 | mod = mod*factor/50; |
817 | 818 | ||
818 | if (type == Saturation) { | 819 | if (type == Saturation) { |
819 | s -= s * mod/256; | 820 | s -= s * mod/256; |
820 | if (s<0) s=0; if (s>255) s=255; | 821 | if (s<0) s=0; if (s>255) s=255; |
821 | } | 822 | } |
822 | else { // HueShift | 823 | else { // HueShift |
823 | h += mod; | 824 | h += mod; |
824 | while(h<0) h+=360; | 825 | while(h<0) h+=360; |
825 | h %= 360; | 826 | h %= 360; |
826 | } | 827 | } |
827 | 828 | ||
828 | clr.setHsv(h, s, v); | 829 | clr.setHsv(h, s, v); |
829 | a = qAlpha(*data1); | 830 | a = qAlpha(*data1); |
830 | *data1 = clr.rgb() | ((uint)(a & 0xff) << 24); | 831 | *data1 = clr.rgb() | ((uint)(a & 0xff) << 24); |
831 | } | 832 | } |
832 | data1++; data2++; data2b++; x++; | 833 | data1++; data2++; data2b++; x++; |
833 | if ( (x%x2) ==0) { data2 -= x2; data2b -= x2; } | 834 | if ( (x%x2) ==0) { data2 -= x2; data2b -= x2; } |
834 | } | 835 | } |
835 | } | 836 | } |
836 | return image; | 837 | return image; |
837 | } | 838 | } |
838 | 839 | ||
839 | 840 | ||
840 | 841 | ||
841 | //====================================================================== | 842 | //====================================================================== |
842 | // | 843 | // |
843 | // Blend effects | 844 | // Blend effects |
844 | // | 845 | // |
845 | //====================================================================== | 846 | //====================================================================== |
846 | 847 | ||
847 | 848 | ||
848 | // Nice and fast direct pixel manipulation | 849 | // Nice and fast direct pixel manipulation |
849 | QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity) | 850 | QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity) |
850 | { | 851 | { |
851 | if (dst.width() <= 0 || dst.height() <= 0) | 852 | if (dst.width() <= 0 || dst.height() <= 0) |
852 | return dst; | 853 | return dst; |
853 | 854 | ||
854 | if (opacity < 0.0 || opacity > 1.0) { | 855 | if (opacity < 0.0 || opacity > 1.0) { |
855 | qDebug( "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1] "); | 856 | odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1] " << oendl; |
856 | return dst; | 857 | return dst; |
857 | } | 858 | } |
858 | 859 | ||
859 | int depth = dst.depth(); | 860 | int depth = dst.depth(); |
860 | if (depth != 32) | 861 | if (depth != 32) |
861 | dst = dst.convertDepth(32); | 862 | dst = dst.convertDepth(32); |
862 | 863 | ||
863 | int pixels = dst.width() * dst.height(); | 864 | int pixels = dst.width() * dst.height(); |
864 | int rcol, gcol, bcol; | 865 | int rcol, gcol, bcol; |
865 | clr.rgb(&rcol, &gcol, &bcol); | 866 | clr.rgb(&rcol, &gcol, &bcol); |
866 | 867 | ||
867 | #ifdef WORDS_BIGENDIAN // ARGB (skip alpha) | 868 | #ifdef WORDS_BIGENDIAN // ARGB (skip alpha) |
868 | register unsigned char *data = (unsigned char *)dst.bits() + 1; | 869 | register unsigned char *data = (unsigned char *)dst.bits() + 1; |
869 | #else // BGRA | 870 | #else // BGRA |
870 | register unsigned char *data = (unsigned char *)dst.bits(); | 871 | register unsigned char *data = (unsigned char *)dst.bits(); |
871 | #endif | 872 | #endif |
872 | 873 | ||
873 | for (register int i=0; i<pixels; i++) | 874 | for (register int i=0; i<pixels; i++) |
874 | { | 875 | { |
875 | #ifdef WORDS_BIGENDIAN | 876 | #ifdef WORDS_BIGENDIAN |
876 | *(data++) += (unsigned char)((rcol - *data) * opacity); | 877 | *(data++) += (unsigned char)((rcol - *data) * opacity); |
877 | *(data++) += (unsigned char)((gcol - *data) * opacity); | 878 | *(data++) += (unsigned char)((gcol - *data) * opacity); |
878 | *(data++) += (unsigned char)((bcol - *data) * opacity); | 879 | *(data++) += (unsigned char)((bcol - *data) * opacity); |
879 | #else | 880 | #else |
880 | *(data++) += (unsigned char)((bcol - *data) * opacity); | 881 | *(data++) += (unsigned char)((bcol - *data) * opacity); |
881 | *(data++) += (unsigned char)((gcol - *data) * opacity); | 882 | *(data++) += (unsigned char)((gcol - *data) * opacity); |
882 | *(data++) += (unsigned char)((rcol - *data) * opacity); | 883 | *(data++) += (unsigned char)((rcol - *data) * opacity); |
883 | #endif | 884 | #endif |
884 | data++; // skip alpha | 885 | data++; // skip alpha |
885 | } | 886 | } |
886 | return dst; | 887 | return dst; |
887 | } | 888 | } |
888 | 889 | ||
889 | // Nice and fast direct pixel manipulation | 890 | // Nice and fast direct pixel manipulation |
890 | QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity) | 891 | QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity) |
891 | { | 892 | { |
892 | if (src.width() <= 0 || src.height() <= 0) | 893 | if (src.width() <= 0 || src.height() <= 0) |
893 | return dst; | 894 | return dst; |
894 | if (dst.width() <= 0 || dst.height() <= 0) | 895 | if (dst.width() <= 0 || dst.height() <= 0) |
895 | return dst; | 896 | return dst; |
896 | 897 | ||
897 | if (src.width() != dst.width() || src.height() != dst.height()) { | 898 | if (src.width() != dst.width() || src.height() != dst.height()) { |
898 | qDebug( "WARNING: OImageEffect::blend : src and destination images are not the same size" ); | 899 | odebug << "WARNING: OImageEffect::blend : src and destination images are not the same size" << oendl; |
899 | return dst; | 900 | return dst; |
900 | } | 901 | } |
901 | 902 | ||
902 | if (opacity < 0.0 || opacity > 1.0) { | 903 | if (opacity < 0.0 || opacity > 1.0) { |
903 | qDebug( "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1]" ); | 904 | odebug << "WARNING: OImageEffect::blend : invalid opacity. Range [0, 1]" << oendl; |
904 | return dst; | 905 | return dst; |
905 | } | 906 | } |
906 | 907 | ||
907 | if (src.depth() != 32) src = src.convertDepth(32); | 908 | if (src.depth() != 32) src = src.convertDepth(32); |
908 | if (dst.depth() != 32) dst = dst.convertDepth(32); | 909 | if (dst.depth() != 32) dst = dst.convertDepth(32); |
909 | 910 | ||
910 | int pixels = src.width() * src.height(); | 911 | int pixels = src.width() * src.height(); |
911 | #ifdef WORDS_BIGENDIAN // ARGB (skip alpha) | 912 | #ifdef WORDS_BIGENDIAN // ARGB (skip alpha) |
912 | register unsigned char *data1 = (unsigned char *)dst.bits() + 1; | 913 | register unsigned char *data1 = (unsigned char *)dst.bits() + 1; |
913 | register unsigned char *data2 = (unsigned char *)src.bits() + 1; | 914 | register unsigned char *data2 = (unsigned char *)src.bits() + 1; |
914 | #else // BGRA | 915 | #else // BGRA |
915 | register unsigned char *data1 = (unsigned char *)dst.bits(); | 916 | register unsigned char *data1 = (unsigned char *)dst.bits(); |
916 | register unsigned char *data2 = (unsigned char *)src.bits(); | 917 | register unsigned char *data2 = (unsigned char *)src.bits(); |
917 | #endif | 918 | #endif |
918 | 919 | ||
919 | for (register int i=0; i<pixels; i++) | 920 | for (register int i=0; i<pixels; i++) |
920 | { | 921 | { |
921 | #ifdef WORDS_BIGENDIAN | 922 | #ifdef WORDS_BIGENDIAN |
922 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); | 923 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); |
923 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); | 924 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); |
924 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); | 925 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); |
925 | #else | 926 | #else |
926 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); | 927 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); |
927 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); | 928 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); |
928 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); | 929 | *(data1++) += (unsigned char)((*(data2++) - *data1) * opacity); |
929 | #endif | 930 | #endif |
930 | data1++; // skip alpha | 931 | data1++; // skip alpha |
931 | data2++; | 932 | data2++; |
932 | } | 933 | } |
933 | 934 | ||
934 | return dst; | 935 | return dst; |
935 | } | 936 | } |
936 | 937 | ||
937 | 938 | ||
938 | QImage& OImageEffect::blend(QImage &image, float initial_intensity, | 939 | QImage& OImageEffect::blend(QImage &image, float initial_intensity, |
939 | const QColor &bgnd, GradientType eff, | 940 | const QColor &bgnd, GradientType eff, |
940 | bool anti_dir) | 941 | bool anti_dir) |
941 | { | 942 | { |
942 | if (image.width() == 0 || image.height() == 0 || image.depth()!=32 ) { | 943 | if (image.width() == 0 || image.height() == 0 || image.depth()!=32 ) { |
943 | qDebug( "WARNING: OImageEffect::blend : invalid image" ); | 944 | odebug << "WARNING: OImageEffect::blend : invalid image" << oendl; |
944 | return image; | 945 | return image; |
945 | } | 946 | } |
946 | 947 | ||
947 | int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue(); | 948 | int r_bgnd = bgnd.red(), g_bgnd = bgnd.green(), b_bgnd = bgnd.blue(); |
948 | int r, g, b; | 949 | int r, g, b; |
949 | int ind; | 950 | int ind; |
950 | 951 | ||
951 | unsigned int xi, xf, yi, yf; | 952 | unsigned int xi, xf, yi, yf; |
952 | unsigned int a; | 953 | unsigned int a; |
953 | 954 | ||
954 | // check the boundaries of the initial intesity param | 955 | // check the boundaries of the initial intesity param |
955 | float unaffected = 1; | 956 | float unaffected = 1; |
956 | if (initial_intensity > 1) initial_intensity = 1; | 957 | if (initial_intensity > 1) initial_intensity = 1; |
957 | if (initial_intensity < -1) initial_intensity = -1; | 958 | if (initial_intensity < -1) initial_intensity = -1; |
958 | if (initial_intensity < 0) { | 959 | if (initial_intensity < 0) { |
959 | unaffected = 1. + initial_intensity; | 960 | unaffected = 1. + initial_intensity; |
960 | initial_intensity = 0; | 961 | initial_intensity = 0; |
961 | } | 962 | } |
962 | 963 | ||
963 | 964 | ||
964 | float intensity = initial_intensity; | 965 | float intensity = initial_intensity; |
965 | float var = 1. - initial_intensity; | 966 | float var = 1. - initial_intensity; |
966 | 967 | ||
967 | if (anti_dir) { | 968 | if (anti_dir) { |
968 | initial_intensity = intensity = 1.; | 969 | initial_intensity = intensity = 1.; |
969 | var = -var; | 970 | var = -var; |
970 | } | 971 | } |
971 | 972 | ||
972 | register int x, y; | 973 | register int x, y; |
973 | 974 | ||
974 | unsigned int *data = (unsigned int *)image.bits(); | 975 | unsigned int *data = (unsigned int *)image.bits(); |
975 | 976 | ||
976 | int image_width = image.width(); //Those can't change | 977 | int image_width = image.width(); //Those can't change |
977 | int image_height = image.height(); | 978 | int image_height = image.height(); |
978 | 979 | ||
979 | 980 | ||
980 | if( eff == VerticalGradient || eff == HorizontalGradient ) { | 981 | if( eff == VerticalGradient || eff == HorizontalGradient ) { |
981 | 982 | ||
982 | // set the image domain to apply the effect to | 983 | // set the image domain to apply the effect to |
983 | xi = 0, xf = image_width; | 984 | xi = 0, xf = image_width; |
984 | yi = 0, yf = image_height; | 985 | yi = 0, yf = image_height; |
985 | if (eff == VerticalGradient) { | 986 | if (eff == VerticalGradient) { |
986 | if (anti_dir) yf = (int)(image_height * unaffected); | 987 | if (anti_dir) yf = (int)(image_height * unaffected); |
987 | else yi = (int)(image_height * (1 - unaffected)); | 988 | else yi = (int)(image_height * (1 - unaffected)); |
988 | } | 989 | } |
989 | else { | 990 | else { |
990 | if (anti_dir) xf = (int)(image_width * unaffected); | 991 | if (anti_dir) xf = (int)(image_width * unaffected); |
991 | else xi = (int)(image_height * (1 - unaffected)); | 992 | else xi = (int)(image_height * (1 - unaffected)); |
992 | } | 993 | } |
993 | 994 | ||
994 | var /= (eff == VerticalGradient?yf-yi:xf-xi); | 995 | var /= (eff == VerticalGradient?yf-yi:xf-xi); |
995 | 996 | ||
996 | int ind_base; | 997 | int ind_base; |
997 | for (y = yi; y < (int)yf; y++) { | 998 | for (y = yi; y < (int)yf; y++) { |
998 | intensity = eff == VerticalGradient? intensity + var : | 999 | intensity = eff == VerticalGradient? intensity + var : |
999 | initial_intensity; | 1000 | initial_intensity; |
1000 | ind_base = image_width * y ; | 1001 | ind_base = image_width * y ; |
1001 | for (x = xi; x < (int)xf ; x++) { | 1002 | for (x = xi; x < (int)xf ; x++) { |
1002 | if (eff == HorizontalGradient) intensity += var; | 1003 | if (eff == HorizontalGradient) intensity += var; |
1003 | ind = x + ind_base; | 1004 | ind = x + ind_base; |
1004 | r = qRed (data[ind]) + (int)(intensity * | 1005 | r = qRed (data[ind]) + (int)(intensity * |
1005 | (r_bgnd - qRed (data[ind]))); | 1006 | (r_bgnd - qRed (data[ind]))); |
1006 | g = qGreen(data[ind]) + (int)(intensity * | 1007 | g = qGreen(data[ind]) + (int)(intensity * |
1007 | (g_bgnd - qGreen(data[ind]))); | 1008 | (g_bgnd - qGreen(data[ind]))); |
1008 | b = qBlue (data[ind]) + (int)(intensity * | 1009 | b = qBlue (data[ind]) + (int)(intensity * |
1009 | (b_bgnd - qBlue (data[ind]))); | 1010 | (b_bgnd - qBlue (data[ind]))); |
1010 | if (r > 255) r = 255; if (r < 0 ) r = 0; | 1011 | if (r > 255) r = 255; if (r < 0 ) r = 0; |
1011 | if (g > 255) g = 255; if (g < 0 ) g = 0; | 1012 | if (g > 255) g = 255; if (g < 0 ) g = 0; |
1012 | if (b > 255) b = 255; if (b < 0 ) b = 0; | 1013 | if (b > 255) b = 255; if (b < 0 ) b = 0; |
1013 | a = qAlpha(data[ind]); | 1014 | a = qAlpha(data[ind]); |
1014 | data[ind] = qRgba(r, g, b, a); | 1015 | data[ind] = qRgba(r, g, b, a); |
1015 | } | 1016 | } |
1016 | } | 1017 | } |
1017 | } | 1018 | } |
1018 | else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) { | 1019 | else if (eff == DiagonalGradient || eff == CrossDiagonalGradient) { |
1019 | float xvar = var / 2 / image_width; // / unaffected; | 1020 | float xvar = var / 2 / image_width; // / unaffected; |
1020 | float yvar = var / 2 / image_height; // / unaffected; | 1021 | float yvar = var / 2 / image_height; // / unaffected; |
1021 | float tmp; | 1022 | float tmp; |
1022 | 1023 | ||
1023 | for (x = 0; x < image_width ; x++) { | 1024 | for (x = 0; x < image_width ; x++) { |
1024 | tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1); | 1025 | tmp = xvar * (eff == DiagonalGradient? x : image.width()-x-1); |
1025 | ind = x; | 1026 | ind = x; |
1026 | for (y = 0; y < image_height ; y++) { | 1027 | for (y = 0; y < image_height ; y++) { |
1027 | intensity = initial_intensity + tmp + yvar * y; | 1028 | intensity = initial_intensity + tmp + yvar * y; |
1028 | 1029 | ||
1029 | r = qRed (data[ind]) + (int)(intensity * | 1030 | r = qRed (data[ind]) + (int)(intensity * |
1030 | (r_bgnd - qRed (data[ind]))); | 1031 | (r_bgnd - qRed (data[ind]))); |
1031 | g = qGreen(data[ind]) + (int)(intensity * | 1032 | g = qGreen(data[ind]) + (int)(intensity * |
1032 | (g_bgnd - qGreen(data[ind]))); | 1033 | (g_bgnd - qGreen(data[ind]))); |
1033 | b = qBlue (data[ind]) + (int)(intensity * | 1034 | b = qBlue (data[ind]) + (int)(intensity * |
1034 | (b_bgnd - qBlue (data[ind]))); | 1035 | (b_bgnd - qBlue (data[ind]))); |
1035 | if (r > 255) r = 255; if (r < 0 ) r = 0; | 1036 | if (r > 255) r = 255; if (r < 0 ) r = 0; |
1036 | if (g > 255) g = 255; if (g < 0 ) g = 0; | 1037 | if (g > 255) g = 255; if (g < 0 ) g = 0; |
1037 | if (b > 255) b = 255; if (b < 0 ) b = 0; | 1038 | if (b > 255) b = 255; if (b < 0 ) b = 0; |
1038 | a = qAlpha(data[ind]); | 1039 | a = qAlpha(data[ind]); |
1039 | data[ind] = qRgba(r, g, b, a); | 1040 | data[ind] = qRgba(r, g, b, a); |
1040 | 1041 | ||
1041 | ind += image_width; | 1042 | ind += image_width; |
1042 | } | 1043 | } |
1043 | } | 1044 | } |
1044 | } | 1045 | } |
1045 | 1046 | ||
1046 | else if (eff == RectangleGradient || eff == EllipticGradient) { | 1047 | else if (eff == RectangleGradient || eff == EllipticGradient) { |
1047 | float xvar; | 1048 | float xvar; |
1048 | float yvar; | 1049 | float yvar; |
1049 | 1050 | ||
1050 | for (x = 0; x < image_width / 2 + image_width % 2; x++) { | 1051 | for (x = 0; x < image_width / 2 + image_width % 2; x++) { |
1051 | xvar = var / image_width * (image_width - x*2/unaffected-1); | 1052 | xvar = var / image_width * (image_width - x*2/unaffected-1); |
1052 | for (y = 0; y < image_height / 2 + image_height % 2; y++) { | 1053 | for (y = 0; y < image_height / 2 + image_height % 2; y++) { |
1053 | yvar = var / image_height * (image_height - y*2/unaffected -1); | 1054 | yvar = var / image_height * (image_height - y*2/unaffected -1); |
1054 | 1055 | ||
1055 | if (eff == RectangleGradient) | 1056 | if (eff == RectangleGradient) |
1056 | intensity = initial_intensity + QMAX(xvar, yvar); | 1057 | intensity = initial_intensity + QMAX(xvar, yvar); |
1057 | else | 1058 | else |
1058 | intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar); | 1059 | intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar); |
1059 | if (intensity > 1) intensity = 1; | 1060 | if (intensity > 1) intensity = 1; |
1060 | if (intensity < 0) intensity = 0; | 1061 | if (intensity < 0) intensity = 0; |
1061 | 1062 | ||
1062 | //NW | 1063 | //NW |
1063 | ind = x + image_width * y ; | 1064 | ind = x + image_width * y ; |
1064 | r = qRed (data[ind]) + (int)(intensity * | 1065 | r = qRed (data[ind]) + (int)(intensity * |
1065 | (r_bgnd - qRed (data[ind]))); | 1066 | (r_bgnd - qRed (data[ind]))); |
1066 | g = qGreen(data[ind]) + (int)(intensity * | 1067 | g = qGreen(data[ind]) + (int)(intensity * |
1067 | (g_bgnd - qGreen(data[ind]))); | 1068 | (g_bgnd - qGreen(data[ind]))); |
1068 | b = qBlue (data[ind]) + (int)(intensity * | 1069 | b = qBlue (data[ind]) + (int)(intensity * |
1069 | (b_bgnd - qBlue (data[ind]))); | 1070 | (b_bgnd - qBlue (data[ind]))); |
1070 | if (r > 255) r = 255; if (r < 0 ) r = 0; | 1071 | if (r > 255) r = 255; if (r < 0 ) r = 0; |
1071 | if (g > 255) g = 255; if (g < 0 ) g = 0; | 1072 | if (g > 255) g = 255; if (g < 0 ) g = 0; |
1072 | if (b > 255) b = 255; if (b < 0 ) b = 0; | 1073 | if (b > 255) b = 255; if (b < 0 ) b = 0; |
1073 | a = qAlpha(data[ind]); | 1074 | a = qAlpha(data[ind]); |
1074 | data[ind] = qRgba(r, g, b, a); | 1075 | data[ind] = qRgba(r, g, b, a); |
1075 | 1076 | ||
1076 | //NE | 1077 | //NE |
1077 | ind = image_width - x - 1 + image_width * y ; | 1078 | ind = image_width - x - 1 + image_width * y ; |
1078 | r = qRed (data[ind]) + (int)(intensity * | 1079 | r = qRed (data[ind]) + (int)(intensity * |
1079 | (r_bgnd - qRed (data[ind]))); | 1080 | (r_bgnd - qRed (data[ind]))); |
1080 | g = qGreen(data[ind]) + (int)(intensity * | 1081 | g = qGreen(data[ind]) + (int)(intensity * |
1081 | (g_bgnd - qGreen(data[ind]))); | 1082 | (g_bgnd - qGreen(data[ind]))); |
1082 | b = qBlue (data[ind]) + (int)(intensity * | 1083 | b = qBlue (data[ind]) + (int)(intensity * |
1083 | (b_bgnd - qBlue (data[ind]))); | 1084 | (b_bgnd - qBlue (data[ind]))); |
1084 | if (r > 255) r = 255; if (r < 0 ) r = 0; | 1085 | if (r > 255) r = 255; if (r < 0 ) r = 0; |
1085 | if (g > 255) g = 255; if (g < 0 ) g = 0; | 1086 | if (g > 255) g = 255; if (g < 0 ) g = 0; |
1086 | if (b > 255) b = 255; if (b < 0 ) b = 0; | 1087 | if (b > 255) b = 255; if (b < 0 ) b = 0; |
1087 | a = qAlpha(data[ind]); | 1088 | a = qAlpha(data[ind]); |
1088 | data[ind] = qRgba(r, g, b, a); | 1089 | data[ind] = qRgba(r, g, b, a); |
1089 | } | 1090 | } |
1090 | } | 1091 | } |
1091 | 1092 | ||
1092 | //CT loop is doubled because of stupid central row/column issue. | 1093 | //CT loop is doubled because of stupid central row/column issue. |
1093 | // other solution? | 1094 | // other solution? |
1094 | for (x = 0; x < image_width / 2; x++) { | 1095 | for (x = 0; x < image_width / 2; x++) { |
1095 | xvar = var / image_width * (image_width - x*2/unaffected-1); | 1096 | xvar = var / image_width * (image_width - x*2/unaffected-1); |
1096 | for (y = 0; y < image_height / 2; y++) { | 1097 | for (y = 0; y < image_height / 2; y++) { |
1097 | yvar = var / image_height * (image_height - y*2/unaffected -1); | 1098 | yvar = var / image_height * (image_height - y*2/unaffected -1); |
1098 | 1099 | ||
1099 | if (eff == RectangleGradient) | 1100 | if (eff == RectangleGradient) |
1100 | intensity = initial_intensity + QMAX(xvar, yvar); | 1101 | intensity = initial_intensity + QMAX(xvar, yvar); |
1101 | else | 1102 | else |
1102 | intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar); | 1103 | intensity = initial_intensity + sqrt(xvar * xvar + yvar * yvar); |
1103 | if (intensity > 1) intensity = 1; | 1104 | if (intensity > 1) intensity = 1; |
1104 | if (intensity < 0) intensity = 0; | 1105 | if (intensity < 0) intensity = 0; |
1105 | 1106 | ||
1106 | //SW | 1107 | //SW |
1107 | ind = x + image_width * (image_height - y -1) ; | 1108 | ind = x + image_width * (image_height - y -1) ; |
1108 | r = qRed (data[ind]) + (int)(intensity * | 1109 | r = qRed (data[ind]) + (int)(intensity * |
1109 | (r_bgnd - qRed (data[ind]))); | 1110 | (r_bgnd - qRed (data[ind]))); |
1110 | g = qGreen(data[ind]) + (int)(intensity * | 1111 | g = qGreen(data[ind]) + (int)(intensity * |
1111 | (g_bgnd - qGreen(data[ind]))); | 1112 | (g_bgnd - qGreen(data[ind]))); |
1112 | b = qBlue (data[ind]) + (int)(intensity * | 1113 | b = qBlue (data[ind]) + (int)(intensity * |
1113 | (b_bgnd - qBlue (data[ind]))); | 1114 | (b_bgnd - qBlue (data[ind]))); |
1114 | if (r > 255) r = 255; if (r < 0 ) r = 0; | 1115 | if (r > 255) r = 255; if (r < 0 ) r = 0; |
1115 | if (g > 255) g = 255; if (g < 0 ) g = 0; | 1116 | if (g > 255) g = 255; if (g < 0 ) g = 0; |
1116 | if (b > 255) b = 255; if (b < 0 ) b = 0; | 1117 | if (b > 255) b = 255; if (b < 0 ) b = 0; |
1117 | a = qAlpha(data[ind]); | 1118 | a = qAlpha(data[ind]); |
1118 | data[ind] = qRgba(r, g, b, a); | 1119 | data[ind] = qRgba(r, g, b, a); |
1119 | 1120 | ||
1120 | //SE | 1121 | //SE |
1121 | ind = image_width-x-1 + image_width * (image_height - y - 1) ; | 1122 | ind = image_width-x-1 + image_width * (image_height - y - 1) ; |
1122 | r = qRed (data[ind]) + (int)(intensity * | 1123 | r = qRed (data[ind]) + (int)(intensity * |
1123 | (r_bgnd - qRed (data[ind]))); | 1124 | (r_bgnd - qRed (data[ind]))); |
1124 | g = qGreen(data[ind]) + (int)(intensity * | 1125 | g = qGreen(data[ind]) + (int)(intensity * |
1125 | (g_bgnd - qGreen(data[ind]))); | 1126 | (g_bgnd - qGreen(data[ind]))); |
1126 | b = qBlue (data[ind]) + (int)(intensity * | 1127 | b = qBlue (data[ind]) + (int)(intensity * |
1127 | (b_bgnd - qBlue (data[ind]))); | 1128 | (b_bgnd - qBlue (data[ind]))); |
1128 | if (r > 255) r = 255; if (r < 0 ) r = 0; | 1129 | if (r > 255) r = 255; if (r < 0 ) r = 0; |
1129 | if (g > 255) g = 255; if (g < 0 ) g = 0; | 1130 | if (g > 255) g = 255; if (g < 0 ) g = 0; |
1130 | if (b > 255) b = 255; if (b < 0 ) b = 0; | 1131 | if (b > 255) b = 255; if (b < 0 ) b = 0; |
1131 | a = qAlpha(data[ind]); | 1132 | a = qAlpha(data[ind]); |
1132 | data[ind] = qRgba(r, g, b, a); | 1133 | data[ind] = qRgba(r, g, b, a); |
1133 | } | 1134 | } |
1134 | } | 1135 | } |
1135 | } | 1136 | } |
1136 | else qDebug( "OImageEffect::blend effect not implemented" ); | 1137 | else odebug << "OImageEffect::blend effect not implemented" << oendl; |
1137 | return image; | 1138 | return image; |
1138 | } | 1139 | } |
1139 | 1140 | ||
1140 | // Not very efficient as we create a third big image... | 1141 | // Not very efficient as we create a third big image... |
1141 | // | 1142 | // |
1142 | QImage& OImageEffect::blend(QImage &image1, QImage &image2, | 1143 | QImage& OImageEffect::blend(QImage &image1, QImage &image2, |
1143 | GradientType gt, int xf, int yf) | 1144 | GradientType gt, int xf, int yf) |
1144 | { | 1145 | { |
1145 | if (image1.width() == 0 || image1.height() == 0 || | 1146 | if (image1.width() == 0 || image1.height() == 0 || |
1146 | image2.width() == 0 || image2.height() == 0) | 1147 | image2.width() == 0 || image2.height() == 0) |
1147 | return image1; | 1148 | return image1; |
1148 | 1149 | ||
1149 | QImage image3; | 1150 | QImage image3; |
1150 | 1151 | ||
1151 | image3 = OImageEffect::unbalancedGradient(image1.size(), | 1152 | image3 = OImageEffect::unbalancedGradient(image1.size(), |
1152 | QColor(0,0,0), QColor(255,255,255), | 1153 | QColor(0,0,0), QColor(255,255,255), |
1153 | gt, xf, yf, 0); | 1154 | gt, xf, yf, 0); |
1154 | 1155 | ||
1155 | return blend(image1,image2,image3, Red); // Channel to use is arbitrary | 1156 | return blend(image1,image2,image3, Red); // Channel to use is arbitrary |
1156 | } | 1157 | } |
1157 | 1158 | ||
1158 | // Blend image2 into image1, using an RBG channel of blendImage | 1159 | // Blend image2 into image1, using an RBG channel of blendImage |
1159 | // | 1160 | // |
1160 | QImage& OImageEffect::blend(QImage &image1, QImage &image2, | 1161 | QImage& OImageEffect::blend(QImage &image1, QImage &image2, |
1161 | QImage &blendImage, RGBComponent channel) | 1162 | QImage &blendImage, RGBComponent channel) |
1162 | { | 1163 | { |
1163 | if (image1.width() == 0 || image1.height() == 0 || | 1164 | if (image1.width() == 0 || image1.height() == 0 || |
1164 | image2.width() == 0 || image2.height() == 0 || | 1165 | image2.width() == 0 || image2.height() == 0 || |
1165 | blendImage.width() == 0 || blendImage.height() == 0) { | 1166 | blendImage.width() == 0 || blendImage.height() == 0) { |
1166 | qDebug( "OImageEffect::blend effect invalid image" ); | 1167 | odebug << "OImageEffect::blend effect invalid image" << oendl; |
1167 | return image1; | 1168 | return image1; |
1168 | } | 1169 | } |
1169 | 1170 | ||
1170 | int r, g, b; | 1171 | int r, g, b; |
1171 | int ind1, ind2, ind3; | 1172 | int ind1, ind2, ind3; |
1172 | 1173 | ||
1173 | unsigned int x1, x2, x3, y1, y2, y3; | 1174 | unsigned int x1, x2, x3, y1, y2, y3; |
1174 | unsigned int a; | 1175 | unsigned int a; |
1175 | 1176 | ||
1176 | register int x, y; | 1177 | register int x, y; |
1177 | 1178 | ||
1178 | // for image1 and image2, we only handle depth 32 | 1179 | // for image1 and image2, we only handle depth 32 |
1179 | if (image1.depth()<32) image1 = image1.convertDepth(32); | 1180 | if (image1.depth()<32) image1 = image1.convertDepth(32); |
1180 | if (image2.depth()<32) image2 = image2.convertDepth(32); | 1181 | if (image2.depth()<32) image2 = image2.convertDepth(32); |
1181 | 1182 | ||
1182 | // for blendImage, we handle depth 8 and 32 | 1183 | // for blendImage, we handle depth 8 and 32 |
1183 | if (blendImage.depth()<8) blendImage = blendImage.convertDepth(8); | 1184 | if (blendImage.depth()<8) blendImage = blendImage.convertDepth(8); |
1184 | 1185 | ||
1185 | unsigned int *colorTable3 = (blendImage.depth()==8) ? | 1186 | unsigned int *colorTable3 = (blendImage.depth()==8) ? |
1186 | blendImage.colorTable():0; | 1187 | blendImage.colorTable():0; |
1187 | 1188 | ||
1188 | unsigned int *data1 = (unsigned int *)image1.bits(); | 1189 | unsigned int *data1 = (unsigned int *)image1.bits(); |
1189 | unsigned int *data2 = (unsigned int *)image2.bits(); | 1190 | unsigned int *data2 = (unsigned int *)image2.bits(); |
1190 | unsigned int *data3 = (unsigned int *)blendImage.bits(); | 1191 | unsigned int *data3 = (unsigned int *)blendImage.bits(); |
1191 | unsigned char *data3b = (unsigned char *)blendImage.bits(); | 1192 | unsigned char *data3b = (unsigned char *)blendImage.bits(); |
1192 | unsigned int color3; | 1193 | unsigned int color3; |
1193 | 1194 | ||
1194 | x1 = image1.width(); y1 = image1.height(); | 1195 | x1 = image1.width(); y1 = image1.height(); |
1195 | x2 = image2.width(); y2 = image2.height(); | 1196 | x2 = image2.width(); y2 = image2.height(); |
1196 | x3 = blendImage.width(); y3 = blendImage.height(); | 1197 | x3 = blendImage.width(); y3 = blendImage.height(); |
1197 | 1198 | ||
1198 | for (y = 0; y < (int)y1; y++) { | 1199 | for (y = 0; y < (int)y1; y++) { |
1199 | ind1 = x1*y; | 1200 | ind1 = x1*y; |
1200 | ind2 = x2*(y%y2); | 1201 | ind2 = x2*(y%y2); |
1201 | ind3 = x3*(y%y3); | 1202 | ind3 = x3*(y%y3); |
1202 | 1203 | ||
1203 | x=0; | 1204 | x=0; |
1204 | while(x < (int)x1) { | 1205 | while(x < (int)x1) { |
1205 | color3 = (colorTable3) ? colorTable3[data3b[ind3]] : data3[ind3]; | 1206 | color3 = (colorTable3) ? colorTable3[data3b[ind3]] : data3[ind3]; |
1206 | 1207 | ||
1207 | a = (channel == Red) ? qRed(color3) : | 1208 | a = (channel == Red) ? qRed(color3) : |
1208 | (channel == Green) ? qGreen(color3) : | 1209 | (channel == Green) ? qGreen(color3) : |
1209 | (channel == Blue) ? qBlue(color3) : qGray(color3); | 1210 | (channel == Blue) ? qBlue(color3) : qGray(color3); |
1210 | 1211 | ||
1211 | r = (a*qRed(data1[ind1]) + (256-a)*qRed(data2[ind2]))/256; | 1212 | r = (a*qRed(data1[ind1]) + (256-a)*qRed(data2[ind2]))/256; |
1212 | g = (a*qGreen(data1[ind1]) + (256-a)*qGreen(data2[ind2]))/256; | 1213 | g = (a*qGreen(data1[ind1]) + (256-a)*qGreen(data2[ind2]))/256; |
1213 | b = (a*qBlue(data1[ind1]) + (256-a)*qBlue(data2[ind2]))/256; | 1214 | b = (a*qBlue(data1[ind1]) + (256-a)*qBlue(data2[ind2]))/256; |
1214 | 1215 | ||
1215 | a = qAlpha(data1[ind1]); | 1216 | a = qAlpha(data1[ind1]); |
1216 | data1[ind1] = qRgba(r, g, b, a); | 1217 | data1[ind1] = qRgba(r, g, b, a); |
1217 | 1218 | ||
1218 | ind1++; ind2++; ind3++; x++; | 1219 | ind1++; ind2++; ind3++; x++; |
1219 | if ( (x%x2) ==0) ind2 -= x2; | 1220 | if ( (x%x2) ==0) ind2 -= x2; |
1220 | if ( (x%x3) ==0) ind3 -= x3; | 1221 | if ( (x%x3) ==0) ind3 -= x3; |
1221 | } | 1222 | } |
1222 | } | 1223 | } |
1223 | return image1; | 1224 | return image1; |
1224 | } | 1225 | } |
1225 | 1226 | ||
1226 | 1227 | ||
1227 | //====================================================================== | 1228 | //====================================================================== |
1228 | // | 1229 | // |
1229 | // Hash effects | 1230 | // Hash effects |
1230 | // | 1231 | // |
1231 | //====================================================================== | 1232 | //====================================================================== |
1232 | 1233 | ||
1233 | unsigned int OImageEffect::lHash(unsigned int c) | 1234 | unsigned int OImageEffect::lHash(unsigned int c) |
1234 | { | 1235 | { |
1235 | unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c); | 1236 | unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c); |
1236 | unsigned char nr, ng, nb; | 1237 | unsigned char nr, ng, nb; |
1237 | nr =(r >> 1) + (r >> 2); nr = nr > r ? 0 : nr; | 1238 | nr =(r >> 1) + (r >> 2); nr = nr > r ? 0 : nr; |
1238 | ng =(g >> 1) + (g >> 2); ng = ng > g ? 0 : ng; | 1239 | ng =(g >> 1) + (g >> 2); ng = ng > g ? 0 : ng; |
1239 | nb =(b >> 1) + (b >> 2); nb = nb > b ? 0 : nb; | 1240 | nb =(b >> 1) + (b >> 2); nb = nb > b ? 0 : nb; |
1240 | 1241 | ||
1241 | return qRgba(nr, ng, nb, a); | 1242 | return qRgba(nr, ng, nb, a); |
1242 | } | 1243 | } |
1243 | 1244 | ||
1244 | 1245 | ||
1245 | // ----------------------------------------------------------------------------- | 1246 | // ----------------------------------------------------------------------------- |
1246 | 1247 | ||
1247 | unsigned int OImageEffect::uHash(unsigned int c) | 1248 | unsigned int OImageEffect::uHash(unsigned int c) |
1248 | { | 1249 | { |
1249 | unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c); | 1250 | unsigned char r = qRed(c), g = qGreen(c), b = qBlue(c), a = qAlpha(c); |
1250 | unsigned char nr, ng, nb; | 1251 | unsigned char nr, ng, nb; |
1251 | nr = r + (r >> 3); nr = nr < r ? ~0 : nr; | 1252 | nr = r + (r >> 3); nr = nr < r ? ~0 : nr; |
1252 | ng = g + (g >> 3); ng = ng < g ? ~0 : ng; | 1253 | ng = g + (g >> 3); ng = ng < g ? ~0 : ng; |
1253 | nb = b + (b >> 3); nb = nb < b ? ~0 : nb; | 1254 | nb = b + (b >> 3); nb = nb < b ? ~0 : nb; |
1254 | 1255 | ||
1255 | return qRgba(nr, ng, nb, a); | 1256 | return qRgba(nr, ng, nb, a); |
1256 | } | 1257 | } |
1257 | 1258 | ||
1258 | 1259 | ||
1259 | // ----------------------------------------------------------------------------- | 1260 | // ----------------------------------------------------------------------------- |
1260 | 1261 | ||
1261 | QImage& OImageEffect::hash(QImage &image, Lighting lite, unsigned int spacing) | 1262 | QImage& OImageEffect::hash(QImage &image, Lighting lite, unsigned int spacing) |
1262 | { | 1263 | { |
1263 | if (image.width() == 0 || image.height() == 0) { | 1264 | if (image.width() == 0 || image.height() == 0) { |
1264 | qDebug( "OImageEffect::hash effect invalid image" ); | 1265 | odebug << "OImageEffect::hash effect invalid image" << oendl; |
1265 | return image; | 1266 | return image; |
1266 | } | 1267 | } |
1267 | 1268 | ||
1268 | register int x, y; | 1269 | register int x, y; |
1269 | unsigned int *data = (unsigned int *)image.bits(); | 1270 | unsigned int *data = (unsigned int *)image.bits(); |
1270 | unsigned int ind; | 1271 | unsigned int ind; |
1271 | 1272 | ||
1272 | //CT no need to do it if not enough space | 1273 | //CT no need to do it if not enough space |
1273 | if ((lite == NorthLite || | 1274 | if ((lite == NorthLite || |
1274 | lite == SouthLite)&& | 1275 | lite == SouthLite)&& |
1275 | (unsigned)image.height() < 2+spacing) return image; | 1276 | (unsigned)image.height() < 2+spacing) return image; |
1276 | if ((lite == EastLite || | 1277 | if ((lite == EastLite || |
1277 | lite == WestLite)&& | 1278 | lite == WestLite)&& |
1278 | (unsigned)image.height() < 2+spacing) return image; | 1279 | (unsigned)image.height() < 2+spacing) return image; |
1279 | 1280 | ||
1280 | if (lite == NorthLite || lite == SouthLite) { | 1281 | if (lite == NorthLite || lite == SouthLite) { |
1281 | for (y = 0 ; y < image.height(); y = y + 2 + spacing) { | 1282 | for (y = 0 ; y < image.height(); y = y + 2 + spacing) { |
1282 | for (x = 0; x < image.width(); x++) { | 1283 | for (x = 0; x < image.width(); x++) { |
1283 | ind = x + image.width() * y; | 1284 | ind = x + image.width() * y; |
1284 | data[ind] = lite==NorthLite?uHash(data[ind]):lHash(data[ind]); | 1285 | data[ind] = lite==NorthLite?uHash(data[ind]):lHash(data[ind]); |
1285 | 1286 | ||
1286 | ind = ind + image.width(); | 1287 | ind = ind + image.width(); |
1287 | data[ind] = lite==NorthLite?lHash(data[ind]):uHash(data[ind]); | 1288 | data[ind] = lite==NorthLite?lHash(data[ind]):uHash(data[ind]); |
1288 | } | 1289 | } |
1289 | } | 1290 | } |
1290 | } | 1291 | } |
1291 | 1292 | ||
1292 | else if (lite == EastLite || lite == WestLite) { | 1293 | else if (lite == EastLite || lite == WestLite) { |
1293 | for (y = 0 ; y < image.height(); y++) { | 1294 | for (y = 0 ; y < image.height(); y++) { |
1294 | for (x = 0; x < image.width(); x = x + 2 + spacing) { | 1295 | for (x = 0; x < image.width(); x = x + 2 + spacing) { |
1295 | ind = x + image.width() * y; | 1296 | ind = x + image.width() * y; |
1296 | data[ind] = lite==EastLite?uHash(data[ind]):lHash(data[ind]); | 1297 | data[ind] = lite==EastLite?uHash(data[ind]):lHash(data[ind]); |
1297 | 1298 | ||
1298 | ind++; | 1299 | ind++; |
1299 | data[ind] = lite==EastLite?lHash(data[ind]):uHash(data[ind]); | 1300 | data[ind] = lite==EastLite?lHash(data[ind]):uHash(data[ind]); |
1300 | } | 1301 | } |
1301 | } | 1302 | } |
1302 | } | 1303 | } |
1303 | 1304 | ||
1304 | else if (lite == NWLite || lite == SELite) { | 1305 | else if (lite == NWLite || lite == SELite) { |
1305 | for (y = 0 ; y < image.height(); y++) { | 1306 | for (y = 0 ; y < image.height(); y++) { |
1306 | for (x = 0; | 1307 | for (x = 0; |
1307 | x < (int)(image.width() - ((y & 1)? 1 : 0) * spacing); | 1308 | x < (int)(image.width() - ((y & 1)? 1 : 0) * spacing); |
1308 | x = x + 2 + spacing) { | 1309 | x = x + 2 + spacing) { |
1309 | ind = x + image.width() * y + ((y & 1)? 1 : 0); | 1310 | ind = x + image.width() * y + ((y & 1)? 1 : 0); |
1310 | data[ind] = lite==NWLite?uHash(data[ind]):lHash(data[ind]); | 1311 | data[ind] = lite==NWLite?uHash(data[ind]):lHash(data[ind]); |
1311 | 1312 | ||
1312 | ind++; | 1313 | ind++; |
1313 | data[ind] = lite==NWLite?lHash(data[ind]):uHash(data[ind]); | 1314 | data[ind] = lite==NWLite?lHash(data[ind]):uHash(data[ind]); |
1314 | } | 1315 | } |
1315 | } | 1316 | } |
1316 | } | 1317 | } |
1317 | 1318 | ||
1318 | else if (lite == SWLite || lite == NELite) { | 1319 | else if (lite == SWLite || lite == NELite) { |
1319 | for (y = 0 ; y < image.height(); y++) { | 1320 | for (y = 0 ; y < image.height(); y++) { |
1320 | for (x = 0 + ((y & 1)? 1 : 0); x < image.width(); x = x + 2 + spacing) { | 1321 | for (x = 0 + ((y & 1)? 1 : 0); x < image.width(); x = x + 2 + spacing) { |
1321 | ind = x + image.width() * y - ((y & 1)? 1 : 0); | 1322 | ind = x + image.width() * y - ((y & 1)? 1 : 0); |
1322 | data[ind] = lite==SWLite?uHash(data[ind]):lHash(data[ind]); | 1323 | data[ind] = lite==SWLite?uHash(data[ind]):lHash(data[ind]); |
1323 | 1324 | ||
1324 | ind++; | 1325 | ind++; |
1325 | data[ind] = lite==SWLite?lHash(data[ind]):uHash(data[ind]); | 1326 | data[ind] = lite==SWLite?lHash(data[ind]):uHash(data[ind]); |
1326 | } | 1327 | } |
1327 | } | 1328 | } |
1328 | } | 1329 | } |
1329 | 1330 | ||
1330 | return image; | 1331 | return image; |
1331 | } | 1332 | } |
1332 | 1333 | ||
1333 | 1334 | ||
1334 | //====================================================================== | 1335 | //====================================================================== |
1335 | // | 1336 | // |
1336 | // Flatten effects | 1337 | // Flatten effects |
1337 | // | 1338 | // |
1338 | //====================================================================== | 1339 | //====================================================================== |
1339 | 1340 | ||
1340 | QImage& OImageEffect::flatten(QImage &img, const QColor &ca, | 1341 | QImage& OImageEffect::flatten(QImage &img, const QColor &ca, |
1341 | const QColor &cb, int ncols) | 1342 | const QColor &cb, int ncols) |
1342 | { | 1343 | { |
1343 | if (img.width() == 0 || img.height() == 0) | 1344 | if (img.width() == 0 || img.height() == 0) |
1344 | return img; | 1345 | return img; |
1345 | 1346 | ||
1346 | // a bitmap is easy... | 1347 | // a bitmap is easy... |
1347 | if (img.depth() == 1) { | 1348 | if (img.depth() == 1) { |
1348 | img.setColor(0, ca.rgb()); | 1349 | img.setColor(0, ca.rgb()); |
1349 | img.setColor(1, cb.rgb()); | 1350 | img.setColor(1, cb.rgb()); |
1350 | return img; | 1351 | return img; |
1351 | } | 1352 | } |
1352 | 1353 | ||
1353 | int r1 = ca.red(); int r2 = cb.red(); | 1354 | int r1 = ca.red(); int r2 = cb.red(); |
1354 | int g1 = ca.green(); int g2 = cb.green(); | 1355 | int g1 = ca.green(); int g2 = cb.green(); |
1355 | int b1 = ca.blue(); int b2 = cb.blue(); | 1356 | int b1 = ca.blue(); int b2 = cb.blue(); |
1356 | int min = 0, max = 255; | 1357 | int min = 0, max = 255; |
1357 | 1358 | ||
1358 | QRgb col; | 1359 | QRgb col; |
1359 | 1360 | ||
1360 | // Get minimum and maximum greylevel. | 1361 | // Get minimum and maximum greylevel. |
1361 | if (img.numColors()) { | 1362 | if (img.numColors()) { |
1362 | // pseudocolor | 1363 | // pseudocolor |
1363 | for (int i = 0; i < img.numColors(); i++) { | 1364 | for (int i = 0; i < img.numColors(); i++) { |
1364 | col = img.color(i); | 1365 | col = img.color(i); |
1365 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; | 1366 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; |
1366 | min = QMIN(min, mean); | 1367 | min = QMIN(min, mean); |
1367 | max = QMAX(max, mean); | 1368 | max = QMAX(max, mean); |
1368 | } | 1369 | } |
1369 | } else { | 1370 | } else { |
1370 | // truecolor | 1371 | // truecolor |
1371 | for (int y=0; y < img.height(); y++) | 1372 | for (int y=0; y < img.height(); y++) |
1372 | for (int x=0; x < img.width(); x++) { | 1373 | for (int x=0; x < img.width(); x++) { |
1373 | col = img.pixel(x, y); | 1374 | col = img.pixel(x, y); |
1374 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; | 1375 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; |
1375 | min = QMIN(min, mean); | 1376 | min = QMIN(min, mean); |
1376 | max = QMAX(max, mean); | 1377 | max = QMAX(max, mean); |
1377 | } | 1378 | } |
1378 | } | 1379 | } |
1379 | 1380 | ||
1380 | // Conversion factors | 1381 | // Conversion factors |
1381 | float sr = ((float) r2 - r1) / (max - min); | 1382 | float sr = ((float) r2 - r1) / (max - min); |
1382 | float sg = ((float) g2 - g1) / (max - min); | 1383 | float sg = ((float) g2 - g1) / (max - min); |
1383 | float sb = ((float) b2 - b1) / (max - min); | 1384 | float sb = ((float) b2 - b1) / (max - min); |
1384 | 1385 | ||
1385 | 1386 | ||
1386 | // Repaint the image | 1387 | // Repaint the image |
1387 | if (img.numColors()) { | 1388 | if (img.numColors()) { |
1388 | for (int i=0; i < img.numColors(); i++) { | 1389 | for (int i=0; i < img.numColors(); i++) { |
1389 | col = img.color(i); | 1390 | col = img.color(i); |
1390 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; | 1391 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; |
1391 | int r = (int) (sr * (mean - min) + r1 + 0.5); | 1392 | int r = (int) (sr * (mean - min) + r1 + 0.5); |
1392 | int g = (int) (sg * (mean - min) + g1 + 0.5); | 1393 | int g = (int) (sg * (mean - min) + g1 + 0.5); |
1393 | int b = (int) (sb * (mean - min) + b1 + 0.5); | 1394 | int b = (int) (sb * (mean - min) + b1 + 0.5); |
1394 | img.setColor(i, qRgba(r, g, b, qAlpha(col))); | 1395 | img.setColor(i, qRgba(r, g, b, qAlpha(col))); |
1395 | } | 1396 | } |
1396 | } else { | 1397 | } else { |
1397 | for (int y=0; y < img.height(); y++) | 1398 | for (int y=0; y < img.height(); y++) |
1398 | for (int x=0; x < img.width(); x++) { | 1399 | for (int x=0; x < img.width(); x++) { |
1399 | col = img.pixel(x, y); | 1400 | col = img.pixel(x, y); |
1400 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; | 1401 | int mean = (qRed(col) + qGreen(col) + qBlue(col)) / 3; |
1401 | int r = (int) (sr * (mean - min) + r1 + 0.5); | 1402 | int r = (int) (sr * (mean - min) + r1 + 0.5); |
1402 | int g = (int) (sg * (mean - min) + g1 + 0.5); | 1403 | int g = (int) (sg * (mean - min) + g1 + 0.5); |
1403 | int b = (int) (sb * (mean - min) + b1 + 0.5); | 1404 | int b = (int) (sb * (mean - min) + b1 + 0.5); |
1404 | img.setPixel(x, y, qRgba(r, g, b, qAlpha(col))); | 1405 | img.setPixel(x, y, qRgba(r, g, b, qAlpha(col))); |
1405 | } | 1406 | } |
1406 | } | 1407 | } |
1407 | 1408 | ||
1408 | 1409 | ||
1409 | // Dither if necessary | 1410 | // Dither if necessary |
1410 | if ( (ncols <= 0) || ((img.numColors() != 0) && (img.numColors() <= ncols))) | 1411 | if ( (ncols <= 0) || ((img.numColors() != 0) && (img.numColors() <= ncols))) |
1411 | return img; | 1412 | return img; |
1412 | 1413 | ||
1413 | if (ncols == 1) ncols++; | 1414 | if (ncols == 1) ncols++; |
1414 | if (ncols > 256) ncols = 256; | 1415 | if (ncols > 256) ncols = 256; |
1415 | 1416 | ||
1416 | QColor *pal = new QColor[ncols]; | 1417 | QColor *pal = new QColor[ncols]; |
1417 | sr = ((float) r2 - r1) / (ncols - 1); | 1418 | sr = ((float) r2 - r1) / (ncols - 1); |
1418 | sg = ((float) g2 - g1) / (ncols - 1); | 1419 | sg = ((float) g2 - g1) / (ncols - 1); |
1419 | sb = ((float) b2 - b1) / (ncols - 1); | 1420 | sb = ((float) b2 - b1) / (ncols - 1); |
1420 | 1421 | ||
1421 | for (int i=0; i<ncols; i++) | 1422 | for (int i=0; i<ncols; i++) |
1422 | pal[i] = QColor(r1 + int(sr*i), g1 + int(sg*i), b1 + int(sb*i)); | 1423 | pal[i] = QColor(r1 + int(sr*i), g1 + int(sg*i), b1 + int(sb*i)); |
1423 | 1424 | ||
1424 | dither(img, pal, ncols); | 1425 | dither(img, pal, ncols); |
1425 | 1426 | ||
1426 | delete[] pal; | 1427 | delete[] pal; |
1427 | return img; | 1428 | return img; |
1428 | } | 1429 | } |
1429 | 1430 | ||
1430 | 1431 | ||
1431 | //====================================================================== | 1432 | //====================================================================== |
1432 | // | 1433 | // |
1433 | // Fade effects | 1434 | // Fade effects |
1434 | // | 1435 | // |
1435 | //====================================================================== | 1436 | //====================================================================== |
1436 | 1437 | ||
1437 | QImage& OImageEffect::fade(QImage &img, float val, const QColor &color) | 1438 | QImage& OImageEffect::fade(QImage &img, float val, const QColor &color) |
1438 | { | 1439 | { |
1439 | if (img.width() == 0 || img.height() == 0) | 1440 | if (img.width() == 0 || img.height() == 0) |
1440 | return img; | 1441 | return img; |
1441 | 1442 | ||
1442 | // We don't handle bitmaps | 1443 | // We don't handle bitmaps |
1443 | if (img.depth() == 1) | 1444 | if (img.depth() == 1) |
1444 | return img; | 1445 | return img; |
1445 | 1446 | ||
1446 | unsigned char tbl[256]; | 1447 | unsigned char tbl[256]; |
1447 | for (int i=0; i<256; i++) | 1448 | for (int i=0; i<256; i++) |
1448 | tbl[i] = (int) (val * i + 0.5); | 1449 | tbl[i] = (int) (val * i + 0.5); |
1449 | 1450 | ||
1450 | int red = color.red(); | 1451 | int red = color.red(); |
1451 | int green = color.green(); | 1452 | int green = color.green(); |
1452 | int blue = color.blue(); | 1453 | int blue = color.blue(); |
1453 | 1454 | ||
1454 | QRgb col; | 1455 | QRgb col; |
1455 | int r, g, b, cr, cg, cb; | 1456 | int r, g, b, cr, cg, cb; |
1456 | 1457 | ||
1457 | if (img.depth() <= 8) { | 1458 | if (img.depth() <= 8) { |
1458 | // pseudo color | 1459 | // pseudo color |
1459 | for (int i=0; i<img.numColors(); i++) { | 1460 | for (int i=0; i<img.numColors(); i++) { |
1460 | col = img.color(i); | 1461 | col = img.color(i); |
1461 | cr = qRed(col); cg = qGreen(col); cb = qBlue(col); | 1462 | cr = qRed(col); cg = qGreen(col); cb = qBlue(col); |
1462 | if (cr > red) | 1463 | if (cr > red) |
1463 | r = cr - tbl[cr - red]; | 1464 | r = cr - tbl[cr - red]; |
1464 | else | 1465 | else |
1465 | r = cr + tbl[red - cr]; | 1466 | r = cr + tbl[red - cr]; |
1466 | if (cg > green) | 1467 | if (cg > green) |
1467 | g = cg - tbl[cg - green]; | 1468 | g = cg - tbl[cg - green]; |
1468 | else | 1469 | else |
1469 | g = cg + tbl[green - cg]; | 1470 | g = cg + tbl[green - cg]; |
1470 | if (cb > blue) | 1471 | if (cb > blue) |
1471 | b = cb - tbl[cb - blue]; | 1472 | b = cb - tbl[cb - blue]; |
1472 | else | 1473 | else |
1473 | b = cb + tbl[blue - cb]; | 1474 | b = cb + tbl[blue - cb]; |
1474 | img.setColor(i, qRgba(r, g, b, qAlpha(col))); | 1475 | img.setColor(i, qRgba(r, g, b, qAlpha(col))); |
1475 | } | 1476 | } |
1476 | 1477 | ||
1477 | } else { | 1478 | } else { |
1478 | // truecolor | 1479 | // truecolor |
1479 | for (int y=0; y<img.height(); y++) { | 1480 | for (int y=0; y<img.height(); y++) { |
1480 | QRgb *data = (QRgb *) img.scanLine(y); | 1481 | QRgb *data = (QRgb *) img.scanLine(y); |
1481 | for (int x=0; x<img.width(); x++) { | 1482 | for (int x=0; x<img.width(); x++) { |
1482 | col = *data; | 1483 | col = *data; |
1483 | cr = qRed(col); cg = qGreen(col); cb = qBlue(col); | 1484 | cr = qRed(col); cg = qGreen(col); cb = qBlue(col); |
1484 | if (cr > red) | 1485 | if (cr > red) |
1485 | r = cr - tbl[cr - red]; | 1486 | r = cr - tbl[cr - red]; |
1486 | else | 1487 | else |
1487 | r = cr + tbl[red - cr]; | 1488 | r = cr + tbl[red - cr]; |
1488 | if (cg > green) | 1489 | if (cg > green) |
1489 | g = cg - tbl[cg - green]; | 1490 | g = cg - tbl[cg - green]; |
1490 | else | 1491 | else |
1491 | g = cg + tbl[green - cg]; | 1492 | g = cg + tbl[green - cg]; |
1492 | if (cb > blue) | 1493 | if (cb > blue) |
1493 | b = cb - tbl[cb - blue]; | 1494 | b = cb - tbl[cb - blue]; |
1494 | else | 1495 | else |
1495 | b = cb + tbl[blue - cb]; | 1496 | b = cb + tbl[blue - cb]; |
1496 | *data++ = qRgba(r, g, b, qAlpha(col)); | 1497 | *data++ = qRgba(r, g, b, qAlpha(col)); |
1497 | } | 1498 | } |
1498 | } | 1499 | } |
1499 | } | 1500 | } |
1500 | 1501 | ||
1501 | return img; | 1502 | return img; |
1502 | } | 1503 | } |
1503 | 1504 | ||
1504 | //====================================================================== | 1505 | //====================================================================== |
1505 | // | 1506 | // |
1506 | // Color effects | 1507 | // Color effects |
1507 | // | 1508 | // |
1508 | //====================================================================== | 1509 | //====================================================================== |
1509 | 1510 | ||
1510 | // This code is adapted from code (C) Rik Hemsley <rik@kde.org> | 1511 | // This code is adapted from code (C) Rik Hemsley <rik@kde.org> |
1511 | // | 1512 | // |
1512 | // The formula used (r + b + g) /3 is different from the qGray formula | 1513 | // The formula used (r + b + g) /3 is different from the qGray formula |
1513 | // used by Qt. This is because our formula is much much faster. If, | 1514 | // used by Qt. This is because our formula is much much faster. If, |
1514 | // however, it turns out that this is producing sub-optimal images, | 1515 | // however, it turns out that this is producing sub-optimal images, |
1515 | // then it will have to change (kurt) | 1516 | // then it will have to change (kurt) |
1516 | // | 1517 | // |
1517 | // It does produce lower quality grayscale ;-) Use fast == true for the fast | 1518 | // It does produce lower quality grayscale ;-) Use fast == true for the fast |
1518 | // algorithm, false for the higher quality one (mosfet). | 1519 | // algorithm, false for the higher quality one (mosfet). |
1519 | QImage& OImageEffect::toGray(QImage &img, bool fast) | 1520 | QImage& OImageEffect::toGray(QImage &img, bool fast) |
1520 | { | 1521 | { |
1521 | if (img.width() == 0 || img.height() == 0) | 1522 | if (img.width() == 0 || img.height() == 0) |
1522 | return img; | 1523 | return img; |
1523 | 1524 | ||
1524 | if(fast){ | 1525 | if(fast){ |
1525 | if (img.depth() == 32) { | 1526 | if (img.depth() == 32) { |
1526 | register uchar * r(img.bits()); | 1527 | register uchar * r(img.bits()); |
1527 | register uchar * g(img.bits() + 1); | 1528 | register uchar * g(img.bits() + 1); |
1528 | register uchar * b(img.bits() + 2); | 1529 | register uchar * b(img.bits() + 2); |
1529 | 1530 | ||
1530 | uchar * end(img.bits() + img.numBytes()); | 1531 | uchar * end(img.bits() + img.numBytes()); |
1531 | 1532 | ||
1532 | while (r != end) { | 1533 | while (r != end) { |
1533 | 1534 | ||
1534 | *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3 | 1535 | *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3 |
1535 | 1536 | ||
1536 | r += 4; | 1537 | r += 4; |
1537 | g += 4; | 1538 | g += 4; |
1538 | b += 4; | 1539 | b += 4; |
1539 | } | 1540 | } |
1540 | } | 1541 | } |
1541 | else | 1542 | else |
1542 | { | 1543 | { |
1543 | for (int i = 0; i < img.numColors(); i++) | 1544 | for (int i = 0; i < img.numColors(); i++) |
1544 | { | 1545 | { |
1545 | register uint r = qRed(img.color(i)); | 1546 | register uint r = qRed(img.color(i)); |
1546 | register uint g = qGreen(img.color(i)); | 1547 | register uint g = qGreen(img.color(i)); |
1547 | register uint b = qBlue(img.color(i)); | 1548 | register uint b = qBlue(img.color(i)); |
1548 | 1549 | ||
1549 | register uint gray = (((r + g) >> 1) + b) >> 1; | 1550 | register uint gray = (((r + g) >> 1) + b) >> 1; |
1550 | img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i)))); | 1551 | img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i)))); |
1551 | } | 1552 | } |
1552 | } | 1553 | } |
1553 | } | 1554 | } |
1554 | else{ | 1555 | else{ |
1555 | int pixels = img.depth() > 8 ? img.width()*img.height() : | 1556 | int pixels = img.depth() > 8 ? img.width()*img.height() : |
1556 | img.numColors(); | 1557 | img.numColors(); |
1557 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : | 1558 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : |
1558 | (unsigned int *)img.colorTable(); | 1559 | (unsigned int *)img.colorTable(); |
1559 | int val, i; | 1560 | int val, i; |
1560 | for(i=0; i < pixels; ++i){ | 1561 | for(i=0; i < pixels; ++i){ |
1561 | val = qGray(data[i]); | 1562 | val = qGray(data[i]); |
1562 | data[i] = qRgba(val, val, val, qAlpha(data[i])); | 1563 | data[i] = qRgba(val, val, val, qAlpha(data[i])); |
1563 | } | 1564 | } |
1564 | } | 1565 | } |
1565 | return img; | 1566 | return img; |
1566 | } | 1567 | } |
1567 | 1568 | ||
1568 | // CT 29Jan2000 - desaturation algorithms | 1569 | // CT 29Jan2000 - desaturation algorithms |
1569 | QImage& OImageEffect::desaturate(QImage &img, float desat) | 1570 | QImage& OImageEffect::desaturate(QImage &img, float desat) |
1570 | { | 1571 | { |
1571 | if (img.width() == 0 || img.height() == 0) | 1572 | if (img.width() == 0 || img.height() == 0) |
1572 | return img; | 1573 | return img; |
1573 | 1574 | ||
1574 | if (desat < 0) desat = 0.; | 1575 | if (desat < 0) desat = 0.; |
1575 | if (desat > 1) desat = 1.; | 1576 | if (desat > 1) desat = 1.; |
1576 | int pixels = img.depth() > 8 ? img.width()*img.height() : | 1577 | int pixels = img.depth() > 8 ? img.width()*img.height() : |
1577 | img.numColors(); | 1578 | img.numColors(); |
1578 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : | 1579 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : |
1579 | (unsigned int *)img.colorTable(); | 1580 | (unsigned int *)img.colorTable(); |
1580 | int h, s, v, i; | 1581 | int h, s, v, i; |
1581 | QColor clr; // keep constructor out of loop (mosfet) | 1582 | QColor clr; // keep constructor out of loop (mosfet) |
1582 | for(i=0; i < pixels; ++i){ | 1583 | for(i=0; i < pixels; ++i){ |
1583 | clr.setRgb(data[i]); | 1584 | clr.setRgb(data[i]); |
1584 | clr.hsv(&h, &s, &v); | 1585 | clr.hsv(&h, &s, &v); |
1585 | clr.setHsv(h, (int)(s * (1. - desat)), v); | 1586 | clr.setHsv(h, (int)(s * (1. - desat)), v); |
1586 | data[i] = clr.rgb(); | 1587 | data[i] = clr.rgb(); |
1587 | } | 1588 | } |
1588 | return img; | 1589 | return img; |
1589 | } | 1590 | } |
1590 | 1591 | ||
1591 | // Contrast stuff (mosfet) | 1592 | // Contrast stuff (mosfet) |
1592 | QImage& OImageEffect::contrast(QImage &img, int c) | 1593 | QImage& OImageEffect::contrast(QImage &img, int c) |
1593 | { | 1594 | { |
1594 | if (img.width() == 0 || img.height() == 0) | 1595 | if (img.width() == 0 || img.height() == 0) |
1595 | return img; | 1596 | return img; |
1596 | 1597 | ||
1597 | if(c > 255) | 1598 | if(c > 255) |
1598 | c = 255; | 1599 | c = 255; |
1599 | if(c < -255) | 1600 | if(c < -255) |
1600 | c = -255; | 1601 | c = -255; |
1601 | int pixels = img.depth() > 8 ? img.width()*img.height() : | 1602 | int pixels = img.depth() > 8 ? img.width()*img.height() : |
1602 | img.numColors(); | 1603 | img.numColors(); |
1603 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : | 1604 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : |
1604 | (unsigned int *)img.colorTable(); | 1605 | (unsigned int *)img.colorTable(); |
1605 | int i, r, g, b; | 1606 | int i, r, g, b; |
1606 | for(i=0; i < pixels; ++i){ | 1607 | for(i=0; i < pixels; ++i){ |
1607 | r = qRed(data[i]); | 1608 | r = qRed(data[i]); |
1608 | g = qGreen(data[i]); | 1609 | g = qGreen(data[i]); |
1609 | b = qBlue(data[i]); | 1610 | b = qBlue(data[i]); |
1610 | if(qGray(data[i]) <= 127){ | 1611 | if(qGray(data[i]) <= 127){ |
1611 | if(r - c <= 255) | 1612 | if(r - c <= 255) |
1612 | r -= c; | 1613 | r -= c; |
1613 | if(g - c <= 255) | 1614 | if(g - c <= 255) |
1614 | g -= c; | 1615 | g -= c; |
1615 | if(b - c <= 255) | 1616 | if(b - c <= 255) |
1616 | b -= c; | 1617 | b -= c; |
1617 | } | 1618 | } |
1618 | else{ | 1619 | else{ |
1619 | if(r + c <= 255) | 1620 | if(r + c <= 255) |
1620 | r += c; | 1621 | r += c; |
1621 | if(g + c <= 255) | 1622 | if(g + c <= 255) |
1622 | g += c; | 1623 | g += c; |
1623 | if(b + c <= 255) | 1624 | if(b + c <= 255) |
1624 | b += c; | 1625 | b += c; |
1625 | } | 1626 | } |
1626 | data[i] = qRgba(r, g, b, qAlpha(data[i])); | 1627 | data[i] = qRgba(r, g, b, qAlpha(data[i])); |
1627 | } | 1628 | } |
1628 | return(img); | 1629 | return(img); |
1629 | } | 1630 | } |
1630 | 1631 | ||
1631 | //====================================================================== | 1632 | //====================================================================== |
1632 | // | 1633 | // |
1633 | // Dithering effects | 1634 | // Dithering effects |
1634 | // | 1635 | // |
1635 | //====================================================================== | 1636 | //====================================================================== |
1636 | 1637 | ||
1637 | // adapted from kFSDither (C) 1997 Martin Jones (mjones@kde.org) | 1638 | // adapted from kFSDither (C) 1997 Martin Jones (mjones@kde.org) |
1638 | // | 1639 | // |
1639 | // Floyd-Steinberg dithering | 1640 | // Floyd-Steinberg dithering |
1640 | // Ref: Bitmapped Graphics Programming in C++ | 1641 | // Ref: Bitmapped Graphics Programming in C++ |
1641 | // Marv Luse, Addison-Wesley Publishing, 1993. | 1642 | // Marv Luse, Addison-Wesley Publishing, 1993. |
1642 | QImage& OImageEffect::dither(QImage &img, const QColor *palette, int size) | 1643 | QImage& OImageEffect::dither(QImage &img, const QColor *palette, int size) |
1643 | { | 1644 | { |
1644 | if (img.width() == 0 || img.height() == 0 || | 1645 | if (img.width() == 0 || img.height() == 0 || |
1645 | palette == 0 || img.depth() <= 8) | 1646 | palette == 0 || img.depth() <= 8) |
1646 | return img; | 1647 | return img; |
1647 | 1648 | ||
1648 | QImage dImage( img.width(), img.height(), 8, size ); | 1649 | QImage dImage( img.width(), img.height(), 8, size ); |
1649 | int i; | 1650 | int i; |
1650 | 1651 | ||
1651 | dImage.setNumColors( size ); | 1652 | dImage.setNumColors( size ); |
1652 | for ( i = 0; i < size; i++ ) | 1653 | for ( i = 0; i < size; i++ ) |
1653 | dImage.setColor( i, palette[ i ].rgb() ); | 1654 | dImage.setColor( i, palette[ i ].rgb() ); |
1654 | 1655 | ||
1655 | int *rerr1 = new int [ img.width() * 2 ]; | 1656 | int *rerr1 = new int [ img.width() * 2 ]; |
1656 | int *gerr1 = new int [ img.width() * 2 ]; | 1657 | int *gerr1 = new int [ img.width() * 2 ]; |
1657 | int *berr1 = new int [ img.width() * 2 ]; | 1658 | int *berr1 = new int [ img.width() * 2 ]; |
1658 | 1659 | ||
1659 | memset( rerr1, 0, sizeof( int ) * img.width() * 2 ); | 1660 | memset( rerr1, 0, sizeof( int ) * img.width() * 2 ); |
1660 | memset( gerr1, 0, sizeof( int ) * img.width() * 2 ); | 1661 | memset( gerr1, 0, sizeof( int ) * img.width() * 2 ); |
1661 | memset( berr1, 0, sizeof( int ) * img.width() * 2 ); | 1662 | memset( berr1, 0, sizeof( int ) * img.width() * 2 ); |
1662 | 1663 | ||
1663 | int *rerr2 = rerr1 + img.width(); | 1664 | int *rerr2 = rerr1 + img.width(); |
1664 | int *gerr2 = gerr1 + img.width(); | 1665 | int *gerr2 = gerr1 + img.width(); |
1665 | int *berr2 = berr1 + img.width(); | 1666 | int *berr2 = berr1 + img.width(); |
1666 | 1667 | ||
1667 | for ( int j = 0; j < img.height(); j++ ) | 1668 | for ( int j = 0; j < img.height(); j++ ) |
1668 | { | 1669 | { |
1669 | uint *ip = (uint * )img.scanLine( j ); | 1670 | uint *ip = (uint * )img.scanLine( j ); |
1670 | uchar *dp = dImage.scanLine( j ); | 1671 | uchar *dp = dImage.scanLine( j ); |
1671 | 1672 | ||
1672 | for ( i = 0; i < img.width(); i++ ) | 1673 | for ( i = 0; i < img.width(); i++ ) |
1673 | { | 1674 | { |
1674 | rerr1[i] = rerr2[i] + qRed( *ip ); | 1675 | rerr1[i] = rerr2[i] + qRed( *ip ); |
1675 | rerr2[i] = 0; | 1676 | rerr2[i] = 0; |
1676 | gerr1[i] = gerr2[i] + qGreen( *ip ); | 1677 | gerr1[i] = gerr2[i] + qGreen( *ip ); |
1677 | gerr2[i] = 0; | 1678 | gerr2[i] = 0; |
1678 | berr1[i] = berr2[i] + qBlue( *ip ); | 1679 | berr1[i] = berr2[i] + qBlue( *ip ); |
1679 | berr2[i] = 0; | 1680 | berr2[i] = 0; |
1680 | ip++; | 1681 | ip++; |
1681 | } | 1682 | } |
1682 | 1683 | ||
1683 | *dp++ = nearestColor( rerr1[0], gerr1[0], berr1[0], palette, size ); | 1684 | *dp++ = nearestColor( rerr1[0], gerr1[0], berr1[0], palette, size ); |
1684 | 1685 | ||
1685 | for ( i = 1; i < img.width()-1; i++ ) | 1686 | for ( i = 1; i < img.width()-1; i++ ) |
1686 | { | 1687 | { |
1687 | int indx = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size ); | 1688 | int indx = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size ); |
1688 | *dp = indx; | 1689 | *dp = indx; |
1689 | 1690 | ||
1690 | int rerr = rerr1[i]; | 1691 | int rerr = rerr1[i]; |
1691 | rerr -= palette[indx].red(); | 1692 | rerr -= palette[indx].red(); |
1692 | int gerr = gerr1[i]; | 1693 | int gerr = gerr1[i]; |
1693 | gerr -= palette[indx].green(); | 1694 | gerr -= palette[indx].green(); |
1694 | int berr = berr1[i]; | 1695 | int berr = berr1[i]; |
1695 | berr -= palette[indx].blue(); | 1696 | berr -= palette[indx].blue(); |
1696 | 1697 | ||
1697 | // diffuse red error | 1698 | // diffuse red error |
1698 | rerr1[ i+1 ] += ( rerr * 7 ) >> 4; | 1699 | rerr1[ i+1 ] += ( rerr * 7 ) >> 4; |
1699 | rerr2[ i-1 ] += ( rerr * 3 ) >> 4; | 1700 | rerr2[ i-1 ] += ( rerr * 3 ) >> 4; |
1700 | rerr2[ i ] += ( rerr * 5 ) >> 4; | 1701 | rerr2[ i ] += ( rerr * 5 ) >> 4; |
1701 | rerr2[ i+1 ] += ( rerr ) >> 4; | 1702 | rerr2[ i+1 ] += ( rerr ) >> 4; |
1702 | 1703 | ||
1703 | // diffuse green error | 1704 | // diffuse green error |
1704 | gerr1[ i+1 ] += ( gerr * 7 ) >> 4; | 1705 | gerr1[ i+1 ] += ( gerr * 7 ) >> 4; |
1705 | gerr2[ i-1 ] += ( gerr * 3 ) >> 4; | 1706 | gerr2[ i-1 ] += ( gerr * 3 ) >> 4; |
1706 | gerr2[ i ] += ( gerr * 5 ) >> 4; | 1707 | gerr2[ i ] += ( gerr * 5 ) >> 4; |
1707 | gerr2[ i+1 ] += ( gerr ) >> 4; | 1708 | gerr2[ i+1 ] += ( gerr ) >> 4; |
1708 | 1709 | ||
1709 | // diffuse red error | 1710 | // diffuse red error |
1710 | berr1[ i+1 ] += ( berr * 7 ) >> 4; | 1711 | berr1[ i+1 ] += ( berr * 7 ) >> 4; |
1711 | berr2[ i-1 ] += ( berr * 3 ) >> 4; | 1712 | berr2[ i-1 ] += ( berr * 3 ) >> 4; |
1712 | berr2[ i ] += ( berr * 5 ) >> 4; | 1713 | berr2[ i ] += ( berr * 5 ) >> 4; |
1713 | berr2[ i+1 ] += ( berr ) >> 4; | 1714 | berr2[ i+1 ] += ( berr ) >> 4; |
1714 | 1715 | ||
1715 | dp++; | 1716 | dp++; |
1716 | } | 1717 | } |
1717 | 1718 | ||
1718 | *dp = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size ); | 1719 | *dp = nearestColor( rerr1[i], gerr1[i], berr1[i], palette, size ); |
1719 | } | 1720 | } |
1720 | 1721 | ||
1721 | delete [] rerr1; | 1722 | delete [] rerr1; |
1722 | delete [] gerr1; | 1723 | delete [] gerr1; |
1723 | delete [] berr1; | 1724 | delete [] berr1; |
1724 | 1725 | ||
1725 | img = dImage; | 1726 | img = dImage; |
1726 | return img; | 1727 | return img; |
1727 | } | 1728 | } |
1728 | 1729 | ||
1729 | int OImageEffect::nearestColor( int r, int g, int b, const QColor *palette, int size ) | 1730 | int OImageEffect::nearestColor( int r, int g, int b, const QColor *palette, int size ) |
1730 | { | 1731 | { |
1731 | if (palette == 0) | 1732 | if (palette == 0) |
1732 | return 0; | 1733 | return 0; |
1733 | 1734 | ||
1734 | int dr = palette[0].red() - r; | 1735 | int dr = palette[0].red() - r; |
1735 | int dg = palette[0].green() - g; | 1736 | int dg = palette[0].green() - g; |
1736 | int db = palette[0].blue() - b; | 1737 | int db = palette[0].blue() - b; |
1737 | 1738 | ||
1738 | int minDist = dr*dr + dg*dg + db*db; | 1739 | int minDist = dr*dr + dg*dg + db*db; |
1739 | int nearest = 0; | 1740 | int nearest = 0; |
1740 | 1741 | ||
1741 | for (int i = 1; i < size; i++ ) | 1742 | for (int i = 1; i < size; i++ ) |
1742 | { | 1743 | { |
1743 | dr = palette[i].red() - r; | 1744 | dr = palette[i].red() - r; |
1744 | dg = palette[i].green() - g; | 1745 | dg = palette[i].green() - g; |
1745 | db = palette[i].blue() - b; | 1746 | db = palette[i].blue() - b; |
1746 | 1747 | ||
1747 | int dist = dr*dr + dg*dg + db*db; | 1748 | int dist = dr*dr + dg*dg + db*db; |
1748 | 1749 | ||
1749 | if ( dist < minDist ) | 1750 | if ( dist < minDist ) |
1750 | { | 1751 | { |
1751 | minDist = dist; | 1752 | minDist = dist; |
1752 | nearest = i; | 1753 | nearest = i; |
1753 | } | 1754 | } |
1754 | } | 1755 | } |
1755 | 1756 | ||
1756 | return nearest; | 1757 | return nearest; |
1757 | } | 1758 | } |
1758 | 1759 | ||
1759 | bool OImageEffect::blend( | 1760 | bool OImageEffect::blend( |
1760 | const QImage & upper, | 1761 | const QImage & upper, |
1761 | const QImage & lower, | 1762 | const QImage & lower, |
1762 | QImage & output | 1763 | QImage & output |
1763 | ) | 1764 | ) |
1764 | { | 1765 | { |
1765 | if ( | 1766 | if ( |
1766 | upper.width() > lower.width() || | 1767 | upper.width() > lower.width() || |
1767 | upper.height() > lower.height() || | 1768 | upper.height() > lower.height() || |
1768 | upper.depth() != 32 || | 1769 | upper.depth() != 32 || |
1769 | lower.depth() != 32 | 1770 | lower.depth() != 32 |
1770 | ) | 1771 | ) |
1771 | { | 1772 | { |
1772 | qDebug( "OImageEffect::blend : Sizes not correct" ); | 1773 | odebug << "OImageEffect::blend : Sizes not correct" << oendl; |
1773 | return false; | 1774 | return false; |
1774 | } | 1775 | } |
1775 | 1776 | ||
1776 | output = lower.copy(); | 1777 | output = lower.copy(); |
1777 | 1778 | ||
1778 | register uchar *i, *o; | 1779 | register uchar *i, *o; |
1779 | register int a; | 1780 | register int a; |
1780 | register int col; | 1781 | register int col; |
1781 | register int w = upper.width(); | 1782 | register int w = upper.width(); |
1782 | int row(upper.height() - 1); | 1783 | int row(upper.height() - 1); |
1783 | 1784 | ||
1784 | do { | 1785 | do { |
1785 | 1786 | ||
1786 | i = upper.scanLine(row); | 1787 | i = upper.scanLine(row); |
1787 | o = output.scanLine(row); | 1788 | o = output.scanLine(row); |
1788 | 1789 | ||
1789 | col = w << 2; | 1790 | col = w << 2; |
1790 | --col; | 1791 | --col; |
1791 | 1792 | ||
1792 | do { | 1793 | do { |
1793 | 1794 | ||
1794 | while (!(a = i[col]) && (col != 3)) { | 1795 | while (!(a = i[col]) && (col != 3)) { |
1795 | --col; --col; --col; --col; | 1796 | --col; --col; --col; --col; |
1796 | } | 1797 | } |
1797 | 1798 | ||
1798 | --col; | 1799 | --col; |
1799 | o[col] += ((i[col] - o[col]) * a) >> 8; | 1800 | o[col] += ((i[col] - o[col]) * a) >> 8; |
1800 | 1801 | ||
1801 | --col; | 1802 | --col; |
1802 | o[col] += ((i[col] - o[col]) * a) >> 8; | 1803 | o[col] += ((i[col] - o[col]) * a) >> 8; |
1803 | 1804 | ||
1804 | --col; | 1805 | --col; |
1805 | o[col] += ((i[col] - o[col]) * a) >> 8; | 1806 | o[col] += ((i[col] - o[col]) * a) >> 8; |
1806 | 1807 | ||
1807 | } while (col--); | 1808 | } while (col--); |
1808 | 1809 | ||
1809 | } while (row--); | 1810 | } while (row--); |
1810 | 1811 | ||
1811 | return true; | 1812 | return true; |
1812 | } | 1813 | } |
1813 | 1814 | ||
1814 | #if 0 | 1815 | #if 0 |
1815 | // Not yet... | 1816 | // Not yet... |
1816 | bool OImageEffect::blend( | 1817 | bool OImageEffect::blend( |
1817 | const QImage & upper, | 1818 | const QImage & upper, |
1818 | const QImage & lower, | 1819 | const QImage & lower, |
1819 | QImage & output, | 1820 | QImage & output, |
1820 | const QRect & destRect | 1821 | const QRect & destRect |
1821 | ) | 1822 | ) |
1822 | { | 1823 | { |
1823 | output = lower.copy(); | 1824 | output = lower.copy(); |
1824 | return output; | 1825 | return output; |
1825 | } | 1826 | } |
1826 | 1827 | ||
1827 | #endif | 1828 | #endif |
1828 | 1829 | ||
1829 | bool OImageEffect::blend( | 1830 | bool OImageEffect::blend( |
1830 | int &x, int &y, | 1831 | int &x, int &y, |
1831 | const QImage & upper, | 1832 | const QImage & upper, |
1832 | const QImage & lower, | 1833 | const QImage & lower, |
1833 | QImage & output | 1834 | QImage & output |
1834 | ) | 1835 | ) |
1835 | { | 1836 | { |
1836 | int cx=0, cy=0, cw=upper.width(), ch=upper.height(); | 1837 | int cx=0, cy=0, cw=upper.width(), ch=upper.height(); |
1837 | 1838 | ||
1838 | if ( upper.width() + x > lower.width() || | 1839 | if ( upper.width() + x > lower.width() || |
1839 | upper.height() + y > lower.height() || | 1840 | upper.height() + y > lower.height() || |
1840 | x < 0 || y < 0 || | 1841 | x < 0 || y < 0 || |
1841 | upper.depth() != 32 || lower.depth() != 32 ) | 1842 | upper.depth() != 32 || lower.depth() != 32 ) |
1842 | { | 1843 | { |
1843 | if ( x > lower.width() || y > lower.height() ) return false; | 1844 | if ( x > lower.width() || y > lower.height() ) return false; |
1844 | if ( upper.width()<=0 || upper.height() <= 0 ) return false; | 1845 | if ( upper.width()<=0 || upper.height() <= 0 ) return false; |
1845 | if ( lower.width()<=0 || lower.height() <= 0 ) return false; | 1846 | if ( lower.width()<=0 || lower.height() <= 0 ) return false; |
1846 | 1847 | ||
1847 | if (x<0) {cx=-x; cw+=x; x=0; }; | 1848 | if (x<0) {cx=-x; cw+=x; x=0; }; |
1848 | if (cw + x > lower.width()) { cw=lower.width()-x; }; | 1849 | if (cw + x > lower.width()) { cw=lower.width()-x; }; |
1849 | if (y<0) {cy=-y; ch+=y; y=0; }; | 1850 | if (y<0) {cy=-y; ch+=y; y=0; }; |
1850 | if (ch + y > lower.height()) { ch=lower.height()-y; }; | 1851 | if (ch + y > lower.height()) { ch=lower.height()-y; }; |
1851 | 1852 | ||
1852 | if ( cx >= upper.width() || cy >= upper.height() ) return true; | 1853 | if ( cx >= upper.width() || cy >= upper.height() ) return true; |
1853 | if ( cw <= 0 || ch <= 0 ) return true; | 1854 | if ( cw <= 0 || ch <= 0 ) return true; |
1854 | } | 1855 | } |
1855 | 1856 | ||
1856 | output.create(cw,ch,32); | 1857 | output.create(cw,ch,32); |
1857 | // output.setAlphaBuffer(true); // I should do some benchmarks to see if | 1858 | // output.setAlphaBuffer(true); // I should do some benchmarks to see if |
1858 | // this is worth the effort | 1859 | // this is worth the effort |
1859 | 1860 | ||
1860 | register QRgb *i, *o, *b; | 1861 | register QRgb *i, *o, *b; |
1861 | 1862 | ||
1862 | register int a; | 1863 | register int a; |
1863 | register int j,k; | 1864 | register int j,k; |
1864 | for (j=0; j<ch; j++) | 1865 | for (j=0; j<ch; j++) |
1865 | { | 1866 | { |
1866 | b=reinterpret_cast<QRgb *>(&lower.scanLine(y+j) [ (x+cw) << 2 ]); | 1867 | b=reinterpret_cast<QRgb *>(&lower.scanLine(y+j) [ (x+cw) << 2 ]); |
1867 | i=reinterpret_cast<QRgb *>(&upper.scanLine(cy+j)[ (cx+cw) << 2 ]); | 1868 | i=reinterpret_cast<QRgb *>(&upper.scanLine(cy+j)[ (cx+cw) << 2 ]); |
1868 | o=reinterpret_cast<QRgb *>(&output.scanLine(j) [ cw << 2 ]); | 1869 | o=reinterpret_cast<QRgb *>(&output.scanLine(j) [ cw << 2 ]); |
1869 | 1870 | ||
1870 | k=cw-1; | 1871 | k=cw-1; |
1871 | --b; --i; --o; | 1872 | --b; --i; --o; |
1872 | do | 1873 | do |
1873 | { | 1874 | { |
1874 | while ( !(a=qAlpha(*i)) && k>0 ) | 1875 | while ( !(a=qAlpha(*i)) && k>0 ) |
1875 | { | 1876 | { |
1876 | i--; | 1877 | i--; |
1877 | //*o=0; | 1878 | //*o=0; |
1878 | *o=*b; | 1879 | *o=*b; |
1879 | --o; --b; | 1880 | --o; --b; |
1880 | k--; | 1881 | k--; |
1881 | }; | 1882 | }; |
1882 | // *o=0xFF; | 1883 | // *o=0xFF; |
1883 | *o = qRgb(qRed(*b) + (((qRed(*i) - qRed(*b)) * a) >> 8), | 1884 | *o = qRgb(qRed(*b) + (((qRed(*i) - qRed(*b)) * a) >> 8), |
1884 | qGreen(*b) + (((qGreen(*i) - qGreen(*b)) * a) >> 8), | 1885 | qGreen(*b) + (((qGreen(*i) - qGreen(*b)) * a) >> 8), |
1885 | qBlue(*b) + (((qBlue(*i) - qBlue(*b)) * a) >> 8)); | 1886 | qBlue(*b) + (((qBlue(*i) - qBlue(*b)) * a) >> 8)); |
1886 | --i; --o; --b; | 1887 | --i; --o; --b; |
1887 | } while (k--); | 1888 | } while (k--); |
1888 | } | 1889 | } |
1889 | 1890 | ||
1890 | return true; | 1891 | return true; |
1891 | } | 1892 | } |
1892 | 1893 | ||
1893 | bool OImageEffect::blendOnLower( | 1894 | bool OImageEffect::blendOnLower( |
1894 | int x, int y, | 1895 | int x, int y, |
1895 | const QImage & upper, | 1896 | const QImage & upper, |
1896 | const QImage & lower | 1897 | const QImage & lower |
1897 | ) | 1898 | ) |
1898 | { | 1899 | { |
1899 | int cx=0, cy=0, cw=upper.width(), ch=upper.height(); | 1900 | int cx=0, cy=0, cw=upper.width(), ch=upper.height(); |
1900 | 1901 | ||
1901 | if ( upper.depth() != 32 || lower.depth() != 32 ) return false; | 1902 | if ( upper.depth() != 32 || lower.depth() != 32 ) return false; |
1902 | if ( x + cw > lower.width() || | 1903 | if ( x + cw > lower.width() || |
1903 | y + ch > lower.height() || | 1904 | y + ch > lower.height() || |
1904 | x < 0 || y < 0 ) | 1905 | x < 0 || y < 0 ) |
1905 | { | 1906 | { |
1906 | if ( x > lower.width() || y > lower.height() ) return true; | 1907 | if ( x > lower.width() || y > lower.height() ) return true; |
1907 | if ( upper.width()<=0 || upper.height() <= 0 ) return true; | 1908 | if ( upper.width()<=0 || upper.height() <= 0 ) return true; |
1908 | if ( lower.width()<=0 || lower.height() <= 0 ) return true; | 1909 | if ( lower.width()<=0 || lower.height() <= 0 ) return true; |
1909 | 1910 | ||
1910 | if (x<0) {cx=-x; cw+=x; x=0; }; | 1911 | if (x<0) {cx=-x; cw+=x; x=0; }; |
1911 | if (cw + x > lower.width()) { cw=lower.width()-x; }; | 1912 | if (cw + x > lower.width()) { cw=lower.width()-x; }; |
1912 | if (y<0) {cy=-y; ch+=y; y=0; }; | 1913 | if (y<0) {cy=-y; ch+=y; y=0; }; |
1913 | if (ch + y > lower.height()) { ch=lower.height()-y; }; | 1914 | if (ch + y > lower.height()) { ch=lower.height()-y; }; |
1914 | 1915 | ||
1915 | if ( cx >= upper.width() || cy >= upper.height() ) return true; | 1916 | if ( cx >= upper.width() || cy >= upper.height() ) return true; |
1916 | if ( cw <= 0 || ch <= 0 ) return true; | 1917 | if ( cw <= 0 || ch <= 0 ) return true; |
1917 | } | 1918 | } |
1918 | 1919 | ||
1919 | register uchar *i, *b; | 1920 | register uchar *i, *b; |
1920 | register int a; | 1921 | register int a; |
1921 | register int k; | 1922 | register int k; |
1922 | 1923 | ||
1923 | for (int j=0; j<ch; j++) | 1924 | for (int j=0; j<ch; j++) |
1924 | { | 1925 | { |
1925 | b=&lower.scanLine(y+j) [ (x+cw) << 2 ]; | 1926 | b=&lower.scanLine(y+j) [ (x+cw) << 2 ]; |
1926 | i=&upper.scanLine(cy+j)[ (cx+cw) << 2 ]; | 1927 | i=&upper.scanLine(cy+j)[ (cx+cw) << 2 ]; |
1927 | 1928 | ||
1928 | k=cw-1; | 1929 | k=cw-1; |
1929 | --b; --i; | 1930 | --b; --i; |
1930 | do | 1931 | do |
1931 | { | 1932 | { |
1932 | #ifndef WORDS_BIGENDIAN | 1933 | #ifndef WORDS_BIGENDIAN |
1933 | while ( !(a=*i) && k>0 ) | 1934 | while ( !(a=*i) && k>0 ) |
1934 | #else | 1935 | #else |
1935 | while ( !(a=*(i-3)) && k>0 ) | 1936 | while ( !(a=*(i-3)) && k>0 ) |
1936 | #endif | 1937 | #endif |
1937 | { | 1938 | { |
1938 | i-=4; b-=4; k--; | 1939 | i-=4; b-=4; k--; |
1939 | }; | 1940 | }; |
1940 | 1941 | ||
1941 | #ifndef WORDS_BIGENDIAN | 1942 | #ifndef WORDS_BIGENDIAN |
1942 | --i; --b; | 1943 | --i; --b; |
1943 | *b += ( ((*i - *b) * a) >> 8 ); | 1944 | *b += ( ((*i - *b) * a) >> 8 ); |
1944 | --i; --b; | 1945 | --i; --b; |
1945 | *b += ( ((*i - *b) * a) >> 8 ); | 1946 | *b += ( ((*i - *b) * a) >> 8 ); |
1946 | --i; --b; | 1947 | --i; --b; |
1947 | *b += ( ((*i - *b) * a) >> 8 ); | 1948 | *b += ( ((*i - *b) * a) >> 8 ); |
1948 | --i; --b; | 1949 | --i; --b; |
1949 | #else | 1950 | #else |
1950 | *b += ( ((*i - *b) * a) >> 8 ); | 1951 | *b += ( ((*i - *b) * a) >> 8 ); |
1951 | --i; --b; | 1952 | --i; --b; |
1952 | *b += ( ((*i - *b) * a) >> 8 ); | 1953 | *b += ( ((*i - *b) * a) >> 8 ); |
1953 | --i; --b; | 1954 | --i; --b; |
1954 | *b += ( ((*i - *b) * a) >> 8 ); | 1955 | *b += ( ((*i - *b) * a) >> 8 ); |
1955 | i -= 2; b -= 2; | 1956 | i -= 2; b -= 2; |
1956 | #endif | 1957 | #endif |
1957 | } while (k--); | 1958 | } while (k--); |
1958 | } | 1959 | } |
1959 | 1960 | ||
1960 | return true; | 1961 | return true; |
1961 | } | 1962 | } |
1962 | 1963 | ||
1963 | // For selected icons | 1964 | // For selected icons |
1964 | QImage& OImageEffect::selectedImage( QImage &img, const QColor &col ) | 1965 | QImage& OImageEffect::selectedImage( QImage &img, const QColor &col ) |
1965 | { | 1966 | { |
1966 | return blend( col, img, 0.5); | 1967 | return blend( col, img, 0.5); |
1967 | } | 1968 | } |
1968 | 1969 | ||
1969 | // | 1970 | // |
1970 | // =================================================================== | 1971 | // =================================================================== |
1971 | // Effects originally ported from ImageMagick for PixiePlus, plus a few | 1972 | // Effects originally ported from ImageMagick for PixiePlus, plus a few |
1972 | // new ones. (mosfet 12/29/01) | 1973 | // new ones. (mosfet 12/29/01) |
1973 | // =================================================================== | 1974 | // =================================================================== |
1974 | // | 1975 | // |
1975 | 1976 | ||
1976 | void OImageEffect::normalize(QImage &img) | 1977 | void OImageEffect::normalize(QImage &img) |
1977 | { | 1978 | { |
1978 | int *histogram, threshold_intensity, intense; | 1979 | int *histogram, threshold_intensity, intense; |
1979 | int x, y, i; | 1980 | int x, y, i; |
1980 | 1981 | ||
1981 | unsigned int gray_value; | 1982 | unsigned int gray_value; |
1982 | unsigned int *normalize_map; | 1983 | unsigned int *normalize_map; |
1983 | unsigned int high, low; | 1984 | unsigned int high, low; |
1984 | 1985 | ||
1985 | // allocate histogram and normalize map | 1986 | // allocate histogram and normalize map |
1986 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); | 1987 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); |
1987 | normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int)); | 1988 | normalize_map = (unsigned int *)malloc((MaxRGB+1)*sizeof(unsigned int)); |
1988 | if(!normalize_map || !histogram){ | 1989 | if(!normalize_map || !histogram){ |
1989 | qWarning("Unable to allocate normalize histogram and map"); | 1990 | owarn << "Unable to allocate normalize histogram and map" << oendl; |
1990 | free(normalize_map); | 1991 | free(normalize_map); |
1991 | free(histogram); | 1992 | free(histogram); |
1992 | return; | 1993 | return; |
1993 | } | 1994 | } |
1994 | 1995 | ||
1995 | // form histogram | 1996 | // form histogram |
1996 | if(img.depth() > 8){ // DirectClass | 1997 | if(img.depth() > 8){ // DirectClass |
1997 | unsigned int *data; | 1998 | unsigned int *data; |
1998 | for(y=0; y < img.height(); ++y){ | 1999 | for(y=0; y < img.height(); ++y){ |
1999 | data = (unsigned int *)img.scanLine(y); | 2000 | data = (unsigned int *)img.scanLine(y); |
2000 | for(x=0; x < img.width(); ++x){ | 2001 | for(x=0; x < img.width(); ++x){ |
2001 | gray_value = intensityValue(data[x]); | 2002 | gray_value = intensityValue(data[x]); |
2002 | histogram[gray_value]++; | 2003 | histogram[gray_value]++; |
2003 | } | 2004 | } |
2004 | } | 2005 | } |
2005 | } | 2006 | } |
2006 | else{ // PsudeoClass | 2007 | else{ // PsudeoClass |
2007 | unsigned char *data; | 2008 | unsigned char *data; |
2008 | unsigned int *cTable = img.colorTable(); | 2009 | unsigned int *cTable = img.colorTable(); |
2009 | for(y=0; y < img.height(); ++y){ | 2010 | for(y=0; y < img.height(); ++y){ |
2010 | data = (unsigned char *)img.scanLine(y); | 2011 | data = (unsigned char *)img.scanLine(y); |
2011 | for(x=0; x < img.width(); ++x){ | 2012 | for(x=0; x < img.width(); ++x){ |
2012 | gray_value = intensityValue(*(cTable+data[x])); | 2013 | gray_value = intensityValue(*(cTable+data[x])); |
2013 | histogram[gray_value]++; | 2014 | histogram[gray_value]++; |
2014 | } | 2015 | } |
2015 | } | 2016 | } |
2016 | } | 2017 | } |
2017 | 2018 | ||
2018 | // find histogram boundaries by locating the 1 percent levels | 2019 | // find histogram boundaries by locating the 1 percent levels |
2019 | threshold_intensity = (img.width()*img.height())/100; | 2020 | threshold_intensity = (img.width()*img.height())/100; |
2020 | intense = 0; | 2021 | intense = 0; |
2021 | for(low=0; low < MaxRGB; ++low){ | 2022 | for(low=0; low < MaxRGB; ++low){ |
2022 | intense+=histogram[low]; | 2023 | intense+=histogram[low]; |
2023 | if(intense > threshold_intensity) | 2024 | if(intense > threshold_intensity) |
2024 | break; | 2025 | break; |
2025 | } | 2026 | } |
2026 | intense=0; | 2027 | intense=0; |
2027 | for(high=MaxRGB; high != 0; --high){ | 2028 | for(high=MaxRGB; high != 0; --high){ |
2028 | intense+=histogram[high]; | 2029 | intense+=histogram[high]; |
2029 | if(intense > threshold_intensity) | 2030 | if(intense > threshold_intensity) |
2030 | break; | 2031 | break; |
2031 | } | 2032 | } |
2032 | 2033 | ||
2033 | if (low == high){ | 2034 | if (low == high){ |
2034 | // Unreasonable contrast; use zero threshold to determine boundaries. | 2035 | // Unreasonable contrast; use zero threshold to determine boundaries. |
2035 | threshold_intensity=0; | 2036 | threshold_intensity=0; |
2036 | intense=0; | 2037 | intense=0; |
2037 | for(low=0; low < MaxRGB; ++low){ | 2038 | for(low=0; low < MaxRGB; ++low){ |
2038 | intense+=histogram[low]; | 2039 | intense+=histogram[low]; |
2039 | if(intense > threshold_intensity) | 2040 | if(intense > threshold_intensity) |
2040 | break; | 2041 | break; |
2041 | } | 2042 | } |
2042 | intense=0; | 2043 | intense=0; |
2043 | for(high=MaxRGB; high != 0; --high) | 2044 | for(high=MaxRGB; high != 0; --high) |
2044 | { | 2045 | { |
2045 | intense+=histogram[high]; | 2046 | intense+=histogram[high]; |
2046 | if(intense > threshold_intensity) | 2047 | if(intense > threshold_intensity) |
2047 | break; | 2048 | break; |
2048 | } | 2049 | } |
2049 | if(low == high) | 2050 | if(low == high) |
2050 | return; // zero span bound | 2051 | return; // zero span bound |
2051 | } | 2052 | } |
2052 | 2053 | ||
2053 | // Stretch the histogram to create the normalized image mapping. | 2054 | // Stretch the histogram to create the normalized image mapping. |
2054 | for(i=0; i <= MaxRGB; i++){ | 2055 | for(i=0; i <= MaxRGB; i++){ |
2055 | if (i < (int) low) | 2056 | if (i < (int) low) |
2056 | normalize_map[i]=0; | 2057 | normalize_map[i]=0; |
2057 | else{ | 2058 | else{ |
2058 | if(i > (int) high) | 2059 | if(i > (int) high) |
2059 | normalize_map[i]=MaxRGB; | 2060 | normalize_map[i]=MaxRGB; |
2060 | else | 2061 | else |
2061 | normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low); | 2062 | normalize_map[i]=(MaxRGB-1)*(i-low)/(high-low); |
2062 | } | 2063 | } |
2063 | } | 2064 | } |
2064 | // Normalize | 2065 | // Normalize |
2065 | if(img.depth() > 8){ // DirectClass | 2066 | if(img.depth() > 8){ // DirectClass |
2066 | unsigned int *data; | 2067 | unsigned int *data; |
2067 | for(y=0; y < img.height(); ++y){ | 2068 | for(y=0; y < img.height(); ++y){ |
2068 | data = (unsigned int *)img.scanLine(y); | 2069 | data = (unsigned int *)img.scanLine(y); |
2069 | for(x=0; x < img.width(); ++x){ | 2070 | for(x=0; x < img.width(); ++x){ |
2070 | data[x] = qRgba(normalize_map[qRed(data[x])], | 2071 | data[x] = qRgba(normalize_map[qRed(data[x])], |
2071 | normalize_map[qGreen(data[x])], | 2072 | normalize_map[qGreen(data[x])], |
2072 | normalize_map[qBlue(data[x])], | 2073 | normalize_map[qBlue(data[x])], |
2073 | qAlpha(data[x])); | 2074 | qAlpha(data[x])); |
2074 | } | 2075 | } |
2075 | } | 2076 | } |
2076 | } | 2077 | } |
2077 | else{ // PsudeoClass | 2078 | else{ // PsudeoClass |
2078 | int colors = img.numColors(); | 2079 | int colors = img.numColors(); |
2079 | unsigned int *cTable = img.colorTable(); | 2080 | unsigned int *cTable = img.colorTable(); |
2080 | for(i=0; i < colors; ++i){ | 2081 | for(i=0; i < colors; ++i){ |
2081 | cTable[i] = qRgba(normalize_map[qRed(cTable[i])], | 2082 | cTable[i] = qRgba(normalize_map[qRed(cTable[i])], |
2082 | normalize_map[qGreen(cTable[i])], | 2083 | normalize_map[qGreen(cTable[i])], |
2083 | normalize_map[qBlue(cTable[i])], | 2084 | normalize_map[qBlue(cTable[i])], |
2084 | qAlpha(cTable[i])); | 2085 | qAlpha(cTable[i])); |
2085 | } | 2086 | } |
2086 | } | 2087 | } |
2087 | free(histogram); | 2088 | free(histogram); |
2088 | free(normalize_map); | 2089 | free(normalize_map); |
2089 | } | 2090 | } |
2090 | 2091 | ||
2091 | 2092 | ||
2092 | void OImageEffect::equalize(QImage &img) | 2093 | void OImageEffect::equalize(QImage &img) |
2093 | { | 2094 | { |
2094 | int *histogram, *map, *equalize_map; | 2095 | int *histogram, *map, *equalize_map; |
2095 | int x, y, i, j; | 2096 | int x, y, i, j; |
2096 | 2097 | ||
2097 | unsigned int high, low; | 2098 | unsigned int high, low; |
2098 | 2099 | ||
2099 | // allocate histogram and maps | 2100 | // allocate histogram and maps |
2100 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); | 2101 | histogram = (int *)calloc(MaxRGB+1, sizeof(int)); |
2101 | map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); | 2102 | map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); |
2102 | equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); | 2103 | equalize_map = (int *)malloc((MaxRGB+1)*sizeof(unsigned int)); |
2103 | 2104 | ||
2104 | if(!histogram || !map || !equalize_map){ | 2105 | if(!histogram || !map || !equalize_map){ |
2105 | qWarning("Unable to allocate equalize histogram and maps"); | 2106 | owarn << "Unable to allocate equalize histogram and maps" << oendl; |
2106 | free(histogram); | 2107 | free(histogram); |
2107 | free(map); | 2108 | free(map); |
2108 | free(equalize_map); | 2109 | free(equalize_map); |
2109 | return; | 2110 | return; |
2110 | } | 2111 | } |
2111 | // form histogram | 2112 | // form histogram |
2112 | if(img.depth() > 8){ // DirectClass | 2113 | if(img.depth() > 8){ // DirectClass |
2113 | unsigned int *data; | 2114 | unsigned int *data; |
2114 | for(y=0; y < img.height(); ++y){ | 2115 | for(y=0; y < img.height(); ++y){ |
2115 | data = (unsigned int *)img.scanLine(y); | 2116 | data = (unsigned int *)img.scanLine(y); |
2116 | for(x=0; x < img.width(); ++x){ | 2117 | for(x=0; x < img.width(); ++x){ |
2117 | histogram[intensityValue(data[x])]++; | 2118 | histogram[intensityValue(data[x])]++; |
2118 | } | 2119 | } |
2119 | } | 2120 | } |
2120 | } | 2121 | } |
2121 | else{ // PsudeoClass | 2122 | else{ // PsudeoClass |
2122 | unsigned char *data; | 2123 | unsigned char *data; |
2123 | unsigned int *cTable = img.colorTable(); | 2124 | unsigned int *cTable = img.colorTable(); |
2124 | for(y=0; y < img.height(); ++y){ | 2125 | for(y=0; y < img.height(); ++y){ |
2125 | data = (unsigned char *)img.scanLine(y); | 2126 | data = (unsigned char *)img.scanLine(y); |
2126 | for(x=0; x < img.width(); ++x){ | 2127 | for(x=0; x < img.width(); ++x){ |
2127 | histogram[intensityValue(*(cTable+data[x]))]++; | 2128 | histogram[intensityValue(*(cTable+data[x]))]++; |
2128 | } | 2129 | } |
2129 | } | 2130 | } |
2130 | } | 2131 | } |
2131 | 2132 | ||
2132 | // integrate the histogram to get the equalization map. | 2133 | // integrate the histogram to get the equalization map. |
2133 | j=0; | 2134 | j=0; |
2134 | for(i=0; i <= MaxRGB; i++){ | 2135 | for(i=0; i <= MaxRGB; i++){ |
2135 | j+=histogram[i]; | 2136 | j+=histogram[i]; |
2136 | map[i]=j; | 2137 | map[i]=j; |
2137 | } | 2138 | } |
2138 | free(histogram); | 2139 | free(histogram); |
2139 | if(map[MaxRGB] == 0){ | 2140 | if(map[MaxRGB] == 0){ |
2140 | free(equalize_map); | 2141 | free(equalize_map); |
2141 | free(map); | 2142 | free(map); |
2142 | return; | 2143 | return; |
2143 | } | 2144 | } |
2144 | // equalize | 2145 | // equalize |
2145 | low=map[0]; | 2146 | low=map[0]; |
2146 | high=map[MaxRGB]; | 2147 | high=map[MaxRGB]; |
2147 | for(i=0; i <= MaxRGB; i++) | 2148 | for(i=0; i <= MaxRGB; i++) |
2148 | equalize_map[i]=(unsigned int) | 2149 | equalize_map[i]=(unsigned int) |
2149 | ((((double) (map[i]-low))*MaxRGB)/QMAX(high-low,1)); | 2150 | ((((double) (map[i]-low))*MaxRGB)/QMAX(high-low,1)); |
2150 | free(map); | 2151 | free(map); |
2151 | // stretch the histogram | 2152 | // stretch the histogram |
2152 | if(img.depth() > 8){ // DirectClass | 2153 | if(img.depth() > 8){ // DirectClass |
2153 | unsigned int *data; | 2154 | unsigned int *data; |
2154 | for(y=0; y < img.height(); ++y){ | 2155 | for(y=0; y < img.height(); ++y){ |
2155 | data = (unsigned int *)img.scanLine(y); | 2156 | data = (unsigned int *)img.scanLine(y); |
2156 | for(x=0; x < img.width(); ++x){ | 2157 | for(x=0; x < img.width(); ++x){ |
2157 | data[x] = qRgba(equalize_map[qRed(data[x])], | 2158 | data[x] = qRgba(equalize_map[qRed(data[x])], |
2158 | equalize_map[qGreen(data[x])], | 2159 | equalize_map[qGreen(data[x])], |
2159 | equalize_map[qBlue(data[x])], | 2160 | equalize_map[qBlue(data[x])], |
2160 | qAlpha(data[x])); | 2161 | qAlpha(data[x])); |
2161 | } | 2162 | } |
2162 | } | 2163 | } |
2163 | } | 2164 | } |
2164 | else{ // PsudeoClass | 2165 | else{ // PsudeoClass |
2165 | int colors = img.numColors(); | 2166 | int colors = img.numColors(); |
2166 | unsigned int *cTable = img.colorTable(); | 2167 | unsigned int *cTable = img.colorTable(); |
2167 | for(i=0; i < colors; ++i){ | 2168 | for(i=0; i < colors; ++i){ |
2168 | cTable[i] = qRgba(equalize_map[qRed(cTable[i])], | 2169 | cTable[i] = qRgba(equalize_map[qRed(cTable[i])], |
2169 | equalize_map[qGreen(cTable[i])], | 2170 | equalize_map[qGreen(cTable[i])], |
2170 | equalize_map[qBlue(cTable[i])], | 2171 | equalize_map[qBlue(cTable[i])], |
2171 | qAlpha(cTable[i])); | 2172 | qAlpha(cTable[i])); |
2172 | } | 2173 | } |
2173 | } | 2174 | } |
2174 | free(equalize_map); | 2175 | free(equalize_map); |
2175 | } | 2176 | } |
2176 | 2177 | ||
2177 | QImage OImageEffect::sample(QImage &src, int w, int h) | 2178 | QImage OImageEffect::sample(QImage &src, int w, int h) |
2178 | { | 2179 | { |
2179 | if(w == src.width() && h == src.height()) | 2180 | if(w == src.width() && h == src.height()) |
2180 | return(src); | 2181 | return(src); |
2181 | 2182 | ||
2182 | double *x_offset, *y_offset; | 2183 | double *x_offset, *y_offset; |
2183 | int j, k, y; | 2184 | int j, k, y; |
2184 | register int x; | 2185 | register int x; |
2185 | QImage dest(w, h, src.depth()); | 2186 | QImage dest(w, h, src.depth()); |
2186 | 2187 | ||
2187 | x_offset = (double *)malloc(w*sizeof(double)); | 2188 | x_offset = (double *)malloc(w*sizeof(double)); |
2188 | y_offset = (double *)malloc(h*sizeof(double)); | 2189 | y_offset = (double *)malloc(h*sizeof(double)); |
2189 | if(!x_offset || !y_offset){ | 2190 | if(!x_offset || !y_offset){ |
2190 | qWarning("Unable to allocate pixels buffer"); | 2191 | owarn << "Unable to allocate pixels buffer" << oendl; |
2191 | free(x_offset); | 2192 | free(x_offset); |
2192 | free(y_offset); | 2193 | free(y_offset); |
2193 | return(src); | 2194 | return(src); |
2194 | } | 2195 | } |
2195 | 2196 | ||
2196 | // init pixel offsets | 2197 | // init pixel offsets |
2197 | for(x=0; x < w; ++x) | 2198 | for(x=0; x < w; ++x) |
2198 | x_offset[x] = x*src.width()/((double)w); | 2199 | x_offset[x] = x*src.width()/((double)w); |
2199 | for(y=0; y < h; ++y) | 2200 | for(y=0; y < h; ++y) |
2200 | y_offset[y] = y*src.height()/((double)h); | 2201 | y_offset[y] = y*src.height()/((double)h); |
2201 | 2202 | ||
2202 | // sample each row | 2203 | // sample each row |
2203 | if(src.depth() > 8){ // DirectClass source image | 2204 | if(src.depth() > 8){ // DirectClass source image |
2204 | unsigned int *srcData, *destData; | 2205 | unsigned int *srcData, *destData; |
2205 | unsigned int *pixels; | 2206 | unsigned int *pixels; |
2206 | pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int)); | 2207 | pixels = (unsigned int *)malloc(src.width()*sizeof(unsigned int)); |
2207 | if(!pixels){ | 2208 | if(!pixels){ |
2208 | qWarning("Unable to allocate pixels buffer"); | 2209 | owarn << "Unable to allocate pixels buffer" << oendl; |
2209 | free(pixels); | 2210 | free(pixels); |
2210 | free(x_offset); | 2211 | free(x_offset); |
2211 | free(y_offset); | 2212 | free(y_offset); |
2212 | return(src); | 2213 | return(src); |
2213 | } | 2214 | } |
2214 | j = (-1); | 2215 | j = (-1); |
2215 | for(y=0; y < h; ++y){ | 2216 | for(y=0; y < h; ++y){ |
2216 | destData = (unsigned int *)dest.scanLine(y); | 2217 | destData = (unsigned int *)dest.scanLine(y); |
2217 | if(j != y_offset[y]){ | 2218 | if(j != y_offset[y]){ |
2218 | // read a scan line | 2219 | // read a scan line |
2219 | j = (int)(y_offset[y]); | 2220 | j = (int)(y_offset[y]); |
2220 | srcData = (unsigned int *)src.scanLine(j); | 2221 | srcData = (unsigned int *)src.scanLine(j); |
2221 | (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned int)); | 2222 | (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned int)); |
2222 | } | 2223 | } |
2223 | // sample each column | 2224 | // sample each column |
2224 | for(x=0; x < w; ++x){ | 2225 | for(x=0; x < w; ++x){ |
2225 | k = (int)(x_offset[x]); | 2226 | k = (int)(x_offset[x]); |
2226 | destData[x] = pixels[k]; | 2227 | destData[x] = pixels[k]; |
2227 | } | 2228 | } |
2228 | } | 2229 | } |
2229 | free(pixels); | 2230 | free(pixels); |
2230 | } | 2231 | } |
2231 | else{ // PsudeoClass source image | 2232 | else{ // PsudeoClass source image |
2232 | unsigned char *srcData, *destData; | 2233 | unsigned char *srcData, *destData; |
2233 | unsigned char *pixels; | 2234 | unsigned char *pixels; |
2234 | pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char)); | 2235 | pixels = (unsigned char *)malloc(src.width()*sizeof(unsigned char)); |
2235 | if(!pixels){ | 2236 | if(!pixels){ |
2236 | qWarning("Unable to allocate pixels buffer"); | 2237 | owarn << "Unable to allocate pixels buffer" << oendl; |
2237 | free(pixels); | 2238 | free(pixels); |
2238 | free(x_offset); | 2239 | free(x_offset); |
2239 | free(y_offset); | 2240 | free(y_offset); |
2240 | return(src); | 2241 | return(src); |
2241 | } | 2242 | } |
2242 | // copy colortable | 2243 | // copy colortable |
2243 | dest.setNumColors(src.numColors()); | 2244 | dest.setNumColors(src.numColors()); |
2244 | (void)memcpy(dest.colorTable(), src.colorTable(), | 2245 | (void)memcpy(dest.colorTable(), src.colorTable(), |
2245 | src.numColors()*sizeof(unsigned int)); | 2246 | src.numColors()*sizeof(unsigned int)); |
2246 | 2247 | ||
2247 | // sample image | 2248 | // sample image |
2248 | j = (-1); | 2249 | j = (-1); |
2249 | for(y=0; y < h; ++y){ | 2250 | for(y=0; y < h; ++y){ |
2250 | destData = (unsigned char *)dest.scanLine(y); | 2251 | destData = (unsigned char *)dest.scanLine(y); |
2251 | if(j != y_offset[y]){ | 2252 | if(j != y_offset[y]){ |
2252 | // read a scan line | 2253 | // read a scan line |
2253 | j = (int)(y_offset[y]); | 2254 | j = (int)(y_offset[y]); |
2254 | srcData = (unsigned char *)src.scanLine(j); | 2255 | srcData = (unsigned char *)src.scanLine(j); |
2255 | (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned char)); | 2256 | (void)memcpy(pixels, srcData, src.width()*sizeof(unsigned char)); |
2256 | } | 2257 | } |
2257 | // sample each column | 2258 | // sample each column |
2258 | for(x=0; x < w; ++x){ | 2259 | for(x=0; x < w; ++x){ |
2259 | k = (int)(x_offset[x]); | 2260 | k = (int)(x_offset[x]); |
2260 | destData[x] = pixels[k]; | 2261 | destData[x] = pixels[k]; |
2261 | } | 2262 | } |
2262 | } | 2263 | } |
2263 | free(pixels); | 2264 | free(pixels); |
2264 | } | 2265 | } |
2265 | free(x_offset); | 2266 | free(x_offset); |
2266 | free(y_offset); | 2267 | free(y_offset); |
2267 | return(dest); | 2268 | return(dest); |
2268 | } | 2269 | } |
2269 | 2270 | ||
2270 | void OImageEffect::threshold(QImage &img, unsigned int threshold) | 2271 | void OImageEffect::threshold(QImage &img, unsigned int threshold) |
2271 | { | 2272 | { |
2272 | int i, count; | 2273 | int i, count; |
2273 | unsigned int *data; | 2274 | unsigned int *data; |
2274 | if(img.depth() > 8){ // DirectClass | 2275 | if(img.depth() > 8){ // DirectClass |
2275 | count = img.width()*img.height(); | 2276 | count = img.width()*img.height(); |
2276 | data = (unsigned int *)img.bits(); | 2277 | data = (unsigned int *)img.bits(); |
2277 | } | 2278 | } |
2278 | else{ // PsudeoClass | 2279 | else{ // PsudeoClass |
2279 | count = img.numColors(); | 2280 | count = img.numColors(); |
2280 | data = (unsigned int *)img.colorTable(); | 2281 | data = (unsigned int *)img.colorTable(); |
2281 | } | 2282 | } |
2282 | for(i=0; i < count; ++i) | 2283 | for(i=0; i < count; ++i) |
2283 | data[i] = intensityValue(data[i]) < threshold ? Qt::black.rgb() : Qt::white.rgb(); | 2284 | data[i] = intensityValue(data[i]) < threshold ? Qt::black.rgb() : Qt::white.rgb(); |
2284 | } | 2285 | } |
2285 | 2286 | ||
2286 | QImage OImageEffect::charcoal(QImage &src, double factor) | 2287 | QImage OImageEffect::charcoal(QImage &src, double factor) |
2287 | { | 2288 | { |
2288 | QImage dest(src); | 2289 | QImage dest(src); |
2289 | dest.detach(); | 2290 | dest.detach(); |
2290 | toGray(dest); | 2291 | toGray(dest); |
2291 | dest = edge(dest, factor); | 2292 | dest = edge(dest, factor); |
2292 | dest = blur(dest, factor); | 2293 | dest = blur(dest, factor); |
2293 | normalize(dest); | 2294 | normalize(dest); |
2294 | dest.invertPixels(false); | 2295 | dest.invertPixels(false); |
2295 | return(dest); | 2296 | return(dest); |
2296 | } | 2297 | } |
2297 | 2298 | ||
2298 | void OImageEffect::hull(const int x_offset, const int y_offset, | 2299 | void OImageEffect::hull(const int x_offset, const int y_offset, |
2299 | const int polarity, const int columns, | 2300 | const int polarity, const int columns, |
2300 | const int rows, | 2301 | const int rows, |
2301 | unsigned int *f, unsigned int *g) | 2302 | unsigned int *f, unsigned int *g) |
2302 | { | 2303 | { |
2303 | int x, y; | 2304 | int x, y; |
2304 | 2305 | ||
2305 | unsigned int *p, *q, *r, *s; | 2306 | unsigned int *p, *q, *r, *s; |
2306 | unsigned int v; | 2307 | unsigned int v; |
2307 | if(f == NULL || g == NULL) | 2308 | if(f == NULL || g == NULL) |
2308 | return; | 2309 | return; |
2309 | p=f+(columns+2); | 2310 | p=f+(columns+2); |
2310 | q=g+(columns+2); | 2311 | q=g+(columns+2); |
2311 | r=p+(y_offset*(columns+2)+x_offset); | 2312 | r=p+(y_offset*(columns+2)+x_offset); |
2312 | for (y=0; y < rows; y++){ | 2313 | for (y=0; y < rows; y++){ |
2313 | p++; | 2314 | p++; |
2314 | q++; | 2315 | q++; |
2315 | r++; | 2316 | r++; |
2316 | if(polarity > 0) | 2317 | if(polarity > 0) |
2317 | for (x=0; x < columns; x++){ | 2318 | for (x=0; x < columns; x++){ |
2318 | v=(*p); | 2319 | v=(*p); |
2319 | if (*r > v) | 2320 | if (*r > v) |
2320 | v++; | 2321 | v++; |
2321 | *q=v; | 2322 | *q=v; |
2322 | p++; | 2323 | p++; |
2323 | q++; | 2324 | q++; |
2324 | r++; | 2325 | r++; |
2325 | } | 2326 | } |
2326 | else | 2327 | else |
2327 | for(x=0; x < columns; x++){ | 2328 | for(x=0; x < columns; x++){ |
2328 | v=(*p); | 2329 | v=(*p); |
2329 | if (v > (unsigned int) (*r+1)) | 2330 | if (v > (unsigned int) (*r+1)) |
2330 | v--; | 2331 | v--; |
2331 | *q=v; | 2332 | *q=v; |
2332 | p++; | 2333 | p++; |
2333 | q++; | 2334 | q++; |
2334 | r++; | 2335 | r++; |
2335 | } | 2336 | } |
2336 | p++; | 2337 | p++; |
2337 | q++; | 2338 | q++; |
2338 | r++; | 2339 | r++; |
2339 | } | 2340 | } |
2340 | p=f+(columns+2); | 2341 | p=f+(columns+2); |
2341 | q=g+(columns+2); | 2342 | q=g+(columns+2); |
2342 | r=q+(y_offset*(columns+2)+x_offset); | 2343 | r=q+(y_offset*(columns+2)+x_offset); |
2343 | s=q-(y_offset*(columns+2)+x_offset); | 2344 | s=q-(y_offset*(columns+2)+x_offset); |
2344 | for(y=0; y < rows; y++){ | 2345 | for(y=0; y < rows; y++){ |
2345 | p++; | 2346 | p++; |
2346 | q++; | 2347 | q++; |
2347 | r++; | 2348 | r++; |
2348 | s++; | 2349 | s++; |
2349 | if(polarity > 0) | 2350 | if(polarity > 0) |
2350 | for(x=0; x < (int) columns; x++){ | 2351 | for(x=0; x < (int) columns; x++){ |
2351 | v=(*q); | 2352 | v=(*q); |
2352 | if (((unsigned int) (*s+1) > v) && (*r > v)) | 2353 | if (((unsigned int) (*s+1) > v) && (*r > v)) |
2353 | v++; | 2354 | v++; |
2354 | *p=v; | 2355 | *p=v; |
2355 | p++; | 2356 | p++; |
2356 | q++; | 2357 | q++; |
2357 | r++; | 2358 | r++; |
2358 | s++; | 2359 | s++; |
2359 | } | 2360 | } |
2360 | else | 2361 | else |
2361 | for (x=0; x < columns; x++){ | 2362 | for (x=0; x < columns; x++){ |
2362 | v=(*q); | 2363 | v=(*q); |
2363 | if (((unsigned int) (*s+1) < v) && (*r < v)) | 2364 | if (((unsigned int) (*s+1) < v) && (*r < v)) |
2364 | v--; | 2365 | v--; |
2365 | *p=v; | 2366 | *p=v; |
2366 | p++; | 2367 | p++; |
2367 | q++; | 2368 | q++; |
2368 | r++; | 2369 | r++; |
2369 | s++; | 2370 | s++; |
2370 | } | 2371 | } |
2371 | p++; | 2372 | p++; |
2372 | q++; | 2373 | q++; |
2373 | r++; | 2374 | r++; |
2374 | s++; | 2375 | s++; |
2375 | } | 2376 | } |
2376 | } | 2377 | } |
2377 | 2378 | ||
2378 | QImage OImageEffect::despeckle(QImage &src) | 2379 | QImage OImageEffect::despeckle(QImage &src) |
2379 | { | 2380 | { |
2380 | int i, j, x, y; | 2381 | int i, j, x, y; |
2381 | unsigned int *blue_channel, *red_channel, *green_channel, *buffer, | 2382 | unsigned int *blue_channel, *red_channel, *green_channel, *buffer, |
2382 | *alpha_channel; | 2383 | *alpha_channel; |
2383 | int packets; | 2384 | int packets; |
2384 | static const int | 2385 | static const int |
2385 | X[4]= {0, 1, 1,-1}, | 2386 | X[4]= {0, 1, 1,-1}, |
2386 | Y[4]= {1, 0, 1, 1}; | 2387 | Y[4]= {1, 0, 1, 1}; |
2387 | 2388 | ||
2388 | unsigned int *destData; | 2389 | unsigned int *destData; |
2389 | QImage dest(src.width(), src.height(), 32); | 2390 | QImage dest(src.width(), src.height(), 32); |
2390 | 2391 | ||
2391 | packets = (src.width()+2)*(src.height()+2); | 2392 | packets = (src.width()+2)*(src.height()+2); |
2392 | red_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); | 2393 | red_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); |
2393 | green_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); | 2394 | green_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); |
2394 | blue_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); | 2395 | blue_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); |
2395 | alpha_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); | 2396 | alpha_channel = (unsigned int *)calloc(packets, sizeof(unsigned int)); |
2396 | buffer = (unsigned int *)calloc(packets, sizeof(unsigned int)); | 2397 | buffer = (unsigned int *)calloc(packets, sizeof(unsigned int)); |
2397 | if(!red_channel || ! green_channel || ! blue_channel || ! alpha_channel || | 2398 | if(!red_channel || ! green_channel || ! blue_channel || ! alpha_channel || |
2398 | !buffer){ | 2399 | !buffer){ |
2399 | free(red_channel); | 2400 | free(red_channel); |
2400 | free(green_channel); | 2401 | free(green_channel); |
2401 | free(blue_channel); | 2402 | free(blue_channel); |
2402 | free(alpha_channel); | 2403 | free(alpha_channel); |
2403 | free(buffer); | 2404 | free(buffer); |
2404 | return(src); | 2405 | return(src); |
2405 | } | 2406 | } |
2406 | 2407 | ||
2407 | // copy image pixels to color component buffers | 2408 | // copy image pixels to color component buffers |
2408 | j = src.width()+2; | 2409 | j = src.width()+2; |
2409 | if(src.depth() > 8){ // DirectClass source image | 2410 | if(src.depth() > 8){ // DirectClass source image |
2410 | unsigned int *srcData; | 2411 | unsigned int *srcData; |
2411 | for(y=0; y < src.height(); ++y){ | 2412 | for(y=0; y < src.height(); ++y){ |
2412 | srcData = (unsigned int *)src.scanLine(y); | 2413 | srcData = (unsigned int *)src.scanLine(y); |
2413 | ++j; | 2414 | ++j; |
2414 | for(x=0; x < src.width(); ++x){ | 2415 | for(x=0; x < src.width(); ++x){ |
2415 | red_channel[j] = qRed(srcData[x]); | 2416 | red_channel[j] = qRed(srcData[x]); |
2416 | green_channel[j] = qGreen(srcData[x]); | 2417 | green_channel[j] = qGreen(srcData[x]); |
2417 | blue_channel[j] = qBlue(srcData[x]); | 2418 | blue_channel[j] = qBlue(srcData[x]); |
2418 | alpha_channel[j] = qAlpha(srcData[x]); | 2419 | alpha_channel[j] = qAlpha(srcData[x]); |
2419 | ++j; | 2420 | ++j; |
2420 | } | 2421 | } |
2421 | ++j; | 2422 | ++j; |
2422 | } | 2423 | } |
2423 | } | 2424 | } |
2424 | else{ // PsudeoClass source image | 2425 | else{ // PsudeoClass source image |
2425 | unsigned char *srcData; | 2426 | unsigned char *srcData; |
2426 | unsigned int *cTable = src.colorTable(); | 2427 | unsigned int *cTable = src.colorTable(); |
2427 | unsigned int pixel; | 2428 | unsigned int pixel; |
2428 | for(y=0; y < src.height(); ++y){ | 2429 | for(y=0; y < src.height(); ++y){ |
2429 | srcData = (unsigned char *)src.scanLine(y); | 2430 | srcData = (unsigned char *)src.scanLine(y); |
2430 | ++j; | 2431 | ++j; |
2431 | for(x=0; x < src.width(); ++x){ | 2432 | for(x=0; x < src.width(); ++x){ |
2432 | pixel = *(cTable+srcData[x]); | 2433 | pixel = *(cTable+srcData[x]); |
2433 | red_channel[j] = qRed(pixel); | 2434 | red_channel[j] = qRed(pixel); |
2434 | green_channel[j] = qGreen(pixel); | 2435 | green_channel[j] = qGreen(pixel); |
2435 | blue_channel[j] = qBlue(pixel); | 2436 | blue_channel[j] = qBlue(pixel); |
2436 | alpha_channel[j] = qAlpha(pixel); | 2437 | alpha_channel[j] = qAlpha(pixel); |
2437 | ++j; | 2438 | ++j; |
2438 | } | 2439 | } |
2439 | ++j; | 2440 | ++j; |
2440 | } | 2441 | } |
2441 | } | 2442 | } |
2442 | // reduce speckle in red channel | 2443 | // reduce speckle in red channel |
2443 | for(i=0; i < 4; i++){ | 2444 | for(i=0; i < 4; i++){ |
2444 | hull(X[i],Y[i],1,src.width(),src.height(),red_channel,buffer); | 2445 | hull(X[i],Y[i],1,src.width(),src.height(),red_channel,buffer); |
2445 | hull(-X[i],-Y[i],1,src.width(),src.height(),red_channel,buffer); | 2446 | hull(-X[i],-Y[i],1,src.width(),src.height(),red_channel,buffer); |
2446 | hull(-X[i],-Y[i],-1,src.width(),src.height(),red_channel,buffer); | 2447 | hull(-X[i],-Y[i],-1,src.width(),src.height(),red_channel,buffer); |
2447 | hull(X[i],Y[i],-1,src.width(),src.height(),red_channel,buffer); | 2448 | hull(X[i],Y[i],-1,src.width(),src.height(),red_channel,buffer); |
2448 | } | 2449 | } |
2449 | // reduce speckle in green channel | 2450 | // reduce speckle in green channel |
2450 | for (i=0; i < packets; i++) | 2451 | for (i=0; i < packets; i++) |
2451 | buffer[i]=0; | 2452 | buffer[i]=0; |
2452 | for (i=0; i < 4; i++){ | 2453 | for (i=0; i < 4; i++){ |
2453 | hull(X[i],Y[i],1,src.width(),src.height(),green_channel,buffer); | 2454 | hull(X[i],Y[i],1,src.width(),src.height(),green_channel,buffer); |
2454 | hull(-X[i],-Y[i],1,src.width(),src.height(),green_channel,buffer); | 2455 | hull(-X[i],-Y[i],1,src.width(),src.height(),green_channel,buffer); |
2455 | hull(-X[i],-Y[i],-1,src.width(),src.height(),green_channel,buffer); | 2456 | hull(-X[i],-Y[i],-1,src.width(),src.height(),green_channel,buffer); |
2456 | hull(X[i],Y[i],-1,src.width(),src.height(),green_channel,buffer); | 2457 | hull(X[i],Y[i],-1,src.width(),src.height(),green_channel,buffer); |
2457 | } | 2458 | } |
2458 | // reduce speckle in blue channel | 2459 | // reduce speckle in blue channel |
2459 | for (i=0; i < packets; i++) | 2460 | for (i=0; i < packets; i++) |
2460 | buffer[i]=0; | 2461 | buffer[i]=0; |
2461 | for (i=0; i < 4; i++){ | 2462 | for (i=0; i < 4; i++){ |
2462 | hull(X[i],Y[i],1,src.width(),src.height(),blue_channel,buffer); | 2463 | hull(X[i],Y[i],1,src.width(),src.height(),blue_channel,buffer); |
2463 | hull(-X[i],-Y[i],1,src.width(),src.height(),blue_channel,buffer); | 2464 | hull(-X[i],-Y[i],1,src.width(),src.height(),blue_channel,buffer); |
2464 | hull(-X[i],-Y[i],-1,src.width(),src.height(),blue_channel,buffer); | 2465 | hull(-X[i],-Y[i],-1,src.width(),src.height(),blue_channel,buffer); |
2465 | hull(X[i],Y[i],-1,src.width(),src.height(),blue_channel,buffer); | 2466 | hull(X[i],Y[i],-1,src.width(),src.height(),blue_channel,buffer); |
2466 | } | 2467 | } |
2467 | // copy color component buffers to despeckled image | 2468 | // copy color component buffers to despeckled image |
2468 | j = dest.width()+2; | 2469 | j = dest.width()+2; |
2469 | for(y=0; y < dest.height(); ++y) | 2470 | for(y=0; y < dest.height(); ++y) |
2470 | { | 2471 | { |
2471 | destData = (unsigned int *)dest.scanLine(y); | 2472 | destData = (unsigned int *)dest.scanLine(y); |
2472 | ++j; | 2473 | ++j; |
2473 | for (x=0; x < dest.width(); ++x) | 2474 | for (x=0; x < dest.width(); ++x) |
2474 | { | 2475 | { |
2475 | destData[x] = qRgba(red_channel[j], green_channel[j], | 2476 | destData[x] = qRgba(red_channel[j], green_channel[j], |
2476 | blue_channel[j], alpha_channel[j]); | 2477 | blue_channel[j], alpha_channel[j]); |
2477 | ++j; | 2478 | ++j; |
2478 | } | 2479 | } |
2479 | ++j; | 2480 | ++j; |
2480 | } | 2481 | } |
2481 | free(buffer); | 2482 | free(buffer); |
2482 | free(red_channel); | 2483 | free(red_channel); |
2483 | free(green_channel); | 2484 | free(green_channel); |
2484 | free(blue_channel); | 2485 | free(blue_channel); |
2485 | free(alpha_channel); | 2486 | free(alpha_channel); |
2486 | return(dest); | 2487 | return(dest); |
2487 | } | 2488 | } |
2488 | 2489 | ||
2489 | unsigned int OImageEffect::generateNoise(unsigned int pixel, | 2490 | unsigned int OImageEffect::generateNoise(unsigned int pixel, |
2490 | NoiseType noise_type) | 2491 | NoiseType noise_type) |
2491 | { | 2492 | { |
2492 | #define NoiseEpsilon 1.0e-5 | 2493 | #define NoiseEpsilon 1.0e-5 |
2493 | #define NoiseMask 0x7fff | 2494 | #define NoiseMask 0x7fff |
2494 | #define SigmaUniform 4.0 | 2495 | #define SigmaUniform 4.0 |
2495 | #define SigmaGaussian 4.0 | 2496 | #define SigmaGaussian 4.0 |
2496 | #define SigmaImpulse 0.10 | 2497 | #define SigmaImpulse 0.10 |
2497 | #define SigmaLaplacian 10.0 | 2498 | #define SigmaLaplacian 10.0 |
2498 | #define SigmaMultiplicativeGaussian 0.5 | 2499 | #define SigmaMultiplicativeGaussian 0.5 |
2499 | #define SigmaPoisson 0.05 | 2500 | #define SigmaPoisson 0.05 |
2500 | #define TauGaussian 20.0 | 2501 | #define TauGaussian 20.0 |
2501 | 2502 | ||
2502 | double alpha, beta, sigma, value; | 2503 | double alpha, beta, sigma, value; |
2503 | alpha=(double) (rand() & NoiseMask)/NoiseMask; | 2504 | alpha=(double) (rand() & NoiseMask)/NoiseMask; |
2504 | if (alpha == 0.0) | 2505 | if (alpha == 0.0) |
2505 | alpha=1.0; | 2506 | alpha=1.0; |
2506 | switch(noise_type){ | 2507 | switch(noise_type){ |
2507 | case UniformNoise: | 2508 | case UniformNoise: |
2508 | default: | 2509 | default: |
2509 | { | 2510 | { |
2510 | value=(double) pixel+SigmaUniform*(alpha-0.5); | 2511 | value=(double) pixel+SigmaUniform*(alpha-0.5); |
2511 | break; | 2512 | break; |
2512 | } | 2513 | } |
2513 | case GaussianNoise: | 2514 | case GaussianNoise: |
2514 | { | 2515 | { |
2515 | double tau; | 2516 | double tau; |
2516 | 2517 | ||
2517 | beta=(double) (rand() & NoiseMask)/NoiseMask; | 2518 | beta=(double) (rand() & NoiseMask)/NoiseMask; |
2518 | sigma=sqrt(-2.0*log(alpha))*cos(2.0*M_PI*beta); | 2519 | sigma=sqrt(-2.0*log(alpha))*cos(2.0*M_PI*beta); |
2519 | tau=sqrt(-2.0*log(alpha))*sin(2.0*M_PI*beta); | 2520 | tau=sqrt(-2.0*log(alpha))*sin(2.0*M_PI*beta); |
2520 | value=(double) pixel+ | 2521 | value=(double) pixel+ |
2521 | (sqrt((double) pixel)*SigmaGaussian*sigma)+(TauGaussian*tau); | 2522 | (sqrt((double) pixel)*SigmaGaussian*sigma)+(TauGaussian*tau); |
2522 | break; | 2523 | break; |
2523 | } | 2524 | } |
2524 | case MultiplicativeGaussianNoise: | 2525 | case MultiplicativeGaussianNoise: |
2525 | { | 2526 | { |
2526 | if (alpha <= NoiseEpsilon) | 2527 | if (alpha <= NoiseEpsilon) |
2527 | sigma=MaxRGB; | 2528 | sigma=MaxRGB; |
2528 | else | 2529 | else |
2529 | sigma=sqrt(-2.0*log(alpha)); | 2530 | sigma=sqrt(-2.0*log(alpha)); |
2530 | beta=(rand() & NoiseMask)/NoiseMask; | 2531 | beta=(rand() & NoiseMask)/NoiseMask; |
2531 | value=(double) pixel+ | 2532 | value=(double) pixel+ |
2532 | pixel*SigmaMultiplicativeGaussian*sigma*cos(2.0*M_PI*beta); | 2533 | pixel*SigmaMultiplicativeGaussian*sigma*cos(2.0*M_PI*beta); |
2533 | break; | 2534 | break; |
2534 | } | 2535 | } |
2535 | case ImpulseNoise: | 2536 | case ImpulseNoise: |
2536 | { | 2537 | { |
2537 | if (alpha < (SigmaImpulse/2.0)) | 2538 | if (alpha < (SigmaImpulse/2.0)) |
2538 | value=0; | 2539 | value=0; |
2539 | else | 2540 | else |
2540 | if (alpha >= (1.0-(SigmaImpulse/2.0))) | 2541 | if (alpha >= (1.0-(SigmaImpulse/2.0))) |
2541 | value=MaxRGB; | 2542 | value=MaxRGB; |
2542 | else | 2543 | else |
2543 | value=pixel; | 2544 | value=pixel; |
2544 | break; | 2545 | break; |
2545 | } | 2546 | } |
2546 | case LaplacianNoise: | 2547 | case LaplacianNoise: |
2547 | { | 2548 | { |
2548 | if (alpha <= 0.5) | 2549 | if (alpha <= 0.5) |
2549 | { | 2550 | { |
2550 | if (alpha <= NoiseEpsilon) | 2551 | if (alpha <= NoiseEpsilon) |
2551 | value=(double) pixel-MaxRGB; | 2552 | value=(double) pixel-MaxRGB; |
2552 | else | 2553 | else |
2553 | value=(double) pixel+SigmaLaplacian*log(2.0*alpha); | 2554 | value=(double) pixel+SigmaLaplacian*log(2.0*alpha); |
2554 | break; | 2555 | break; |
2555 | } | 2556 | } |
2556 | beta=1.0-alpha; | 2557 | beta=1.0-alpha; |
2557 | if (beta <= (0.5*NoiseEpsilon)) | 2558 | if (beta <= (0.5*NoiseEpsilon)) |
2558 | value=(double) pixel+MaxRGB; | 2559 | value=(double) pixel+MaxRGB; |
2559 | else | 2560 | else |
2560 | value=(double) pixel-SigmaLaplacian*log(2.0*beta); | 2561 | value=(double) pixel-SigmaLaplacian*log(2.0*beta); |
2561 | break; | 2562 | break; |
2562 | } | 2563 | } |
2563 | case PoissonNoise: | 2564 | case PoissonNoise: |
2564 | { | 2565 | { |
2565 | register int | 2566 | register int |
2566 | i; | 2567 | i; |
2567 | 2568 | ||
2568 | for (i=0; alpha > exp(-SigmaPoisson*pixel); i++) | 2569 | for (i=0; alpha > exp(-SigmaPoisson*pixel); i++) |
2569 | { | 2570 | { |
2570 | beta=(double) (rand() & NoiseMask)/NoiseMask; | 2571 | beta=(double) (rand() & NoiseMask)/NoiseMask; |
2571 | alpha=alpha*beta; | 2572 | alpha=alpha*beta; |
2572 | } | 2573 | } |
2573 | value=i/SigmaPoisson; | 2574 | value=i/SigmaPoisson; |
2574 | break; | 2575 | break; |
2575 | } | 2576 | } |
2576 | } | 2577 | } |
2577 | if(value < 0.0) | 2578 | if(value < 0.0) |
2578 | return(0); | 2579 | return(0); |
2579 | if(value > MaxRGB) | 2580 | if(value > MaxRGB) |
2580 | return(MaxRGB); | 2581 | return(MaxRGB); |
2581 | return((unsigned int) (value+0.5)); | 2582 | return((unsigned int) (value+0.5)); |
2582 | } | 2583 | } |
2583 | 2584 | ||
2584 | QImage OImageEffect::addNoise(QImage &src, NoiseType noise_type) | 2585 | QImage OImageEffect::addNoise(QImage &src, NoiseType noise_type) |
2585 | { | 2586 | { |
2586 | int x, y; | 2587 | int x, y; |
2587 | QImage dest(src.width(), src.height(), 32); | 2588 | QImage dest(src.width(), src.height(), 32); |
2588 | unsigned int *destData; | 2589 | unsigned int *destData; |
2589 | 2590 | ||
2590 | if(src.depth() > 8){ // DirectClass source image | 2591 | if(src.depth() > 8){ // DirectClass source image |
2591 | unsigned int *srcData; | 2592 | unsigned int *srcData; |
2592 | for(y=0; y < src.height(); ++y){ | 2593 | for(y=0; y < src.height(); ++y){ |
2593 | srcData = (unsigned int *)src.scanLine(y); | 2594 | srcData = (unsigned int *)src.scanLine(y); |
2594 | destData = (unsigned int *)dest.scanLine(y); | 2595 | destData = (unsigned int *)dest.scanLine(y); |
2595 | for(x=0; x < src.width(); ++x){ | 2596 | for(x=0; x < src.width(); ++x){ |
2596 | destData[x] = qRgba(generateNoise(qRed(srcData[x]), noise_type), | 2597 | destData[x] = qRgba(generateNoise(qRed(srcData[x]), noise_type), |
2597 | generateNoise(qGreen(srcData[x]), noise_type), | 2598 | generateNoise(qGreen(srcData[x]), noise_type), |
2598 | generateNoise(qBlue(srcData[x]), noise_type), | 2599 | generateNoise(qBlue(srcData[x]), noise_type), |
2599 | qAlpha(srcData[x])); | 2600 | qAlpha(srcData[x])); |
2600 | } | 2601 | } |
2601 | } | 2602 | } |
2602 | } | 2603 | } |
2603 | else{ // PsudeoClass source image | 2604 | else{ // PsudeoClass source image |
2604 | unsigned char *srcData; | 2605 | unsigned char *srcData; |
2605 | unsigned int *cTable = src.colorTable(); | 2606 | unsigned int *cTable = src.colorTable(); |
2606 | unsigned int pixel; | 2607 | unsigned int pixel; |
2607 | for(y=0; y < src.height(); ++y){ | 2608 | for(y=0; y < src.height(); ++y){ |
2608 | srcData = (unsigned char *)src.scanLine(y); | 2609 | srcData = (unsigned char *)src.scanLine(y); |
2609 | destData = (unsigned int *)dest.scanLine(y); | 2610 | destData = (unsigned int *)dest.scanLine(y); |
2610 | for(x=0; x < src.width(); ++x){ | 2611 | for(x=0; x < src.width(); ++x){ |
2611 | pixel = *(cTable+srcData[x]); | 2612 | pixel = *(cTable+srcData[x]); |
2612 | destData[x] = qRgba(generateNoise(qRed(pixel), noise_type), | 2613 | destData[x] = qRgba(generateNoise(qRed(pixel), noise_type), |
2613 | generateNoise(qGreen(pixel), noise_type), | 2614 | generateNoise(qGreen(pixel), noise_type), |
2614 | generateNoise(qBlue(pixel), noise_type), | 2615 | generateNoise(qBlue(pixel), noise_type), |
2615 | qAlpha(pixel)); | 2616 | qAlpha(pixel)); |
2616 | } | 2617 | } |
2617 | } | 2618 | } |
2618 | 2619 | ||
2619 | } | 2620 | } |
2620 | return(dest); | 2621 | return(dest); |
2621 | } | 2622 | } |
2622 | 2623 | ||
2623 | unsigned int OImageEffect::interpolateColor(QImage *image, double x_offset, | 2624 | unsigned int OImageEffect::interpolateColor(QImage *image, double x_offset, |
2624 | double y_offset, | 2625 | double y_offset, |
2625 | unsigned int background) | 2626 | unsigned int background) |
2626 | { | 2627 | { |
2627 | double alpha, beta; | 2628 | double alpha, beta; |
2628 | unsigned int p, q, r, s; | 2629 | unsigned int p, q, r, s; |
2629 | int x, y; | 2630 | int x, y; |
2630 | 2631 | ||
2631 | x = (int)x_offset; | 2632 | x = (int)x_offset; |
2632 | y = (int)y_offset; | 2633 | y = (int)y_offset; |
2633 | if((x < -1) || (x >= image->width()) || (y < -1) || (y >= image->height())) | 2634 | if((x < -1) || (x >= image->width()) || (y < -1) || (y >= image->height())) |
2634 | return(background); | 2635 | return(background); |
2635 | if(image->depth() > 8){ | 2636 | if(image->depth() > 8){ |
2636 | if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) { | 2637 | if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) { |
2637 | unsigned int *t = (unsigned int *)image->scanLine(y); | 2638 | unsigned int *t = (unsigned int *)image->scanLine(y); |
2638 | p = t[x]; | 2639 | p = t[x]; |
2639 | q = t[x+1]; | 2640 | q = t[x+1]; |
2640 | r = t[x+image->width()]; | 2641 | r = t[x+image->width()]; |
2641 | s = t[x+image->width()+1]; | 2642 | s = t[x+image->width()+1]; |
2642 | } | 2643 | } |
2643 | else{ | 2644 | else{ |
2644 | unsigned int *t = (unsigned int *)image->scanLine(y); | 2645 | unsigned int *t = (unsigned int *)image->scanLine(y); |
2645 | p = background; | 2646 | p = background; |
2646 | if((x >= 0) && (y >= 0)){ | 2647 | if((x >= 0) && (y >= 0)){ |
2647 | p = t[x]; | 2648 | p = t[x]; |
2648 | } | 2649 | } |
2649 | q = background; | 2650 | q = background; |
2650 | if(((x+1) < image->width()) && (y >= 0)){ | 2651 | if(((x+1) < image->width()) && (y >= 0)){ |
2651 | q = t[x+1]; | 2652 | q = t[x+1]; |
2652 | } | 2653 | } |
2653 | r = background; | 2654 | r = background; |
2654 | if((x >= 0) && ((y+1) < image->height())){ | 2655 | if((x >= 0) && ((y+1) < image->height())){ |
2655 | t = (unsigned int *)image->scanLine(y+1); | 2656 | t = (unsigned int *)image->scanLine(y+1); |
2656 | r = t[x+image->width()]; | 2657 | r = t[x+image->width()]; |
2657 | } | 2658 | } |
2658 | s = background; | 2659 | s = background; |
2659 | if(((x+1) < image->width()) && ((y+1) < image->height())){ | 2660 | if(((x+1) < image->width()) && ((y+1) < image->height())){ |
2660 | t = (unsigned int *)image->scanLine(y+1); | 2661 | t = (unsigned int *)image->scanLine(y+1); |
2661 | s = t[x+image->width()+1]; | 2662 | s = t[x+image->width()+1]; |
2662 | } | 2663 | } |
2663 | 2664 | ||
2664 | } | 2665 | } |
2665 | } | 2666 | } |
2666 | else{ | 2667 | else{ |
2667 | unsigned int *colorTable = (unsigned int *)image->colorTable(); | 2668 | unsigned int *colorTable = (unsigned int *)image->colorTable(); |
2668 | if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) { | 2669 | if((x >= 0) && (y >= 0) && (x < (image->width()-1)) && (y < (image->height()-1))) { |
2669 | unsigned char *t; | 2670 | unsigned char *t; |
2670 | t = (unsigned char *)image->scanLine(y); | 2671 | t = (unsigned char *)image->scanLine(y); |
2671 | p = *(colorTable+t[x]); | 2672 | p = *(colorTable+t[x]); |
2672 | q = *(colorTable+t[x+1]); | 2673 | q = *(colorTable+t[x+1]); |
2673 | t = (unsigned char *)image->scanLine(y+1); | 2674 | t = (unsigned char *)image->scanLine(y+1); |
2674 | r = *(colorTable+t[x]); | 2675 | r = *(colorTable+t[x]); |
2675 | s = *(colorTable+t[x+1]); | 2676 | s = *(colorTable+t[x+1]); |
2676 | } | 2677 | } |
2677 | else{ | 2678 | else{ |
2678 | unsigned char *t; | 2679 | unsigned char *t; |
2679 | p = background; | 2680 | p = background; |
2680 | if((x >= 0) && (y >= 0)){ | 2681 | if((x >= 0) && (y >= 0)){ |
2681 | t = (unsigned char *)image->scanLine(y); | 2682 | t = (unsigned char *)image->scanLine(y); |
2682 | p = *(colorTable+t[x]); | 2683 | p = *(colorTable+t[x]); |
2683 | } | 2684 | } |
2684 | q = background; | 2685 | q = background; |
2685 | if(((x+1) < image->width()) && (y >= 0)){ | 2686 | if(((x+1) < image->width()) && (y >= 0)){ |
2686 | t = (unsigned char *)image->scanLine(y); | 2687 | t = (unsigned char *)image->scanLine(y); |
2687 | q = *(colorTable+t[x+1]); | 2688 | q = *(colorTable+t[x+1]); |
2688 | } | 2689 | } |
2689 | r = background; | 2690 | r = background; |
2690 | if((x >= 0) && ((y+1) < image->height())){ | 2691 | if((x >= 0) && ((y+1) < image->height())){ |
2691 | t = (unsigned char *)image->scanLine(y+1); | 2692 | t = (unsigned char *)image->scanLine(y+1); |
2692 | r = *(colorTable+t[x]); | 2693 | r = *(colorTable+t[x]); |
2693 | } | 2694 | } |
2694 | s = background; | 2695 | s = background; |
2695 | if(((x+1) < image->width()) && ((y+1) < image->height())){ | 2696 | if(((x+1) < image->width()) && ((y+1) < image->height())){ |
2696 | t = (unsigned char *)image->scanLine(y+1); | 2697 | t = (unsigned char *)image->scanLine(y+1); |
2697 | s = *(colorTable+t[x+1]); | 2698 | s = *(colorTable+t[x+1]); |
2698 | } | 2699 | } |
2699 | 2700 | ||
2700 | } | 2701 | } |
2701 | 2702 | ||
2702 | } | 2703 | } |
2703 | x_offset -= floor(x_offset); | 2704 | x_offset -= floor(x_offset); |
2704 | y_offset -= floor(y_offset); | 2705 | y_offset -= floor(y_offset); |
2705 | alpha = 1.0-x_offset; | 2706 | alpha = 1.0-x_offset; |
2706 | beta = 1.0-y_offset; | 2707 | beta = 1.0-y_offset; |
2707 | 2708 | ||
2708 | return(qRgba((unsigned char)(beta*(alpha*qRed(p)+x_offset*qRed(q))+y_offset*(alpha*qRed(r)+x_offset*qRed(s))), | 2709 | return(qRgba((unsigned char)(beta*(alpha*qRed(p)+x_offset*qRed(q))+y_offset*(alpha*qRed(r)+x_offset*qRed(s))), |
2709 | (unsigned char)(beta*(alpha*qGreen(p)+x_offset*qGreen(q))+y_offset*(alpha*qGreen(r)+x_offset*qGreen(s))), | 2710 | (unsigned char)(beta*(alpha*qGreen(p)+x_offset*qGreen(q))+y_offset*(alpha*qGreen(r)+x_offset*qGreen(s))), |
2710 | (unsigned char)(beta*(alpha*qBlue(p)+x_offset*qBlue(q))+y_offset*(alpha*qBlue(r)+x_offset*qBlue(s))), | 2711 | (unsigned char)(beta*(alpha*qBlue(p)+x_offset*qBlue(q))+y_offset*(alpha*qBlue(r)+x_offset*qBlue(s))), |
2711 | (unsigned char)(beta*(alpha*qAlpha(p)+x_offset*qAlpha(q))+y_offset*(alpha*qAlpha(r)+x_offset*qAlpha(s))))); | 2712 | (unsigned char)(beta*(alpha*qAlpha(p)+x_offset*qAlpha(q))+y_offset*(alpha*qAlpha(r)+x_offset*qAlpha(s))))); |
2712 | } | 2713 | } |
2713 | 2714 | ||
2714 | QImage OImageEffect::implode(QImage &src, double factor, | 2715 | QImage OImageEffect::implode(QImage &src, double factor, |
2715 | unsigned int background) | 2716 | unsigned int background) |
2716 | { | 2717 | { |
2717 | double amount, distance, radius; | 2718 | double amount, distance, radius; |
2718 | double x_center, x_distance, x_scale; | 2719 | double x_center, x_distance, x_scale; |
2719 | double y_center, y_distance, y_scale; | 2720 | double y_center, y_distance, y_scale; |
2720 | unsigned int *destData; | 2721 | unsigned int *destData; |
2721 | int x, y; | 2722 | int x, y; |
2722 | 2723 | ||
2723 | QImage dest(src.width(), src.height(), 32); | 2724 | QImage dest(src.width(), src.height(), 32); |
2724 | 2725 | ||
2725 | // compute scaling factor | 2726 | // compute scaling factor |
2726 | x_scale = 1.0; | 2727 | x_scale = 1.0; |
2727 | y_scale = 1.0; | 2728 | y_scale = 1.0; |
2728 | x_center = (double)0.5*src.width(); | 2729 | x_center = (double)0.5*src.width(); |
2729 | y_center = (double)0.5*src.height(); | 2730 | y_center = (double)0.5*src.height(); |
2730 | radius=x_center; | 2731 | radius=x_center; |
2731 | if(src.width() > src.height()) | 2732 | if(src.width() > src.height()) |
2732 | y_scale = (double)src.width()/src.height(); | 2733 | y_scale = (double)src.width()/src.height(); |
2733 | else if(src.width() < src.height()){ | 2734 | else if(src.width() < src.height()){ |
2734 | x_scale = (double) src.height()/src.width(); | 2735 | x_scale = (double) src.height()/src.width(); |
2735 | radius = y_center; | 2736 | radius = y_center; |
2736 | } | 2737 | } |
2737 | amount=factor/10.0; | 2738 | amount=factor/10.0; |
2738 | if(amount >= 0) | 2739 | if(amount >= 0) |
2739 | amount/=10.0; | 2740 | amount/=10.0; |
2740 | if(src.depth() > 8){ // DirectClass source image | 2741 | if(src.depth() > 8){ // DirectClass source image |
2741 | unsigned int *srcData; | 2742 | unsigned int *srcData; |
2742 | for(y=0; y < src.height(); ++y){ | 2743 | for(y=0; y < src.height(); ++y){ |
2743 | srcData = (unsigned int *)src.scanLine(y); | 2744 | srcData = (unsigned int *)src.scanLine(y); |
2744 | destData = (unsigned int *)dest.scanLine(y); | 2745 | destData = (unsigned int *)dest.scanLine(y); |
2745 | y_distance=y_scale*(y-y_center); | 2746 | y_distance=y_scale*(y-y_center); |
2746 | for(x=0; x < src.width(); ++x){ | 2747 | for(x=0; x < src.width(); ++x){ |
2747 | destData[x] = srcData[x]; | 2748 | destData[x] = srcData[x]; |
2748 | x_distance = x_scale*(x-x_center); | 2749 | x_distance = x_scale*(x-x_center); |
2749 | distance= x_distance*x_distance+y_distance*y_distance; | 2750 | distance= x_distance*x_distance+y_distance*y_distance; |
2750 | if(distance < (radius*radius)){ | 2751 | if(distance < (radius*radius)){ |
2751 | double factor; | 2752 | double factor; |
2752 | // Implode the pixel. | 2753 | // Implode the pixel. |
2753 | factor=1.0; | 2754 | factor=1.0; |
2754 | if(distance > 0.0) | 2755 | if(distance > 0.0) |
2755 | factor= | 2756 | factor= |
2756 | pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount); | 2757 | pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount); |
2757 | destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center, | 2758 | destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center, |
2758 | factor*y_distance/y_scale+y_center, | 2759 | factor*y_distance/y_scale+y_center, |
2759 | background); | 2760 | background); |
2760 | } | 2761 | } |
2761 | } | 2762 | } |
2762 | } | 2763 | } |
2763 | } | 2764 | } |
2764 | else{ // PsudeoClass source image | 2765 | else{ // PsudeoClass source image |
2765 | unsigned char *srcData; | 2766 | unsigned char *srcData; |
2766 | unsigned char idx; | 2767 | unsigned char idx; |
2767 | unsigned int *cTable = src.colorTable(); | 2768 | unsigned int *cTable = src.colorTable(); |
2768 | for(y=0; y < src.height(); ++y){ | 2769 | for(y=0; y < src.height(); ++y){ |
2769 | srcData = (unsigned char *)src.scanLine(y); | 2770 | srcData = (unsigned char *)src.scanLine(y); |
2770 | destData = (unsigned int *)dest.scanLine(y); | 2771 | destData = (unsigned int *)dest.scanLine(y); |
2771 | y_distance=y_scale*(y-y_center); | 2772 | y_distance=y_scale*(y-y_center); |
2772 | for(x=0; x < src.width(); ++x){ | 2773 | for(x=0; x < src.width(); ++x){ |
2773 | idx = srcData[x]; | 2774 | idx = srcData[x]; |
2774 | destData[x] = cTable[idx]; | 2775 | destData[x] = cTable[idx]; |
2775 | x_distance = x_scale*(x-x_center); | 2776 | x_distance = x_scale*(x-x_center); |
2776 | distance= x_distance*x_distance+y_distance*y_distance; | 2777 | distance= x_distance*x_distance+y_distance*y_distance; |
2777 | if(distance < (radius*radius)){ | 2778 | if(distance < (radius*radius)){ |
2778 | double factor; | 2779 | double factor; |
2779 | // Implode the pixel. | 2780 | // Implode the pixel. |
2780 | factor=1.0; | 2781 | factor=1.0; |
2781 | if(distance > 0.0) | 2782 | if(distance > 0.0) |
2782 | factor= | 2783 | factor= |
2783 | pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount); | 2784 | pow(sin(0.5000000000000001*M_PI*sqrt(distance)/radius),-amount); |
2784 | destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center, | 2785 | destData[x] = interpolateColor(&src, factor*x_distance/x_scale+x_center, |
2785 | factor*y_distance/y_scale+y_center, | 2786 | factor*y_distance/y_scale+y_center, |
2786 | background); | 2787 | background); |
2787 | } | 2788 | } |
2788 | } | 2789 | } |
2789 | } | 2790 | } |
2790 | 2791 | ||
2791 | } | 2792 | } |
2792 | return(dest); | 2793 | return(dest); |
2793 | } | 2794 | } |
2794 | 2795 | ||
2795 | QImage OImageEffect::rotate(QImage &img, RotateDirection r) | 2796 | QImage OImageEffect::rotate(QImage &img, RotateDirection r) |
2796 | { | 2797 | { |
2797 | QImage dest; | 2798 | QImage dest; |
2798 | int x, y; | 2799 | int x, y; |
2799 | if(img.depth() > 8){ | 2800 | if(img.depth() > 8){ |
2800 | unsigned int *srcData, *destData; | 2801 | unsigned int *srcData, *destData; |
2801 | switch(r){ | 2802 | switch(r){ |
2802 | case Rotate90: | 2803 | case Rotate90: |
2803 | dest.create(img.height(), img.width(), img.depth()); | 2804 | dest.create(img.height(), img.width(), img.depth()); |
2804 | for(y=0; y < img.height(); ++y){ | 2805 | for(y=0; y < img.height(); ++y){ |
2805 | srcData = (unsigned int *)img.scanLine(y); | 2806 | srcData = (unsigned int *)img.scanLine(y); |
2806 | for(x=0; x < img.width(); ++x){ | 2807 | for(x=0; x < img.width(); ++x){ |
2807 | destData = (unsigned int *)dest.scanLine(x); | 2808 | destData = (unsigned int *)dest.scanLine(x); |
2808 | destData[img.height()-y-1] = srcData[x]; | 2809 | destData[img.height()-y-1] = srcData[x]; |
2809 | } | 2810 | } |
2810 | } | 2811 | } |
2811 | break; | 2812 | break; |
2812 | case Rotate180: | 2813 | case Rotate180: |
2813 | dest.create(img.width(), img.height(), img.depth()); | 2814 | dest.create(img.width(), img.height(), img.depth()); |
2814 | for(y=0; y < img.height(); ++y){ | 2815 | for(y=0; y < img.height(); ++y){ |
2815 | srcData = (unsigned int *)img.scanLine(y); | 2816 | srcData = (unsigned int *)img.scanLine(y); |
2816 | destData = (unsigned int *)dest.scanLine(img.height()-y-1); | 2817 | destData = (unsigned int *)dest.scanLine(img.height()-y-1); |
2817 | for(x=0; x < img.width(); ++x) | 2818 | for(x=0; x < img.width(); ++x) |
2818 | destData[img.width()-x-1] = srcData[x]; | 2819 | destData[img.width()-x-1] = srcData[x]; |
2819 | } | 2820 | } |
2820 | break; | 2821 | break; |
2821 | case Rotate270: | 2822 | case Rotate270: |
2822 | dest.create(img.height(), img.width(), img.depth()); | 2823 | dest.create(img.height(), img.width(), img.depth()); |
2823 | for(y=0; y < img.height(); ++y){ | 2824 | for(y=0; y < img.height(); ++y){ |
2824 | srcData = (unsigned int *)img.scanLine(y); | 2825 | srcData = (unsigned int *)img.scanLine(y); |
2825 | for(x=0; x < img.width(); ++x){ | 2826 | for(x=0; x < img.width(); ++x){ |
2826 | destData = (unsigned int *)dest.scanLine(img.width()-x-1); | 2827 | destData = (unsigned int *)dest.scanLine(img.width()-x-1); |
2827 | destData[y] = srcData[x]; | 2828 | destData[y] = srcData[x]; |
2828 | } | 2829 | } |
2829 | } | 2830 | } |
2830 | break; | 2831 | break; |
2831 | default: | 2832 | default: |
2832 | dest = img; | 2833 | dest = img; |
2833 | break; | 2834 | break; |
2834 | } | 2835 | } |
2835 | } | 2836 | } |
2836 | else{ | 2837 | else{ |
2837 | unsigned char *srcData, *destData; | 2838 | unsigned char *srcData, *destData; |
2838 | unsigned int *srcTable, *destTable; | 2839 | unsigned int *srcTable, *destTable; |
2839 | switch(r){ | 2840 | switch(r){ |
2840 | case Rotate90: | 2841 | case Rotate90: |
2841 | dest.create(img.height(), img.width(), img.depth()); | 2842 | dest.create(img.height(), img.width(), img.depth()); |
2842 | dest.setNumColors(img.numColors()); | 2843 | dest.setNumColors(img.numColors()); |
2843 | srcTable = (unsigned int *)img.colorTable(); | 2844 | srcTable = (unsigned int *)img.colorTable(); |
2844 | destTable = (unsigned int *)dest.colorTable(); | 2845 | destTable = (unsigned int *)dest.colorTable(); |
2845 | for(x=0; x < img.numColors(); ++x) | 2846 | for(x=0; x < img.numColors(); ++x) |
2846 | destTable[x] = srcTable[x]; | 2847 | destTable[x] = srcTable[x]; |
2847 | for(y=0; y < img.height(); ++y){ | 2848 | for(y=0; y < img.height(); ++y){ |
2848 | srcData = (unsigned char *)img.scanLine(y); | 2849 | srcData = (unsigned char *)img.scanLine(y); |
2849 | for(x=0; x < img.width(); ++x){ | 2850 | for(x=0; x < img.width(); ++x){ |
2850 | destData = (unsigned char *)dest.scanLine(x); | 2851 | destData = (unsigned char *)dest.scanLine(x); |
2851 | destData[img.height()-y-1] = srcData[x]; | 2852 | destData[img.height()-y-1] = srcData[x]; |
2852 | } | 2853 | } |
2853 | } | 2854 | } |
2854 | break; | 2855 | break; |
2855 | case Rotate180: | 2856 | case Rotate180: |
2856 | dest.create(img.width(), img.height(), img.depth()); | 2857 | dest.create(img.width(), img.height(), img.depth()); |
2857 | dest.setNumColors(img.numColors()); | 2858 | dest.setNumColors(img.numColors()); |
2858 | srcTable = (unsigned int *)img.colorTable(); | 2859 | srcTable = (unsigned int *)img.colorTable(); |
2859 | destTable = (unsigned int *)dest.colorTable(); | 2860 | destTable = (unsigned int *)dest.colorTable(); |
2860 | for(x=0; x < img.numColors(); ++x) | 2861 | for(x=0; x < img.numColors(); ++x) |
2861 | destTable[x] = srcTable[x]; | 2862 | destTable[x] = srcTable[x]; |
2862 | for(y=0; y < img.height(); ++y){ | 2863 | for(y=0; y < img.height(); ++y){ |
2863 | srcData = (unsigned char *)img.scanLine(y); | 2864 | srcData = (unsigned char *)img.scanLine(y); |
2864 | destData = (unsigned char *)dest.scanLine(img.height()-y-1); | 2865 | destData = (unsigned char *)dest.scanLine(img.height()-y-1); |
2865 | for(x=0; x < img.width(); ++x) | 2866 | for(x=0; x < img.width(); ++x) |
2866 | destData[img.width()-x-1] = srcData[x]; | 2867 | destData[img.width()-x-1] = srcData[x]; |
2867 | } | 2868 | } |
2868 | break; | 2869 | break; |
2869 | case Rotate270: | 2870 | case Rotate270: |
2870 | dest.create(img.height(), img.width(), img.depth()); | 2871 | dest.create(img.height(), img.width(), img.depth()); |
2871 | dest.setNumColors(img.numColors()); | 2872 | dest.setNumColors(img.numColors()); |
2872 | srcTable = (unsigned int *)img.colorTable(); | 2873 | srcTable = (unsigned int *)img.colorTable(); |
2873 | destTable = (unsigned int *)dest.colorTable(); | 2874 | destTable = (unsigned int *)dest.colorTable(); |
2874 | for(x=0; x < img.numColors(); ++x) | 2875 | for(x=0; x < img.numColors(); ++x) |
2875 | destTable[x] = srcTable[x]; | 2876 | destTable[x] = srcTable[x]; |
2876 | for(y=0; y < img.height(); ++y){ | 2877 | for(y=0; y < img.height(); ++y){ |
2877 | srcData = (unsigned char *)img.scanLine(y); | 2878 | srcData = (unsigned char *)img.scanLine(y); |
2878 | for(x=0; x < img.width(); ++x){ | 2879 | for(x=0; x < img.width(); ++x){ |
2879 | destData = (unsigned char *)dest.scanLine(img.width()-x-1); | 2880 | destData = (unsigned char *)dest.scanLine(img.width()-x-1); |
2880 | destData[y] = srcData[x]; | 2881 | destData[y] = srcData[x]; |
2881 | } | 2882 | } |
2882 | } | 2883 | } |
2883 | break; | 2884 | break; |
2884 | default: | 2885 | default: |
2885 | dest = img; | 2886 | dest = img; |
2886 | break; | 2887 | break; |
2887 | } | 2888 | } |
2888 | 2889 | ||
2889 | } | 2890 | } |
2890 | return(dest); | 2891 | return(dest); |
2891 | } | 2892 | } |
2892 | 2893 | ||
2893 | void OImageEffect::solarize(QImage &img, double factor) | 2894 | void OImageEffect::solarize(QImage &img, double factor) |
2894 | { | 2895 | { |
2895 | int i, count; | 2896 | int i, count; |
2896 | int threshold; | 2897 | int threshold; |
2897 | unsigned int *data; | 2898 | unsigned int *data; |
2898 | 2899 | ||
2899 | threshold = (int)(factor*(MaxRGB+1)/100.0); | 2900 | threshold = (int)(factor*(MaxRGB+1)/100.0); |
2900 | if(img.depth() < 32){ | 2901 | if(img.depth() < 32){ |
2901 | data = (unsigned int *)img.colorTable(); | 2902 | data = (unsigned int *)img.colorTable(); |
2902 | count = img.numColors(); | 2903 | count = img.numColors(); |
2903 | } | 2904 | } |
2904 | else{ | 2905 | else{ |
2905 | data = (unsigned int *)img.bits(); | 2906 | data = (unsigned int *)img.bits(); |
2906 | count = img.width()*img.height(); | 2907 | count = img.width()*img.height(); |
2907 | } | 2908 | } |
2908 | for(i=0; i < count; ++i){ | 2909 | for(i=0; i < count; ++i){ |
2909 | data[i] = qRgba(qRed(data[i]) > threshold ? MaxRGB-qRed(data[i]) : qRed(data[i]), | 2910 | data[i] = qRgba(qRed(data[i]) > threshold ? MaxRGB-qRed(data[i]) : qRed(data[i]), |
2910 | qGreen(data[i]) > threshold ? MaxRGB-qGreen(data[i]) : qGreen(data[i]), | 2911 | qGreen(data[i]) > threshold ? MaxRGB-qGreen(data[i]) : qGreen(data[i]), |
2911 | qBlue(data[i]) > threshold ? MaxRGB-qBlue(data[i]) : qBlue(data[i]), | 2912 | qBlue(data[i]) > threshold ? MaxRGB-qBlue(data[i]) : qBlue(data[i]), |
2912 | qAlpha(data[i])); | 2913 | qAlpha(data[i])); |
2913 | } | 2914 | } |
2914 | } | 2915 | } |
2915 | 2916 | ||
2916 | QImage OImageEffect::spread(QImage &src, unsigned int amount) | 2917 | QImage OImageEffect::spread(QImage &src, unsigned int amount) |
2917 | { | 2918 | { |
2918 | int quantum, x, y; | 2919 | int quantum, x, y; |
2919 | int x_distance, y_distance; | 2920 | int x_distance, y_distance; |
2920 | if(src.width() < 3 || src.height() < 3) | 2921 | if(src.width() < 3 || src.height() < 3) |
2921 | return(src); | 2922 | return(src); |
2922 | QImage dest(src); | 2923 | QImage dest(src); |
2923 | dest.detach(); | 2924 | dest.detach(); |
2924 | quantum=(amount+1) >> 1; | 2925 | quantum=(amount+1) >> 1; |
2925 | if(src.depth() > 8){ // DirectClass source image | 2926 | if(src.depth() > 8){ // DirectClass source image |
2926 | unsigned int *p, *q; | 2927 | unsigned int *p, *q; |
2927 | for(y=0; y < src.height(); y++){ | 2928 | for(y=0; y < src.height(); y++){ |
2928 | q = (unsigned int *)dest.scanLine(y); | 2929 | q = (unsigned int *)dest.scanLine(y); |
2929 | for(x=0; x < src.width(); x++){ | 2930 | for(x=0; x < src.width(); x++){ |
2930 | x_distance = x + ((rand() & (amount+1))-quantum); | 2931 | x_distance = x + ((rand() & (amount+1))-quantum); |
2931 | y_distance = y + ((rand() & (amount+1))-quantum); | 2932 | y_distance = y + ((rand() & (amount+1))-quantum); |
2932 | x_distance = QMIN(x_distance, src.width()-1); | 2933 | x_distance = QMIN(x_distance, src.width()-1); |
2933 | y_distance = QMIN(y_distance, src.height()-1); | 2934 | y_distance = QMIN(y_distance, src.height()-1); |
2934 | if(x_distance < 0) | 2935 | if(x_distance < 0) |
2935 | x_distance = 0; | 2936 | x_distance = 0; |
2936 | if(y_distance < 0) | 2937 | if(y_distance < 0) |
2937 | y_distance = 0; | 2938 | y_distance = 0; |
2938 | p = (unsigned int *)src.scanLine(y_distance); | 2939 | p = (unsigned int *)src.scanLine(y_distance); |
2939 | p += x_distance; | 2940 | p += x_distance; |
2940 | *q++=(*p); | 2941 | *q++=(*p); |
2941 | } | 2942 | } |
2942 | } | 2943 | } |
2943 | } | 2944 | } |
2944 | else{ // PsudeoClass source image | 2945 | else{ // PsudeoClass source image |
2945 | // just do colortable values | 2946 | // just do colortable values |
2946 | unsigned char *p, *q; | 2947 | unsigned char *p, *q; |
2947 | for(y=0; y < src.height(); y++){ | 2948 | for(y=0; y < src.height(); y++){ |
2948 | q = (unsigned char *)dest.scanLine(y); | 2949 | q = (unsigned char *)dest.scanLine(y); |
2949 | for(x=0; x < src.width(); x++){ | 2950 | for(x=0; x < src.width(); x++){ |
2950 | x_distance = x + ((rand() & (amount+1))-quantum); | 2951 | x_distance = x + ((rand() & (amount+1))-quantum); |
2951 | y_distance = y + ((rand() & (amount+1))-quantum); | 2952 | y_distance = y + ((rand() & (amount+1))-quantum); |
2952 | x_distance = QMIN(x_distance, src.width()-1); | 2953 | x_distance = QMIN(x_distance, src.width()-1); |
2953 | y_distance = QMIN(y_distance, src.height()-1); | 2954 | y_distance = QMIN(y_distance, src.height()-1); |
2954 | if(x_distance < 0) | 2955 | if(x_distance < 0) |
2955 | x_distance = 0; | 2956 | x_distance = 0; |
2956 | if(y_distance < 0) | 2957 | if(y_distance < 0) |
2957 | y_distance = 0; | 2958 | y_distance = 0; |
2958 | p = (unsigned char *)src.scanLine(y_distance); | 2959 | p = (unsigned char *)src.scanLine(y_distance); |
2959 | p += x_distance; | 2960 | p += x_distance; |
2960 | *q++=(*p); | 2961 | *q++=(*p); |
2961 | } | 2962 | } |
2962 | } | 2963 | } |
2963 | } | 2964 | } |
2964 | return(dest); | 2965 | return(dest); |
2965 | } | 2966 | } |
2966 | 2967 | ||
2967 | QImage OImageEffect::swirl(QImage &src, double degrees, | 2968 | QImage OImageEffect::swirl(QImage &src, double degrees, |
2968 | unsigned int background) | 2969 | unsigned int background) |
2969 | { | 2970 | { |
2970 | double cosine, distance, factor, radius, sine, x_center, x_distance, | 2971 | double cosine, distance, factor, radius, sine, x_center, x_distance, |
2971 | x_scale, y_center, y_distance, y_scale; | 2972 | x_scale, y_center, y_distance, y_scale; |
2972 | int x, y; | 2973 | int x, y; |
2973 | unsigned int *q; | 2974 | unsigned int *q; |
2974 | QImage dest(src.width(), src.height(), 32); | 2975 | QImage dest(src.width(), src.height(), 32); |
2975 | 2976 | ||
2976 | // compute scaling factor | 2977 | // compute scaling factor |
2977 | x_center = src.width()/2.0; | 2978 | x_center = src.width()/2.0; |
2978 | y_center = src.height()/2.0; | 2979 | y_center = src.height()/2.0; |
2979 | radius = QMAX(x_center,y_center); | 2980 | radius = QMAX(x_center,y_center); |
2980 | x_scale=1.0; | 2981 | x_scale=1.0; |
2981 | y_scale=1.0; | 2982 | y_scale=1.0; |
2982 | if(src.width() > src.height()) | 2983 | if(src.width() > src.height()) |
2983 | y_scale=(double)src.width()/src.height(); | 2984 | y_scale=(double)src.width()/src.height(); |
2984 | else if(src.width() < src.height()) | 2985 | else if(src.width() < src.height()) |
2985 | x_scale=(double)src.height()/src.width(); | 2986 | x_scale=(double)src.height()/src.width(); |
2986 | degrees=DegreesToRadians(degrees); | 2987 | degrees=DegreesToRadians(degrees); |
2987 | // swirl each row | 2988 | // swirl each row |
2988 | if(src.depth() > 8){ // DirectClass source image | 2989 | if(src.depth() > 8){ // DirectClass source image |
2989 | unsigned int *p; | 2990 | unsigned int *p; |
2990 | for(y=0; y < src.height(); y++){ | 2991 | for(y=0; y < src.height(); y++){ |
2991 | p = (unsigned int *)src.scanLine(y); | 2992 | p = (unsigned int *)src.scanLine(y); |
2992 | q = (unsigned int *)dest.scanLine(y); | 2993 | q = (unsigned int *)dest.scanLine(y); |
2993 | y_distance = y_scale*(y-y_center); | 2994 | y_distance = y_scale*(y-y_center); |
2994 | for(x=0; x < src.width(); x++){ | 2995 | for(x=0; x < src.width(); x++){ |
2995 | // determine if the pixel is within an ellipse | 2996 | // determine if the pixel is within an ellipse |
2996 | *q=(*p); | 2997 | *q=(*p); |
2997 | x_distance = x_scale*(x-x_center); | 2998 | x_distance = x_scale*(x-x_center); |
2998 | distance = x_distance*x_distance+y_distance*y_distance; | 2999 | distance = x_distance*x_distance+y_distance*y_distance; |
2999 | if (distance < (radius*radius)){ | 3000 | if (distance < (radius*radius)){ |
3000 | // swirl | 3001 | // swirl |
3001 | factor = 1.0-sqrt(distance)/radius; | 3002 | factor = 1.0-sqrt(distance)/radius; |
3002 | sine = sin(degrees*factor*factor); | 3003 | sine = sin(degrees*factor*factor); |
3003 | cosine = cos(degrees*factor*factor); | 3004 | cosine = cos(degrees*factor*factor); |
3004 | *q = interpolateColor(&src, | 3005 | *q = interpolateColor(&src, |
3005 | (cosine*x_distance-sine*y_distance)/x_scale+x_center, | 3006 | (cosine*x_distance-sine*y_distance)/x_scale+x_center, |
3006 | (sine*x_distance+cosine*y_distance)/y_scale+y_center, | 3007 | (sine*x_distance+cosine*y_distance)/y_scale+y_center, |
3007 | background); | 3008 | background); |
3008 | } | 3009 | } |
3009 | p++; | 3010 | p++; |
3010 | q++; | 3011 | q++; |
3011 | } | 3012 | } |
3012 | } | 3013 | } |
3013 | } | 3014 | } |
3014 | else{ // PsudeoClass source image | 3015 | else{ // PsudeoClass source image |
3015 | unsigned char *p; | 3016 | unsigned char *p; |
3016 | unsigned int *cTable = (unsigned int *)src.colorTable(); | 3017 | unsigned int *cTable = (unsigned int *)src.colorTable(); |
3017 | for(y=0; y < src.height(); y++){ | 3018 | for(y=0; y < src.height(); y++){ |
3018 | p = (unsigned char *)src.scanLine(y); | 3019 | p = (unsigned char *)src.scanLine(y); |
3019 | q = (unsigned int *)dest.scanLine(y); | 3020 | q = (unsigned int *)dest.scanLine(y); |
3020 | y_distance = y_scale*(y-y_center); | 3021 | y_distance = y_scale*(y-y_center); |
3021 | for(x=0; x < src.width(); x++){ | 3022 | for(x=0; x < src.width(); x++){ |
3022 | // determine if the pixel is within an ellipse | 3023 | // determine if the pixel is within an ellipse |
3023 | *q = *(cTable+(*p)); | 3024 | *q = *(cTable+(*p)); |
3024 | x_distance = x_scale*(x-x_center); | 3025 | x_distance = x_scale*(x-x_center); |
3025 | distance = x_distance*x_distance+y_distance*y_distance; | 3026 | distance = x_distance*x_distance+y_distance*y_distance; |
3026 | if (distance < (radius*radius)){ | 3027 | if (distance < (radius*radius)){ |
3027 | // swirl | 3028 | // swirl |
3028 | factor = 1.0-sqrt(distance)/radius; | 3029 | factor = 1.0-sqrt(distance)/radius; |
3029 | sine = sin(degrees*factor*factor); | 3030 | sine = sin(degrees*factor*factor); |
3030 | cosine = cos(degrees*factor*factor); | 3031 | cosine = cos(degrees*factor*factor); |
3031 | *q = interpolateColor(&src, | 3032 | *q = interpolateColor(&src, |
3032 | (cosine*x_distance-sine*y_distance)/x_scale+x_center, | 3033 | (cosine*x_distance-sine*y_distance)/x_scale+x_center, |
3033 | (sine*x_distance+cosine*y_distance)/y_scale+y_center, | 3034 | (sine*x_distance+cosine*y_distance)/y_scale+y_center, |
3034 | background); | 3035 | background); |
3035 | } | 3036 | } |
3036 | p++; | 3037 | p++; |
3037 | q++; | 3038 | q++; |
3038 | } | 3039 | } |
3039 | } | 3040 | } |
3040 | 3041 | ||
3041 | } | 3042 | } |
3042 | return(dest); | 3043 | return(dest); |
3043 | } | 3044 | } |
3044 | 3045 | ||
3045 | QImage OImageEffect::wave(QImage &src, double amplitude, double wavelength, | 3046 | QImage OImageEffect::wave(QImage &src, double amplitude, double wavelength, |
3046 | unsigned int background) | 3047 | unsigned int background) |
3047 | { | 3048 | { |
3048 | double *sine_map; | 3049 | double *sine_map; |
3049 | int x, y; | 3050 | int x, y; |
3050 | unsigned int *q; | 3051 | unsigned int *q; |
3051 | 3052 | ||
3052 | QImage dest(src.width(), src.height() + (int)(2*fabs(amplitude)), 32); | 3053 | QImage dest(src.width(), src.height() + (int)(2*fabs(amplitude)), 32); |
3053 | // allocate sine map | 3054 | // allocate sine map |
3054 | sine_map = (double *)malloc(dest.width()*sizeof(double)); | 3055 | sine_map = (double *)malloc(dest.width()*sizeof(double)); |
3055 | if(!sine_map) | 3056 | if(!sine_map) |
3056 | return(src); | 3057 | return(src); |
3057 | for(x=0; x < dest.width(); ++x) | 3058 | for(x=0; x < dest.width(); ++x) |
3058 | sine_map[x]=fabs(amplitude)+amplitude*sin((2*M_PI*x)/wavelength); | 3059 | sine_map[x]=fabs(amplitude)+amplitude*sin((2*M_PI*x)/wavelength); |
3059 | // wave image | 3060 | // wave image |
3060 | for(y=0; y < dest.height(); ++y){ | 3061 | for(y=0; y < dest.height(); ++y){ |
3061 | q = (unsigned int *)dest.scanLine(y); | 3062 | q = (unsigned int *)dest.scanLine(y); |
3062 | for (x=0; x < dest.width(); x++){ | 3063 | for (x=0; x < dest.width(); x++){ |
3063 | *q=interpolateColor(&src, x, (int)(y-sine_map[x]), background); | 3064 | *q=interpolateColor(&src, x, (int)(y-sine_map[x]), background); |
3064 | ++q; | 3065 | ++q; |
3065 | } | 3066 | } |
3066 | } | 3067 | } |
3067 | free(sine_map); | 3068 | free(sine_map); |
3068 | return(dest); | 3069 | return(dest); |
3069 | } | 3070 | } |
3070 | 3071 | ||
3071 | QImage OImageEffect::oilPaint(QImage &src, int radius) | 3072 | QImage OImageEffect::oilPaint(QImage &src, int radius) |
3072 | { | 3073 | { |
3073 | // TODO 8bpp src! | 3074 | // TODO 8bpp src! |
3074 | if(src.depth() < 32){ | 3075 | if(src.depth() < 32){ |
3075 | qWarning("Oil Paint source image < 32bpp. Convert before using!"); | 3076 | owarn << "Oil Paint source image < 32bpp. Convert before using!" << oendl; |
3076 | return(src); | 3077 | return(src); |
3077 | } | 3078 | } |
3078 | int j, k, i, x, y; | 3079 | int j, k, i, x, y; |
3079 | unsigned int *histogram; | 3080 | unsigned int *histogram; |
3080 | unsigned int *s; | 3081 | unsigned int *s; |
3081 | unsigned int count; | 3082 | unsigned int count; |
3082 | 3083 | ||
3083 | unsigned int *srcData, *destData; | 3084 | unsigned int *srcData, *destData; |
3084 | 3085 | ||
3085 | QImage dest(src); | 3086 | QImage dest(src); |
3086 | dest.detach(); | 3087 | dest.detach(); |
3087 | histogram = (unsigned int *) malloc((MaxRGB+1)*sizeof(unsigned int)); | 3088 | histogram = (unsigned int *) malloc((MaxRGB+1)*sizeof(unsigned int)); |
3088 | if(!histogram) | 3089 | if(!histogram) |
3089 | return(src); | 3090 | return(src); |
3090 | // paint each row | 3091 | // paint each row |
3091 | k=0; | 3092 | k=0; |
3092 | for(y = radius; y < src.height(); ++y){ | 3093 | for(y = radius; y < src.height(); ++y){ |
3093 | srcData = (unsigned int *)src.scanLine(y-radius); | 3094 | srcData = (unsigned int *)src.scanLine(y-radius); |
3094 | destData = (unsigned int *)dest.scanLine(y); | 3095 | destData = (unsigned int *)dest.scanLine(y); |
3095 | srcData += radius*src.width()+radius; | 3096 | srcData += radius*src.width()+radius; |
3096 | destData += radius; | 3097 | destData += radius; |
3097 | for(x=radius; x < src.width()-radius; ++x){ | 3098 | for(x=radius; x < src.width()-radius; ++x){ |
3098 | // determine most frequent color | 3099 | // determine most frequent color |
3099 | count = 0; | 3100 | count = 0; |
3100 | for(i=0; i < MaxRGB+1; ++i) | 3101 | for(i=0; i < MaxRGB+1; ++i) |
3101 | histogram[i] = 0; | 3102 | histogram[i] = 0; |
3102 | for(i=0; i < radius; ++i){ | 3103 | for(i=0; i < radius; ++i){ |
3103 | s = srcData-(radius-1)*src.width()-i-1; | 3104 | s = srcData-(radius-1)*src.width()-i-1; |
3104 | for(j =0; j < (2*i+1); ++j){ | 3105 | for(j =0; j < (2*i+1); ++j){ |
3105 | k = intensityValue(*s); | 3106 | k = intensityValue(*s); |
3106 | histogram[k]++; | 3107 | histogram[k]++; |
3107 | if(histogram[k] > count){ | 3108 | if(histogram[k] > count){ |
3108 | *destData = *s; | 3109 | *destData = *s; |
3109 | count = histogram[k]; | 3110 | count = histogram[k]; |
3110 | } | 3111 | } |
3111 | ++s; | 3112 | ++s; |
3112 | } | 3113 | } |
3113 | s = srcData+(radius-i)*src.width()-i-1; | 3114 | s = srcData+(radius-i)*src.width()-i-1; |
3114 | for(j =0; j < (2*i+1); ++j){ | 3115 | for(j =0; j < (2*i+1); ++j){ |
3115 | k = intensityValue(*s); | 3116 | k = intensityValue(*s); |
3116 | histogram[k]++; | 3117 | histogram[k]++; |
3117 | if(histogram[k] > count){ | 3118 | if(histogram[k] > count){ |
3118 | *destData = *s; | 3119 | *destData = *s; |
3119 | count = histogram[k]; | 3120 | count = histogram[k]; |
3120 | } | 3121 | } |
3121 | ++s; | 3122 | ++s; |
3122 | } | 3123 | } |
3123 | } | 3124 | } |
3124 | s = srcData-radius; | 3125 | s = srcData-radius; |
3125 | for(j =0; j < (2*i+1); ++j){ | 3126 | for(j =0; j < (2*i+1); ++j){ |
3126 | k = intensityValue(*s); | 3127 | k = intensityValue(*s); |
3127 | histogram[k]++; | 3128 | histogram[k]++; |
3128 | if(histogram[k] > count){ | 3129 | if(histogram[k] > count){ |
3129 | *destData = *s; | 3130 | *destData = *s; |
3130 | count = histogram[k]; | 3131 | count = histogram[k]; |
3131 | } | 3132 | } |
3132 | ++s; | 3133 | ++s; |
3133 | } | 3134 | } |
3134 | ++srcData; | 3135 | ++srcData; |
3135 | ++destData; | 3136 | ++destData; |
3136 | } | 3137 | } |
3137 | } | 3138 | } |
3138 | free(histogram); | 3139 | free(histogram); |
3139 | return(dest); | 3140 | return(dest); |
3140 | } | 3141 | } |
3141 | 3142 | ||
3142 | // | 3143 | // |
3143 | // The following methods work by computing a value from neighboring pixels | 3144 | // The following methods work by computing a value from neighboring pixels |
3144 | // (mosfet 12/28/01) | 3145 | // (mosfet 12/28/01) |
3145 | // | 3146 | // |
3146 | 3147 | ||
3147 | QImage OImageEffect::edge(QImage &src, double factor) | 3148 | QImage OImageEffect::edge(QImage &src, double factor) |
3148 | { | 3149 | { |
3149 | #define Edge(weight) \ | 3150 | #define Edge(weight) \ |
3150 | total_red+=(weight)*qRed(*s); \ | 3151 | total_red+=(weight)*qRed(*s); \ |
3151 | total_green+=(weight)*qGreen(*s); \ | 3152 | total_green+=(weight)*qGreen(*s); \ |
3152 | total_blue+=(weight)*qBlue(*s); \ | 3153 | total_blue+=(weight)*qBlue(*s); \ |
3153 | total_opacity+=(weight)*qAlpha(*s); \ | 3154 | total_opacity+=(weight)*qAlpha(*s); \ |
3154 | s++; | 3155 | s++; |
3155 | 3156 | ||
3156 | #define Edge256(weight) \ | 3157 | #define Edge256(weight) \ |
3157 | total_red+=(weight)*qRed(*(cTable+(*s))); \ | 3158 | total_red+=(weight)*qRed(*(cTable+(*s))); \ |
3158 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ | 3159 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ |
3159 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ | 3160 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ |
3160 | total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ | 3161 | total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ |
3161 | s++; | 3162 | s++; |
3162 | 3163 | ||
3163 | if(src.width() < 3 || src.height() < 3) | 3164 | if(src.width() < 3 || src.height() < 3) |
3164 | return(src); | 3165 | return(src); |
3165 | 3166 | ||
3166 | double total_blue, total_green, total_opacity, total_red, weight; | 3167 | double total_blue, total_green, total_opacity, total_red, weight; |
3167 | 3168 | ||
3168 | int x, y; | 3169 | int x, y; |
3169 | 3170 | ||
3170 | unsigned int *q; | 3171 | unsigned int *q; |
3171 | 3172 | ||
3172 | QImage dest(src.width(), src.height(), 32); | 3173 | QImage dest(src.width(), src.height(), 32); |
3173 | weight=factor/8.0; | 3174 | weight=factor/8.0; |
3174 | if(src.depth() > 8){ // DirectClass source image | 3175 | if(src.depth() > 8){ // DirectClass source image |
3175 | unsigned int *p, *s; | 3176 | unsigned int *p, *s; |
3176 | for(y=0; y < src.height(); ++y){ | 3177 | for(y=0; y < src.height(); ++y){ |
3177 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); | 3178 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); |
3178 | q = (unsigned int *)dest.scanLine(y); | 3179 | q = (unsigned int *)dest.scanLine(y); |
3179 | // edge detect this row of pixels. | 3180 | // edge detect this row of pixels. |
3180 | *q++=(*(p+src.width())); | 3181 | *q++=(*(p+src.width())); |
3181 | for(x=1; x < src.width()-1; ++x){ | 3182 | for(x=1; x < src.width()-1; ++x){ |
3182 | // compute weighted average of target pixel color components. | 3183 | // compute weighted average of target pixel color components. |
3183 | total_red=0.0; | 3184 | total_red=0.0; |
3184 | total_green=0.0; | 3185 | total_green=0.0; |
3185 | total_blue=0.0; | 3186 | total_blue=0.0; |
3186 | total_opacity=0.0; | 3187 | total_opacity=0.0; |
3187 | s=p; | 3188 | s=p; |
3188 | Edge(-weight/8); Edge(-weight/8) Edge(-weight/8); | 3189 | Edge(-weight/8); Edge(-weight/8) Edge(-weight/8); |
3189 | s=p+src.width(); | 3190 | s=p+src.width(); |
3190 | Edge(-weight/8); Edge(weight); Edge(-weight/8); | 3191 | Edge(-weight/8); Edge(weight); Edge(-weight/8); |
3191 | s=p+2*src.width(); | 3192 | s=p+2*src.width(); |
3192 | Edge(-weight/8); Edge(-weight/8); Edge(-weight/8); | 3193 | Edge(-weight/8); Edge(-weight/8); Edge(-weight/8); |
3193 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), | 3194 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), |
3194 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), | 3195 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), |
3195 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), | 3196 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), |
3196 | (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity)); | 3197 | (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity)); |
3197 | p++; | 3198 | p++; |
3198 | q++; | 3199 | q++; |
3199 | } | 3200 | } |
3200 | p++; | 3201 | p++; |
3201 | *q++=(*p); | 3202 | *q++=(*p); |
3202 | } | 3203 | } |
3203 | } | 3204 | } |
3204 | else{ // PsudeoClass source image | 3205 | else{ // PsudeoClass source image |
3205 | unsigned char *p, *p2, *p3, *s; | 3206 | unsigned char *p, *p2, *p3, *s; |
3206 | unsigned int *cTable = src.colorTable(); | 3207 | unsigned int *cTable = src.colorTable(); |
3207 | int scanLineIdx; | 3208 | int scanLineIdx; |
3208 | for(y=0; y < src.height(); ++y){ | 3209 | for(y=0; y < src.height(); ++y){ |
3209 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); | 3210 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); |
3210 | p = (unsigned char *)src.scanLine(scanLineIdx); | 3211 | p = (unsigned char *)src.scanLine(scanLineIdx); |
3211 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); | 3212 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); |
3212 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); | 3213 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); |
3213 | q = (unsigned int *)dest.scanLine(y); | 3214 | q = (unsigned int *)dest.scanLine(y); |
3214 | // edge detect this row of pixels. | 3215 | // edge detect this row of pixels. |
3215 | *q++=(*(cTable+(*p2))); | 3216 | *q++=(*(cTable+(*p2))); |
3216 | for(x=1; x < src.width()-1; ++x){ | 3217 | for(x=1; x < src.width()-1; ++x){ |
3217 | // compute weighted average of target pixel color components. | 3218 | // compute weighted average of target pixel color components. |
3218 | total_red=0.0; | 3219 | total_red=0.0; |
3219 | total_green=0.0; | 3220 | total_green=0.0; |
3220 | total_blue=0.0; | 3221 | total_blue=0.0; |
3221 | total_opacity=0.0; | 3222 | total_opacity=0.0; |
3222 | s=p; | 3223 | s=p; |
3223 | Edge256(-weight/8); Edge256(-weight/8) Edge256(-weight/8); | 3224 | Edge256(-weight/8); Edge256(-weight/8) Edge256(-weight/8); |
3224 | s=p2; | 3225 | s=p2; |
3225 | Edge256(-weight/8); Edge256(weight); Edge256(-weight/8); | 3226 | Edge256(-weight/8); Edge256(weight); Edge256(-weight/8); |
3226 | s=p3; | 3227 | s=p3; |
3227 | Edge256(-weight/8); Edge256(-weight/8); Edge256(-weight/8); | 3228 | Edge256(-weight/8); Edge256(-weight/8); Edge256(-weight/8); |
3228 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), | 3229 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), |
3229 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), | 3230 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), |
3230 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), | 3231 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), |
3231 | (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity)); | 3232 | (unsigned char)((total_opacity < 0) ? 0 : (total_opacity > MaxRGB) ? MaxRGB : total_opacity)); |
3232 | p++; | 3233 | p++; |
3233 | p2++; | 3234 | p2++; |
3234 | p3++; | 3235 | p3++; |
3235 | q++; | 3236 | q++; |
3236 | } | 3237 | } |
3237 | p++; | 3238 | p++; |
3238 | *q++=(*(cTable+(*p))); | 3239 | *q++=(*(cTable+(*p))); |
3239 | } | 3240 | } |
3240 | } | 3241 | } |
3241 | return(dest); | 3242 | return(dest); |
3242 | } | 3243 | } |
3243 | 3244 | ||
3244 | QImage OImageEffect::sharpen(QImage &src, double factor) | 3245 | QImage OImageEffect::sharpen(QImage &src, double factor) |
3245 | { | 3246 | { |
3246 | #define Sharpen(weight) \ | 3247 | #define Sharpen(weight) \ |
3247 | total_red+=(weight)*qRed(*s); \ | 3248 | total_red+=(weight)*qRed(*s); \ |
3248 | total_green+=(weight)*qGreen(*s); \ | 3249 | total_green+=(weight)*qGreen(*s); \ |
3249 | total_blue+=(weight)*qBlue(*s); \ | 3250 | total_blue+=(weight)*qBlue(*s); \ |
3250 | total_opacity+=(weight)*qAlpha(*s); \ | 3251 | total_opacity+=(weight)*qAlpha(*s); \ |
3251 | s++; | 3252 | s++; |
3252 | 3253 | ||
3253 | #define Sharpen256(weight) \ | 3254 | #define Sharpen256(weight) \ |
3254 | total_red+=(weight)*qRed(*(cTable+(*s))); \ | 3255 | total_red+=(weight)*qRed(*(cTable+(*s))); \ |
3255 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ | 3256 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ |
3256 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ | 3257 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ |
3257 | total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ | 3258 | total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ |
3258 | s++; | 3259 | s++; |
3259 | 3260 | ||
3260 | if(src.width() < 3 || src.height() < 3) | 3261 | if(src.width() < 3 || src.height() < 3) |
3261 | return(src); | 3262 | return(src); |
3262 | 3263 | ||
3263 | double total_blue, total_green, total_opacity, total_red; | 3264 | double total_blue, total_green, total_opacity, total_red; |
3264 | double quantum, weight; | 3265 | double quantum, weight; |
3265 | unsigned char r, g, b, a; | 3266 | unsigned char r, g, b, a; |
3266 | 3267 | ||
3267 | int x, y; | 3268 | int x, y; |
3268 | unsigned int *q; | 3269 | unsigned int *q; |
3269 | 3270 | ||
3270 | QImage dest(src.width(), src.height(), 32); | 3271 | QImage dest(src.width(), src.height(), 32); |
3271 | weight = ((100.0-factor)/2.0+13.0); | 3272 | weight = ((100.0-factor)/2.0+13.0); |
3272 | quantum = QMAX(weight-12.0, 1.0); | 3273 | quantum = QMAX(weight-12.0, 1.0); |
3273 | if(src.depth() > 8){ // DirectClass source image | 3274 | if(src.depth() > 8){ // DirectClass source image |
3274 | unsigned int *p, *s; | 3275 | unsigned int *p, *s; |
3275 | for(y=0; y < src.height(); ++y){ | 3276 | for(y=0; y < src.height(); ++y){ |
3276 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); | 3277 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); |
3277 | q = (unsigned int *)dest.scanLine(y); | 3278 | q = (unsigned int *)dest.scanLine(y); |
3278 | // sharpen this row of pixels. | 3279 | // sharpen this row of pixels. |
3279 | *q++=(*(p+src.width())); | 3280 | *q++=(*(p+src.width())); |
3280 | for(x=1; x < src.width()-1; ++x){ | 3281 | for(x=1; x < src.width()-1; ++x){ |
3281 | // compute weighted average of target pixel color components. | 3282 | // compute weighted average of target pixel color components. |
3282 | total_red=0.0; | 3283 | total_red=0.0; |
3283 | total_green=0.0; | 3284 | total_green=0.0; |
3284 | total_blue=0.0; | 3285 | total_blue=0.0; |
3285 | total_opacity=0.0; | 3286 | total_opacity=0.0; |
3286 | s=p; | 3287 | s=p; |
3287 | Sharpen(-1); Sharpen(-2); Sharpen(-1); | 3288 | Sharpen(-1); Sharpen(-2); Sharpen(-1); |
3288 | s=p+src.width(); | 3289 | s=p+src.width(); |
3289 | Sharpen(-2); Sharpen(weight); Sharpen(-2); | 3290 | Sharpen(-2); Sharpen(weight); Sharpen(-2); |
3290 | s=p+2*src.width(); | 3291 | s=p+2*src.width(); |
3291 | Sharpen(-1); Sharpen(-2); Sharpen(-1); | 3292 | Sharpen(-1); Sharpen(-2); Sharpen(-1); |
3292 | if(total_red < 0) | 3293 | if(total_red < 0) |
3293 | r=0; | 3294 | r=0; |
3294 | else if(total_red > (int)(MaxRGB*quantum)) | 3295 | else if(total_red > (int)(MaxRGB*quantum)) |
3295 | r = (unsigned char)MaxRGB; | 3296 | r = (unsigned char)MaxRGB; |
3296 | else | 3297 | else |
3297 | r = (unsigned char)((total_red+(quantum/2.0))/quantum); | 3298 | r = (unsigned char)((total_red+(quantum/2.0))/quantum); |
3298 | 3299 | ||
3299 | if(total_green < 0) | 3300 | if(total_green < 0) |
3300 | g = 0; | 3301 | g = 0; |
3301 | else if(total_green > (int)(MaxRGB*quantum)) | 3302 | else if(total_green > (int)(MaxRGB*quantum)) |
3302 | g = (unsigned char)MaxRGB; | 3303 | g = (unsigned char)MaxRGB; |
3303 | else | 3304 | else |
3304 | g = (unsigned char)((total_green+(quantum/2.0))/quantum); | 3305 | g = (unsigned char)((total_green+(quantum/2.0))/quantum); |
3305 | 3306 | ||
3306 | if(total_blue < 0) | 3307 | if(total_blue < 0) |
3307 | b = 0; | 3308 | b = 0; |
3308 | else if(total_blue > (int)(MaxRGB*quantum)) | 3309 | else if(total_blue > (int)(MaxRGB*quantum)) |
3309 | b = (unsigned char)MaxRGB; | 3310 | b = (unsigned char)MaxRGB; |
3310 | else | 3311 | else |
3311 | b = (unsigned char)((total_blue+(quantum/2.0))/quantum); | 3312 | b = (unsigned char)((total_blue+(quantum/2.0))/quantum); |
3312 | 3313 | ||
3313 | if(total_opacity < 0) | 3314 | if(total_opacity < 0) |
3314 | a = 0; | 3315 | a = 0; |
3315 | else if(total_opacity > (int)(MaxRGB*quantum)) | 3316 | else if(total_opacity > (int)(MaxRGB*quantum)) |
3316 | a = (unsigned char)MaxRGB; | 3317 | a = (unsigned char)MaxRGB; |
3317 | else | 3318 | else |
3318 | a= (unsigned char)((total_opacity+(quantum/2.0))/quantum); | 3319 | a= (unsigned char)((total_opacity+(quantum/2.0))/quantum); |
3319 | 3320 | ||
3320 | *q = qRgba(r, g, b, a); | 3321 | *q = qRgba(r, g, b, a); |
3321 | 3322 | ||
3322 | p++; | 3323 | p++; |
3323 | q++; | 3324 | q++; |
3324 | } | 3325 | } |
3325 | p++; | 3326 | p++; |
3326 | *q++=(*p); | 3327 | *q++=(*p); |
3327 | } | 3328 | } |
3328 | } | 3329 | } |
3329 | else{ // PsudeoClass source image | 3330 | else{ // PsudeoClass source image |
3330 | unsigned char *p, *p2, *p3, *s; | 3331 | unsigned char *p, *p2, *p3, *s; |
3331 | unsigned int *cTable = src.colorTable(); | 3332 | unsigned int *cTable = src.colorTable(); |
3332 | int scanLineIdx; | 3333 | int scanLineIdx; |
3333 | for(y=0; y < src.height(); ++y){ | 3334 | for(y=0; y < src.height(); ++y){ |
3334 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); | 3335 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); |
3335 | p = (unsigned char *)src.scanLine(scanLineIdx); | 3336 | p = (unsigned char *)src.scanLine(scanLineIdx); |
3336 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); | 3337 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); |
3337 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); | 3338 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); |
3338 | q = (unsigned int *)dest.scanLine(y); | 3339 | q = (unsigned int *)dest.scanLine(y); |
3339 | // sharpen this row of pixels. | 3340 | // sharpen this row of pixels. |
3340 | *q++=(*(cTable+(*p2))); | 3341 | *q++=(*(cTable+(*p2))); |
3341 | for(x=1; x < src.width()-1; ++x){ | 3342 | for(x=1; x < src.width()-1; ++x){ |
3342 | // compute weighted average of target pixel color components. | 3343 | // compute weighted average of target pixel color components. |
3343 | total_red=0.0; | 3344 | total_red=0.0; |
3344 | total_green=0.0; | 3345 | total_green=0.0; |
3345 | total_blue=0.0; | 3346 | total_blue=0.0; |
3346 | total_opacity=0.0; | 3347 | total_opacity=0.0; |
3347 | s=p; | 3348 | s=p; |
3348 | Sharpen256(-1); Sharpen256(-2); Sharpen256(-1); | 3349 | Sharpen256(-1); Sharpen256(-2); Sharpen256(-1); |
3349 | s=p2; | 3350 | s=p2; |
3350 | Sharpen256(-2); Sharpen256(weight); Sharpen256(-2); | 3351 | Sharpen256(-2); Sharpen256(weight); Sharpen256(-2); |
3351 | s=p3; | 3352 | s=p3; |
3352 | Sharpen256(-1); Sharpen256(-2); Sharpen256(-1); | 3353 | Sharpen256(-1); Sharpen256(-2); Sharpen256(-1); |
3353 | if(total_red < 0) | 3354 | if(total_red < 0) |
3354 | r=0; | 3355 | r=0; |
3355 | else if(total_red > (int)(MaxRGB*quantum)) | 3356 | else if(total_red > (int)(MaxRGB*quantum)) |
3356 | r = (unsigned char)MaxRGB; | 3357 | r = (unsigned char)MaxRGB; |
3357 | else | 3358 | else |
3358 | r = (unsigned char)((total_red+(quantum/2.0))/quantum); | 3359 | r = (unsigned char)((total_red+(quantum/2.0))/quantum); |
3359 | 3360 | ||
3360 | if(total_green < 0) | 3361 | if(total_green < 0) |
3361 | g = 0; | 3362 | g = 0; |
3362 | else if(total_green > (int)(MaxRGB*quantum)) | 3363 | else if(total_green > (int)(MaxRGB*quantum)) |
3363 | g = (unsigned char)MaxRGB; | 3364 | g = (unsigned char)MaxRGB; |
3364 | else | 3365 | else |
3365 | g = (unsigned char)((total_green+(quantum/2.0))/quantum); | 3366 | g = (unsigned char)((total_green+(quantum/2.0))/quantum); |
3366 | 3367 | ||
3367 | if(total_blue < 0) | 3368 | if(total_blue < 0) |
3368 | b = 0; | 3369 | b = 0; |
3369 | else if(total_blue > (int)(MaxRGB*quantum)) | 3370 | else if(total_blue > (int)(MaxRGB*quantum)) |
3370 | b = (unsigned char)MaxRGB; | 3371 | b = (unsigned char)MaxRGB; |
3371 | else | 3372 | else |
3372 | b = (unsigned char)((total_blue+(quantum/2.0))/quantum); | 3373 | b = (unsigned char)((total_blue+(quantum/2.0))/quantum); |
3373 | 3374 | ||
3374 | if(total_opacity < 0) | 3375 | if(total_opacity < 0) |
3375 | a = 0; | 3376 | a = 0; |
3376 | else if(total_opacity > (int)(MaxRGB*quantum)) | 3377 | else if(total_opacity > (int)(MaxRGB*quantum)) |
3377 | a = (unsigned char)MaxRGB; | 3378 | a = (unsigned char)MaxRGB; |
3378 | else | 3379 | else |
3379 | a = (unsigned char)((total_opacity+(quantum/2.0))/quantum); | 3380 | a = (unsigned char)((total_opacity+(quantum/2.0))/quantum); |
3380 | 3381 | ||
3381 | *q = qRgba(r, g, b, a); | 3382 | *q = qRgba(r, g, b, a); |
3382 | 3383 | ||
3383 | p++; | 3384 | p++; |
3384 | p2++; | 3385 | p2++; |
3385 | p3++; | 3386 | p3++; |
3386 | q++; | 3387 | q++; |
3387 | } | 3388 | } |
3388 | p++; | 3389 | p++; |
3389 | *q++=(*(cTable+(*p))); | 3390 | *q++=(*(cTable+(*p))); |
3390 | } | 3391 | } |
3391 | } | 3392 | } |
3392 | return(dest); | 3393 | return(dest); |
3393 | } | 3394 | } |
3394 | 3395 | ||
3395 | QImage OImageEffect::emboss(QImage &src) | 3396 | QImage OImageEffect::emboss(QImage &src) |
3396 | { | 3397 | { |
3397 | #define Emboss(weight) \ | 3398 | #define Emboss(weight) \ |
3398 | total_red+=(weight)*qRed(*s); \ | 3399 | total_red+=(weight)*qRed(*s); \ |
3399 | total_green+=(weight)*qGreen(*s); \ | 3400 | total_green+=(weight)*qGreen(*s); \ |
3400 | total_blue+=(weight)*qBlue(*s); \ | 3401 | total_blue+=(weight)*qBlue(*s); \ |
3401 | s++; | 3402 | s++; |
3402 | 3403 | ||
3403 | #define Emboss256(weight) \ | 3404 | #define Emboss256(weight) \ |
3404 | total_red+=(weight)*qRed(*(cTable+(*s))); \ | 3405 | total_red+=(weight)*qRed(*(cTable+(*s))); \ |
3405 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ | 3406 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ |
3406 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ | 3407 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ |
3407 | s++; | 3408 | s++; |
3408 | 3409 | ||
3409 | if(src.width() < 3 || src.height() < 3) | 3410 | if(src.width() < 3 || src.height() < 3) |
3410 | return(src); | 3411 | return(src); |
3411 | 3412 | ||
3412 | double total_blue, total_green, total_red; | 3413 | double total_blue, total_green, total_red; |
3413 | int x, y; | 3414 | int x, y; |
3414 | unsigned int *q; | 3415 | unsigned int *q; |
3415 | 3416 | ||
3416 | QImage dest(src.width(), src.height(), 32); | 3417 | QImage dest(src.width(), src.height(), 32); |
3417 | if(src.depth() > 8){ // DirectClass source image | 3418 | if(src.depth() > 8){ // DirectClass source image |
3418 | unsigned int *p, *s; | 3419 | unsigned int *p, *s; |
3419 | for(y=0; y < src.height(); ++y){ | 3420 | for(y=0; y < src.height(); ++y){ |
3420 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); | 3421 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); |
3421 | q = (unsigned int *)dest.scanLine(y); | 3422 | q = (unsigned int *)dest.scanLine(y); |
3422 | // emboss this row of pixels. | 3423 | // emboss this row of pixels. |
3423 | *q++=(*(p+src.width())); | 3424 | *q++=(*(p+src.width())); |
3424 | for(x=1; x < src.width()-1; ++x){ | 3425 | for(x=1; x < src.width()-1; ++x){ |
3425 | // compute weighted average of target pixel color components. | 3426 | // compute weighted average of target pixel color components. |
3426 | total_red=0.0; | 3427 | total_red=0.0; |
3427 | total_green=0.0; | 3428 | total_green=0.0; |
3428 | total_blue=0.0; | 3429 | total_blue=0.0; |
3429 | s=p; | 3430 | s=p; |
3430 | Emboss(-1); Emboss(-2); Emboss( 0); | 3431 | Emboss(-1); Emboss(-2); Emboss( 0); |
3431 | s=p+src.width(); | 3432 | s=p+src.width(); |
3432 | Emboss(-2); Emboss( 0); Emboss( 2); | 3433 | Emboss(-2); Emboss( 0); Emboss( 2); |
3433 | s=p+2*src.width(); | 3434 | s=p+2*src.width(); |
3434 | Emboss( 0); Emboss( 2); Emboss( 1); | 3435 | Emboss( 0); Emboss( 2); Emboss( 1); |
3435 | total_red += (MaxRGB+1)/2; | 3436 | total_red += (MaxRGB+1)/2; |
3436 | total_green += (MaxRGB+1)/2; | 3437 | total_green += (MaxRGB+1)/2; |
3437 | total_blue += (MaxRGB+1)/2; | 3438 | total_blue += (MaxRGB+1)/2; |
3438 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), | 3439 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), |
3439 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), | 3440 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), |
3440 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), | 3441 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), |
3441 | 255); | 3442 | 255); |
3442 | p++; | 3443 | p++; |
3443 | q++; | 3444 | q++; |
3444 | } | 3445 | } |
3445 | p++; | 3446 | p++; |
3446 | *q++=(*p); | 3447 | *q++=(*p); |
3447 | } | 3448 | } |
3448 | } | 3449 | } |
3449 | else{ // PsudeoClass source image | 3450 | else{ // PsudeoClass source image |
3450 | unsigned char *p, *p2, *p3, *s; | 3451 | unsigned char *p, *p2, *p3, *s; |
3451 | unsigned int *cTable = src.colorTable(); | 3452 | unsigned int *cTable = src.colorTable(); |
3452 | int scanLineIdx; | 3453 | int scanLineIdx; |
3453 | for(y=0; y < src.height(); ++y){ | 3454 | for(y=0; y < src.height(); ++y){ |
3454 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); | 3455 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); |
3455 | p = (unsigned char *)src.scanLine(scanLineIdx); | 3456 | p = (unsigned char *)src.scanLine(scanLineIdx); |
3456 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); | 3457 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); |
3457 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); | 3458 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); |
3458 | q = (unsigned int *)dest.scanLine(y); | 3459 | q = (unsigned int *)dest.scanLine(y); |
3459 | // emboss this row of pixels. | 3460 | // emboss this row of pixels. |
3460 | *q++=(*(cTable+(*p2))); | 3461 | *q++=(*(cTable+(*p2))); |
3461 | for(x=1; x < src.width()-1; ++x){ | 3462 | for(x=1; x < src.width()-1; ++x){ |
3462 | // compute weighted average of target pixel color components. | 3463 | // compute weighted average of target pixel color components. |
3463 | total_red=0.0; | 3464 | total_red=0.0; |
3464 | total_green=0.0; | 3465 | total_green=0.0; |
3465 | total_blue=0.0; | 3466 | total_blue=0.0; |
3466 | s=p; | 3467 | s=p; |
3467 | Emboss256(-1); Emboss256(-2); Emboss256(0); | 3468 | Emboss256(-1); Emboss256(-2); Emboss256(0); |
3468 | s=p2; | 3469 | s=p2; |
3469 | Emboss256(-2); Emboss256(0); Emboss256(2); | 3470 | Emboss256(-2); Emboss256(0); Emboss256(2); |
3470 | s=p3; | 3471 | s=p3; |
3471 | Emboss256(0); Emboss256(2); Emboss256(1); | 3472 | Emboss256(0); Emboss256(2); Emboss256(1); |
3472 | total_red += (MaxRGB+1)/2; | 3473 | total_red += (MaxRGB+1)/2; |
3473 | total_green += (MaxRGB+1)/2; | 3474 | total_green += (MaxRGB+1)/2; |
3474 | total_blue += (MaxRGB+1)/2; | 3475 | total_blue += (MaxRGB+1)/2; |
3475 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), | 3476 | *q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red), |
3476 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), | 3477 | (unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green), |
3477 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), | 3478 | (unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue), |
3478 | 255); | 3479 | 255); |
3479 | p++; | 3480 | p++; |
3480 | p2++; | 3481 | p2++; |
3481 | p3++; | 3482 | p3++; |
3482 | q++; | 3483 | q++; |
3483 | } | 3484 | } |
3484 | p++; | 3485 | p++; |
3485 | *q++=(*(cTable+(*p))); | 3486 | *q++=(*(cTable+(*p))); |
3486 | } | 3487 | } |
3487 | } | 3488 | } |
3488 | toGray(dest); | 3489 | toGray(dest); |
3489 | normalize(dest); | 3490 | normalize(dest); |
3490 | return(dest); | 3491 | return(dest); |
3491 | } | 3492 | } |
3492 | 3493 | ||
3493 | QImage OImageEffect::shade(QImage &src, bool color_shading, double azimuth, | 3494 | QImage OImageEffect::shade(QImage &src, bool color_shading, double azimuth, |
3494 | double elevation) | 3495 | double elevation) |
3495 | { | 3496 | { |
3496 | struct PointInfo{ | 3497 | struct PointInfo{ |
3497 | double x, y, z; | 3498 | double x, y, z; |
3498 | }; | 3499 | }; |
3499 | 3500 | ||
3500 | double distance, normal_distance, shade; | 3501 | double distance, normal_distance, shade; |
3501 | int x, y; | 3502 | int x, y; |
3502 | 3503 | ||
3503 | struct PointInfo light, normal; | 3504 | struct PointInfo light, normal; |
3504 | 3505 | ||
3505 | unsigned int *q; | 3506 | unsigned int *q; |
3506 | 3507 | ||
3507 | QImage dest(src.width(), src.height(), 32); | 3508 | QImage dest(src.width(), src.height(), 32); |
3508 | 3509 | ||
3509 | azimuth = DegreesToRadians(azimuth); | 3510 | azimuth = DegreesToRadians(azimuth); |
3510 | elevation = DegreesToRadians(elevation); | 3511 | elevation = DegreesToRadians(elevation); |
3511 | light.x = MaxRGB*cos(azimuth)*cos(elevation); | 3512 | light.x = MaxRGB*cos(azimuth)*cos(elevation); |
3512 | light.y = MaxRGB*sin(azimuth)*cos(elevation); | 3513 | light.y = MaxRGB*sin(azimuth)*cos(elevation); |
3513 | light.z = MaxRGB*sin(elevation); | 3514 | light.z = MaxRGB*sin(elevation); |
3514 | normal.z= 2*MaxRGB; // constant Z of surface normal | 3515 | normal.z= 2*MaxRGB; // constant Z of surface normal |
3515 | 3516 | ||
3516 | if(src.depth() > 8){ // DirectClass source image | 3517 | if(src.depth() > 8){ // DirectClass source image |
3517 | unsigned int *p, *s0, *s1, *s2; | 3518 | unsigned int *p, *s0, *s1, *s2; |
3518 | for(y=0; y < src.height(); ++y){ | 3519 | for(y=0; y < src.height(); ++y){ |
3519 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); | 3520 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); |
3520 | q = (unsigned int *)dest.scanLine(y); | 3521 | q = (unsigned int *)dest.scanLine(y); |
3521 | // shade this row of pixels. | 3522 | // shade this row of pixels. |
3522 | *q++=(*(p+src.width())); | 3523 | *q++=(*(p+src.width())); |
3523 | p++; | 3524 | p++; |
3524 | s0 = p; | 3525 | s0 = p; |
3525 | s1 = p + src.width(); | 3526 | s1 = p + src.width(); |
3526 | s2 = p + 2*src.width(); | 3527 | s2 = p + 2*src.width(); |
3527 | for(x=1; x < src.width()-1; ++x){ | 3528 | for(x=1; x < src.width()-1; ++x){ |
3528 | // determine the surface normal and compute shading. | 3529 | // determine the surface normal and compute shading. |
3529 | normal.x=intensityValue(*(s0-1))+intensityValue(*(s1-1))+intensityValue(*(s2-1))- | 3530 | normal.x=intensityValue(*(s0-1))+intensityValue(*(s1-1))+intensityValue(*(s2-1))- |
3530 | (double) intensityValue(*(s0+1))-(double) intensityValue(*(s1+1))- | 3531 | (double) intensityValue(*(s0+1))-(double) intensityValue(*(s1+1))- |
3531 | (double) intensityValue(*(s2+1)); | 3532 | (double) intensityValue(*(s2+1)); |
3532 | normal.y=intensityValue(*(s2-1))+intensityValue(*s2)+intensityValue(*(s2+1))- | 3533 | normal.y=intensityValue(*(s2-1))+intensityValue(*s2)+intensityValue(*(s2+1))- |
3533 | (double) intensityValue(*(s0-1))-(double) intensityValue(*s0)- | 3534 | (double) intensityValue(*(s0-1))-(double) intensityValue(*s0)- |
3534 | (double) intensityValue(*(s0+1)); | 3535 | (double) intensityValue(*(s0+1)); |
3535 | if((normal.x == 0) && (normal.y == 0)) | 3536 | if((normal.x == 0) && (normal.y == 0)) |
3536 | shade=light.z; | 3537 | shade=light.z; |
3537 | else{ | 3538 | else{ |
3538 | shade=0.0; | 3539 | shade=0.0; |
3539 | distance=normal.x*light.x+normal.y*light.y+normal.z*light.z; | 3540 | distance=normal.x*light.x+normal.y*light.y+normal.z*light.z; |
3540 | if (distance > 0.0){ | 3541 | if (distance > 0.0){ |
3541 | normal_distance= | 3542 | normal_distance= |
3542 | normal.x*normal.x+normal.y*normal.y+normal.z*normal.z; | 3543 | normal.x*normal.x+normal.y*normal.y+normal.z*normal.z; |
3543 | if(fabs(normal_distance) > 0.0000001) | 3544 | if(fabs(normal_distance) > 0.0000001) |
3544 | shade=distance/sqrt(normal_distance); | 3545 | shade=distance/sqrt(normal_distance); |
3545 | } | 3546 | } |
3546 | } | 3547 | } |
3547 | if(!color_shading){ | 3548 | if(!color_shading){ |
3548 | *q = qRgba((unsigned char)(shade), | 3549 | *q = qRgba((unsigned char)(shade), |
3549 | (unsigned char)(shade), | 3550 | (unsigned char)(shade), |
3550 | (unsigned char)(shade), | 3551 | (unsigned char)(shade), |
3551 | qAlpha(*s1)); | 3552 | qAlpha(*s1)); |
3552 | } | 3553 | } |
3553 | else{ | 3554 | else{ |
3554 | *q = qRgba((unsigned char)((shade*qRed(*s1))/(MaxRGB+1)), | 3555 | *q = qRgba((unsigned char)((shade*qRed(*s1))/(MaxRGB+1)), |
3555 | (unsigned char)((shade*qGreen(*s1))/(MaxRGB+1)), | 3556 | (unsigned char)((shade*qGreen(*s1))/(MaxRGB+1)), |
3556 | (unsigned char)((shade*qBlue(*s1))/(MaxRGB+1)), | 3557 | (unsigned char)((shade*qBlue(*s1))/(MaxRGB+1)), |
3557 | qAlpha(*s1)); | 3558 | qAlpha(*s1)); |
3558 | } | 3559 | } |
3559 | ++s0; | 3560 | ++s0; |
3560 | ++s1; | 3561 | ++s1; |
3561 | ++s2; | 3562 | ++s2; |
3562 | q++; | 3563 | q++; |
3563 | } | 3564 | } |
3564 | *q++=(*s1); | 3565 | *q++=(*s1); |
3565 | } | 3566 | } |
3566 | } | 3567 | } |
3567 | else{ // PsudeoClass source image | 3568 | else{ // PsudeoClass source image |
3568 | unsigned char *p, *s0, *s1, *s2; | 3569 | unsigned char *p, *s0, *s1, *s2; |
3569 | int scanLineIdx; | 3570 | int scanLineIdx; |
3570 | unsigned int *cTable = (unsigned int *)src.colorTable(); | 3571 | unsigned int *cTable = (unsigned int *)src.colorTable(); |
3571 | for(y=0; y < src.height(); ++y){ | 3572 | for(y=0; y < src.height(); ++y){ |
3572 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); | 3573 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); |
3573 | p = (unsigned char *)src.scanLine(scanLineIdx); | 3574 | p = (unsigned char *)src.scanLine(scanLineIdx); |
3574 | q = (unsigned int *)dest.scanLine(y); | 3575 | q = (unsigned int *)dest.scanLine(y); |
3575 | // shade this row of pixels. | 3576 | // shade this row of pixels. |
3576 | s0 = p; | 3577 | s0 = p; |
3577 | s1 = (unsigned char *) src.scanLine(scanLineIdx+1); | 3578 | s1 = (unsigned char *) src.scanLine(scanLineIdx+1); |
3578 | s2 = (unsigned char *) src.scanLine(scanLineIdx+2); | 3579 | s2 = (unsigned char *) src.scanLine(scanLineIdx+2); |
3579 | *q++=(*(cTable+(*s1))); | 3580 | *q++=(*(cTable+(*s1))); |
3580 | ++p; | 3581 | ++p; |
3581 | ++s0; | 3582 | ++s0; |
3582 | ++s1; | 3583 | ++s1; |
3583 | ++s2; | 3584 | ++s2; |
3584 | for(x=1; x < src.width()-1; ++x){ | 3585 | for(x=1; x < src.width()-1; ++x){ |
3585 | // determine the surface normal and compute shading. | 3586 | // determine the surface normal and compute shading. |
3586 | normal.x=intensityValue(*(cTable+(*(s0-1))))+intensityValue(*(cTable+(*(s1-1))))+intensityValue(*(cTable+(*(s2-1))))- | 3587 | normal.x=intensityValue(*(cTable+(*(s0-1))))+intensityValue(*(cTable+(*(s1-1))))+intensityValue(*(cTable+(*(s2-1))))- |
3587 | (double) intensityValue(*(cTable+(*(s0+1))))-(double) intensityValue(*(cTable+(*(s1+1))))- | 3588 | (double) intensityValue(*(cTable+(*(s0+1))))-(double) intensityValue(*(cTable+(*(s1+1))))- |
3588 | (double) intensityValue(*(cTable+(*(s2+1)))); | 3589 | (double) intensityValue(*(cTable+(*(s2+1)))); |
3589 | normal.y=intensityValue(*(cTable+(*(s2-1))))+intensityValue(*(cTable+(*s2)))+intensityValue(*(cTable+(*(s2+1))))- | 3590 | normal.y=intensityValue(*(cTable+(*(s2-1))))+intensityValue(*(cTable+(*s2)))+intensityValue(*(cTable+(*(s2+1))))- |
3590 | (double) intensityValue(*(cTable+(*(s0-1))))-(double) intensityValue(*(cTable+(*s0)))- | 3591 | (double) intensityValue(*(cTable+(*(s0-1))))-(double) intensityValue(*(cTable+(*s0)))- |
3591 | (double) intensityValue(*(cTable+(*(s0+1)))); | 3592 | (double) intensityValue(*(cTable+(*(s0+1)))); |
3592 | if((normal.x == 0) && (normal.y == 0)) | 3593 | if((normal.x == 0) && (normal.y == 0)) |
3593 | shade=light.z; | 3594 | shade=light.z; |
3594 | else{ | 3595 | else{ |
3595 | shade=0.0; | 3596 | shade=0.0; |
3596 | distance=normal.x*light.x+normal.y*light.y+normal.z*light.z; | 3597 | distance=normal.x*light.x+normal.y*light.y+normal.z*light.z; |
3597 | if (distance > 0.0){ | 3598 | if (distance > 0.0){ |
3598 | normal_distance= | 3599 | normal_distance= |
3599 | normal.x*normal.x+normal.y*normal.y+normal.z*normal.z; | 3600 | normal.x*normal.x+normal.y*normal.y+normal.z*normal.z; |
3600 | if(fabs(normal_distance) > 0.0000001) | 3601 | if(fabs(normal_distance) > 0.0000001) |
3601 | shade=distance/sqrt(normal_distance); | 3602 | shade=distance/sqrt(normal_distance); |
3602 | } | 3603 | } |
3603 | } | 3604 | } |
3604 | if(!color_shading){ | 3605 | if(!color_shading){ |
3605 | *q = qRgba((unsigned char)(shade), | 3606 | *q = qRgba((unsigned char)(shade), |
3606 | (unsigned char)(shade), | 3607 | (unsigned char)(shade), |
3607 | (unsigned char)(shade), | 3608 | (unsigned char)(shade), |
3608 | qAlpha(*(cTable+(*s1)))); | 3609 | qAlpha(*(cTable+(*s1)))); |
3609 | } | 3610 | } |
3610 | else{ | 3611 | else{ |
3611 | *q = qRgba((unsigned char)((shade*qRed(*(cTable+(*s1))))/(MaxRGB+1)), | 3612 | *q = qRgba((unsigned char)((shade*qRed(*(cTable+(*s1))))/(MaxRGB+1)), |
3612 | (unsigned char)((shade*qGreen(*(cTable+(*s1))))/(MaxRGB+1)), | 3613 | (unsigned char)((shade*qGreen(*(cTable+(*s1))))/(MaxRGB+1)), |
3613 | (unsigned char)((shade*qBlue(*(cTable+(*s1))))/(MaxRGB+1)), | 3614 | (unsigned char)((shade*qBlue(*(cTable+(*s1))))/(MaxRGB+1)), |
3614 | qAlpha(*s1)); | 3615 | qAlpha(*s1)); |
3615 | } | 3616 | } |
3616 | ++s0; | 3617 | ++s0; |
3617 | ++s1; | 3618 | ++s1; |
3618 | ++s2; | 3619 | ++s2; |
3619 | q++; | 3620 | q++; |
3620 | } | 3621 | } |
3621 | *q++=(*(cTable+(*s1))); | 3622 | *q++=(*(cTable+(*s1))); |
3622 | } | 3623 | } |
3623 | } | 3624 | } |
3624 | return(dest); | 3625 | return(dest); |
3625 | } | 3626 | } |
3626 | 3627 | ||
3627 | QImage OImageEffect::blur(QImage &src, double factor) | 3628 | QImage OImageEffect::blur(QImage &src, double factor) |
3628 | { | 3629 | { |
3629 | 3630 | ||
3630 | #define Blur(weight) \ | 3631 | #define Blur(weight) \ |
3631 | total_red+=(weight)*qRed(*s); \ | 3632 | total_red+=(weight)*qRed(*s); \ |
3632 | total_green+=(weight)*qGreen(*s); \ | 3633 | total_green+=(weight)*qGreen(*s); \ |
3633 | total_blue+=(weight)*qBlue(*s); \ | 3634 | total_blue+=(weight)*qBlue(*s); \ |
3634 | total_opacity+=(weight)*qAlpha(*s); \ | 3635 | total_opacity+=(weight)*qAlpha(*s); \ |
3635 | s++; | 3636 | s++; |
3636 | 3637 | ||
3637 | #define Blur256(weight) \ | 3638 | #define Blur256(weight) \ |
3638 | total_red+=(weight)*qRed(*(cTable+(*s))); \ | 3639 | total_red+=(weight)*qRed(*(cTable+(*s))); \ |
3639 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ | 3640 | total_green+=(weight)*qGreen(*(cTable+(*s))); \ |
3640 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ | 3641 | total_blue+=(weight)*qBlue(*(cTable+(*s))); \ |
3641 | total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ | 3642 | total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \ |
3642 | s++; | 3643 | s++; |
3643 | 3644 | ||
3644 | if(src.width() < 3 || src.height() < 3) | 3645 | if(src.width() < 3 || src.height() < 3) |
3645 | return(src); | 3646 | return(src); |
3646 | 3647 | ||
3647 | double quantum, total_blue, total_green, total_opacity, total_red, weight; | 3648 | double quantum, total_blue, total_green, total_opacity, total_red, weight; |
3648 | 3649 | ||
3649 | int x, y; | 3650 | int x, y; |
3650 | unsigned int *q; | 3651 | unsigned int *q; |
3651 | 3652 | ||
3652 | QImage dest(src.width(), src.height(), 32); | 3653 | QImage dest(src.width(), src.height(), 32); |
3653 | weight=((100.0-factor)/2)+1; | 3654 | weight=((100.0-factor)/2)+1; |
3654 | quantum = QMAX(weight+12.0, 1.0); | 3655 | quantum = QMAX(weight+12.0, 1.0); |
3655 | if(src.depth() > 8){ // DirectClass source image | 3656 | if(src.depth() > 8){ // DirectClass source image |
3656 | unsigned int *p, *s; | 3657 | unsigned int *p, *s; |
3657 | for(y=0; y < src.height(); ++y){ | 3658 | for(y=0; y < src.height(); ++y){ |
3658 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); | 3659 | p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3)); |
3659 | q = (unsigned int *)dest.scanLine(y); | 3660 | q = (unsigned int *)dest.scanLine(y); |
3660 | // blur this row of pixels. | 3661 | // blur this row of pixels. |
3661 | *q++=(*(p+src.width())); | 3662 | *q++=(*(p+src.width())); |
3662 | for(x=1; x < src.width()-1; ++x){ | 3663 | for(x=1; x < src.width()-1; ++x){ |
3663 | // compute weighted average of target pixel color components. | 3664 | // compute weighted average of target pixel color components. |
3664 | total_red=0.0; | 3665 | total_red=0.0; |
3665 | total_green=0.0; | 3666 | total_green=0.0; |
3666 | total_blue=0.0; | 3667 | total_blue=0.0; |
3667 | total_opacity=0.0; | 3668 | total_opacity=0.0; |
3668 | s=p; | 3669 | s=p; |
3669 | Blur(1); Blur(2); Blur(1); | 3670 | Blur(1); Blur(2); Blur(1); |
3670 | s=p+src.width(); | 3671 | s=p+src.width(); |
3671 | Blur(2); Blur(weight); Blur(2); | 3672 | Blur(2); Blur(weight); Blur(2); |
3672 | s=p+2*src.width(); | 3673 | s=p+2*src.width(); |
3673 | Blur(1); Blur(2); Blur(1); | 3674 | Blur(1); Blur(2); Blur(1); |
3674 | *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum), | 3675 | *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum), |
3675 | (unsigned char)((total_green+(quantum/2))/quantum), | 3676 | (unsigned char)((total_green+(quantum/2))/quantum), |
3676 | (unsigned char)((total_blue+(quantum/2))/quantum), | 3677 | (unsigned char)((total_blue+(quantum/2))/quantum), |
3677 | (unsigned char)((total_opacity+(quantum/2))/quantum)); | 3678 | (unsigned char)((total_opacity+(quantum/2))/quantum)); |
3678 | p++; | 3679 | p++; |
3679 | q++; | 3680 | q++; |
3680 | } | 3681 | } |
3681 | p++; | 3682 | p++; |
3682 | *q++=(*p); | 3683 | *q++=(*p); |
3683 | } | 3684 | } |
3684 | } | 3685 | } |
3685 | else{ // PsudeoClass source image | 3686 | else{ // PsudeoClass source image |
3686 | unsigned char *p, *p2, *p3, *s; | 3687 | unsigned char *p, *p2, *p3, *s; |
3687 | unsigned int *cTable = src.colorTable(); | 3688 | unsigned int *cTable = src.colorTable(); |
3688 | int scanLineIdx; | 3689 | int scanLineIdx; |
3689 | for(y=0; y < src.height(); ++y){ | 3690 | for(y=0; y < src.height(); ++y){ |
3690 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); | 3691 | scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3); |
3691 | p = (unsigned char *)src.scanLine(scanLineIdx); | 3692 | p = (unsigned char *)src.scanLine(scanLineIdx); |
3692 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); | 3693 | p2 = (unsigned char *)src.scanLine(scanLineIdx+1); |
3693 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); | 3694 | p3 = (unsigned char *)src.scanLine(scanLineIdx+2); |
3694 | q = (unsigned int *)dest.scanLine(y); | 3695 | q = (unsigned int *)dest.scanLine(y); |
3695 | // blur this row of pixels. | 3696 | // blur this row of pixels. |
3696 | *q++=(*(cTable+(*p2))); | 3697 | *q++=(*(cTable+(*p2))); |
3697 | for(x=1; x < src.width()-1; ++x){ | 3698 | for(x=1; x < src.width()-1; ++x){ |
3698 | // compute weighted average of target pixel color components. | 3699 | // compute weighted average of target pixel color components. |
3699 | total_red=0.0; | 3700 | total_red=0.0; |
3700 | total_green=0.0; | 3701 | total_green=0.0; |
3701 | total_blue=0.0; | 3702 | total_blue=0.0; |
3702 | total_opacity=0.0; | 3703 | total_opacity=0.0; |
3703 | s=p; | 3704 | s=p; |
3704 | Blur256(1); Blur256(2); Blur256(1); | 3705 | Blur256(1); Blur256(2); Blur256(1); |
3705 | s=p2; | 3706 | s=p2; |
3706 | Blur256(2); Blur256(weight); Blur256(2); | 3707 | Blur256(2); Blur256(weight); Blur256(2); |
3707 | s=p3; | 3708 | s=p3; |
3708 | Blur256(1); Blur256(2); Blur256(1); | 3709 | Blur256(1); Blur256(2); Blur256(1); |
3709 | *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum), | 3710 | *q = qRgba((unsigned char)((total_red+(quantum/2))/quantum), |
3710 | (unsigned char)((total_green+(quantum/2))/quantum), | 3711 | (unsigned char)((total_green+(quantum/2))/quantum), |
3711 | (unsigned char)((total_blue+(quantum/2))/quantum), | 3712 | (unsigned char)((total_blue+(quantum/2))/quantum), |
3712 | (unsigned char)((total_opacity+(quantum/2))/quantum)); | 3713 | (unsigned char)((total_opacity+(quantum/2))/quantum)); |
3713 | p++; | 3714 | p++; |
3714 | p2++; | 3715 | p2++; |
3715 | p3++; | 3716 | p3++; |
3716 | q++; | 3717 | q++; |
3717 | } | 3718 | } |
3718 | p++; | 3719 | p++; |
3719 | *q++=(*(cTable+(*p))); | 3720 | *q++=(*(cTable+(*p))); |
3720 | } | 3721 | } |
3721 | } | 3722 | } |
3722 | return(dest); | 3723 | return(dest); |
3723 | } | 3724 | } |
3724 | 3725 | ||
3725 | // High quality, expensive HSV contrast. You can do a faster one by just | 3726 | // High quality, expensive HSV contrast. You can do a faster one by just |
3726 | // taking a grayscale threshold (ie: 128) and incrementing RGB color | 3727 | // taking a grayscale threshold (ie: 128) and incrementing RGB color |
3727 | // channels above it and decrementing those below it, but this gives much | 3728 | // channels above it and decrementing those below it, but this gives much |
3728 | // better results. (mosfet 12/28/01) | 3729 | // better results. (mosfet 12/28/01) |
3729 | void OImageEffect::contrastHSV(QImage &img, bool sharpen) | 3730 | void OImageEffect::contrastHSV(QImage &img, bool sharpen) |
3730 | { | 3731 | { |
3731 | int i, sign; | 3732 | int i, sign; |
3732 | unsigned int *data; | 3733 | unsigned int *data; |
3733 | int count; | 3734 | int count; |
3734 | double brightness, scale, theta; | 3735 | double brightness, scale, theta; |
3735 | QColor c; | 3736 | QColor c; |
3736 | int h, s, v; | 3737 | int h, s, v; |
3737 | 3738 | ||
3738 | sign = sharpen ? 1 : -1; | 3739 | sign = sharpen ? 1 : -1; |
3739 | scale=0.5000000000000001; | 3740 | scale=0.5000000000000001; |
3740 | if(img.depth() > 8){ | 3741 | if(img.depth() > 8){ |
3741 | count = img.width()*img.height(); | 3742 | count = img.width()*img.height(); |
3742 | data = (unsigned int *)img.bits(); | 3743 | data = (unsigned int *)img.bits(); |
3743 | } | 3744 | } |
3744 | else{ | 3745 | else{ |
3745 | count = img.numColors(); | 3746 | count = img.numColors(); |
3746 | data = (unsigned int *)img.colorTable(); | 3747 | data = (unsigned int *)img.colorTable(); |
3747 | } | 3748 | } |
3748 | for(i=0; i < count; ++i){ | 3749 | for(i=0; i < count; ++i){ |
3749 | c.setRgb(data[i]); | 3750 | c.setRgb(data[i]); |
3750 | c.hsv(&h, &s, &v); | 3751 | c.hsv(&h, &s, &v); |
3751 | brightness = v/255.0; | 3752 | brightness = v/255.0; |
3752 | theta=(brightness-0.5)*M_PI; | 3753 | theta=(brightness-0.5)*M_PI; |
3753 | brightness+=scale*(((scale*((sin(theta)+1.0)))-brightness)*sign); | 3754 | brightness+=scale*(((scale*((sin(theta)+1.0)))-brightness)*sign); |
3754 | if (brightness > 1.0) | 3755 | if (brightness > 1.0) |
3755 | brightness=1.0; | 3756 | brightness=1.0; |
3756 | else | 3757 | else |
3757 | if (brightness < 0) | 3758 | if (brightness < 0) |
3758 | brightness=0.0; | 3759 | brightness=0.0; |
3759 | v = (int)(brightness*255); | 3760 | v = (int)(brightness*255); |
3760 | c.setHsv(h, s, v); | 3761 | c.setHsv(h, s, v); |
3761 | data[i] = qRgba(c.red(), c.green(), c.blue(), qAlpha(data[i])); | 3762 | data[i] = qRgba(c.red(), c.green(), c.blue(), qAlpha(data[i])); |
3762 | } | 3763 | } |
3763 | } | 3764 | } |
3764 | 3765 | ||
3765 | 3766 | ||
3766 | 3767 | ||
3767 | 3768 | ||
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp index ec503dd..38f3fe2 100644 --- a/libopie2/opieui/olistview.cpp +++ b/libopie2/opieui/olistview.cpp | |||
@@ -1,613 +1,613 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de> | |
4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
5 | .=l. | 4 | .=l. |
6 | .>+-= | 5 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 12 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 20 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
28 | 27 | ||
29 | */ | 28 | */ |
30 | 29 | ||
31 | /* QT */ | 30 | /* QT */ |
32 | 31 | ||
33 | #include <qcolor.h> | 32 | #include <qcolor.h> |
34 | #include <qheader.h> | 33 | #include <qheader.h> |
35 | #include <qpainter.h> | 34 | #include <qpainter.h> |
36 | #include <qpixmap.h> | 35 | #include <qpixmap.h> |
37 | 36 | ||
38 | /* OPIE */ | 37 | /* OPIE */ |
39 | 38 | ||
39 | #include <opie2/odebug.h> | ||
40 | #include <opie2/olistview.h> | 40 | #include <opie2/olistview.h> |
41 | 41 | ||
42 | /*====================================================================================== | 42 | /*====================================================================================== |
43 | * OListView | 43 | * OListView |
44 | *======================================================================================*/ | 44 | *======================================================================================*/ |
45 | 45 | ||
46 | OListView::OListView( QWidget *parent, const char *name ) | 46 | OListView::OListView( QWidget *parent, const char *name ) |
47 | :QListView( parent, name ) | 47 | :QListView( parent, name ) |
48 | { | 48 | { |
49 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* | 49 | //FIXME: get from global settings and calculate ==> see oglobalsettings.* |
50 | 50 | ||
51 | m_alternateBackground = QColor( 238, 246, 255 ); | 51 | m_alternateBackground = QColor( 238, 246, 255 ); |
52 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); | 52 | m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine ); |
53 | m_fullWidth = true; | 53 | m_fullWidth = true; |
54 | connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); | 54 | connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*))); |
55 | } | 55 | } |
56 | 56 | ||
57 | OListView::~OListView() | 57 | OListView::~OListView() |
58 | { | 58 | { |
59 | } | 59 | } |
60 | 60 | ||
61 | void OListView::setFullWidth( bool fullWidth ) | 61 | void OListView::setFullWidth( bool fullWidth ) |
62 | { | 62 | { |
63 | m_fullWidth = m_fullWidth; | 63 | m_fullWidth = m_fullWidth; |
64 | #if QT_VERSION > 290 | 64 | #if QT_VERSION > 290 |
65 | header()->setStretchEnabled( fullWidth, columns()-1 ); | 65 | header()->setStretchEnabled( fullWidth, columns()-1 ); |
66 | #endif | 66 | #endif |
67 | } | 67 | } |
68 | 68 | ||
69 | bool OListView::fullWidth() const | 69 | bool OListView::fullWidth() const |
70 | { | 70 | { |
71 | return m_fullWidth; | 71 | return m_fullWidth; |
72 | } | 72 | } |
73 | 73 | ||
74 | int OListView::addColumn( const QString& label, int width ) | 74 | int OListView::addColumn( const QString& label, int width ) |
75 | { | 75 | { |
76 | int result = QListView::addColumn( label, width ); | 76 | int result = QListView::addColumn( label, width ); |
77 | #if QT_VERSION > 290 | 77 | #if QT_VERSION > 290 |
78 | if (m_fullWidth) { | 78 | if (m_fullWidth) { |
79 | header()->setStretchEnabled( false, columns()-2 ); | 79 | header()->setStretchEnabled( false, columns()-2 ); |
80 | header()->setStretchEnabled( true, columns()-1 ); | 80 | header()->setStretchEnabled( true, columns()-1 ); |
81 | } | 81 | } |
82 | #endif | 82 | #endif |
83 | return result; | 83 | return result; |
84 | } | 84 | } |
85 | 85 | ||
86 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) | 86 | int OListView::addColumn( const QIconSet& iconset, const QString& label, int width ) |
87 | { | 87 | { |
88 | int result = QListView::addColumn( iconset, label, width ); | 88 | int result = QListView::addColumn( iconset, label, width ); |
89 | #if QT_VERSION > 290 | 89 | #if QT_VERSION > 290 |
90 | if (m_fullWidth) { | 90 | if (m_fullWidth) { |
91 | header()->setStretchEnabled( false, columns()-2 ); | 91 | header()->setStretchEnabled( false, columns()-2 ); |
92 | header()->setStretchEnabled( true, columns()-1 ); | 92 | header()->setStretchEnabled( true, columns()-1 ); |
93 | } | 93 | } |
94 | #endif | 94 | #endif |
95 | return result; | 95 | return result; |
96 | } | 96 | } |
97 | 97 | ||
98 | void OListView::removeColumn( int index ) | 98 | void OListView::removeColumn( int index ) |
99 | { | 99 | { |
100 | QListView::removeColumn(index); | 100 | QListView::removeColumn(index); |
101 | #if QT_VERSION > 290 | 101 | #if QT_VERSION > 290 |
102 | if ( m_fullWidth && index == columns() ) | 102 | if ( m_fullWidth && index == columns() ) |
103 | { | 103 | { |
104 | header()->setStretchEnabled( true, columns()-1 ); | 104 | header()->setStretchEnabled( true, columns()-1 ); |
105 | } | 105 | } |
106 | #endif | 106 | #endif |
107 | } | 107 | } |
108 | 108 | ||
109 | const QColor& OListView::alternateBackground() const | 109 | const QColor& OListView::alternateBackground() const |
110 | { | 110 | { |
111 | return m_alternateBackground; | 111 | return m_alternateBackground; |
112 | } | 112 | } |
113 | 113 | ||
114 | void OListView::setAlternateBackground( const QColor &c ) | 114 | void OListView::setAlternateBackground( const QColor &c ) |
115 | { | 115 | { |
116 | m_alternateBackground = c; | 116 | m_alternateBackground = c; |
117 | repaint(); | 117 | repaint(); |
118 | } | 118 | } |
119 | 119 | ||
120 | const QPen& OListView::columnSeparator() const | 120 | const QPen& OListView::columnSeparator() const |
121 | { | 121 | { |
122 | return m_columnSeparator; | 122 | return m_columnSeparator; |
123 | } | 123 | } |
124 | 124 | ||
125 | void OListView::setColumnSeparator( const QPen& p ) | 125 | void OListView::setColumnSeparator( const QPen& p ) |
126 | { | 126 | { |
127 | m_columnSeparator = p; | 127 | m_columnSeparator = p; |
128 | repaint(); | 128 | repaint(); |
129 | } | 129 | } |
130 | 130 | ||
131 | void OListView::expand(QListViewItem *item) | 131 | void OListView::expand(QListViewItem *item) |
132 | { | 132 | { |
133 | ((OListViewItem*)item)->expand(); | 133 | ((OListViewItem*)item)->expand(); |
134 | } | 134 | } |
135 | 135 | ||
136 | OListViewItem* OListView::childFactory() | 136 | OListViewItem* OListView::childFactory() |
137 | { | 137 | { |
138 | return new OListViewItem( this ); | 138 | return new OListViewItem( this ); |
139 | } | 139 | } |
140 | 140 | ||
141 | #ifndef QT_NO_DATASTREAM | 141 | #ifndef QT_NO_DATASTREAM |
142 | void OListView::serializeTo( QDataStream& s ) const | 142 | void OListView::serializeTo( QDataStream& s ) const |
143 | { | 143 | { |
144 | #warning Caution... the binary format is still under construction... | 144 | #warning Caution... the binary format is still under construction... |
145 | qDebug( "storing OListView..." ); | 145 | odebug << "storing OListView..." << oendl; |
146 | 146 | ||
147 | // store number of columns and the labels | 147 | // store number of columns and the labels |
148 | s << columns(); | 148 | s << columns(); |
149 | for ( int i = 0; i < columns(); ++i ) | 149 | for ( int i = 0; i < columns(); ++i ) |
150 | s << columnText( i ); | 150 | s << columnText( i ); |
151 | 151 | ||
152 | // calculate the number of top-level items to serialize | 152 | // calculate the number of top-level items to serialize |
153 | int items = 0; | 153 | int items = 0; |
154 | QListViewItem* item = firstChild(); | 154 | QListViewItem* item = firstChild(); |
155 | while ( item ) | 155 | while ( item ) |
156 | { | 156 | { |
157 | item = item->nextSibling(); | 157 | item = item->nextSibling(); |
158 | items++; | 158 | items++; |
159 | } | 159 | } |
160 | 160 | ||
161 | // store number of items and the items itself | 161 | // store number of items and the items itself |
162 | s << items; | 162 | s << items; |
163 | item = firstChild(); | 163 | item = firstChild(); |
164 | for ( int i = 0; i < items; ++i ) | 164 | for ( int i = 0; i < items; ++i ) |
165 | { | 165 | { |
166 | s << *static_cast<OListViewItem*>( item ); | 166 | s << *static_cast<OListViewItem*>( item ); |
167 | item = item->nextSibling(); | 167 | item = item->nextSibling(); |
168 | } | 168 | } |
169 | 169 | ||
170 | qDebug( "OListview stored." ); | 170 | odebug << "OListview stored." << oendl; |
171 | } | 171 | } |
172 | 172 | ||
173 | void OListView::serializeFrom( QDataStream& s ) | 173 | void OListView::serializeFrom( QDataStream& s ) |
174 | { | 174 | { |
175 | #warning Caution... the binary format is still under construction... | 175 | #warning Caution... the binary format is still under construction... |
176 | qDebug( "loading OListView..." ); | 176 | odebug << "loading OListView..." << oendl; |
177 | 177 | ||
178 | int cols; | 178 | int cols; |
179 | s >> cols; | 179 | s >> cols; |
180 | qDebug( "read number of columns = %d", cols ); | 180 | qDebug( "read number of columns = %d", cols ); |
181 | 181 | ||
182 | while ( columns() < cols ) addColumn( QString::null ); | 182 | while ( columns() < cols ) addColumn( QString::null ); |
183 | 183 | ||
184 | for ( int i = 0; i < cols; ++i ) | 184 | for ( int i = 0; i < cols; ++i ) |
185 | { | 185 | { |
186 | QString coltext; | 186 | QString coltext; |
187 | s >> coltext; | 187 | s >> coltext; |
188 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); | 188 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); |
189 | setColumnText( i, coltext ); | 189 | setColumnText( i, coltext ); |
190 | } | 190 | } |
191 | 191 | ||
192 | int items; | 192 | int items; |
193 | s >> items; | 193 | s >> items; |
194 | qDebug( "read number of items = %d", items ); | 194 | qDebug( "read number of items = %d", items ); |
195 | 195 | ||
196 | for ( int i = 0; i < items; ++i ) | 196 | for ( int i = 0; i < items; ++i ) |
197 | { | 197 | { |
198 | OListViewItem* item = childFactory(); | 198 | OListViewItem* item = childFactory(); |
199 | s >> *item; | 199 | s >> *item; |
200 | } | 200 | } |
201 | 201 | ||
202 | qDebug( "OListView loaded." ); | 202 | odebug << "OListView loaded." << oendl; |
203 | 203 | ||
204 | } | 204 | } |
205 | 205 | ||
206 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) | 206 | QDataStream& operator<<( QDataStream& s, const OListView& lv ) |
207 | { | 207 | { |
208 | lv.serializeTo( s ); | 208 | lv.serializeTo( s ); |
209 | } | 209 | } |
210 | 210 | ||
211 | QDataStream& operator>>( QDataStream& s, OListView& lv ) | 211 | QDataStream& operator>>( QDataStream& s, OListView& lv ) |
212 | { | 212 | { |
213 | lv.serializeFrom( s ); | 213 | lv.serializeFrom( s ); |
214 | } | 214 | } |
215 | #endif // QT_NO_DATASTREAM | 215 | #endif // QT_NO_DATASTREAM |
216 | 216 | ||
217 | /*====================================================================================== | 217 | /*====================================================================================== |
218 | * OListViewItem | 218 | * OListViewItem |
219 | *======================================================================================*/ | 219 | *======================================================================================*/ |
220 | 220 | ||
221 | OListViewItem::OListViewItem(QListView *parent) | 221 | OListViewItem::OListViewItem(QListView *parent) |
222 | : QListViewItem(parent) | 222 | : QListViewItem(parent) |
223 | { | 223 | { |
224 | init(); | 224 | init(); |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | OListViewItem::OListViewItem(QListViewItem *parent) | 228 | OListViewItem::OListViewItem(QListViewItem *parent) |
229 | : QListViewItem(parent) | 229 | : QListViewItem(parent) |
230 | { | 230 | { |
231 | init(); | 231 | init(); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
235 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) | 235 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after) |
236 | : QListViewItem(parent, after) | 236 | : QListViewItem(parent, after) |
237 | { | 237 | { |
238 | init(); | 238 | init(); |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) | 242 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after) |
243 | : QListViewItem(parent, after) | 243 | : QListViewItem(parent, after) |
244 | { | 244 | { |
245 | init(); | 245 | init(); |
246 | } | 246 | } |
247 | 247 | ||
248 | 248 | ||
249 | OListViewItem::OListViewItem(QListView *parent, | 249 | OListViewItem::OListViewItem(QListView *parent, |
250 | QString label1, QString label2, QString label3, QString label4, | 250 | QString label1, QString label2, QString label3, QString label4, |
251 | QString label5, QString label6, QString label7, QString label8) | 251 | QString label5, QString label6, QString label7, QString label8) |
252 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 252 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
253 | { | 253 | { |
254 | init(); | 254 | init(); |
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | OListViewItem::OListViewItem(QListViewItem *parent, | 258 | OListViewItem::OListViewItem(QListViewItem *parent, |
259 | QString label1, QString label2, QString label3, QString label4, | 259 | QString label1, QString label2, QString label3, QString label4, |
260 | QString label5, QString label6, QString label7, QString label8) | 260 | QString label5, QString label6, QString label7, QString label8) |
261 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) | 261 | : QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8) |
262 | { | 262 | { |
263 | init(); | 263 | init(); |
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, | 267 | OListViewItem::OListViewItem(QListView *parent, QListViewItem *after, |
268 | QString label1, QString label2, QString label3, QString label4, | 268 | QString label1, QString label2, QString label3, QString label4, |
269 | QString label5, QString label6, QString label7, QString label8) | 269 | QString label5, QString label6, QString label7, QString label8) |
270 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 270 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
271 | { | 271 | { |
272 | init(); | 272 | init(); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, | 276 | OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after, |
277 | QString label1, QString label2, QString label3, QString label4, | 277 | QString label1, QString label2, QString label3, QString label4, |
278 | QString label5, QString label6, QString label7, QString label8) | 278 | QString label5, QString label6, QString label7, QString label8) |
279 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) | 279 | : QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8) |
280 | { | 280 | { |
281 | init(); | 281 | init(); |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | OListViewItem::~OListViewItem() | 285 | OListViewItem::~OListViewItem() |
286 | { | 286 | { |
287 | } | 287 | } |
288 | 288 | ||
289 | 289 | ||
290 | void OListViewItem::init() | 290 | void OListViewItem::init() |
291 | { | 291 | { |
292 | m_known = false; | 292 | m_known = false; |
293 | } | 293 | } |
294 | 294 | ||
295 | 295 | ||
296 | const QColor &OListViewItem::backgroundColor() | 296 | const QColor &OListViewItem::backgroundColor() |
297 | { | 297 | { |
298 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : | 298 | return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() : |
299 | listView()->viewport()->colorGroup().base(); | 299 | listView()->viewport()->colorGroup().base(); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | bool OListViewItem::isAlternate() | 303 | bool OListViewItem::isAlternate() |
304 | { | 304 | { |
305 | OListView *lv = static_cast<OListView*>( listView() ); | 305 | OListView *lv = static_cast<OListView*>( listView() ); |
306 | 306 | ||
307 | // check if the item above is an OListViewItem | 307 | // check if the item above is an OListViewItem |
308 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); | 308 | OListViewItem *above = static_cast<OListViewItem*>( itemAbove() ); |
309 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ | 309 | /*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/ |
310 | 310 | ||
311 | // check if we have a valid alternate background color | 311 | // check if we have a valid alternate background color |
312 | if (!(lv && lv->alternateBackground().isValid())) return false; | 312 | if (!(lv && lv->alternateBackground().isValid())) return false; |
313 | 313 | ||
314 | m_known = above ? above->m_known : true; | 314 | m_known = above ? above->m_known : true; |
315 | if (m_known) | 315 | if (m_known) |
316 | { | 316 | { |
317 | m_odd = above ? !above->m_odd : false; | 317 | m_odd = above ? !above->m_odd : false; |
318 | } | 318 | } |
319 | else | 319 | else |
320 | { | 320 | { |
321 | OListViewItem *item; | 321 | OListViewItem *item; |
322 | bool previous = true; | 322 | bool previous = true; |
323 | if (parent()) | 323 | if (parent()) |
324 | { | 324 | { |
325 | item = static_cast<OListViewItem *>(parent()); | 325 | item = static_cast<OListViewItem *>(parent()); |
326 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; | 326 | if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd; |
327 | item = static_cast<OListViewItem *>(parent()->firstChild()); | 327 | item = static_cast<OListViewItem *>(parent()->firstChild()); |
328 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ | 328 | /* if ( !item.inherits( "OListViewItem" ) item = 0; */ |
329 | } | 329 | } |
330 | else | 330 | else |
331 | { | 331 | { |
332 | item = static_cast<OListViewItem *>(lv->firstChild()); | 332 | item = static_cast<OListViewItem *>(lv->firstChild()); |
333 | } | 333 | } |
334 | 334 | ||
335 | while(item) | 335 | while(item) |
336 | { | 336 | { |
337 | item->m_odd = previous = !previous; | 337 | item->m_odd = previous = !previous; |
338 | item->m_known = true; | 338 | item->m_known = true; |
339 | item = static_cast<OListViewItem *>(item->nextSibling()); | 339 | item = static_cast<OListViewItem *>(item->nextSibling()); |
340 | /* if (!item.inherits( "OListViewItem" ) ) break; */ | 340 | /* if (!item.inherits( "OListViewItem" ) ) break; */ |
341 | } | 341 | } |
342 | } | 342 | } |
343 | return m_odd; | 343 | return m_odd; |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) | 347 | void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) |
348 | { | 348 | { |
349 | QColorGroup _cg = cg; | 349 | QColorGroup _cg = cg; |
350 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); | 350 | const QPixmap *pm = listView()->viewport()->backgroundPixmap(); |
351 | if (pm && !pm->isNull()) | 351 | if (pm && !pm->isNull()) |
352 | { | 352 | { |
353 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); | 353 | _cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) ); |
354 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); | 354 | p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() ); |
355 | } | 355 | } |
356 | else if ( isAlternate() ) | 356 | else if ( isAlternate() ) |
357 | { | 357 | { |
358 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); | 358 | _cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() ); |
359 | } | 359 | } |
360 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 360 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
361 | 361 | ||
362 | //FIXME: Use styling here! | 362 | //FIXME: Use styling here! |
363 | 363 | ||
364 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); | 364 | const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator(); |
365 | p->setPen( pen ); | 365 | p->setPen( pen ); |
366 | p->drawLine( width-1, 0, width-1, height() ); | 366 | p->drawLine( width-1, 0, width-1, height() ); |
367 | } | 367 | } |
368 | 368 | ||
369 | 369 | ||
370 | OListViewItem* OListViewItem::childFactory() | 370 | OListViewItem* OListViewItem::childFactory() |
371 | { | 371 | { |
372 | return new OListViewItem( this ); | 372 | return new OListViewItem( this ); |
373 | } | 373 | } |
374 | 374 | ||
375 | 375 | ||
376 | #ifndef QT_NO_DATASTREAM | 376 | #ifndef QT_NO_DATASTREAM |
377 | void OListViewItem::serializeTo( QDataStream& s ) const | 377 | void OListViewItem::serializeTo( QDataStream& s ) const |
378 | { | 378 | { |
379 | #warning Caution... the binary format is still under construction... | 379 | #warning Caution... the binary format is still under construction... |
380 | qDebug( "storing OListViewItem..." ); | 380 | odebug << "storing OListViewItem..." << oendl; |
381 | 381 | ||
382 | // store item text | 382 | // store item text |
383 | for ( int i = 0; i < listView()->columns(); ++i ) | 383 | for ( int i = 0; i < listView()->columns(); ++i ) |
384 | { | 384 | { |
385 | s << text( i ); | 385 | s << text( i ); |
386 | } | 386 | } |
387 | 387 | ||
388 | // calculate the number of children to serialize | 388 | // calculate the number of children to serialize |
389 | int items = 0; | 389 | int items = 0; |
390 | QListViewItem* item = firstChild(); | 390 | QListViewItem* item = firstChild(); |
391 | while ( item ) | 391 | while ( item ) |
392 | { | 392 | { |
393 | item = item->nextSibling(); | 393 | item = item->nextSibling(); |
394 | items++; | 394 | items++; |
395 | } | 395 | } |
396 | 396 | ||
397 | // store number of items and the items itself | 397 | // store number of items and the items itself |
398 | s << items; | 398 | s << items; |
399 | item = firstChild(); | 399 | item = firstChild(); |
400 | for ( int i = 0; i < items; ++i ) | 400 | for ( int i = 0; i < items; ++i ) |
401 | { | 401 | { |
402 | s << *static_cast<OListViewItem*>( item ); | 402 | s << *static_cast<OListViewItem*>( item ); |
403 | item = item->nextSibling(); | 403 | item = item->nextSibling(); |
404 | } | 404 | } |
405 | 405 | ||
406 | qDebug( "OListviewItem stored." ); | 406 | odebug << "OListviewItem stored." << oendl; |
407 | } | 407 | } |
408 | 408 | ||
409 | 409 | ||
410 | void OListViewItem::serializeFrom( QDataStream& s ) | 410 | void OListViewItem::serializeFrom( QDataStream& s ) |
411 | { | 411 | { |
412 | #warning Caution... the binary format is still under construction... | 412 | #warning Caution... the binary format is still under construction... |
413 | qDebug( "loading OListViewItem..." ); | 413 | odebug << "loading OListViewItem..." << oendl; |
414 | 414 | ||
415 | for ( int i = 0; i < listView()->columns(); ++i ) | 415 | for ( int i = 0; i < listView()->columns(); ++i ) |
416 | { | 416 | { |
417 | QString coltext; | 417 | QString coltext; |
418 | s >> coltext; | 418 | s >> coltext; |
419 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); | 419 | qDebug( "read text '%s' for column %d", (const char*) coltext, i ); |
420 | setText( i, coltext ); | 420 | setText( i, coltext ); |
421 | } | 421 | } |
422 | 422 | ||
423 | int items; | 423 | int items; |
424 | s >> items; | 424 | s >> items; |
425 | qDebug( "read number of items = %d", items ); | 425 | qDebug( "read number of items = %d", items ); |
426 | 426 | ||
427 | for ( int i = 0; i < items; ++i ) | 427 | for ( int i = 0; i < items; ++i ) |
428 | { | 428 | { |
429 | OListViewItem* item = childFactory(); | 429 | OListViewItem* item = childFactory(); |
430 | s >> (*item); | 430 | s >> (*item); |
431 | } | 431 | } |
432 | 432 | ||
433 | qDebug( "OListViewItem loaded." ); | 433 | odebug << "OListViewItem loaded." << oendl; |
434 | } | 434 | } |
435 | 435 | ||
436 | 436 | ||
437 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) | 437 | QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi ) |
438 | { | 438 | { |
439 | lvi.serializeTo( s ); | 439 | lvi.serializeTo( s ); |
440 | } | 440 | } |
441 | 441 | ||
442 | 442 | ||
443 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) | 443 | QDataStream& operator>>( QDataStream& s, OListViewItem& lvi ) |
444 | { | 444 | { |
445 | lvi.serializeFrom( s ); | 445 | lvi.serializeFrom( s ); |
446 | } | 446 | } |
447 | #endif // QT_NO_DATASTREAM | 447 | #endif // QT_NO_DATASTREAM |
448 | 448 | ||
449 | 449 | ||
450 | /*====================================================================================== | 450 | /*====================================================================================== |
451 | * ONamedListView | 451 | * ONamedListView |
452 | *======================================================================================*/ | 452 | *======================================================================================*/ |
453 | 453 | ||
454 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) | 454 | ONamedListView::ONamedListView( QWidget *parent, const char *name ) |
455 | :OListView( parent, name ) | 455 | :OListView( parent, name ) |
456 | { | 456 | { |
457 | } | 457 | } |
458 | 458 | ||
459 | 459 | ||
460 | ONamedListView::~ONamedListView() | 460 | ONamedListView::~ONamedListView() |
461 | { | 461 | { |
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | void ONamedListView::addColumns( const QStringList& columns ) | 465 | void ONamedListView::addColumns( const QStringList& columns ) |
466 | { | 466 | { |
467 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) | 467 | for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it ) |
468 | { | 468 | { |
469 | qDebug( "adding column %s", (const char*) *it ); | 469 | qDebug( "adding column %s", (const char*) *it ); |
470 | addColumn( *it ); | 470 | addColumn( *it ); |
471 | } | 471 | } |
472 | } | 472 | } |
473 | 473 | ||
474 | 474 | ||
475 | int ONamedListView::findColumn( const QString& text ) const | 475 | int ONamedListView::findColumn( const QString& text ) const |
476 | { | 476 | { |
477 | //FIXME: If used excessively, this will slow down performance of updates | 477 | //FIXME: If used excessively, this will slow down performance of updates |
478 | //FIXME: because of the linear search over all column texts. | 478 | //FIXME: because of the linear search over all column texts. |
479 | //FIXME: I will optimize later by using a hash map. | 479 | //FIXME: I will optimize later by using a hash map. |
480 | for ( int i = 0; i < columns(); ++i ) | 480 | for ( int i = 0; i < columns(); ++i ) |
481 | if ( columnText( i ) == text ) | 481 | if ( columnText( i ) == text ) |
482 | return i; | 482 | return i; |
483 | return -1; | 483 | return -1; |
484 | } | 484 | } |
485 | 485 | ||
486 | 486 | ||
487 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const | 487 | ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const |
488 | { | 488 | { |
489 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | 489 | return find( (ONamedListViewItem*) firstChild(), column, text, recurse ); |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const | 493 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const |
494 | { | 494 | { |
495 | ONamedListViewItem* result; | 495 | ONamedListViewItem* result; |
496 | while ( item && item->text( column ) != text ) | 496 | while ( item && item->text( column ) != text ) |
497 | { | 497 | { |
498 | qDebug( "checked %s", (const char*) item->text( column ) ); | 498 | qDebug( "checked %s", (const char*) item->text( column ) ); |
499 | 499 | ||
500 | if ( recurse < 0 || recurse > 0 ) | 500 | if ( recurse < 0 || recurse > 0 ) |
501 | { | 501 | { |
502 | qDebug( "recursion is %d - recursing into...", recurse ); | 502 | qDebug( "recursion is %d - recursing into...", recurse ); |
503 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); | 503 | result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 ); |
504 | if ( result ) return result; | 504 | if ( result ) return result; |
505 | } | 505 | } |
506 | 506 | ||
507 | 507 | ||
508 | item = (ONamedListViewItem*) item->itemBelow(); | 508 | item = (ONamedListViewItem*) item->itemBelow(); |
509 | } | 509 | } |
510 | if ( item && item->text( column ) == text ) | 510 | if ( item && item->text( column ) == text ) |
511 | return item; | 511 | return item; |
512 | else | 512 | else |
513 | return 0; | 513 | return 0; |
514 | } | 514 | } |
515 | 515 | ||
516 | 516 | ||
517 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const | 517 | ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const |
518 | { | 518 | { |
519 | int col = findColumn( column ); | 519 | int col = findColumn( column ); |
520 | if ( col != -1 ) | 520 | if ( col != -1 ) |
521 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | 521 | return find( (ONamedListViewItem*) firstChild(), col, text, recurse ); |
522 | else | 522 | else |
523 | return 0; | 523 | return 0; |
524 | } | 524 | } |
525 | 525 | ||
526 | 526 | ||
527 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const | 527 | ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const |
528 | { | 528 | { |
529 | int col = findColumn( column ); | 529 | int col = findColumn( column ); |
530 | if ( col != -1 ) | 530 | if ( col != -1 ) |
531 | return find( item, col, text, recurse ); | 531 | return find( item, col, text, recurse ); |
532 | else | 532 | else |
533 | return 0; | 533 | return 0; |
534 | } | 534 | } |
535 | 535 | ||
536 | 536 | ||
537 | /*====================================================================================== | 537 | /*====================================================================================== |
538 | * ONamedListViewItem | 538 | * ONamedListViewItem |
539 | *======================================================================================*/ | 539 | *======================================================================================*/ |
540 | 540 | ||
541 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) | 541 | ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts ) |
542 | :OListViewItem( parent ) | 542 | :OListViewItem( parent ) |
543 | { | 543 | { |
544 | setText( texts ); | 544 | setText( texts ); |
545 | } | 545 | } |
546 | 546 | ||
547 | 547 | ||
548 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) | 548 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts ) |
549 | :OListViewItem( parent ) | 549 | :OListViewItem( parent ) |
550 | { | 550 | { |
551 | setText( texts ); | 551 | setText( texts ); |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
555 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) | 555 | ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts ) |
556 | :OListViewItem( parent, after ) | 556 | :OListViewItem( parent, after ) |
557 | { | 557 | { |
558 | setText( texts ); | 558 | setText( texts ); |
559 | } | 559 | } |
560 | 560 | ||
561 | 561 | ||
562 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) | 562 | ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts ) |
563 | :OListViewItem( parent, after ) | 563 | :OListViewItem( parent, after ) |
564 | { | 564 | { |
565 | setText( texts ); | 565 | setText( texts ); |
566 | } | 566 | } |
567 | 567 | ||
568 | 568 | ||
569 | ONamedListViewItem::~ONamedListViewItem() | 569 | ONamedListViewItem::~ONamedListViewItem() |
570 | { | 570 | { |
571 | } | 571 | } |
572 | 572 | ||
573 | 573 | ||
574 | void ONamedListViewItem::setText( const QStringList& texts ) | 574 | void ONamedListViewItem::setText( const QStringList& texts ) |
575 | { | 575 | { |
576 | int col = 0; | 576 | int col = 0; |
577 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) | 577 | for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it ) |
578 | { | 578 | { |
579 | qDebug( "setting column %d = text %s", col, (const char*) *it ); | 579 | qDebug( "setting column %d = text %s", col, (const char*) *it ); |
580 | OListViewItem::setText( col++, *it ); | 580 | OListViewItem::setText( col++, *it ); |
581 | } | 581 | } |
582 | 582 | ||
583 | } | 583 | } |
584 | 584 | ||
585 | 585 | ||
586 | void ONamedListViewItem::setText( const QString& column, const QString& text ) | 586 | void ONamedListViewItem::setText( const QString& column, const QString& text ) |
587 | { | 587 | { |
588 | //FIXME: If used excessively, this will slow down performance of updates | 588 | //FIXME: If used excessively, this will slow down performance of updates |
589 | //FIXME: because of the linear search over all column texts. | 589 | //FIXME: because of the linear search over all column texts. |
590 | //FIXME: I will optimize later by using a hash map. | 590 | //FIXME: I will optimize later by using a hash map. |
591 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | 591 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
592 | if ( col != -1 ) | 592 | if ( col != -1 ) |
593 | OListViewItem::setText( col, text ); | 593 | OListViewItem::setText( col, text ); |
594 | else | 594 | else |
595 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); | 595 | qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column ); |
596 | } | 596 | } |
597 | 597 | ||
598 | 598 | ||
599 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const | 599 | ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const |
600 | { | 600 | { |
601 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); | 601 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse ); |
602 | } | 602 | } |
603 | 603 | ||
604 | 604 | ||
605 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const | 605 | ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const |
606 | { | 606 | { |
607 | int col = ( (ONamedListView*) listView() )->findColumn( column ); | 607 | int col = ( (ONamedListView*) listView() )->findColumn( column ); |
608 | if ( col != -1 ) | 608 | if ( col != -1 ) |
609 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); | 609 | return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse ); |
610 | else | 610 | else |
611 | return 0; | 611 | return 0; |
612 | } | 612 | } |
613 | 613 | ||
diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro index b455602..61f9bbb 100644 --- a/libopie2/opieui/opieui.pro +++ b/libopie2/opieui/opieui.pro | |||
@@ -1,49 +1,47 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on debug | 2 | CONFIG += qt warn_on debug |
3 | DESTDIR = $(OPIEDIR)/lib | 3 | DESTDIR = $(OPIEDIR)/lib |
4 | HEADERS = olistview.h \ | 4 | HEADERS = olistview.h \ |
5 | oimageeffect.h \ | 5 | oimageeffect.h \ |
6 | opixmapeffect.h \ | 6 | opixmapeffect.h \ |
7 | opopupmenu.h \ | 7 | opopupmenu.h \ |
8 | opixmapprovider.h \ | 8 | opixmapprovider.h \ |
9 | oselector.h \ | 9 | oselector.h \ |
10 | oversatileview.h \ | 10 | oversatileview.h \ |
11 | oversatileviewitem.h \ | 11 | oversatileviewitem.h \ |
12 | odialog.h \ | 12 | odialog.h \ |
13 | omessagebox.h \ | 13 | omessagebox.h \ |
14 | oresource.h \ | 14 | oresource.h \ |
15 | oseparator.h | 15 | otaskbarapplet.h \ |
16 | oseparator.h | ||
16 | 17 | ||
17 | SOURCES = olistview.cpp \ | 18 | SOURCES = olistview.cpp \ |
18 | oimageeffect.cpp \ | 19 | oimageeffect.cpp \ |
19 | opixmapeffect.cpp \ | 20 | opixmapeffect.cpp \ |
20 | opopupmenu.cpp \ | 21 | opopupmenu.cpp \ |
21 | opixmapprovider.cpp \ | 22 | opixmapprovider.cpp \ |
22 | oselector.cpp \ | 23 | oselector.cpp \ |
23 | oversatileview.cpp \ | 24 | oversatileview.cpp \ |
24 | oversatileviewitem.cpp \ | 25 | oversatileviewitem.cpp \ |
25 | odialog.cpp \ | 26 | odialog.cpp \ |
26 | oresource.cpp \ | 27 | oresource.cpp \ |
27 | oseparator.cpp | 28 | otaskbarapplet.cpp \ |
29 | oseparator.cpp | ||
28 | 30 | ||
29 | INTERFACES = | 31 | INTERFACES = |
30 | TARGET = opieui2 | 32 | TARGET = opieui2 |
31 | VERSION = 1.8.2 | 33 | VERSION = 1.8.2 |
34 | |||
32 | INCLUDEPATH += $(OPIEDIR)/include | 35 | INCLUDEPATH += $(OPIEDIR)/include |
33 | DEPENDPATH += $(OPIEDIR)/include | 36 | DEPENDPATH += $(OPIEDIR)/include |
34 | LIBS += -lopiecore2 | ||
35 | MOC_DIR = moc | ||
36 | OBJECTS_DIR = obj | ||
37 | 37 | ||
38 | LIBS += -lopiecore2 | ||
38 | 39 | ||
39 | !contains( platform, x11 ) { | 40 | !contains( platform, x11 ) { |
40 | include ( $(OPIEDIR)/include.pro ) | 41 | include ( $(OPIEDIR)/include.pro ) |
41 | HEADERS += otaskbarapplet.h | ||
42 | SOURCES += otaskbarapplet.cpp | ||
43 | } | 42 | } |
44 | 43 | ||
45 | contains( platform, x11 ) { | 44 | contains( platform, x11 ) { |
46 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib | 45 | LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib |
47 | message( Warning: NO otaskbarapplet ATM ) | ||
48 | } | 46 | } |
49 | 47 | ||
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp index 85181dc..98d42c7 100644 --- a/libopie2/opieui/oseparator.cpp +++ b/libopie2/opieui/oseparator.cpp | |||
@@ -1,128 +1,128 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | |||
4 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 3 | Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> | 4 | Copyright (C) 1997 Michael Roth <mroth@wirlweb.de> |
6 | =. | 5 | =. |
7 | .=l. | 6 | .=l. |
8 | .>+-= | 7 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 14 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 22 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
30 | 29 | ||
31 | */ | 30 | */ |
32 | 31 | ||
33 | /* QT */ | ||
34 | |||
35 | #include <qstyle.h> | ||
36 | |||
37 | /* OPIE */ | 32 | /* OPIE */ |
38 | 33 | ||
34 | #include <opie2/odebug.h> | ||
39 | #include <opie2/oseparator.h> | 35 | #include <opie2/oseparator.h> |
40 | 36 | ||
37 | /* QT */ | ||
38 | |||
39 | #include <qstyle.h> | ||
40 | |||
41 | OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) | 41 | OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f) |
42 | : QFrame(parent, name, f) | 42 | : QFrame(parent, name, f) |
43 | { | 43 | { |
44 | setLineWidth(1); | 44 | setLineWidth(1); |
45 | setMidLineWidth(0); | 45 | setMidLineWidth(0); |
46 | setOrientation( HLine ); | 46 | setOrientation( HLine ); |
47 | } | 47 | } |
48 | 48 | ||
49 | 49 | ||
50 | 50 | ||
51 | OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) | 51 | OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f) |
52 | : QFrame(parent, name, f) | 52 | : QFrame(parent, name, f) |
53 | { | 53 | { |
54 | setLineWidth(1); | 54 | setLineWidth(1); |
55 | setMidLineWidth(0); | 55 | setMidLineWidth(0); |
56 | setOrientation( orientation ); | 56 | setOrientation( orientation ); |
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | void OSeparator::setOrientation(int orientation) | 61 | void OSeparator::setOrientation(int orientation) |
62 | { | 62 | { |
63 | switch(orientation) | 63 | switch(orientation) |
64 | { | 64 | { |
65 | case Vertical: | 65 | case Vertical: |
66 | case VLine: | 66 | case VLine: |
67 | setFrameStyle( QFrame::VLine | QFrame::Sunken ); | 67 | setFrameStyle( QFrame::VLine | QFrame::Sunken ); |
68 | setMinimumSize(2, 0); | 68 | setMinimumSize(2, 0); |
69 | break; | 69 | break; |
70 | 70 | ||
71 | default: | 71 | default: |
72 | qWarning( "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" ); | 72 | owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl; |
73 | 73 | ||
74 | case Horizontal: | 74 | case Horizontal: |
75 | case HLine: | 75 | case HLine: |
76 | setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 76 | setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
77 | setMinimumSize(0, 2); | 77 | setMinimumSize(0, 2); |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | int OSeparator::orientation() const | 84 | int OSeparator::orientation() const |
85 | { | 85 | { |
86 | if ( frameStyle() & VLine ) | 86 | if ( frameStyle() & VLine ) |
87 | return VLine; | 87 | return VLine; |
88 | 88 | ||
89 | if ( frameStyle() & HLine ) | 89 | if ( frameStyle() & HLine ) |
90 | return HLine; | 90 | return HLine; |
91 | 91 | ||
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||
95 | void OSeparator::drawFrame(QPainter *p) | 95 | void OSeparator::drawFrame(QPainter *p) |
96 | { | 96 | { |
97 | QPointp1, p2; | 97 | QPointp1, p2; |
98 | QRectr = frameRect(); | 98 | QRectr = frameRect(); |
99 | const QColorGroup & g = colorGroup(); | 99 | const QColorGroup & g = colorGroup(); |
100 | 100 | ||
101 | if ( frameStyle() & HLine ) { | 101 | if ( frameStyle() & HLine ) { |
102 | p1 = QPoint( r.x(), r.height()/2 ); | 102 | p1 = QPoint( r.x(), r.height()/2 ); |
103 | p2 = QPoint( r.x()+r.width(), p1.y() ); | 103 | p2 = QPoint( r.x()+r.width(), p1.y() ); |
104 | } | 104 | } |
105 | else { | 105 | else { |
106 | p1 = QPoint( r.x()+r.width()/2, 0 ); | 106 | p1 = QPoint( r.x()+r.width()/2, 0 ); |
107 | p2 = QPoint( p1.x(), r.height() ); | 107 | p2 = QPoint( p1.x(), r.height() ); |
108 | } | 108 | } |
109 | 109 | ||
110 | #if QT_VERSION < 300 | 110 | #if QT_VERSION < 300 |
111 | style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); | 111 | style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() ); |
112 | #else | 112 | #else |
113 | QStyleOption opt( lineWidth(), midLineWidth() ); | 113 | QStyleOption opt( lineWidth(), midLineWidth() ); |
114 | style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); | 114 | style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt ); |
115 | #endif | 115 | #endif |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | QSize OSeparator::sizeHint() const | 119 | QSize OSeparator::sizeHint() const |
120 | { | 120 | { |
121 | if ( frameStyle() & VLine ) | 121 | if ( frameStyle() & VLine ) |
122 | return QSize(2, 0); | 122 | return QSize(2, 0); |
123 | 123 | ||
124 | if ( frameStyle() & HLine ) | 124 | if ( frameStyle() & HLine ) |
125 | return QSize(0, 2); | 125 | return QSize(0, 2); |
126 | 126 | ||
127 | return QSize(-1, -1); | 127 | return QSize(-1, -1); |
128 | } | 128 | } |
diff --git a/libopie2/opieui/oversatileview.cpp b/libopie2/opieui/oversatileview.cpp index 6808539..65fe3d8 100644 --- a/libopie2/opieui/oversatileview.cpp +++ b/libopie2/opieui/oversatileview.cpp | |||
@@ -1,1179 +1,1180 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 4 | =. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | ||
32 | |||
33 | #include <opie2/odebug.h> | ||
34 | #include <opie2/oversatileview.h> | ||
35 | #include <opie2/oversatileviewitem.h> | ||
36 | #include <opie2/olistview.h> | ||
37 | |||
31 | /* QT */ | 38 | /* QT */ |
32 | 39 | ||
33 | #include <qaction.h> | 40 | #include <qaction.h> |
34 | #include <qbrush.h> | 41 | #include <qbrush.h> |
35 | #include <qfont.h> | 42 | #include <qfont.h> |
36 | #include <qiconset.h> | 43 | #include <qiconset.h> |
37 | #include <qiconview.h> | 44 | #include <qiconview.h> |
38 | #include <qlistview.h> | 45 | #include <qlistview.h> |
39 | #include <qpalette.h> | 46 | #include <qpalette.h> |
40 | #include <qpoint.h> | 47 | #include <qpoint.h> |
41 | #include <qpopupmenu.h> | 48 | #include <qpopupmenu.h> |
42 | #include <qrect.h> | 49 | #include <qrect.h> |
43 | #include <qsize.h> | 50 | #include <qsize.h> |
44 | #include <qstring.h> | 51 | #include <qstring.h> |
45 | #include <qwidgetstack.h> | 52 | #include <qwidgetstack.h> |
46 | 53 | ||
47 | /* OPIE */ | ||
48 | |||
49 | #include <opie2/oversatileview.h> | ||
50 | #include <opie2/oversatileviewitem.h> | ||
51 | #include <opie2/olistview.h> | ||
52 | |||
53 | /* XPM */ | 54 | /* XPM */ |
54 | static const char * view_icon_xpm[] = { | 55 | static const char * view_icon_xpm[] = { |
55 | "16 16 16 1", | 56 | "16 16 16 1", |
56 | " c None", | 57 | " c None", |
57 | ".c #87BD88", | 58 | ".c #87BD88", |
58 | "+c #8BBE8B", | 59 | "+c #8BBE8B", |
59 | "@c #81BA81", | 60 | "@c #81BA81", |
60 | "#c #6DAF6D", | 61 | "#c #6DAF6D", |
61 | "$c #87BD87", | 62 | "$c #87BD87", |
62 | "%c #FCFDFC", | 63 | "%c #FCFDFC", |
63 | "&c #AED0AE", | 64 | "&c #AED0AE", |
64 | "*c #4E9C4C", | 65 | "*c #4E9C4C", |
65 | "=c #91BD91", | 66 | "=c #91BD91", |
66 | "-c #72B172", | 67 | "-c #72B172", |
67 | ";c #448643", | 68 | ";c #448643", |
68 | ">c #519F50", | 69 | ">c #519F50", |
69 | ",c #499247", | 70 | ",c #499247", |
70 | "'c #356A35", | 71 | "'c #356A35", |
71 | ")c #686868", | 72 | ")c #686868", |
72 | " ", | 73 | " ", |
73 | " .+@# .+@# ", | 74 | " .+@# .+@# ", |
74 | " $%&* $%&* ", | 75 | " $%&* $%&* ", |
75 | " @=-; @=-; ", | 76 | " @=-; @=-; ", |
76 | " #>,' #>,' ", | 77 | " #>,' #>,' ", |
77 | " ", | 78 | " ", |
78 | " )))))) )))))) ", | 79 | " )))))) )))))) ", |
79 | " ", | 80 | " ", |
80 | " ", | 81 | " ", |
81 | " .+@# .+@# ", | 82 | " .+@# .+@# ", |
82 | " $%&* $%&* ", | 83 | " $%&* $%&* ", |
83 | " @=-; @=-; ", | 84 | " @=-; @=-; ", |
84 | " #>,' #>,' ", | 85 | " #>,' #>,' ", |
85 | " ", | 86 | " ", |
86 | " )))))) )))))) ", | 87 | " )))))) )))))) ", |
87 | " "}; | 88 | " "}; |
88 | 89 | ||
89 | /* XPM */ | 90 | /* XPM */ |
90 | static const char * view_tree_xpm[] = { | 91 | static const char * view_tree_xpm[] = { |
91 | "16 16 17 1", | 92 | "16 16 17 1", |
92 | " c None", | 93 | " c None", |
93 | ".c #3A3A3A", | 94 | ".c #3A3A3A", |
94 | "+c #87BD88", | 95 | "+c #87BD88", |
95 | "@c #8BBE8B", | 96 | "@c #8BBE8B", |
96 | "#c #81BA81", | 97 | "#c #81BA81", |
97 | "$c #6DAF6D", | 98 | "$c #6DAF6D", |
98 | "%c #87BD87", | 99 | "%c #87BD87", |
99 | "&c #FCFDFC", | 100 | "&c #FCFDFC", |
100 | "*c #AED0AE", | 101 | "*c #AED0AE", |
101 | "=c #4E9C4C", | 102 | "=c #4E9C4C", |
102 | "-c #91BD91", | 103 | "-c #91BD91", |
103 | ";c #72B172", | 104 | ";c #72B172", |
104 | ">c #448643", | 105 | ">c #448643", |
105 | ",c #686868", | 106 | ",c #686868", |
106 | "'c #519F50", | 107 | "'c #519F50", |
107 | ")c #499247", | 108 | ")c #499247", |
108 | "!c #356A35", | 109 | "!c #356A35", |
109 | " . ", | 110 | " . ", |
110 | " . ", | 111 | " . ", |
111 | " . +@#$ ", | 112 | " . +@#$ ", |
112 | " . %&*= ", | 113 | " . %&*= ", |
113 | " .. #-;> ,, ,,,", | 114 | " .. #-;> ,, ,,,", |
114 | " . $')! ", | 115 | " . $')! ", |
115 | " . ", | 116 | " . ", |
116 | " . ", | 117 | " . ", |
117 | " . ", | 118 | " . ", |
118 | " . +@#$ ", | 119 | " . +@#$ ", |
119 | " . %&*= ", | 120 | " . %&*= ", |
120 | " .. #-;> ,, ,,,", | 121 | " .. #-;> ,, ,,,", |
121 | " $')! ", | 122 | " $')! ", |
122 | " ", | 123 | " ", |
123 | " ", | 124 | " ", |
124 | " "}; | 125 | " "}; |
125 | 126 | ||
126 | OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode ) | 127 | OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode ) |
127 | :QWidgetStack( parent, name ), | 128 | :QWidgetStack( parent, name ), |
128 | _viewmode( mode ), _warningpolicy( None ), | 129 | _viewmode( mode ), _warningpolicy( None ), |
129 | _treeleaf(), _treeopened(), _treeclosed(), | 130 | _treeleaf(), _treeopened(), _treeclosed(), |
130 | _iconleaf(), _iconopened(), _iconclosed() | 131 | _iconleaf(), _iconopened(), _iconclosed() |
131 | { | 132 | { |
132 | // | 133 | // |
133 | // Create child widgets and set some reasonable default styles | 134 | // Create child widgets and set some reasonable default styles |
134 | // | 135 | // |
135 | 136 | ||
136 | _listview = new OListView( this, "oversatileview embedded listview" ); | 137 | _listview = new OListView( this, "oversatileview embedded listview" ); |
137 | _iconview = new QIconView( this, "oversatileview embedded iconview" ); | 138 | _iconview = new QIconView( this, "oversatileview embedded iconview" ); |
138 | 139 | ||
139 | _listview->setAllColumnsShowFocus( true ); | 140 | _listview->setAllColumnsShowFocus( true ); |
140 | _listview->setRootIsDecorated( true ); | 141 | _listview->setRootIsDecorated( true ); |
141 | _listview->setShowSortIndicator( true ); | 142 | _listview->setShowSortIndicator( true ); |
142 | _iconview->setGridX( 90 ); | 143 | _iconview->setGridX( 90 ); |
143 | _iconview->setGridY( 42 ); | 144 | _iconview->setGridY( 42 ); |
144 | _iconview->setAutoArrange( true ); | 145 | _iconview->setAutoArrange( true ); |
145 | 146 | ||
146 | #ifdef QWS // TODO: Let this depend on current geometry (rotation) | 147 | #ifdef QWS // TODO: Let this depend on current geometry (rotation) |
147 | _iconview->setArrangement( QIconView::TopToBottom ); | 148 | _iconview->setArrangement( QIconView::TopToBottom ); |
148 | #else | 149 | #else |
149 | _iconview->setArrangement( QIconView::LeftToRight ); | 150 | _iconview->setArrangement( QIconView::LeftToRight ); |
150 | #endif | 151 | #endif |
151 | 152 | ||
152 | _iconview->setResizeMode( QIconView::Adjust ); | 153 | _iconview->setResizeMode( QIconView::Adjust ); |
153 | 154 | ||
154 | // qt-embedded: map stylus right on hold to right button press | 155 | // qt-embedded: map stylus right on hold to right button press |
155 | 156 | ||
156 | #ifdef QWS | 157 | #ifdef QWS |
157 | ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold ); | 158 | ( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold ); |
158 | ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold ); | 159 | ( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold ); |
159 | #endif | 160 | #endif |
160 | 161 | ||
161 | setViewMode( mode ); // TODO: Read last style from config | 162 | setViewMode( mode ); // TODO: Read last style from config |
162 | // setSynchronization( true ); // TODO: Implement this | 163 | // setSynchronization( true ); // TODO: Implement this |
163 | 164 | ||
164 | // create context menu allowing to switch between the views | 165 | // create context menu allowing to switch between the views |
165 | 166 | ||
166 | _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" ); | 167 | _contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" ); |
167 | _contextmenu->setCaption( "Style" ); | 168 | _contextmenu->setCaption( "Style" ); |
168 | _contextmenu->setCheckable( true ); | 169 | _contextmenu->setCheckable( true ); |
169 | QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" ); | 170 | QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" ); |
170 | QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ), | 171 | QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ), |
171 | "View Icons", 0, ag, "viewicon action", true ); | 172 | "View Icons", 0, ag, "viewicon action", true ); |
172 | QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ), | 173 | QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ), |
173 | "View Tree", 0, ag, "viewtree action", true ); | 174 | "View Tree", 0, ag, "viewtree action", true ); |
174 | ag->addTo( _contextmenu ); | 175 | ag->addTo( _contextmenu ); |
175 | if ( mode == Icons ) | 176 | if ( mode == Icons ) |
176 | a1->setOn( true ); | 177 | a1->setOn( true ); |
177 | else if ( mode == Tree ) | 178 | else if ( mode == Tree ) |
178 | a2->setOn( true ); | 179 | a2->setOn( true ); |
179 | connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) ); | 180 | connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) ); |
180 | connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) ); | 181 | connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) ); |
181 | 182 | ||
182 | #if (QT_VERSION >= 0x030000) | 183 | #if (QT_VERSION >= 0x030000) |
183 | connect( _listview, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); | 184 | connect( _listview, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); |
184 | connect( _iconview, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); | 185 | connect( _iconview, SIGNAL( contextMenuRequested( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); |
185 | #else | 186 | #else |
186 | connect( _listview, SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); | 187 | connect( _listview, SIGNAL( rightButtonPressed( QListViewItem*, const QPoint&, int ) ), this, SLOT( contextMenuRequested( QListViewItem*, const QPoint&, int ) ) ); |
187 | connect( _iconview, SIGNAL( rightButtonPressed( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); | 188 | connect( _iconview, SIGNAL( rightButtonPressed( QIconViewItem*, const QPoint& ) ), this, SLOT( contextMenuRequested( QIconViewItem*, const QPoint& ) ) ); |
188 | #endif | 189 | #endif |
189 | 190 | ||
190 | // | 191 | // |
191 | // signal forwarders | 192 | // signal forwarders |
192 | // | 193 | // |
193 | // unfortunately we can't short-circuit all the QListView and QIconView signals | 194 | // unfortunately we can't short-circuit all the QListView and QIconView signals |
194 | // to OVersatileView signals, because the signal/slot mechanism doesn't allow | 195 | // to OVersatileView signals, because the signal/slot mechanism doesn't allow |
195 | // type-conversion :-( | 196 | // type-conversion :-( |
196 | 197 | ||
197 | // common signals for listview | 198 | // common signals for listview |
198 | 199 | ||
199 | connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); | 200 | connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); |
200 | connect( _listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( selectionChanged( QListViewItem * ) ) ); | 201 | connect( _listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, SLOT( selectionChanged( QListViewItem * ) ) ); |
201 | connect( _listview, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( currentChanged( QListViewItem * ) ) ); | 202 | connect( _listview, SIGNAL( currentChanged( QListViewItem * ) ), this, SLOT( currentChanged( QListViewItem * ) ) ); |
202 | connect( _listview, SIGNAL( clicked( QListViewItem * ) ), this, SLOT( clicked( QListViewItem * ) ) ); | 203 | connect( _listview, SIGNAL( clicked( QListViewItem * ) ), this, SLOT( clicked( QListViewItem * ) ) ); |
203 | connect( _listview, SIGNAL( pressed( QListViewItem * ) ), this, SLOT( pressed( QListViewItem * ) ) ); | 204 | connect( _listview, SIGNAL( pressed( QListViewItem * ) ), this, SLOT( pressed( QListViewItem * ) ) ); |
204 | 205 | ||
205 | connect( _listview, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( doubleClicked( QListViewItem * ) ) ); | 206 | connect( _listview, SIGNAL( doubleClicked( QListViewItem * ) ), this, SLOT( doubleClicked( QListViewItem * ) ) ); |
206 | connect( _listview, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( returnPressed( QListViewItem * ) ) ); | 207 | connect( _listview, SIGNAL( returnPressed( QListViewItem * ) ), this, SLOT( returnPressed( QListViewItem * ) ) ); |
207 | 208 | ||
208 | connect( _listview, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( onItem( QListViewItem * ) ) ); | 209 | connect( _listview, SIGNAL( onItem( QListViewItem * ) ), this, SLOT( onItem( QListViewItem * ) ) ); |
209 | connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); | 210 | connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); |
210 | 211 | ||
211 | // common signals for iconview | 212 | // common signals for iconview |
212 | 213 | ||
213 | connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); | 214 | connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); |
214 | connect( _iconview, SIGNAL( selectionChanged( QIconViewItem * ) ), this, SLOT( selectionChanged( QIconViewItem * ) ) ); | 215 | connect( _iconview, SIGNAL( selectionChanged( QIconViewItem * ) ), this, SLOT( selectionChanged( QIconViewItem * ) ) ); |
215 | connect( _iconview, SIGNAL( currentChanged( QIconViewItem * ) ), this, SLOT( currentChanged( QIconViewItem * ) ) ); | 216 | connect( _iconview, SIGNAL( currentChanged( QIconViewItem * ) ), this, SLOT( currentChanged( QIconViewItem * ) ) ); |
216 | connect( _iconview, SIGNAL( clicked( QIconViewItem * ) ), this, SLOT( clicked( QIconViewItem * ) ) ); | 217 | connect( _iconview, SIGNAL( clicked( QIconViewItem * ) ), this, SLOT( clicked( QIconViewItem * ) ) ); |
217 | connect( _iconview, SIGNAL( pressed( QIconViewItem * ) ), this, SLOT( pressed( QIconViewItem * ) ) ); | 218 | connect( _iconview, SIGNAL( pressed( QIconViewItem * ) ), this, SLOT( pressed( QIconViewItem * ) ) ); |
218 | 219 | ||
219 | connect( _iconview, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( doubleClicked( QIconViewItem * ) ) ); | 220 | connect( _iconview, SIGNAL( doubleClicked( QIconViewItem * ) ), this, SLOT( doubleClicked( QIconViewItem * ) ) ); |
220 | connect( _iconview, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( returnPressed( QIconViewItem * ) ) ); | 221 | connect( _iconview, SIGNAL( returnPressed( QIconViewItem * ) ), this, SLOT( returnPressed( QIconViewItem * ) ) ); |
221 | 222 | ||
222 | connect( _iconview, SIGNAL( onItem( QIconViewItem * ) ), this, SLOT( onItem( QIconViewItem * ) ) ); | 223 | connect( _iconview, SIGNAL( onItem( QIconViewItem * ) ), this, SLOT( onItem( QIconViewItem * ) ) ); |
223 | connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); | 224 | connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) ); |
224 | 225 | ||
225 | // listview only signals | 226 | // listview only signals |
226 | 227 | ||
227 | connect( _listview, SIGNAL( expanded( QListViewItem * ) ), this, SLOT( expanded( QListViewItem * ) ) ); | 228 | connect( _listview, SIGNAL( expanded( QListViewItem * ) ), this, SLOT( expanded( QListViewItem * ) ) ); |
228 | connect( _listview, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( collapsed( QListViewItem * ) ) ); | 229 | connect( _listview, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( collapsed( QListViewItem * ) ) ); |
229 | 230 | ||
230 | // iconview only signals | 231 | // iconview only signals |
231 | 232 | ||
232 | connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) ); | 233 | connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) ); |
233 | } | 234 | } |
234 | 235 | ||
235 | OVersatileView::~OVersatileView() | 236 | OVersatileView::~OVersatileView() |
236 | { | 237 | { |
237 | } | 238 | } |
238 | 239 | ||
239 | QPopupMenu* OVersatileView::contextMenu() const | 240 | QPopupMenu* OVersatileView::contextMenu() const |
240 | { | 241 | { |
241 | return _contextmenu; | 242 | return _contextmenu; |
242 | } | 243 | } |
243 | 244 | ||
244 | void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col ) | 245 | void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col ) |
245 | { | 246 | { |
246 | // can't use QObject::inherits here, because ListViewItems, beit Q, O or K, | 247 | // can't use QObject::inherits here, because ListViewItems, beit Q, O or K, |
247 | // do not inherit from QObject - assuming here the programmer is | 248 | // do not inherit from QObject - assuming here the programmer is |
248 | // disciplined enough to only add OVersatileViewItems to an OVersatileView | 249 | // disciplined enough to only add OVersatileViewItems to an OVersatileView |
249 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col ); | 250 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col ); |
250 | } | 251 | } |
251 | 252 | ||
252 | void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos ) | 253 | void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos ) |
253 | { | 254 | { |
254 | // see above | 255 | // see above |
255 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 ); | 256 | popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 ); |
256 | } | 257 | } |
257 | 258 | ||
258 | void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col ) | 259 | void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col ) |
259 | { | 260 | { |
260 | if ( !item ) | 261 | if ( !item ) |
261 | _contextmenu->exec( pos ); | 262 | _contextmenu->exec( pos ); |
262 | else | 263 | else |
263 | emit( contextMenuRequested( item, pos, col ) ); | 264 | emit( contextMenuRequested( item, pos, col ) ); |
264 | } | 265 | } |
265 | 266 | ||
266 | void OVersatileView::setSynchronization( bool sync ) | 267 | void OVersatileView::setSynchronization( bool sync ) |
267 | { | 268 | { |
268 | _synchronization = sync; | 269 | _synchronization = sync; |
269 | } | 270 | } |
270 | 271 | ||
271 | bool OVersatileView::synchronization() | 272 | bool OVersatileView::synchronization() |
272 | { | 273 | { |
273 | return _synchronization; | 274 | return _synchronization; |
274 | } | 275 | } |
275 | 276 | ||
276 | void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ) | 277 | void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed ) |
277 | { | 278 | { |
278 | if ( mode == Tree ) | 279 | if ( mode == Tree ) |
279 | { | 280 | { |
280 | _treeleaf = leaf; | 281 | _treeleaf = leaf; |
281 | _treeopened = opened; | 282 | _treeopened = opened; |
282 | _treeclosed = closed; | 283 | _treeclosed = closed; |
283 | } | 284 | } |
284 | else if ( mode == Icons ) | 285 | else if ( mode == Icons ) |
285 | { | 286 | { |
286 | _iconleaf = leaf; | 287 | _iconleaf = leaf; |
287 | _iconopened = opened; | 288 | _iconopened = opened; |
288 | _iconclosed = closed; | 289 | _iconclosed = closed; |
289 | } | 290 | } |
290 | else | 291 | else |
291 | { | 292 | { |
292 | qDebug( "OVersatileView::setDefaultPixmaps(): invalid mode" ); | 293 | odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl; |
293 | } | 294 | } |
294 | } | 295 | } |
295 | 296 | ||
296 | QIconView* OVersatileView::iconView() const | 297 | QIconView* OVersatileView::iconView() const |
297 | { | 298 | { |
298 | return _iconview; | 299 | return _iconview; |
299 | } | 300 | } |
300 | 301 | ||
301 | OListView* OVersatileView::listView() const | 302 | OListView* OVersatileView::listView() const |
302 | { | 303 | { |
303 | return _listview; | 304 | return _listview; |
304 | } | 305 | } |
305 | 306 | ||
306 | void OVersatileView::setViewMode( int mode ) | 307 | void OVersatileView::setViewMode( int mode ) |
307 | { | 308 | { |
308 | if ( mode == Tree ) | 309 | if ( mode == Tree ) |
309 | { | 310 | { |
310 | _viewmode = mode; | 311 | _viewmode = mode; |
311 | raiseWidget( _listview ); | 312 | raiseWidget( _listview ); |
312 | } | 313 | } |
313 | else if ( mode == Icons ) | 314 | else if ( mode == Icons ) |
314 | { | 315 | { |
315 | _viewmode = mode; | 316 | _viewmode = mode; |
316 | raiseWidget( _iconview ); | 317 | raiseWidget( _iconview ); |
317 | } | 318 | } |
318 | else | 319 | else |
319 | { | 320 | { |
320 | qDebug( "OVersatileView::setViewMode(): invalid mode" ); | 321 | odebug << "OVersatileView::setViewMode(): invalid mode" << oendl; |
321 | } | 322 | } |
322 | } | 323 | } |
323 | 324 | ||
324 | void OVersatileView::setIconViewMode() | 325 | void OVersatileView::setIconViewMode() |
325 | { | 326 | { |
326 | setViewMode( Icons ); | 327 | setViewMode( Icons ); |
327 | } | 328 | } |
328 | 329 | ||
329 | void OVersatileView::setTreeViewMode() | 330 | void OVersatileView::setTreeViewMode() |
330 | { | 331 | { |
331 | setViewMode( Tree ); | 332 | setViewMode( Tree ); |
332 | } | 333 | } |
333 | 334 | ||
334 | bool OVersatileView::isValidViewMode( int mode ) const | 335 | bool OVersatileView::isValidViewMode( int mode ) const |
335 | { | 336 | { |
336 | switch ( _warningpolicy ) | 337 | switch ( _warningpolicy ) |
337 | { | 338 | { |
338 | case OVersatileView::None: | 339 | case OVersatileView::None: |
339 | { | 340 | { |
340 | return true; | 341 | return true; |
341 | } | 342 | } |
342 | case OVersatileView::Warn: | 343 | case OVersatileView::Warn: |
343 | { | 344 | { |
344 | if ( _viewmode != mode ) | 345 | if ( _viewmode != mode ) |
345 | { | 346 | { |
346 | qDebug( "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." ); | 347 | odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; |
347 | return true; | 348 | return true; |
348 | } | 349 | } |
349 | } | 350 | } |
350 | case OVersatileView::WarnReturn: | 351 | case OVersatileView::WarnReturn: |
351 | { | 352 | { |
352 | if ( _viewmode != mode ) | 353 | if ( _viewmode != mode ) |
353 | { | 354 | { |
354 | qDebug( "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." ); | 355 | odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl; |
355 | return false; | 356 | return false; |
356 | } | 357 | } |
357 | } | 358 | } |
358 | default: | 359 | default: |
359 | { | 360 | { |
360 | qWarning( "OVersatileView::isValidViewMode(): Inconsistent object state!" ); | 361 | owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl; |
361 | return true; | 362 | return true; |
362 | } | 363 | } |
363 | } | 364 | } |
364 | } | 365 | } |
365 | void OVersatileView::setWarningPolicy( int policy ) const | 366 | void OVersatileView::setWarningPolicy( int policy ) const |
366 | { | 367 | { |
367 | _warningpolicy = policy; | 368 | _warningpolicy = policy; |
368 | } | 369 | } |
369 | bool OVersatileView::warningPolicy() const | 370 | bool OVersatileView::warningPolicy() const |
370 | { | 371 | { |
371 | return _warningpolicy; | 372 | return _warningpolicy; |
372 | } | 373 | } |
373 | //==============================================================================================// | 374 | //==============================================================================================// |
374 | // Stupid Signal forwarders... | 375 | // Stupid Signal forwarders... |
375 | // Folks, this is why I like python with its dynamic typing: | 376 | // Folks, this is why I like python with its dynamic typing: |
376 | // I can code the following dozens of lines C++ in four Python lines... | 377 | // I can code the following dozens of lines C++ in four Python lines... |
377 | //==============================================================================================// | 378 | //==============================================================================================// |
378 | 379 | ||
379 | void OVersatileView::selectionChanged( QListViewItem * item ) | 380 | void OVersatileView::selectionChanged( QListViewItem * item ) |
380 | { | 381 | { |
381 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 382 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
382 | } | 383 | } |
383 | 384 | ||
384 | void OVersatileView::selectionChanged( QIconViewItem * item ) | 385 | void OVersatileView::selectionChanged( QIconViewItem * item ) |
385 | { | 386 | { |
386 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 387 | emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
387 | } | 388 | } |
388 | 389 | ||
389 | void OVersatileView::currentChanged( QListViewItem * item ) | 390 | void OVersatileView::currentChanged( QListViewItem * item ) |
390 | { | 391 | { |
391 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 392 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
392 | } | 393 | } |
393 | 394 | ||
394 | void OVersatileView::currentChanged( QIconViewItem * item ) | 395 | void OVersatileView::currentChanged( QIconViewItem * item ) |
395 | { | 396 | { |
396 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); | 397 | emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) ); |
397 | } | 398 | } |
398 | 399 | ||
399 | void OVersatileView::clicked( QListViewItem * item ) | 400 | void OVersatileView::clicked( QListViewItem * item ) |
400 | { | 401 | { |
401 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); | 402 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); |
402 | } | 403 | } |
403 | 404 | ||
404 | void OVersatileView::clicked( QIconViewItem * item ) | 405 | void OVersatileView::clicked( QIconViewItem * item ) |
405 | { | 406 | { |
406 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); | 407 | emit( clicked( static_cast<OVersatileViewItem*>( item ) ) ); |
407 | } | 408 | } |
408 | 409 | ||
409 | void OVersatileView::pressed( QListViewItem * item ) | 410 | void OVersatileView::pressed( QListViewItem * item ) |
410 | { | 411 | { |
411 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); | 412 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); |
412 | } | 413 | } |
413 | 414 | ||
414 | void OVersatileView::pressed( QIconViewItem * item ) | 415 | void OVersatileView::pressed( QIconViewItem * item ) |
415 | { | 416 | { |
416 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); | 417 | emit( pressed( static_cast<OVersatileViewItem*>( item ) ) ); |
417 | } | 418 | } |
418 | 419 | ||
419 | void OVersatileView::doubleClicked( QListViewItem * item ) | 420 | void OVersatileView::doubleClicked( QListViewItem * item ) |
420 | { | 421 | { |
421 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); | 422 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); |
422 | } | 423 | } |
423 | 424 | ||
424 | void OVersatileView::doubleClicked( QIconViewItem * item ) | 425 | void OVersatileView::doubleClicked( QIconViewItem * item ) |
425 | { | 426 | { |
426 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); | 427 | emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) ); |
427 | } | 428 | } |
428 | 429 | ||
429 | void OVersatileView::returnPressed( QListViewItem * item ) | 430 | void OVersatileView::returnPressed( QListViewItem * item ) |
430 | { | 431 | { |
431 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); | 432 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); |
432 | } | 433 | } |
433 | 434 | ||
434 | void OVersatileView::returnPressed( QIconViewItem * item ) | 435 | void OVersatileView::returnPressed( QIconViewItem * item ) |
435 | { | 436 | { |
436 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); | 437 | emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) ); |
437 | } | 438 | } |
438 | 439 | ||
439 | void OVersatileView::onItem( QListViewItem * item ) | 440 | void OVersatileView::onItem( QListViewItem * item ) |
440 | { | 441 | { |
441 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); | 442 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); |
442 | } | 443 | } |
443 | 444 | ||
444 | void OVersatileView::onItem( QIconViewItem * item ) | 445 | void OVersatileView::onItem( QIconViewItem * item ) |
445 | { | 446 | { |
446 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); | 447 | emit( onItem( static_cast<OVersatileViewItem*>( item ) ) ); |
447 | } | 448 | } |
448 | 449 | ||
449 | void OVersatileView::expanded( QListViewItem *item ) // QListView | 450 | void OVersatileView::expanded( QListViewItem *item ) // QListView |
450 | { | 451 | { |
451 | //qDebug( "OVersatileView::expanded(): opening tree..." ); | 452 | //odebug << "OVersatileView::expanded(): opening tree..." << oendl; |
452 | if ( !_treeopened.isNull() ) | 453 | if ( !_treeopened.isNull() ) |
453 | item->setPixmap( 0, _treeopened ); | 454 | item->setPixmap( 0, _treeopened ); |
454 | emit( expanded( static_cast<OVersatileViewItem*>( item ) ) ); | 455 | emit( expanded( static_cast<OVersatileViewItem*>( item ) ) ); |
455 | } | 456 | } |
456 | void OVersatileView::collapsed( QListViewItem *item ) // QListView | 457 | void OVersatileView::collapsed( QListViewItem *item ) // QListView |
457 | { | 458 | { |
458 | if ( !_treeclosed.isNull() ) | 459 | if ( !_treeclosed.isNull() ) |
459 | item->setPixmap( 0, _treeclosed ); | 460 | item->setPixmap( 0, _treeclosed ); |
460 | emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) ); | 461 | emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) ); |
461 | } | 462 | } |
462 | 463 | ||
463 | //=============================================================================================// | 464 | //=============================================================================================// |
464 | // OVersatileView Case I - API only existing in QListView or QIconView but not in both! | 465 | // OVersatileView Case I - API only existing in QListView or QIconView but not in both! |
465 | //==============================================================================================// | 466 | //==============================================================================================// |
466 | 467 | ||
467 | int OVersatileView::treeStepSize() const // QListView | 468 | int OVersatileView::treeStepSize() const // QListView |
468 | { | 469 | { |
469 | if ( !isValidViewMode( Tree ) ) | 470 | if ( !isValidViewMode( Tree ) ) |
470 | { | 471 | { |
471 | return -1; | 472 | return -1; |
472 | } | 473 | } |
473 | return _listview->treeStepSize(); | 474 | return _listview->treeStepSize(); |
474 | } | 475 | } |
475 | void OVersatileView::setTreeStepSize( int size ) // QListView | 476 | void OVersatileView::setTreeStepSize( int size ) // QListView |
476 | { | 477 | { |
477 | if ( !isValidViewMode( Tree ) ) | 478 | if ( !isValidViewMode( Tree ) ) |
478 | { | 479 | { |
479 | return; | 480 | return; |
480 | } | 481 | } |
481 | _listview->setTreeStepSize( size ); | 482 | _listview->setTreeStepSize( size ); |
482 | } | 483 | } |
483 | 484 | ||
484 | QHeader * OVersatileView::header() const // QListView | 485 | QHeader * OVersatileView::header() const // QListView |
485 | { | 486 | { |
486 | if ( !isValidViewMode( Tree ) ) | 487 | if ( !isValidViewMode( Tree ) ) |
487 | { | 488 | { |
488 | return 0; | 489 | return 0; |
489 | } | 490 | } |
490 | return _listview->header(); | 491 | return _listview->header(); |
491 | } | 492 | } |
492 | 493 | ||
493 | int OVersatileView::addColumn( const QString &label, int size ) // QListView | 494 | int OVersatileView::addColumn( const QString &label, int size ) // QListView |
494 | { | 495 | { |
495 | if ( !isValidViewMode( Tree ) ) | 496 | if ( !isValidViewMode( Tree ) ) |
496 | { | 497 | { |
497 | return -1; | 498 | return -1; |
498 | } | 499 | } |
499 | return _listview->addColumn( label, size ); | 500 | return _listview->addColumn( label, size ); |
500 | } | 501 | } |
501 | 502 | ||
502 | int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView | 503 | int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView |
503 | { | 504 | { |
504 | if ( !isValidViewMode( Tree ) ) | 505 | if ( !isValidViewMode( Tree ) ) |
505 | { | 506 | { |
506 | return -1; | 507 | return -1; |
507 | } | 508 | } |
508 | return _listview->addColumn( iconset, label, size ); | 509 | return _listview->addColumn( iconset, label, size ); |
509 | } | 510 | } |
510 | 511 | ||
511 | void OVersatileView::removeColumn( int index ) // QListView | 512 | void OVersatileView::removeColumn( int index ) // QListView |
512 | { | 513 | { |
513 | if ( !isValidViewMode( Tree ) ) | 514 | if ( !isValidViewMode( Tree ) ) |
514 | { | 515 | { |
515 | return; | 516 | return; |
516 | } | 517 | } |
517 | _listview->removeColumn( index ); | 518 | _listview->removeColumn( index ); |
518 | } | 519 | } |
519 | void OVersatileView::setColumnText( int column, const QString &label ) // QListView | 520 | void OVersatileView::setColumnText( int column, const QString &label ) // QListView |
520 | { | 521 | { |
521 | if ( !isValidViewMode( Tree ) ) | 522 | if ( !isValidViewMode( Tree ) ) |
522 | { | 523 | { |
523 | return; | 524 | return; |
524 | } | 525 | } |
525 | _listview->setColumnText( column, label ); | 526 | _listview->setColumnText( column, label ); |
526 | } | 527 | } |
527 | void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView | 528 | void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView |
528 | { | 529 | { |
529 | if ( !isValidViewMode( Tree ) ) | 530 | if ( !isValidViewMode( Tree ) ) |
530 | { | 531 | { |
531 | return; | 532 | return; |
532 | } | 533 | } |
533 | _listview->setColumnText( column, iconset, label ); | 534 | _listview->setColumnText( column, iconset, label ); |
534 | } | 535 | } |
535 | QString OVersatileView::columnText( int column ) const // QListView | 536 | QString OVersatileView::columnText( int column ) const // QListView |
536 | { | 537 | { |
537 | if ( !isValidViewMode( Tree ) ) | 538 | if ( !isValidViewMode( Tree ) ) |
538 | { | 539 | { |
539 | return QString::null; | 540 | return QString::null; |
540 | } | 541 | } |
541 | return _listview->columnText( column ); | 542 | return _listview->columnText( column ); |
542 | } | 543 | } |
543 | void OVersatileView::setColumnWidth( int column, int width ) // QListView | 544 | void OVersatileView::setColumnWidth( int column, int width ) // QListView |
544 | { | 545 | { |
545 | if ( !isValidViewMode( Tree ) ) | 546 | if ( !isValidViewMode( Tree ) ) |
546 | { | 547 | { |
547 | return; | 548 | return; |
548 | } | 549 | } |
549 | _listview->setColumnWidth( column, width ); | 550 | _listview->setColumnWidth( column, width ); |
550 | } | 551 | } |
551 | int OVersatileView::columnWidth( int column ) const // QListView | 552 | int OVersatileView::columnWidth( int column ) const // QListView |
552 | { | 553 | { |
553 | if ( !isValidViewMode( Tree ) ) | 554 | if ( !isValidViewMode( Tree ) ) |
554 | { | 555 | { |
555 | return -1; | 556 | return -1; |
556 | } | 557 | } |
557 | return _listview->columnWidth( column ); | 558 | return _listview->columnWidth( column ); |
558 | } | 559 | } |
559 | void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView | 560 | void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView |
560 | { | 561 | { |
561 | if ( !isValidViewMode( Tree ) ) | 562 | if ( !isValidViewMode( Tree ) ) |
562 | { | 563 | { |
563 | return; | 564 | return; |
564 | } | 565 | } |
565 | _listview->setColumnWidth( column, mode ); | 566 | _listview->setColumnWidth( column, mode ); |
566 | } | 567 | } |
567 | int OVersatileView::columns() const // QListView | 568 | int OVersatileView::columns() const // QListView |
568 | { | 569 | { |
569 | if ( !isValidViewMode( Tree ) ) | 570 | if ( !isValidViewMode( Tree ) ) |
570 | { | 571 | { |
571 | return -1; | 572 | return -1; |
572 | } | 573 | } |
573 | return _listview->columns(); | 574 | return _listview->columns(); |
574 | } | 575 | } |
575 | 576 | ||
576 | void OVersatileView::setColumnAlignment( int column, int align ) // QListView | 577 | void OVersatileView::setColumnAlignment( int column, int align ) // QListView |
577 | { | 578 | { |
578 | if ( !isValidViewMode( Tree ) ) | 579 | if ( !isValidViewMode( Tree ) ) |
579 | { | 580 | { |
580 | return; | 581 | return; |
581 | } | 582 | } |
582 | _listview->setColumnAlignment( column, align ); | 583 | _listview->setColumnAlignment( column, align ); |
583 | } | 584 | } |
584 | int OVersatileView::columnAlignment( int column ) const // QListView | 585 | int OVersatileView::columnAlignment( int column ) const // QListView |
585 | { | 586 | { |
586 | if ( !isValidViewMode( Tree ) ) | 587 | if ( !isValidViewMode( Tree ) ) |
587 | { | 588 | { |
588 | return -1; | 589 | return -1; |
589 | } | 590 | } |
590 | return _listview->columnAlignment( column ); | 591 | return _listview->columnAlignment( column ); |
591 | } | 592 | } |
592 | 593 | ||
593 | OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView | 594 | OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView |
594 | { | 595 | { |
595 | if ( !isValidViewMode( Tree ) ) | 596 | if ( !isValidViewMode( Tree ) ) |
596 | { | 597 | { |
597 | return 0; | 598 | return 0; |
598 | } | 599 | } |
599 | return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) ); | 600 | return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) ); |
600 | } | 601 | } |
601 | QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView | 602 | QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView |
602 | { | 603 | { |
603 | if ( !isValidViewMode( Tree ) ) | 604 | if ( !isValidViewMode( Tree ) ) |
604 | { | 605 | { |
605 | return QRect( -1, -1, -1, -1 ); | 606 | return QRect( -1, -1, -1, -1 ); |
606 | } | 607 | } |
607 | return _listview->itemRect( item ); | 608 | return _listview->itemRect( item ); |
608 | } | 609 | } |
609 | int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView | 610 | int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView |
610 | { | 611 | { |
611 | if ( !isValidViewMode( Tree ) ) | 612 | if ( !isValidViewMode( Tree ) ) |
612 | { | 613 | { |
613 | return -1; | 614 | return -1; |
614 | } | 615 | } |
615 | return _listview->itemPos( item ); | 616 | return _listview->itemPos( item ); |
616 | } | 617 | } |
617 | 618 | ||
618 | bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug* | 619 | bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug* |
619 | { | 620 | { |
620 | if ( !isValidViewMode( Tree ) ) | 621 | if ( !isValidViewMode( Tree ) ) |
621 | { | 622 | { |
622 | return false; | 623 | return false; |
623 | } | 624 | } |
624 | return _listview->isSelected( item ); | 625 | return _listview->isSelected( item ); |
625 | } | 626 | } |
626 | 627 | ||
627 | void OVersatileView::setMultiSelection( bool enable ) | 628 | void OVersatileView::setMultiSelection( bool enable ) |
628 | { | 629 | { |
629 | _listview->setMultiSelection( enable ); | 630 | _listview->setMultiSelection( enable ); |
630 | } | 631 | } |
631 | bool OVersatileView::isMultiSelection() const | 632 | bool OVersatileView::isMultiSelection() const |
632 | { | 633 | { |
633 | return _listview->isMultiSelection(); | 634 | return _listview->isMultiSelection(); |
634 | } | 635 | } |
635 | 636 | ||
636 | OVersatileViewItem * OVersatileView::selectedItem() const // QListView | 637 | OVersatileViewItem * OVersatileView::selectedItem() const // QListView |
637 | { | 638 | { |
638 | if ( !isValidViewMode( Tree ) ) | 639 | if ( !isValidViewMode( Tree ) ) |
639 | { | 640 | { |
640 | return 0; | 641 | return 0; |
641 | } | 642 | } |
642 | return static_cast<OVersatileViewItem*>( _listview->selectedItem() ); | 643 | return static_cast<OVersatileViewItem*>( _listview->selectedItem() ); |
643 | } | 644 | } |
644 | void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView | 645 | void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView |
645 | { | 646 | { |
646 | if ( !isValidViewMode( Tree ) ) | 647 | if ( !isValidViewMode( Tree ) ) |
647 | { | 648 | { |
648 | return; | 649 | return; |
649 | } | 650 | } |
650 | _listview->setOpen( item, open ); | 651 | _listview->setOpen( item, open ); |
651 | } | 652 | } |
652 | bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView | 653 | bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView |
653 | { | 654 | { |
654 | if ( !isValidViewMode( Tree ) ) | 655 | if ( !isValidViewMode( Tree ) ) |
655 | { | 656 | { |
656 | return false; | 657 | return false; |
657 | } | 658 | } |
658 | return _listview->isOpen( item ); | 659 | return _listview->isOpen( item ); |
659 | } | 660 | } |
660 | 661 | ||
661 | OVersatileViewItem * OVersatileView::firstChild() const // QListView | 662 | OVersatileViewItem * OVersatileView::firstChild() const // QListView |
662 | { | 663 | { |
663 | if ( !isValidViewMode( Tree ) ) | 664 | if ( !isValidViewMode( Tree ) ) |
664 | { | 665 | { |
665 | return 0; | 666 | return 0; |
666 | } | 667 | } |
667 | return static_cast<OVersatileViewItem*>( _listview->firstChild() ); | 668 | return static_cast<OVersatileViewItem*>( _listview->firstChild() ); |
668 | } | 669 | } |
669 | int OVersatileView::childCount() const // QListView | 670 | int OVersatileView::childCount() const // QListView |
670 | { | 671 | { |
671 | if ( !isValidViewMode( Tree ) ) | 672 | if ( !isValidViewMode( Tree ) ) |
672 | { | 673 | { |
673 | return -1; | 674 | return -1; |
674 | } | 675 | } |
675 | return _listview->childCount(); | 676 | return _listview->childCount(); |
676 | } | 677 | } |
677 | 678 | ||
678 | void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView | 679 | void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView |
679 | { | 680 | { |
680 | if ( !isValidViewMode( Tree ) ) | 681 | if ( !isValidViewMode( Tree ) ) |
681 | { | 682 | { |
682 | return; | 683 | return; |
683 | } | 684 | } |
684 | _listview->setAllColumnsShowFocus( focus ); | 685 | _listview->setAllColumnsShowFocus( focus ); |
685 | } | 686 | } |
686 | bool OVersatileView::allColumnsShowFocus() const // QListView | 687 | bool OVersatileView::allColumnsShowFocus() const // QListView |
687 | { | 688 | { |
688 | if ( !isValidViewMode( Tree ) ) | 689 | if ( !isValidViewMode( Tree ) ) |
689 | { | 690 | { |
690 | return false; | 691 | return false; |
691 | } | 692 | } |
692 | return _listview->allColumnsShowFocus(); | 693 | return _listview->allColumnsShowFocus(); |
693 | } | 694 | } |
694 | 695 | ||
695 | void OVersatileView::setItemMargin( int margin ) // QListView | 696 | void OVersatileView::setItemMargin( int margin ) // QListView |
696 | { | 697 | { |
697 | if ( !isValidViewMode( Tree ) ) | 698 | if ( !isValidViewMode( Tree ) ) |
698 | { | 699 | { |
699 | return; | 700 | return; |
700 | } | 701 | } |
701 | _listview->setItemMargin( margin ); | 702 | _listview->setItemMargin( margin ); |
702 | } | 703 | } |
703 | int OVersatileView::itemMargin() const // QListView | 704 | int OVersatileView::itemMargin() const // QListView |
704 | { | 705 | { |
705 | if ( !isValidViewMode( Tree ) ) | 706 | if ( !isValidViewMode( Tree ) ) |
706 | { | 707 | { |
707 | return -1; | 708 | return -1; |
708 | } | 709 | } |
709 | return _listview->itemMargin(); | 710 | return _listview->itemMargin(); |
710 | } | 711 | } |
711 | 712 | ||
712 | void OVersatileView::setRootIsDecorated( bool decorate ) // QListView | 713 | void OVersatileView::setRootIsDecorated( bool decorate ) // QListView |
713 | { | 714 | { |
714 | if ( !isValidViewMode( Tree ) ) | 715 | if ( !isValidViewMode( Tree ) ) |
715 | { | 716 | { |
716 | return; | 717 | return; |
717 | } | 718 | } |
718 | _listview->setRootIsDecorated( decorate ); | 719 | _listview->setRootIsDecorated( decorate ); |
719 | } | 720 | } |
720 | bool OVersatileView::rootIsDecorated() const // QListView | 721 | bool OVersatileView::rootIsDecorated() const // QListView |
721 | { | 722 | { |
722 | if ( !isValidViewMode( Tree ) ) | 723 | if ( !isValidViewMode( Tree ) ) |
723 | { | 724 | { |
724 | return false; | 725 | return false; |
725 | } | 726 | } |
726 | return _listview->rootIsDecorated(); | 727 | return _listview->rootIsDecorated(); |
727 | } | 728 | } |
728 | 729 | ||
729 | void OVersatileView::setShowSortIndicator( bool show ) // QListView | 730 | void OVersatileView::setShowSortIndicator( bool show ) // QListView |
730 | { | 731 | { |
731 | if ( !isValidViewMode( Tree ) ) | 732 | if ( !isValidViewMode( Tree ) ) |
732 | { | 733 | { |
733 | return; | 734 | return; |
734 | } | 735 | } |
735 | _listview->setShowSortIndicator( show ); | 736 | _listview->setShowSortIndicator( show ); |
736 | } | 737 | } |
737 | bool OVersatileView::showSortIndicator() const // QListView | 738 | bool OVersatileView::showSortIndicator() const // QListView |
738 | { | 739 | { |
739 | if ( !isValidViewMode( Tree ) ) | 740 | if ( !isValidViewMode( Tree ) ) |
740 | { | 741 | { |
741 | return false; | 742 | return false; |
742 | } | 743 | } |
743 | return _listview->showSortIndicator(); | 744 | return _listview->showSortIndicator(); |
744 | } | 745 | } |
745 | 746 | ||
746 | void OVersatileView::triggerUpdate() // QListView | 747 | void OVersatileView::triggerUpdate() // QListView |
747 | { | 748 | { |
748 | if ( !isValidViewMode( Tree ) ) | 749 | if ( !isValidViewMode( Tree ) ) |
749 | { | 750 | { |
750 | return; | 751 | return; |
751 | } | 752 | } |
752 | _listview->triggerUpdate(); | 753 | _listview->triggerUpdate(); |
753 | } | 754 | } |
754 | 755 | ||
755 | // | 756 | // |
756 | // only in QIconView | 757 | // only in QIconView |
757 | // | 758 | // |
758 | 759 | ||
759 | uint OVersatileView::count() const // QIconView | 760 | uint OVersatileView::count() const // QIconView |
760 | { | 761 | { |
761 | if ( !isValidViewMode( Icons ) ) | 762 | if ( !isValidViewMode( Icons ) ) |
762 | { | 763 | { |
763 | return 0; | 764 | return 0; |
764 | } | 765 | } |
765 | return _iconview->count(); | 766 | return _iconview->count(); |
766 | } | 767 | } |
767 | 768 | ||
768 | int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView | 769 | int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView |
769 | { | 770 | { |
770 | if ( !isValidViewMode( Icons ) ) | 771 | if ( !isValidViewMode( Icons ) ) |
771 | { | 772 | { |
772 | return -1; | 773 | return -1; |
773 | } | 774 | } |
774 | return _iconview->index( item ); | 775 | return _iconview->index( item ); |
775 | } | 776 | } |
776 | 777 | ||
777 | OVersatileViewItem* OVersatileView::firstItem() const // QIconView | 778 | OVersatileViewItem* OVersatileView::firstItem() const // QIconView |
778 | { | 779 | { |
779 | if ( !isValidViewMode( Icons ) ) | 780 | if ( !isValidViewMode( Icons ) ) |
780 | { | 781 | { |
781 | return 0; | 782 | return 0; |
782 | } | 783 | } |
783 | return static_cast<OVersatileViewItem*>( _iconview->firstItem() ); | 784 | return static_cast<OVersatileViewItem*>( _iconview->firstItem() ); |
784 | } | 785 | } |
785 | OVersatileViewItem* OVersatileView::lastItem() const // QIconView | 786 | OVersatileViewItem* OVersatileView::lastItem() const // QIconView |
786 | { | 787 | { |
787 | if ( !isValidViewMode( Icons ) ) | 788 | if ( !isValidViewMode( Icons ) ) |
788 | { | 789 | { |
789 | return 0; | 790 | return 0; |
790 | } | 791 | } |
791 | return static_cast<OVersatileViewItem*>( _iconview->lastItem() ); | 792 | return static_cast<OVersatileViewItem*>( _iconview->lastItem() ); |
792 | } | 793 | } |
793 | 794 | ||
794 | OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView | 795 | OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView |
795 | { | 796 | { |
796 | if ( !isValidViewMode( Icons ) ) | 797 | if ( !isValidViewMode( Icons ) ) |
797 | { | 798 | { |
798 | return 0; | 799 | return 0; |
799 | } | 800 | } |
800 | return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) ); | 801 | return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) ); |
801 | } | 802 | } |
802 | OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView | 803 | OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView |
803 | { | 804 | { |
804 | if ( !isValidViewMode( Icons ) ) | 805 | if ( !isValidViewMode( Icons ) ) |
805 | { | 806 | { |
806 | return 0; | 807 | return 0; |
807 | } | 808 | } |
808 | return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) ); | 809 | return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) ); |
809 | } | 810 | } |
810 | 811 | ||
811 | OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView | 812 | OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView |
812 | { | 813 | { |
813 | if ( !isValidViewMode( Icons ) ) | 814 | if ( !isValidViewMode( Icons ) ) |
814 | { | 815 | { |
815 | return 0; | 816 | return 0; |
816 | } | 817 | } |
817 | return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) ); | 818 | return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) ); |
818 | } | 819 | } |
819 | OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView | 820 | OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView |
820 | { | 821 | { |
821 | if ( !isValidViewMode( Icons ) ) | 822 | if ( !isValidViewMode( Icons ) ) |
822 | { | 823 | { |
823 | return 0; | 824 | return 0; |
824 | } | 825 | } |
825 | return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) ); | 826 | return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) ); |
826 | } | 827 | } |
827 | 828 | ||
828 | void OVersatileView::setGridX( int rx ) // QIconView | 829 | void OVersatileView::setGridX( int rx ) // QIconView |
829 | { | 830 | { |
830 | if ( !isValidViewMode( Icons ) ) | 831 | if ( !isValidViewMode( Icons ) ) |
831 | { | 832 | { |
832 | return; | 833 | return; |
833 | } | 834 | } |
834 | _iconview->setGridX( rx ); | 835 | _iconview->setGridX( rx ); |
835 | } | 836 | } |
836 | void OVersatileView::setGridY( int ry ) // QIconView | 837 | void OVersatileView::setGridY( int ry ) // QIconView |
837 | { | 838 | { |
838 | if ( !isValidViewMode( Icons ) ) | 839 | if ( !isValidViewMode( Icons ) ) |
839 | { | 840 | { |
840 | return; | 841 | return; |
841 | } | 842 | } |
842 | _iconview->setGridY( ry ); | 843 | _iconview->setGridY( ry ); |
843 | } | 844 | } |
844 | int OVersatileView::gridX() const // QIconView | 845 | int OVersatileView::gridX() const // QIconView |
845 | { | 846 | { |
846 | if ( !isValidViewMode( Icons ) ) | 847 | if ( !isValidViewMode( Icons ) ) |
847 | { | 848 | { |
848 | return -1; | 849 | return -1; |
849 | } | 850 | } |
850 | return _iconview->gridX(); | 851 | return _iconview->gridX(); |
851 | } | 852 | } |
852 | int OVersatileView::gridY() const // QIconView | 853 | int OVersatileView::gridY() const // QIconView |
853 | { | 854 | { |
854 | if ( !isValidViewMode( Icons ) ) | 855 | if ( !isValidViewMode( Icons ) ) |
855 | { | 856 | { |
856 | return -1; | 857 | return -1; |
857 | } | 858 | } |
858 | return _iconview->gridY(); | 859 | return _iconview->gridY(); |
859 | } | 860 | } |
860 | void OVersatileView::setSpacing( int sp ) // QIconView | 861 | void OVersatileView::setSpacing( int sp ) // QIconView |
861 | { | 862 | { |
862 | if ( !isValidViewMode( Icons ) ) | 863 | if ( !isValidViewMode( Icons ) ) |
863 | { | 864 | { |
864 | return; | 865 | return; |
865 | } | 866 | } |
866 | _iconview->setSpacing( sp ); | 867 | _iconview->setSpacing( sp ); |
867 | } | 868 | } |
868 | int OVersatileView::spacing() const // QIconView | 869 | int OVersatileView::spacing() const // QIconView |
869 | { | 870 | { |
870 | if ( !isValidViewMode( Icons ) ) | 871 | if ( !isValidViewMode( Icons ) ) |
871 | { | 872 | { |
872 | return -1; | 873 | return -1; |
873 | } | 874 | } |
874 | return _iconview->spacing(); | 875 | return _iconview->spacing(); |
875 | } | 876 | } |
876 | void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView | 877 | void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView |
877 | { | 878 | { |
878 | if ( !isValidViewMode( Icons ) ) | 879 | if ( !isValidViewMode( Icons ) ) |
879 | { | 880 | { |
880 | return; | 881 | return; |
881 | } | 882 | } |
882 | _iconview->setItemTextPos( pos ); | 883 | _iconview->setItemTextPos( pos ); |
883 | } | 884 | } |
884 | QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView | 885 | QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView |
885 | { | 886 | { |
886 | if ( !isValidViewMode( Icons ) ) | 887 | if ( !isValidViewMode( Icons ) ) |
887 | { | 888 | { |
888 | return (QIconView::ItemTextPos) -1; | 889 | return (QIconView::ItemTextPos) -1; |
889 | } | 890 | } |
890 | return _iconview->itemTextPos(); | 891 | return _iconview->itemTextPos(); |
891 | } | 892 | } |
892 | void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView | 893 | void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView |
893 | { | 894 | { |
894 | if ( !isValidViewMode( Icons ) ) | 895 | if ( !isValidViewMode( Icons ) ) |
895 | { | 896 | { |
896 | return; | 897 | return; |
897 | } | 898 | } |
898 | _iconview->setItemTextBackground( b ); | 899 | _iconview->setItemTextBackground( b ); |
899 | } | 900 | } |
900 | QBrush OVersatileView::itemTextBackground() const // QIconView | 901 | QBrush OVersatileView::itemTextBackground() const // QIconView |
901 | { | 902 | { |
902 | if ( !isValidViewMode( Icons ) ) | 903 | if ( !isValidViewMode( Icons ) ) |
903 | { | 904 | { |
904 | return QBrush(); | 905 | return QBrush(); |
905 | } | 906 | } |
906 | return _iconview->itemTextBackground(); | 907 | return _iconview->itemTextBackground(); |
907 | } | 908 | } |
908 | void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView | 909 | void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView |
909 | { | 910 | { |
910 | if ( !isValidViewMode( Icons ) ) | 911 | if ( !isValidViewMode( Icons ) ) |
911 | { | 912 | { |
912 | return; | 913 | return; |
913 | } | 914 | } |
914 | _iconview->setArrangement( am ); | 915 | _iconview->setArrangement( am ); |
915 | } | 916 | } |
916 | QIconView::Arrangement OVersatileView::arrangement() const // QIconView | 917 | QIconView::Arrangement OVersatileView::arrangement() const // QIconView |
917 | { | 918 | { |
918 | if ( !isValidViewMode( Icons ) ) | 919 | if ( !isValidViewMode( Icons ) ) |
919 | { | 920 | { |
920 | return (QIconView::Arrangement) -1; | 921 | return (QIconView::Arrangement) -1; |
921 | } | 922 | } |
922 | return _iconview->arrangement(); | 923 | return _iconview->arrangement(); |
923 | } | 924 | } |
924 | void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView | 925 | void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView |
925 | { | 926 | { |
926 | if ( !isValidViewMode( Icons ) ) | 927 | if ( !isValidViewMode( Icons ) ) |
927 | { | 928 | { |
928 | return; | 929 | return; |
929 | } | 930 | } |
930 | _iconview->setResizeMode( am ); | 931 | _iconview->setResizeMode( am ); |
931 | } | 932 | } |
932 | QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView | 933 | QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView |
933 | { | 934 | { |
934 | if ( !isValidViewMode( Icons ) ) | 935 | if ( !isValidViewMode( Icons ) ) |
935 | { | 936 | { |
936 | return (QIconView::ResizeMode) -1; | 937 | return (QIconView::ResizeMode) -1; |
937 | } | 938 | } |
938 | return _iconview->resizeMode(); | 939 | return _iconview->resizeMode(); |
939 | } | 940 | } |
940 | void OVersatileView::setMaxItemWidth( int w ) // QIconView | 941 | void OVersatileView::setMaxItemWidth( int w ) // QIconView |
941 | { | 942 | { |
942 | if ( !isValidViewMode( Icons ) ) | 943 | if ( !isValidViewMode( Icons ) ) |
943 | { | 944 | { |
944 | return; | 945 | return; |
945 | } | 946 | } |
946 | _iconview->setMaxItemWidth( w ); | 947 | _iconview->setMaxItemWidth( w ); |
947 | } | 948 | } |
948 | int OVersatileView::maxItemWidth() const // QIconView | 949 | int OVersatileView::maxItemWidth() const // QIconView |
949 | { | 950 | { |
950 | if ( !isValidViewMode( Icons ) ) | 951 | if ( !isValidViewMode( Icons ) ) |
951 | { | 952 | { |
952 | return -1; | 953 | return -1; |
953 | } | 954 | } |
954 | return _iconview->maxItemWidth(); | 955 | return _iconview->maxItemWidth(); |
955 | } | 956 | } |
956 | void OVersatileView::setMaxItemTextLength( int w ) // QIconView | 957 | void OVersatileView::setMaxItemTextLength( int w ) // QIconView |
957 | { | 958 | { |
958 | if ( !isValidViewMode( Icons ) ) | 959 | if ( !isValidViewMode( Icons ) ) |
959 | { | 960 | { |
960 | return; | 961 | return; |
961 | } | 962 | } |
962 | _iconview->setMaxItemTextLength( w ); | 963 | _iconview->setMaxItemTextLength( w ); |
963 | } | 964 | } |
964 | int OVersatileView::maxItemTextLength() const // QIconView | 965 | int OVersatileView::maxItemTextLength() const // QIconView |
965 | { | 966 | { |
966 | if ( !isValidViewMode( Icons ) ) | 967 | if ( !isValidViewMode( Icons ) ) |
967 | { | 968 | { |
968 | return -1; | 969 | return -1; |
969 | } | 970 | } |
970 | return _iconview->maxItemTextLength(); | 971 | return _iconview->maxItemTextLength(); |
971 | } | 972 | } |
972 | void OVersatileView::setAutoArrange( bool b ) // QIconView | 973 | void OVersatileView::setAutoArrange( bool b ) // QIconView |
973 | { | 974 | { |
974 | if ( !isValidViewMode( Icons ) ) | 975 | if ( !isValidViewMode( Icons ) ) |
975 | { | 976 | { |
976 | return; | 977 | return; |
977 | } | 978 | } |
978 | _iconview->setAutoArrange( b ); | 979 | _iconview->setAutoArrange( b ); |
979 | } | 980 | } |
980 | bool OVersatileView::autoArrange() const // QIconView | 981 | bool OVersatileView::autoArrange() const // QIconView |
981 | { | 982 | { |
982 | if ( !isValidViewMode( Icons ) ) | 983 | if ( !isValidViewMode( Icons ) ) |
983 | { | 984 | { |
984 | return false; | 985 | return false; |
985 | } | 986 | } |
986 | return _iconview->autoArrange(); | 987 | return _iconview->autoArrange(); |
987 | } | 988 | } |
988 | void OVersatileView::setShowToolTips( bool b ) // QIconView | 989 | void OVersatileView::setShowToolTips( bool b ) // QIconView |
989 | { | 990 | { |
990 | if ( !isValidViewMode( Icons ) ) | 991 | if ( !isValidViewMode( Icons ) ) |
991 | { | 992 | { |
992 | return; | 993 | return; |
993 | } | 994 | } |
994 | _iconview->setShowToolTips( b ); | 995 | _iconview->setShowToolTips( b ); |
995 | } | 996 | } |
996 | bool OVersatileView::showToolTips() const // QIconView | 997 | bool OVersatileView::showToolTips() const // QIconView |
997 | { | 998 | { |
998 | if ( !isValidViewMode( Icons ) ) | 999 | if ( !isValidViewMode( Icons ) ) |
999 | { | 1000 | { |
1000 | return false; | 1001 | return false; |
1001 | } | 1002 | } |
1002 | return _iconview->showToolTips(); | 1003 | return _iconview->showToolTips(); |
1003 | } | 1004 | } |
1004 | 1005 | ||
1005 | bool OVersatileView::sorting() const // QIconView | 1006 | bool OVersatileView::sorting() const // QIconView |
1006 | { | 1007 | { |
1007 | if ( !isValidViewMode( Icons ) ) | 1008 | if ( !isValidViewMode( Icons ) ) |
1008 | { | 1009 | { |
1009 | return false; | 1010 | return false; |
1010 | } | 1011 | } |
1011 | return _iconview->sorting(); | 1012 | return _iconview->sorting(); |
1012 | } | 1013 | } |
1013 | bool OVersatileView::sortDirection() const // QIconView | 1014 | bool OVersatileView::sortDirection() const // QIconView |
1014 | { | 1015 | { |
1015 | if ( !isValidViewMode( Icons ) ) | 1016 | if ( !isValidViewMode( Icons ) ) |
1016 | { | 1017 | { |
1017 | return false; | 1018 | return false; |
1018 | } | 1019 | } |
1019 | return _iconview->sortDirection(); | 1020 | return _iconview->sortDirection(); |
1020 | } | 1021 | } |
1021 | 1022 | ||
1022 | void OVersatileView::setItemsMovable( bool b ) // QIconView | 1023 | void OVersatileView::setItemsMovable( bool b ) // QIconView |
1023 | { | 1024 | { |
1024 | if ( !isValidViewMode( Icons ) ) | 1025 | if ( !isValidViewMode( Icons ) ) |
1025 | { | 1026 | { |
1026 | return; | 1027 | return; |
1027 | } | 1028 | } |
1028 | _iconview->setItemsMovable( b ); | 1029 | _iconview->setItemsMovable( b ); |
1029 | } | 1030 | } |
1030 | bool OVersatileView::itemsMovable() const // QIconView | 1031 | bool OVersatileView::itemsMovable() const // QIconView |
1031 | { | 1032 | { |
1032 | if ( !isValidViewMode( Icons ) ) | 1033 | if ( !isValidViewMode( Icons ) ) |
1033 | { | 1034 | { |
1034 | return false; | 1035 | return false; |
1035 | } | 1036 | } |
1036 | return _iconview->itemsMovable(); | 1037 | return _iconview->itemsMovable(); |
1037 | } | 1038 | } |
1038 | void OVersatileView::setWordWrapIconText( bool b ) // QIconView | 1039 | void OVersatileView::setWordWrapIconText( bool b ) // QIconView |
1039 | { | 1040 | { |
1040 | if ( !isValidViewMode( Icons ) ) | 1041 | if ( !isValidViewMode( Icons ) ) |
1041 | { | 1042 | { |
1042 | return; | 1043 | return; |
1043 | } | 1044 | } |
1044 | _iconview->setWordWrapIconText( b ); | 1045 | _iconview->setWordWrapIconText( b ); |
1045 | } | 1046 | } |
1046 | bool OVersatileView::wordWrapIconText() const // QIconView | 1047 | bool OVersatileView::wordWrapIconText() const // QIconView |
1047 | { | 1048 | { |
1048 | if ( !isValidViewMode( Icons ) ) | 1049 | if ( !isValidViewMode( Icons ) ) |
1049 | { | 1050 | { |
1050 | return false; | 1051 | return false; |
1051 | } | 1052 | } |
1052 | return _iconview->wordWrapIconText(); | 1053 | return _iconview->wordWrapIconText(); |
1053 | } | 1054 | } |
1054 | 1055 | ||
1055 | void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView | 1056 | void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView |
1056 | { | 1057 | { |
1057 | if ( !isValidViewMode( Icons ) ) | 1058 | if ( !isValidViewMode( Icons ) ) |
1058 | { | 1059 | { |
1059 | return; | 1060 | return; |
1060 | } | 1061 | } |
1061 | _iconview->arrangeItemsInGrid( grid, update ); | 1062 | _iconview->arrangeItemsInGrid( grid, update ); |
1062 | } | 1063 | } |
1063 | void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView | 1064 | void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView |
1064 | { | 1065 | { |
1065 | if ( !isValidViewMode( Icons ) ) | 1066 | if ( !isValidViewMode( Icons ) ) |
1066 | { | 1067 | { |
1067 | return; | 1068 | return; |
1068 | } | 1069 | } |
1069 | _iconview->arrangeItemsInGrid( update ); | 1070 | _iconview->arrangeItemsInGrid( update ); |
1070 | } | 1071 | } |
1071 | void OVersatileView::updateContents() // QIconView | 1072 | void OVersatileView::updateContents() // QIconView |
1072 | { | 1073 | { |
1073 | if ( !isValidViewMode( Icons ) ) | 1074 | if ( !isValidViewMode( Icons ) ) |
1074 | { | 1075 | { |
1075 | return; | 1076 | return; |
1076 | } | 1077 | } |
1077 | _iconview->updateContents(); | 1078 | _iconview->updateContents(); |
1078 | } | 1079 | } |
1079 | 1080 | ||
1080 | //==============================================================================================// | 1081 | //==============================================================================================// |
1081 | // OVersatileView Case II - QListView / QIconView common API | 1082 | // OVersatileView Case II - QListView / QIconView common API |
1082 | //==============================================================================================// | 1083 | //==============================================================================================// |
1083 | 1084 | ||
1084 | void OVersatileView::clear() | 1085 | void OVersatileView::clear() |
1085 | { | 1086 | { |
1086 | _iconview->clear(); | 1087 | _iconview->clear(); |
1087 | _listview->clear(); | 1088 | _listview->clear(); |
1088 | } | 1089 | } |
1089 | 1090 | ||
1090 | void OVersatileView::setFont( const QFont & font ) | 1091 | void OVersatileView::setFont( const QFont & font ) |
1091 | { | 1092 | { |
1092 | _iconview->setFont( font ); | 1093 | _iconview->setFont( font ); |
1093 | _listview->setFont( font ); | 1094 | _listview->setFont( font ); |
1094 | } | 1095 | } |
1095 | void OVersatileView::setPalette( const QPalette & palette ) | 1096 | void OVersatileView::setPalette( const QPalette & palette ) |
1096 | { | 1097 | { |
1097 | _iconview->setPalette( palette ); | 1098 | _iconview->setPalette( palette ); |
1098 | _listview->setPalette( palette ); | 1099 | _listview->setPalette( palette ); |
1099 | } | 1100 | } |
1100 | 1101 | ||
1101 | void OVersatileView::takeItem( OVersatileViewItem * item ) | 1102 | void OVersatileView::takeItem( OVersatileViewItem * item ) |
1102 | { | 1103 | { |
1103 | _iconview->takeItem( item ); | 1104 | _iconview->takeItem( item ); |
1104 | _listview->takeItem( item ); | 1105 | _listview->takeItem( item ); |
1105 | } | 1106 | } |
1106 | 1107 | ||
1107 | void OVersatileView::setSelectionMode( SelectionMode mode ) | 1108 | void OVersatileView::setSelectionMode( SelectionMode mode ) |
1108 | { | 1109 | { |
1109 | _iconview->setSelectionMode( (QIconView::SelectionMode) mode ); | 1110 | _iconview->setSelectionMode( (QIconView::SelectionMode) mode ); |
1110 | _listview->setSelectionMode( (QListView::SelectionMode) mode ); | 1111 | _listview->setSelectionMode( (QListView::SelectionMode) mode ); |
1111 | } | 1112 | } |
1112 | OVersatileView::SelectionMode OVersatileView::selectionMode() const | 1113 | OVersatileView::SelectionMode OVersatileView::selectionMode() const |
1113 | { | 1114 | { |
1114 | return (OVersatileView::SelectionMode) _iconview->selectionMode(); | 1115 | return (OVersatileView::SelectionMode) _iconview->selectionMode(); |
1115 | } | 1116 | } |
1116 | 1117 | ||
1117 | void OVersatileView::selectAll( bool select ) | 1118 | void OVersatileView::selectAll( bool select ) |
1118 | { | 1119 | { |
1119 | _iconview->selectAll( select ); | 1120 | _iconview->selectAll( select ); |
1120 | } | 1121 | } |
1121 | void OVersatileView::clearSelection() | 1122 | void OVersatileView::clearSelection() |
1122 | { | 1123 | { |
1123 | _iconview->clearSelection(); | 1124 | _iconview->clearSelection(); |
1124 | _listview->clearSelection(); | 1125 | _listview->clearSelection(); |
1125 | } | 1126 | } |
1126 | void OVersatileView::invertSelection() | 1127 | void OVersatileView::invertSelection() |
1127 | { | 1128 | { |
1128 | _iconview->invertSelection(); | 1129 | _iconview->invertSelection(); |
1129 | _listview->invertSelection(); | 1130 | _listview->invertSelection(); |
1130 | } | 1131 | } |
1131 | 1132 | ||
1132 | void OVersatileView::ensureItemVisible( const OVersatileViewItem * item ) | 1133 | void OVersatileView::ensureItemVisible( const OVersatileViewItem * item ) |
1133 | { | 1134 | { |
1134 | _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) ); | 1135 | _iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) ); |
1135 | _listview->ensureItemVisible( item ); | 1136 | _listview->ensureItemVisible( item ); |
1136 | } | 1137 | } |
1137 | void OVersatileView::repaintItem( const OVersatileViewItem * item ) const | 1138 | void OVersatileView::repaintItem( const OVersatileViewItem * item ) const |
1138 | { | 1139 | { |
1139 | _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) ); | 1140 | _iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) ); |
1140 | _listview->repaintItem( item ); | 1141 | _listview->repaintItem( item ); |
1141 | } | 1142 | } |
1142 | 1143 | ||
1143 | void OVersatileView::setCurrentItem( OVersatileViewItem * item ) | 1144 | void OVersatileView::setCurrentItem( OVersatileViewItem * item ) |
1144 | { | 1145 | { |
1145 | _iconview->setCurrentItem( item ); | 1146 | _iconview->setCurrentItem( item ); |
1146 | _listview->setCurrentItem( item ); | 1147 | _listview->setCurrentItem( item ); |
1147 | } | 1148 | } |
1148 | OVersatileViewItem * OVersatileView::currentItem() const | 1149 | OVersatileViewItem * OVersatileView::currentItem() const |
1149 | { | 1150 | { |
1150 | return static_cast<OVersatileViewItem*>( _listview->currentItem() ); | 1151 | return static_cast<OVersatileViewItem*>( _listview->currentItem() ); |
1151 | } | 1152 | } |
1152 | 1153 | ||
1153 | // bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation | 1154 | // bool eventFilter( QObject * o, QEvent * ) // use QWidgetStack implementation |
1154 | 1155 | ||
1155 | // QSize minimumSizeHint() const // use QWidgetStack implementation | 1156 | // QSize minimumSizeHint() const // use QWidgetStack implementation |
1156 | // QSizePolicy sizePolicy() const // use QWidgetStack implementation | 1157 | // QSizePolicy sizePolicy() const // use QWidgetStack implementation |
1157 | // QSize sizeHint() const // use QWidgetStack implementation | 1158 | // QSize sizeHint() const // use QWidgetStack implementation |
1158 | 1159 | ||
1159 | //==============================================================================================// | 1160 | //==============================================================================================// |
1160 | // OVersatileView Case III - APIs which differ slightly | 1161 | // OVersatileView Case III - APIs which differ slightly |
1161 | //==============================================================================================// | 1162 | //==============================================================================================// |
1162 | 1163 | ||
1163 | /* | 1164 | /* |
1164 | 1165 | ||
1165 | void OVersatileView::insertItem( OVersatileViewItem * ) // QListView | 1166 | void OVersatileView::insertItem( OVersatileViewItem * ) // QListView |
1166 | void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView | 1167 | void OVersatileView::insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ) // QIconView |
1167 | 1168 | ||
1168 | void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView | 1169 | void OVersatileView::setSelected( OVersatileViewItem *, bool ) // QListView |
1169 | void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView | 1170 | void OVersatileView::setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ) // QIconView |
1170 | 1171 | ||
1171 | void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView | 1172 | void OVersatileView::setSorting( int column, bool increasing = TRUE ) // QListView |
1172 | void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView | 1173 | void OVersatileView::setSorting( bool sort, bool ascending = TRUE ) // QIconView |
1173 | 1174 | ||
1174 | void OVersatileView::sort() // #### make in next major release // QListView | 1175 | void OVersatileView::sort() // #### make in next major release // QListView |
1175 | void OVersatileView::sort( bool ascending = TRUE ) // QIconView | 1176 | void OVersatileView::sort( bool ascending = TRUE ) // QIconView |
1176 | 1177 | ||
1177 | */ | 1178 | */ |
1178 | 1179 | ||
1179 | 1180 | ||