kimageeffect.h
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@interaccess.com> 00003 (C) 1998, 1999 Christian Tibirna <ctibirna@total.net> 00004 (C) 1998, 1999 Dirk Mueller <mueller@kde.org> 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions 00008 are met: 00009 00010 1. Redistributions of source code must retain the above copyright 00011 notice, this list of conditions and the following disclaimer. 00012 2. Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 00027 */ 00028 00029 // $Id: kimageeffect.h 399215 2005-03-20 14:33:45Z mueller $ 00030 00031 #ifndef __KIMAGE_EFFECT_H 00032 #define __KIMAGE_EFFECT_H 00033 00034 #include <kdelibs_export.h> 00035 00036 class QImage; 00037 class QSize; 00038 class QColor; 00039 class QPoint; 00040 class QRect; 00041 00050 class KDEFX_EXPORT KImageEffect 00051 { 00052 public: 00058 enum GradientType { VerticalGradient, 00059 HorizontalGradient, 00060 DiagonalGradient, 00061 CrossDiagonalGradient, 00062 PyramidGradient, 00063 RectangleGradient, 00064 PipeCrossGradient, 00065 EllipticGradient 00066 }; 00067 00073 enum RGBComponent { Red, 00074 Green, 00075 Blue, 00076 Gray, 00077 All 00078 }; 00079 00084 enum Lighting {NorthLite, 00085 NWLite, 00086 WestLite, 00087 SWLite, 00088 SouthLite, 00089 SELite, 00090 EastLite, 00091 NELite 00092 }; 00093 00098 enum ModulationType { Intensity, 00099 Saturation, 00100 HueShift, 00101 Contrast 00102 }; 00103 00108 enum NoiseType { UniformNoise=0, 00109 GaussianNoise, 00110 MultiplicativeGaussianNoise, 00111 ImpulseNoise, 00112 LaplacianNoise, 00113 PoissonNoise 00114 }; 00115 00120 enum RotateDirection{ Rotate90, 00121 Rotate180, 00122 Rotate270 00123 }; 00124 00129 enum BumpmapType { 00130 Linear, 00131 Spherical, 00132 Sinuosidal 00133 }; 00134 00146 static QImage gradient(const QSize &size, const QColor &ca, 00147 const QColor &cb, GradientType type, int ncols=3); 00148 00163 static QImage unbalancedGradient(const QSize &size, const QColor &ca, 00164 const QColor &cb, GradientType type, int xfactor = 100, 00165 int yfactor = 100, int ncols = 3); 00166 00183 static QImage& blend(const QColor& clr, QImage& dst, float opacity); 00184 00201 static QImage& blend(QImage& src, QImage& dst, float opacity); 00202 00217 static QImage& blend(QImage &image, float initial_intensity, 00218 const QColor &bgnd, GradientType eff, 00219 bool anti_dir=false); 00220 00231 static QImage& blend(QImage &image1,QImage &image2, 00232 GradientType gt, int xf=100, int yf=100); 00233 00246 static QImage& blend(QImage &image1, QImage &image2, 00247 QImage &blendImage, RGBComponent channel); 00248 00256 static bool blend(const QImage & upper, const QImage & lower, QImage & output); 00257 // Not yet... static bool blend(const QImage & image1, const QImage & image2, QImage & output, const QRect & destRect); 00258 00275 static bool blend(int &x, int &y, const QImage & upper, const QImage & lower, QImage & output); 00276 00287 static bool blendOnLower(int x, int y, const QImage & upper, const QImage & lower); 00288 00301 static void blendOnLower(const QImage &upper, const QPoint &upperOffset, 00302 QImage &lower, const QRect &lowerRect); 00303 00318 static void blendOnLower(const QImage &upper, const QPoint &upperOffset, 00319 QImage &lower, const QRect &lowerRect, float opacity); 00320 00326 enum Disposition { NoImage = 0, 00327 Centered, 00328 Tiled, 00329 CenterTiled, 00330 CenteredMaxpect, 00331 TiledMaxpect, 00332 Scaled, 00333 CenteredAutoFit 00334 }; 00335 00350 static QRect computeDestinationRect(const QSize &lowerSize, 00351 Disposition disposition, QImage &upper); 00352 00359 static void blendOnLower(QImage &upper, QImage &lower, 00360 Disposition disposition, float opacity); 00361 00371 static QImage& channelIntensity(QImage &image, float percent, 00372 RGBComponent channel); 00373 00384 static QImage& fade(QImage &image, float val, const QColor &color); 00385 00386 00397 static QImage& flatten(QImage &image, const QColor &ca, 00398 const QColor &cb, int ncols=0); 00399 00408 static QImage& hash(QImage &image, Lighting lite=NorthLite, 00409 unsigned int spacing=0); 00410 00424 static QImage& intensity(QImage &image, float percent); 00425 00437 static QImage& modulate(QImage &image, QImage &modImage, bool reverse, 00438 ModulationType type, int factor, RGBComponent channel); 00439 00449 static QImage& toGray(QImage &image, bool fast = false); 00450 00458 static QImage& desaturate(QImage &image, float desat = 0.3); 00459 00469 static QImage& contrast(QImage &image, int c); 00470 00480 static QImage& dither(QImage &image, const QColor *palette, int size); 00481 00488 static QImage& selectedImage( QImage &img, const QColor &col ); 00489 00501 static void contrastHSV(QImage &img, bool sharpen=true); 00502 00509 static void normalize(QImage &img); 00510 00517 static void equalize(QImage &img); 00518 00528 static void threshold(QImage &img, unsigned int value=128); 00529 00538 static void solarize(QImage &img, double factor=50.0); 00539 00553 static QImage emboss(QImage &src, double radius, double sigma); 00554 00558 static QImage emboss(QImage &src); 00559 00568 static QImage despeckle(QImage &src); 00569 00581 static QImage charcoal(QImage &src, double radius, double sigma); 00582 00587 static QImage charcoal(QImage &src, double factor=50.0); 00588 00597 static QImage rotate(QImage &src, RotateDirection r); 00598 00610 static QImage sample(QImage &src, int w, int h); 00611 00620 static QImage addNoise(QImage &src, NoiseType type = GaussianNoise); 00621 00633 static QImage blur(QImage &src, double radius, double sigma); 00634 00639 static QImage blur(QImage &src, double factor=50.0); 00640 00651 static QImage edge(QImage &src, double radius); 00652 00663 static QImage implode(QImage &src, double factor=30.0, 00664 unsigned int background = 0xFFFFFFFF); 00665 00675 static QImage oilPaintConvolve(QImage &src, double radius); 00676 00681 static QImage oilPaint(QImage &src, int radius=3); 00682 00694 static QImage sharpen(QImage &src, double radius, double sigma); 00695 00700 static QImage sharpen(QImage &src, double factor=30.0); 00701 00710 static QImage spread(QImage &src, unsigned int amount=3); 00711 00722 static QImage shade(QImage &src, bool color_shading=true, double azimuth=30.0, 00723 double elevation=30.0); 00734 static QImage swirl(QImage &src, double degrees=50.0, unsigned int background = 00735 0xFFFFFFFF); 00736 00748 static QImage wave(QImage &src, double amplitude=25.0, double frequency=150.0, 00749 unsigned int background = 0xFFFFFFFF); 00750 00771 static QImage bumpmap(QImage &img, QImage &map, double azimuth, double elevation, 00772 int depth, int xofs, int yofs, int waterlevel, 00773 int ambient, bool compensate, bool invert, 00774 BumpmapType type, bool tiled); 00775 00776 private: 00777 00782 static unsigned int lHash(unsigned int c); 00783 static unsigned int uHash(unsigned int c); 00784 00788 static int nearestColor( int r, int g, int b, const QColor *pal, int size ); 00789 00790 static void hull(const int x_offset, const int y_offset, const int polarity, 00791 const int width, const int height, 00792 unsigned int *f, unsigned int *g); 00793 static unsigned int generateNoise(unsigned int pixel, NoiseType type); 00794 static unsigned int interpolateColor(QImage *image, double x, double y, 00795 unsigned int background); 00796 /* Various convolve routines */ 00797 static int getOptimalKernelWidth(double radius, double sigma); 00798 static bool convolveImage(QImage *image, QImage *dest, 00799 const unsigned int order, 00800 const double *kernel); 00801 static void blurScanLine(double *kernel, int width, 00802 unsigned int *src, unsigned int *dest, 00803 int columns); 00804 static int getBlurKernel(int width, double sigma, double **kernel); 00805 }; 00806 00807 #endif