summaryrefslogtreecommitdiff
path: root/libopie2/opieui/oimageeffect.cpp
Unidiff
Diffstat (limited to 'libopie2/opieui/oimageeffect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/oimageeffect.cpp41
1 files changed, 21 insertions, 20 deletions
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
@@ -25,25 +25,26 @@ 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
26THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26THIS 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
42using namespace std; 43using namespace std;
43 44
44inline unsigned int intensityValue(unsigned int color) 45inline 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}
@@ -54,25 +55,25 @@ inline unsigned int intensityValue(unsigned int color)
54// 55//
55//====================================================================== 56//======================================================================
56 57
57QImage OImageEffect::gradient(const QSize &size, const QColor &ca, 58QImage 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;
@@ -340,25 +341,25 @@ QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca,
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;
@@ -559,25 +560,25 @@ QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca,
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
568QImage& OImageEffect::intensity(QImage &image, float percent) 569QImage& 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)
@@ -624,25 +625,25 @@ QImage& OImageEffect::intensity(QImage &image, float percent)
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
632QImage& OImageEffect::channelIntensity(QImage &image, float percent, 633QImage& 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;
@@ -714,25 +715,25 @@ QImage& OImageEffect::channelIntensity(QImage &image, float percent,
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//
721QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse, 722QImage& 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
@@ -843,25 +844,25 @@ QImage& OImageEffect::modulate(QImage &image, QImage &modImage, bool reverse,
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
849QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity) 850QImage& 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)
@@ -886,30 +887,30 @@ QImage& OImageEffect::blend(const QColor& clr, QImage& dst, float opacity)
886 return dst; 887 return dst;
887} 888}
888 889
889// Nice and fast direct pixel manipulation 890// Nice and fast direct pixel manipulation
890QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity) 891QImage& 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();
@@ -931,25 +932,25 @@ QImage& OImageEffect::blend(QImage& src, QImage& dst, float opacity)
931 data2++; 932 data2++;
932 } 933 }
933 934
934 return dst; 935 return dst;
935} 936}
936 937
937 938
938QImage& OImageEffect::blend(QImage &image, float initial_intensity, 939QImage& 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;
@@ -1124,25 +1125,25 @@ QImage& OImageEffect::blend(QImage &image, float initial_intensity,
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//
1142QImage& OImageEffect::blend(QImage &image1, QImage &image2, 1143QImage& 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
@@ -1154,25 +1155,25 @@ QImage& OImageEffect::blend(QImage &image1, QImage &image2,
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//
1160QImage& OImageEffect::blend(QImage &image1, QImage &image2, 1161QImage& 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
@@ -1252,25 +1253,25 @@ unsigned int OImageEffect::uHash(unsigned int c)
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
1261QImage& OImageEffect::hash(QImage &image, Lighting lite, unsigned int spacing) 1262QImage& 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 ||
@@ -1760,25 +1761,25 @@ 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 {
@@ -1977,25 +1978,25 @@ 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]);
@@ -2093,25 +2094,25 @@ 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])]++;
@@ -2178,43 +2179,43 @@ 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);
@@ -2224,25 +2225,25 @@ QImage OImageEffect::sample(QImage &src, int w, int h)
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);
@@ -3063,25 +3064,25 @@ QImage OImageEffect::wave(QImage &src, double amplitude, double wavelength,
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
3071QImage OImageEffect::oilPaint(QImage &src, int radius) 3072QImage 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));