home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kimageeffect.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  31.1 KB  |  808 lines

  1. /* This file is part of the KDE libraries
  2.  Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@interaccess.com>
  3.  (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
  4.  (C) 1998, 1999 Dirk Mueller <mueller@kde.org>
  5.  
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9.  
  10. 1. Redistributions of source code must retain the above copyright
  11.    notice, this list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright
  13.    notice, this list of conditions and the following disclaimer in the
  14.    documentation and/or other materials provided with the distribution.
  15.  
  16. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26.  
  27. */
  28.  
  29. // $Id: kimageeffect.h 399215 2005-03-20 14:33:45Z mueller $
  30.  
  31. #ifndef __KIMAGE_EFFECT_H
  32. #define __KIMAGE_EFFECT_H
  33.  
  34. #include <kdelibs_export.h>
  35.  
  36. class QImage;
  37. class QSize;
  38. class QColor;
  39. class QPoint;
  40. class QRect;
  41.  
  42. /**
  43.  * This class includes various QImage based graphical effects.
  44.  *
  45.  * Everything is
  46.  * static, so there is no need to create an instance of this class. You can
  47.  * just call the static methods. They are encapsulated here merely to provide
  48.  * a common namespace.
  49.  */
  50. class KDEFX_EXPORT KImageEffect
  51. {
  52. public:
  53.     /**
  54.      * This enum provides a gradient type specification
  55.      * @see KImageEffect::blend(), KImageEffect::gradient(),
  56.      * KImageEffect::unbalancedGradient()
  57.      */
  58.     enum GradientType { VerticalGradient,
  59.             HorizontalGradient,
  60.                         DiagonalGradient,
  61.             CrossDiagonalGradient,
  62.                         PyramidGradient,
  63.             RectangleGradient,
  64.                         PipeCrossGradient,
  65.             EllipticGradient
  66.     };
  67.  
  68.     /**
  69.      * This enum provides a RGB channel specification
  70.      * @see KImageEffect::blend(), KImageEffect::channelIntensity(),
  71.      * KImageEffect::modulate()
  72.      */
  73.     enum RGBComponent { Red,   //!< Red channel
  74.             Green, //!< Green channel
  75.             Blue,  //!< Blue channel
  76.             Gray,  //!< Grey channel
  77.             All    //!< All channels
  78.     };
  79.  
  80.     /**
  81.      * This enum provides a lighting direction specification
  82.      * @see KImageEffect::hash()
  83.      */
  84.     enum Lighting {NorthLite, //!< Lighting from the top of the image
  85.            NWLite,    //!< Lighting from the top left of the image
  86.            WestLite,  //!< Lighting from the left of the image
  87.            SWLite,    //!< Lighting from the bottom left of the image
  88.                    SouthLite, //!< Lighting from the bottom of the image
  89.            SELite,    //!< Lighting from the bottom right of the image
  90.            EastLite,  //!< Lighting from the right of the image
  91.            NELite     //!< Lighting from the top right of the image
  92.     };
  93.  
  94.     /**
  95.      * This enum provides a modulation type specification
  96.      * @see KImageEffect::modulate()
  97.      */
  98.     enum ModulationType { Intensity,  //!< Modulate image intensity
  99.               Saturation, //!< Modulate image saturation
  100.               HueShift,   //!< Modulate image hue
  101.               Contrast    //!< Modulate image contrast
  102.     };
  103.  
  104.     /**
  105.      * This enum provides a noise type specification
  106.      * @see KImageEffect::addNoise()
  107.      */
  108.     enum NoiseType { UniformNoise=0,              //!< Uniform distribution
  109.              GaussianNoise,               //!< Gaussian distribution
  110.              MultiplicativeGaussianNoise, //!< Multiplicative Gaussian distribution
  111.                      ImpulseNoise,                //!< Impulse distribution
  112.              LaplacianNoise,              //!< Laplacian distribution
  113.              PoissonNoise                 //!< Poisson distribution
  114.     };
  115.  
  116.     /**
  117.      * This enum provides a rotation specification.
  118.      * @see KImageEffect::rotate()
  119.      */
  120.     enum RotateDirection{ Rotate90,  //!< Rotate 90 degrees to the right.
  121.               Rotate180, //!< Rotate 180 degrees.
  122.               Rotate270  //!< Rotate 90 degrees to the left.
  123.     };
  124.  
  125.     /**
  126.      * This enum lists possible bumpmapping implementations.
  127.      * @see KImageEffect::bumpmap()
  128.      */
  129.     enum BumpmapType {
  130.         Linear,
  131.         Spherical,
  132.         Sinuosidal
  133.     };
  134.  
  135.     /**
  136.      * Create a gradient from color a to color b of the specified type.
  137.      *
  138.      * @param size The desired size of the gradient.
  139.      * @param ca Color a
  140.      * @param cb Color b
  141.      * @param type The type of gradient.
  142.      * @param ncols The number of colors to use when not running on a
  143.      * truecolor display. The gradient will be dithered to this number of
  144.      * colors. Pass 0 to prevent dithering.
  145.      */
  146.     static QImage gradient(const QSize &size, const QColor &ca,
  147.                            const QColor &cb, GradientType type, int ncols=3);
  148.  
  149.     /**
  150.      * Create an unbalanced gradient.
  151.      *
  152.      * An unbalanced gradient is a gradient where the transition from
  153.      * color a to color b is not linear, but in this case, exponential.
  154.      *
  155.      * @param size The desired size of the gradient.
  156.      * @param ca Color a
  157.      * @param cb Color b
  158.      * @param type The type of gradient.
  159.      * @param xfactor The x decay length. Use a value between -200 and 200.
  160.      * @param yfactor The y decay length.
  161.      * @param ncols The number of colors. See KImageEffect:gradient.
  162.      */
  163.     static QImage unbalancedGradient(const QSize &size, const QColor &ca,
  164.         const QColor &cb, GradientType type, int xfactor = 100,
  165.         int yfactor = 100, int ncols = 3);
  166.  
  167.     /**
  168.      * Blends a color into the destination image, using an opacity
  169.      * value for blending one into another. Very fast direct pixel
  170.      * manipulation is used.
  171.      *
  172.      * This function uses MMX and SSE2 instructions to blend the
  173.      * image on processors that support it.
  174.      *
  175.      * @param clr source color to be blended into the destination image.
  176.      * @param dst destination image in which the source will be blended into.
  177.      * @param opacity opacity (between 0.0 and 1.0) which determines how much
  178.      *             the source color will be blended into the destination image.
  179.      * @return The destination image (dst) containing the result.
  180.      * @author Karol Szwed (gallium@kde.org)
  181.      * @author Fredrik Höglund (fredrik@kde.org)
  182.      */
  183.     static QImage& blend(const QColor& clr, QImage& dst, float opacity);
  184.  
  185.     /**
  186.      * Blend the src image into the destination image, using an opacity
  187.      * value for blending one into another. Very fast direct pixel
  188.      * manipulation is used.
  189.      *
  190.      * This function uses MMX and SSE2 instructions to blend the
  191.      * images on processors that support it.
  192.      *
  193.      * @param src source image to be blended into the destination image.
  194.      * @param dst destination image in which the source will be blended into.
  195.      * @param opacity opacity (between 0.0 and 1.0) which determines how much
  196.      *             the source image will be blended into the destination image.
  197.      * @return The destination image (dst) containing the result.
  198.      * @author Karol Szwed (gallium@kde.org)
  199.      * @author Fredrik Höglund (fredrik@kde.org)
  200.      */
  201.     static QImage& blend(QImage& src, QImage& dst, float opacity);
  202.  
  203.     /**
  204.      * Blend the provided image into a background of the indicated color.
  205.      *
  206.      * @param initial_intensity this parameter takes values from -1 to 1:
  207.      *              a) if positive: how much to fade the image in its
  208.      *                              less affected spot
  209.      *              b) if negative: roughly indicates how much of the image
  210.      *                              remains unaffected
  211.      * @param bgnd indicates the color of the background to blend in
  212.      * @param eff lets you choose what kind of blending you like
  213.      * @param anti_dir blend in the opposite direction (makes no much sense
  214.      *                  with concentric blending effects)
  215.      * @param image must be 32bpp
  216.      */
  217.     static QImage& blend(QImage &image, float initial_intensity,
  218.                       const QColor &bgnd, GradientType eff,
  219.                       bool anti_dir=false);
  220.  
  221.     /**
  222.      * Blend an image into another one, using a gradient type
  223.      * for blending from one to another.
  224.      *
  225.      * @param image1 source1 and result of blending
  226.      * @param image2 source2 of blending
  227.      * @param gt gradient type for blending between source1 and source2
  228.      * @param xf x decay length for unbalanced gradient tpye
  229.      * @param yf y decay length for unbalanced gradient tpye
  230.      */
  231.     static QImage& blend(QImage &image1,QImage &image2,
  232.              GradientType gt, int xf=100, int yf=100);
  233.  
  234.     /**
  235.      * Blend an image into another one, using a color channel of a
  236.      * third image for the decision of blending from one to another.
  237.      *
  238.      * @param image1 Source 1 and result of blending
  239.      * @param image2 Source 2 of blending
  240.      * @param blendImage If the gray value of of pixel is 0, the result
  241.      *               for this pixel is that of image1; for a gray value
  242.      *               of 1, the pixel of image2 is used; for a value
  243.      *               in between, a corresponding blending is used.
  244.      * @param channel The RBG channel to use for the blending decision.
  245.      */
  246.     static QImage& blend(QImage &image1, QImage &image2,
  247.              QImage &blendImage, RGBComponent channel);
  248.  
  249.     /**
  250.      * Blend an image into another one, using alpha in the expected way.
  251.      * @param upper the "upper" image
  252.      * @param lower the "lower" image
  253.      * @param output the target image
  254.      * @author Rik Hemsley (rikkus) <rik@kde.org>
  255.      */
  256.     static bool blend(const QImage & upper, const QImage & lower, QImage & output);
  257. // Not yet...    static bool blend(const QImage & image1, const QImage & image2, QImage & output, const QRect & destRect);
  258.  
  259.     /**
  260.      * Blend an image into another one, using alpha in the expected way and
  261.      * over coordinates @p x and @p y with respect to the lower image.
  262.      * The output is a QImage which is the @p upper image already blended
  263.      * with the @p lower one, so its size will be (in general) the same than
  264.      * @p upper instead of the same size than @p lower like the method above.
  265.      * In fact, the size of @p output is like upper's one only when it can be
  266.      * painted on lower, if there has to be some clipping, output's size will
  267.      * be the clipped area and x and y will be set to the correct up-left corner
  268.      * where the clipped rectangle begins.
  269.      * @param x x-coordinate of lower image
  270.      * @param y y-coordinate of lower image
  271.      * @param upper the "upper" image
  272.      * @param lower the "lower" image
  273.      * @param output the target image
  274.      */
  275.     static bool blend(int &x, int &y, const QImage & upper, const QImage & lower, QImage & output);
  276.  
  277.     /**
  278.      * Blend an image into another one, using alpha in the expected way and
  279.      * over coordinates @p x and @p y with respect to the lower image.
  280.      * The output is painted in the own @p lower image. This is an optimization
  281.      * of the blend method above provided by convenience.
  282.      * @param x x-coordinate of lower image
  283.      * @param y y-coordinate of lower image
  284.      * @param upper the "upper" image
  285.      * @param lower the "lower" image, which becomes the output image
  286.      */
  287.     static bool blendOnLower(int x, int y, const QImage & upper, const QImage & lower);
  288.  
  289.     /**
  290.      * Blend part of an image into part of another, using the alpha channel in
  291.      * the expected way.
  292.      * Note that the destination rectangle will be correctly clipped.
  293.      *
  294.      * @param upper the "upper" image
  295.      * @param upperOffset Offset for the part of the upper image to be used.
  296.      * @param lower the "lower" image
  297.      * @param lowerRect Rectangle for the part of the lower image where the
  298.      *                  blending will occur.
  299.      * @since 3.2
  300.      */
  301.     static void blendOnLower(const QImage &upper, const QPoint &upperOffset,
  302.                              QImage &lower, const QRect &lowerRect);
  303.  
  304.     /**
  305.      * Blend part of an image into part of another, using the opacity value
  306.      * and the alpha channel in the expected way.
  307.      * Note that the destination rectangle will be correctly clipped.
  308.      *
  309.      * @param upper the "upper" image
  310.      * @param upperOffset Offset for the part of the upper image to be used.
  311.      * @param lower the "lower" image
  312.      * @param lowerRect Rectangle for the part of the lower image where the
  313.      *                  blending will occur.
  314.      * @param opacity Opacity (between 0.0 and 1.0) which determines how much
  315.      *             the source image will be blended into the destination image.
  316.      * @since 3.2
  317.      */
  318.     static void blendOnLower(const QImage &upper, const QPoint &upperOffset,
  319.                              QImage &lower, const QRect &lowerRect, float opacity);
  320.  
  321.     /**
  322.      * Disposition of a source image on top of a destination image.
  323.      * @see KImageEffect::computeDestinationRect, KImageEffect::blendOnLower
  324.      * @since 3.2
  325.      */
  326.     enum Disposition { NoImage = 0, //!< Don't overlay
  327.                Centered,    //!< Center top image on botton image
  328.                Tiled,       //!< Tile top image on bottom image
  329.                CenterTiled, //!< Center and tile top image on bottom image
  330.                CenteredMaxpect, //!< Center and scale aspect
  331.                TiledMaxpect, //!< Tile and scale aspect
  332.                Scaled,      //!< Scale
  333.                CenteredAutoFit //!< Center and scale or scale aspect
  334.     };
  335.  
  336.     /**
  337.      * Compute the destination rectangle where to draw the upper image on top
  338.      * of another image using the given disposition. For tiled
  339.      * disposition, the rectangle should be duplicated on the whole area to
  340.      * obtained the wanted effect.
  341.      *
  342.      * @param lowerSize The size of the destination image.
  343.      * @param disposition The wanted disposition.
  344.      * @param upper The upper image. Note that this image may be scaled to
  345.      *               adjust to the requested disposition.
  346.      *
  347.      * @return the computed rectangle. Its size may exceed @e lowerSize.
  348.      * @since 3.2
  349.      */
  350.     static QRect computeDestinationRect(const QSize &lowerSize,
  351.                                       Disposition disposition, QImage &upper);
  352.  
  353.     /**
  354.      * Blend an image on top of another using a given disposition and a given
  355.      * opacity. The alpha channel of the upper image is used in the expected
  356.      * way. Beware the upper image may be modified.
  357.      * @since 3.2
  358.      */
  359.     static void blendOnLower(QImage &upper, QImage &lower,
  360.                              Disposition disposition, float opacity);
  361.  
  362.     /**
  363.      * Modifies the intensity of a pixmap's RGB channel component.
  364.      *
  365.      * @param image The QImage to process.
  366.      * @param percent Percent value. Use a negative value to dim.
  367.      * @param channel Which channel(s) should be modified
  368.      * @return The @p image, provided for convenience.
  369.      * @author Daniel M. Duley (mosfet)
  370.      */
  371.     static QImage& channelIntensity(QImage &image, float percent,
  372.                                     RGBComponent channel);
  373.  
  374.     /**
  375.      * Fade an image to a certain background color.
  376.      *
  377.      * The number of colors will not be changed.
  378.      *
  379.      * @param image The QImage to process.
  380.      * @param val   The strength of the effect. 0 <= val <= 1.
  381.      * @param color The background color.
  382.      * @return Returns the image(), provided for convenience.
  383.      */
  384.     static QImage& fade(QImage &image, float val, const QColor &color);
  385.  
  386.  
  387.     /**
  388.      * This recolors a pixmap. The most dark color will become color a,
  389.      * the most bright one color b, and in between.
  390.      *
  391.      * @param image A QImage to process.
  392.      * @param ca Color a
  393.      * @param cb Color b
  394.      * @param ncols The number of colors to dither the image to.
  395.      * Pass 0 to prevent dithering.
  396.      */
  397.     static QImage& flatten(QImage &image, const QColor &ca,
  398.            const QColor &cb, int ncols=0);
  399.  
  400.     /**
  401.      * Build a hash on any given QImage
  402.      *
  403.      * @param image The QImage to process
  404.      * @param lite The hash faces the indicated lighting (cardinal poles).
  405.      * @param spacing How many unmodified pixels in between hashes.
  406.      * @return Returns the image(), provided for convenience.
  407.      */
  408.     static QImage& hash(QImage &image, Lighting lite=NorthLite,
  409.                         unsigned int spacing=0);
  410.  
  411.     /**
  412.      * Either brighten or dim the image by a specified percent.
  413.      * For example, .50 will modify the colors by 50%.
  414.      *
  415.      * This function uses MMX instructions to process the image
  416.      * on processors that support it.
  417.      *
  418.      * @param image The QImage to process.
  419.      * @param percent The percent value. Use a negative value to dim.
  420.      * @return Returns The image(), provided for convenience.
  421.      * @author Daniel M. Duley (mosfet)
  422.      * @author Benjamin Roe (ben@benroe.com)
  423.      */
  424.     static QImage& intensity(QImage &image, float percent);
  425.  
  426.     /**
  427.      * Modulate the image with a color channel of another image.
  428.      *
  429.      * @param image The QImage to modulate and result.
  430.      * @param modImage The QImage to use for modulation.
  431.      * @param reverse Invert the meaning of image/modImage; result is image!
  432.      * @param type The modulation Type to use.
  433.      * @param factor The modulation amplitude; with 0 no effect [-200;200].
  434.      * @param channel The RBG channel of image2 to use for modulation.
  435.      * @return Returns the image(), provided for convenience.
  436.      */
  437.     static QImage& modulate(QImage &image, QImage &modImage, bool reverse,
  438.         ModulationType type, int factor, RGBComponent channel);
  439.  
  440.     /**
  441.      * Convert an image to grayscale.
  442.      *
  443.      * @param image The QImage to process.
  444.      * @param fast Set to @p true in order to use a faster but non-photographic
  445.      * quality algorithm. Appropriate for things such as toolbar icons.
  446.      * @return Returns the image(), provided for convenience.
  447.      * @author Daniel M. Duley (mosfet)
  448.      */
  449.     static QImage& toGray(QImage &image, bool fast = false);
  450.  
  451.     /**
  452.      * Desaturate an image evenly.
  453.      *
  454.      * @param image The QImage to process.
  455.      * @param desat A value between 0 and 1 setting the degree of desaturation
  456.      * @return Returns the image(), provided for convenience.
  457.      */
  458.     static QImage& desaturate(QImage &image, float desat = 0.3);
  459.  
  460.     /**
  461.      * Fast, but low quality contrast of an image. Also see contrastHSV.
  462.      *
  463.      * @param image The QImage to process.
  464.      * @param c A contrast value between -255 to 255.
  465.      * @return The image(), provided for convenience.
  466.      * @author Daniel M. Duley (mosfet)
  467.      * ### KDE 4: remove
  468.      */
  469.     static QImage& contrast(QImage &image, int c);
  470.  
  471.     /**
  472.      * Dither an image using Floyd-Steinberg dithering for low-color
  473.      * situations.
  474.      *
  475.      * @param image The QImage to process.
  476.      * @param palette The color palette to use
  477.      * @param size The size of the palette
  478.      * @return Returns the image(), provided for convenience.
  479.      */
  480.     static QImage& dither(QImage &image, const QColor *palette, int size);
  481.  
  482.     /**
  483.      * Calculate the image for a selected image, for instance a selected icon
  484.      * on the desktop.
  485.      * @param img the QImage to select
  486.      * @param col the selected color, usually from QColorGroup::highlight().
  487.      */
  488.     static QImage& selectedImage( QImage &img, const QColor &col );
  489.  
  490.     /**
  491.      * High quality, expensive HSV contrast. You can do a faster one by just
  492.      * taking a intensity threshold (ie: 128) and incrementing RGB color
  493.      * channels above it and decrementing those below it, but this gives much
  494.      * better results.
  495.      *
  496.      * @param img The QImage to process.
  497.      * @param sharpen If true sharpness is increase, (spiffed). Otherwise
  498.      * it is decreased, (dulled).
  499.      * @author Daniel M. Duley (mosfet)
  500.      */
  501.     static void contrastHSV(QImage &img, bool sharpen=true);
  502.  
  503.     /**
  504.      * Normalises the pixel values to span the full range of color values.
  505.      * This is a contrast enhancement technique.
  506.      * @param img the image that is normalised
  507.      * @author Daniel M. Duley (mosfet)
  508.      */
  509.     static void normalize(QImage &img);
  510.  
  511.     /**
  512.      * Performs histogram equalisation on the reference
  513.      * image.
  514.      * @param img the image that is equalised
  515.      * @author Daniel M. Duley (mosfet)
  516.      */
  517.     static void equalize(QImage &img);
  518.  
  519.     /**
  520.      * Thresholds the reference image. You can also threshold images by using
  521.      * ThresholdDither in the various QPixmap/QImage convert methods, but this
  522.      * lets you specify a threshold value.
  523.      *
  524.      * @param img The QImage to process.
  525.      * @param value The threshold value.
  526.      * @author Daniel M. Duley (mosfet)
  527.      */
  528.     static void threshold(QImage &img, unsigned int value=128);
  529.  
  530.     /**
  531.      * Produces a 'solarization' effect seen when exposing a photographic
  532.      * film to light during the development process.
  533.      *
  534.      * @param img The QImage to process.
  535.      * @param factor The extent of the solarization (0-99.9)
  536.      * @author Daniel M. Duley (mosfet)
  537.      */
  538.     static void solarize(QImage &img, double factor=50.0);
  539.  
  540.     /**
  541.      * Embosses the source image. This involves highlighting the edges
  542.      * and applying various other enhancements in order to get a metal
  543.      * effect.
  544.      *
  545.      * @param src The QImage to process.
  546.      * @param radius The radius of the gaussian not counting the
  547.      * center pixel. Use 0 and a suitable radius will be automatically used.
  548.      * @param sigma The standard deviation of the gaussian. Use 1 if you're not
  549.      * sure.
  550.      * @return The embossed image. The original is not changed.
  551.      * @author Daniel M. Duley (mosfet)
  552.      */
  553.     static QImage emboss(QImage &src, double radius, double sigma);
  554.  
  555.     /**
  556.      * Convenience method.
  557.      */
  558.     static QImage emboss(QImage &src);
  559.  
  560.     /**
  561.      * Minimizes speckle noise in the source image using the 8 hull
  562.      * algorithm.
  563.      *
  564.      * @param src The QImage to process.
  565.      * @return The despeckled image. The original is not changed.
  566.      * @author Daniel M. Duley (mosfet)
  567.      */
  568.     static QImage despeckle(QImage &src);
  569.  
  570.     /**
  571.      * Produces a neat little "charcoal" effect.
  572.      *
  573.      * @param src The QImage to process.
  574.      * @param radius The radius of the gaussian not counting the
  575.      * center pixel. Use 0 and a suitable radius will be automatically used.
  576.      * @param sigma The standard deviation of the gaussian. Use 1 if you're not
  577.      * sure.
  578.      * @return The charcoal image. The original is not changed.
  579.      * @author Daniel M. Duley (mosfet)
  580.      */
  581.     static QImage charcoal(QImage &src, double radius, double sigma);
  582.  
  583.     /**
  584.      * This is provided for binary compatability only! Use the above method
  585.      * with a radius and sigma instead!
  586.      */
  587.      static QImage charcoal(QImage &src, double factor=50.0);
  588.  
  589.     /**
  590.      * Rotates the image by the specified amount
  591.      *
  592.      * @param src The QImage to process.
  593.      * @param r The rotate direction.
  594.      * @return The rotated image. The original is not changed.
  595.      * @author Daniel M. Duley (mosfet)
  596.      */
  597.     static QImage rotate(QImage &src, RotateDirection r);
  598.  
  599.     /**
  600.      * Scales an image using simple pixel sampling. This does not produce
  601.      * nearly as nice a result as QImage::smoothScale(), but has the
  602.      * advantage of being much faster - only a few milliseconds.
  603.      *
  604.      * @param src The QImage to process.
  605.      * @param w The new width.
  606.      * @param h The new height.
  607.      * @return The scaled image. The original is not changed.
  608.      * @author Daniel M. Duley (mosfet)
  609.      */
  610.     static QImage sample(QImage &src, int w, int h);
  611.  
  612.     /**
  613.      * Adds noise to an image.
  614.      *
  615.      * @param src The QImage to process.
  616.      * @param type The algorithm used to generate the noise.
  617.      * @return The image with noise added. The original is not changed.
  618.      * @author Daniel M. Duley (mosfet)
  619.      */
  620.     static QImage addNoise(QImage &src, NoiseType type = GaussianNoise);
  621.  
  622.     /**
  623.      * Blurs an image by convolving pixel neighborhoods.
  624.      *
  625.      * @param src The QImage to process.
  626.      * @param radius The radius of the gaussian not counting the
  627.      * center pixel. Use 0 and a suitable radius will be automatically used.
  628.      * @param sigma The standard deviation of the gaussian. Use 1 if you're not
  629.      * sure.
  630.      * @return The blurred image. The original is not changed.
  631.      * @author Daniel M. Duley (mosfet)
  632.      */
  633.     static QImage blur(QImage &src, double radius, double sigma);
  634.  
  635.     /**
  636.      * This is provided for binary compatability only! Use the above method
  637.      * with a radius and sigma instead!
  638.      */
  639.     static QImage blur(QImage &src, double factor=50.0);
  640.  
  641.     /**
  642.      * Detects edges in an image using pixel neighborhoods and an edge
  643.      * detection mask.
  644.      *
  645.      * @param src The QImage to process.
  646.      * @param radius The radius of the gaussian not counting the
  647.      * center pixel. Use 0 and a suitable radius will be automatically used.
  648.      * @return The image with edges detected. The original is not changed.
  649.      * @author Daniel M. Duley (mosfet)
  650.      */
  651.     static QImage edge(QImage &src, double radius);
  652.  
  653.     /**
  654.      * Implodes an image by a specified percent.
  655.      *
  656.      * @param src The QImage to process.
  657.      * @param factor The extent of the implosion.
  658.      * @param background An RGBA value to use for the background. After the
  659.      * effect some pixels may be "empty". This value is used for those pixels.
  660.      * @return The imploded image. The original is not changed.
  661.      * @author Daniel M. Duley (mosfet)
  662.      */
  663.     static QImage implode(QImage &src, double factor=30.0,
  664.                    unsigned int background = 0xFFFFFFFF);
  665.  
  666.     /**
  667.      * Produces an oil painting effect.
  668.      *
  669.      * @param src The QImage to process.
  670.      * @param radius The radius of the gaussian not counting the
  671.      * center pixel. Use 0 and a suitable radius will be automatically used.
  672.      * @return The new image. The original is not changed.
  673.      * @author Daniel M. Duley (mosfet)
  674.      */
  675.     static QImage oilPaintConvolve(QImage &src, double radius);
  676.  
  677.     /**
  678.      * This is provided for binary compatability only! Use the above method
  679.      * instead!
  680.      */
  681.     static QImage oilPaint(QImage &src, int radius=3);
  682.  
  683.     /**
  684.      * Sharpens the pixels in the image using pixel neighborhoods.
  685.      *
  686.      * @param src The QImage to process.
  687.      * @param radius The radius of the gaussian not counting the
  688.      * center pixel. Use 0 and a suitable radius will be automatically used.
  689.      * @param sigma The standard deviation of the gaussian. Use 1 if you're not
  690.      * sure.
  691.      * @return The sharpened image. The original is not changed.
  692.      * @author Daniel M. Duley (mosfet)
  693.      */
  694.     static QImage sharpen(QImage &src, double radius, double sigma);
  695.  
  696.     /**
  697.      * This is provided for binary compatability only! Use the above method
  698.      * instead!
  699.      */
  700.     static QImage sharpen(QImage &src, double factor=30.0);
  701.  
  702.     /**
  703.      * Randomly displaces pixels.
  704.      *
  705.      * @param src The QImage to process.
  706.      * @param amount The vicinity for choosing a random pixel to swap.
  707.      * @return The image with pixels displaced. The original is not changed.
  708.      * @author Daniel M. Duley (mosfet)
  709.      */
  710.     static QImage spread(QImage &src, unsigned int amount=3);
  711.  
  712.     /**
  713.      * Shades the image using a distance light source.
  714.      *
  715.      * @param src The QImage to process.
  716.      * @param color_shading If true do color shading, otherwise do grayscale.
  717.      * @param azimuth Determines the light source and direction.
  718.      * @param elevation Determines the light source and direction.
  719.      * @return The shaded image. The original is not changed.
  720.      * @author Daniel M. Duley (mosfet)
  721.      */
  722.     static QImage shade(QImage &src, bool color_shading=true, double azimuth=30.0,
  723.                         double elevation=30.0);
  724.     /**
  725.      * Swirls the image by a specified amount
  726.      *
  727.      * @param src The QImage to process.
  728.      * @param degrees The tightness of the swirl.
  729.      * @param background An RGBA value to use for the background. After the
  730.      * effect some pixels may be "empty". This value is used for those pixels.
  731.      * @return The swirled image. The original is not changed.
  732.      * @author Daniel M. Duley (mosfet)
  733.      */
  734.     static QImage swirl(QImage &src, double degrees=50.0, unsigned int background =
  735.                          0xFFFFFFFF);
  736.  
  737.     /**
  738.      * Modifies the pixels along a sine wave.
  739.      *
  740.      * @param src        The QImage to process.
  741.      * @param amplitude  The amplitude of the sine wave.
  742.      * @param frequency  The frequency of the sine wave.
  743.      * @param background An RGBA value to use for the background. After the
  744.      * effect some pixels may be "empty". This value is used for those pixels.
  745.      * @return The new image. The original is not changed.
  746.      * @author Daniel M. Duley (mosfet)
  747.      */
  748.     static QImage wave(QImage &src, double amplitude=25.0, double frequency=150.0,
  749.                         unsigned int background = 0xFFFFFFFF);
  750.  
  751.     /**
  752.      * A bumpmapping algorithm.
  753.      *
  754.      * @param img the image you want bumpmap
  755.      * @param map the map used
  756.      * @param azimuth azimuth
  757.      * @param elevation elevation
  758.      * @param depth depth (not the depth of the image, but of the map)
  759.      * @param xofs X offset
  760.      * @param yofs Y offset
  761.      * @param waterlevel level that full transparency should represent
  762.      * @param ambient ambient lighting factor
  763.      * @param compensate compensate for darkening
  764.      * @param invert invert bumpmap
  765.      * @param type type of the bumpmap
  766.      * @param tiled tile the bumpmap over the image through the Y offset
  767.      *
  768.      * @return The destination image (dst) containing the result.
  769.      * @author Zack Rusin <zack@kde.org>
  770.      */
  771.     static QImage bumpmap(QImage &img, QImage &map, double azimuth, double elevation,
  772.                           int depth, int xofs, int yofs, int waterlevel,
  773.                           int ambient, bool compensate, bool invert,
  774.                           BumpmapType type, bool tiled);
  775.  
  776. private:
  777.  
  778.     /**
  779.      * Helper function to fast calc some altered (lighten, shaded) colors
  780.      *
  781.      */
  782.     static unsigned int lHash(unsigned int c);
  783.     static unsigned int uHash(unsigned int c);
  784.  
  785.     /**
  786.      * Helper function to find the nearest color to the RBG triplet
  787.      */
  788.     static int nearestColor( int r, int g, int b, const QColor *pal, int size );
  789.  
  790.     static void hull(const int x_offset, const int y_offset, const int polarity,
  791.                      const int width, const int height,
  792.                      unsigned int *f, unsigned int *g);
  793.     static unsigned int generateNoise(unsigned int pixel, NoiseType type);
  794.     static unsigned int interpolateColor(QImage *image, double x, double y,
  795.                                          unsigned int background);
  796.     /* Various convolve routines */
  797.     static int getOptimalKernelWidth(double radius, double sigma);
  798.     static bool convolveImage(QImage *image, QImage *dest,
  799.                               const unsigned int order,
  800.                               const double *kernel);
  801.     static void blurScanLine(double *kernel, int width,
  802.                              unsigned int *src, unsigned int *dest,
  803.                              int columns);
  804.     static int getBlurKernel(int width, double sigma, double **kernel);
  805. };
  806.  
  807. #endif
  808.