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 / kpixmapeffect.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  7.9 KB  |  219 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
  3.               (C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
  4.               (C) 1998, 1999 Dirk Mueller <mueller@kde.org>
  5.  
  6. */
  7.  
  8. // $Id: kpixmapeffect.h 399215 2005-03-20 14:33:45Z mueller $
  9.  
  10. #ifndef __KPIXMAP_EFFECT_H
  11. #define __KPIXMAP_EFFECT_H
  12.  
  13. #include <kdelibs_export.h>
  14.  
  15. #include <qsize.h>
  16. class KPixmap;
  17. class QColor;
  18.  
  19. /**
  20.  * This class includes various pixmap-based graphical effects.
  21.  *
  22.  * Everything is
  23.  * static, so there is no need to create an instance of this class. You can
  24.  * just call the static methods. They are encapsulated here merely to provide
  25.  * a common namespace.
  26.  */
  27. class KDEFX_EXPORT KPixmapEffect
  28. {
  29. public:
  30.     enum GradientType { VerticalGradient, HorizontalGradient,
  31.             DiagonalGradient, CrossDiagonalGradient,
  32.             PyramidGradient, RectangleGradient,
  33.             PipeCrossGradient, EllipticGradient };
  34.     enum RGBComponent { Red, Green, Blue };
  35.  
  36.     enum Lighting {NorthLite, NWLite, WestLite, SWLite,
  37.            SouthLite, SELite, EastLite, NELite};
  38.  
  39.     /**
  40.      * Creates a gradient from color a to color b of the specified type.
  41.      *
  42.      * @param pixmap The pixmap to process.
  43.      * @param ca Color a.
  44.      * @param cb Color b.
  45.      * @param type The type of gradient.
  46.      * @param ncols The number of colors to use when not running on a
  47.      * truecolor display. The gradient will be dithered to this number of
  48.      * colors. Pass 0 to prevent dithering.
  49.      * @return Returns the generated pixmap, for convenience.
  50.      */
  51.     static KPixmap& gradient(KPixmap& pixmap, const QColor &ca, const QColor &cb,
  52.                             GradientType type, int ncols=3);
  53.  
  54.     /**
  55.      * Creates an unbalanced gradient.
  56.      *
  57.      * An unbalanced gradient is a gradient where the transition from
  58.      * color a to color b is not linear, but in this case, exponential.
  59.      *
  60.      * @param pixmap The pixmap that should be written.
  61.      * @param ca Color a.
  62.      * @param cb Color b.
  63.      * @param type The type of gradient.
  64.      * @param xfactor The x decay length. Use a value between -200 and 200.
  65.      * @param yfactor The y decay length.
  66.      * @param ncols The number of colors. See #gradient.
  67.      * @return The generated pixmap, for convencience.
  68.      */
  69.     static KPixmap& unbalancedGradient(KPixmap& pixmap, const QColor &ca,
  70.                    const QColor &cb, GradientType type, int xfactor = 100,
  71.                    int yfactor = 100, int ncols=3);
  72.  
  73.     /**
  74.      * Creates a pixmap of a given size with the given pixmap.
  75.      *
  76.      * if the
  77.      * given size is bigger than the size of the pixmap, the pixmap is
  78.      * tiled.
  79.      *
  80.      * @param pixmap This is the source pixmap
  81.      * @param size   The size the new pixmap should have.
  82.      * @return The generated, tiled pixmap.
  83.      */
  84.     static KPixmap createTiled(const KPixmap& pixmap, QSize size);
  85.  
  86.     /**
  87.      * Either brightens or dims a pixmap by a specified ratio.
  88.      *
  89.      * @param pixmap The pixmap to process.
  90.      * @param ratio The ratio to use. Use negative value to dim.
  91.      * @return Returns The pixmap(), provided for convenience.
  92.      */
  93.     static KPixmap& intensity(KPixmap& pixmap, float ratio);
  94.  
  95.     /**
  96.      * Modifies the intensity of a pixmap's RGB channel component.
  97.      *
  98.      * @param pixmap The pixmap to process.
  99.      * @param ratio value. Use negative value to dim.
  100.      * @param channel Which channel(s) should be modified
  101.      * @return Returns the pixmap(), provided for convenience.
  102.      */
  103.     static KPixmap& channelIntensity(KPixmap& pixmap, float ratio,
  104.                                     RGBComponent channel);
  105.  
  106.     /**
  107.      * Blends the provided pixmap into a background of the indicated color.
  108.      *
  109.      * @param pixmap The pixmap to process.
  110.      * @param initial_intensity this parameter takes values from -1 to 1:
  111.      *              @li If positive, it tells how much to fade the image in its
  112.      *                              less affected spot.
  113.      *              @li If negative, it tells roughly indicates how much of the image
  114.      *                              remains unaffected
  115.      * @param bgnd Indicates the color of the background to blend in.
  116.      * @param eff Lets you choose what kind of blending you like.
  117.      * @param anti_dir Blend in the opposite direction (makes no much sense
  118.      *                  with concentric blending effects).
  119.      * @param ncols The number of colors to dither the pixmap to. Only
  120.      *                  used for 8 bpp pixmaps.
  121.      * @return Returns the pixmap(), provided for convenience.
  122.      */
  123.     static KPixmap& blend(KPixmap& pixmap, float initial_intensity,
  124.                          const QColor &bgnd, GradientType eff,
  125.                          bool anti_dir=false, int ncols=3);
  126.  
  127.     /**
  128.      * Builds a hash on any given pixmap.
  129.      *
  130.      * @param pixmap The pixmap to process.
  131.      * @param lite The hash faces the indicated lighting (cardinal poles)
  132.      * @param spacing How many unmodified pixels inbetween hashes.
  133.      * @param ncols The number of colors to dither the pixmap to.
  134.      * Only used for 8 bpp pixmaps.
  135.      * @return Returns The pixmap(), provided for convenience.
  136.      */
  137.     static KPixmap& hash(KPixmap& pixmap, Lighting lite=NorthLite,
  138.                         unsigned int spacing=0, int ncols=3);
  139.  
  140.     /**
  141.      * Creates a pattern from a pixmap.
  142.      *
  143.      * The given pixmap is "flattened"
  144.      * between color a to color b.
  145.      * Doesn't change the original pixmap.
  146.      *
  147.      * @param pixmap The pixmap to process.
  148.      * @param size The size of the returned pixmap. If @p size is larger than
  149.      * the original, the resulting pixmap will be tiled.
  150.      * @param ca Color a.
  151.      * @param cb Color b.
  152.      * @param ncols The number of colors to use. The image will be
  153.      * dithered to this depth. Pass zero to prevent dithering.
  154.      * @return The resulting pixmap.
  155.      */
  156.     static KPixmap pattern(const KPixmap& pixmap, QSize size,
  157.                    const QColor &ca, const QColor &cb, int ncols=8);
  158.  
  159.     /**
  160.      * Fades a pixmap to a certain color.
  161.      *
  162.      * @param pixmap The pixmap to process.
  163.      * @param val The strength of the effect. 0 <= val <= 1.
  164.      * @param color The color to blend to.
  165.      * @return Returns the pixmap(), provided for convenience.
  166.      */
  167.     static KPixmap& fade(KPixmap& pixmap, double val, const QColor &color);
  168.  
  169.     /**
  170.      * Converts a pixmap to grayscale.
  171.      *
  172.      * @param pixmap The pixmap to process.
  173.      * @param fast Set to @p true in order to use a faster but non-photographic
  174.      * quality algorithm. Appropriate for things such as toolbar icons.
  175.      * @return Returns the pixmap(), provided for convenience.
  176.      */
  177.     static KPixmap& toGray(KPixmap& pixmap, bool fast=false);
  178.  
  179.     /**
  180.      * Desaturates a pixmap.
  181.      *
  182.      * @param pixmap The pixmap to process.
  183.      * @param desat A value between 0 and 1 setting the degree of desaturation
  184.      * @return Returns The pixmap(), provided for convenience.
  185.      */
  186.     static KPixmap& desaturate(KPixmap& pixmap, float desat = 0.3);
  187.  
  188.     /**
  189.      * Modifies the contrast of a pixmap.
  190.      *
  191.      * @param pixmap The pixmap to process.
  192.      * @param c A contrast value between -255 and 255.
  193.      * @return Returns the pixmap(), provided for convenience.
  194.      */
  195.     static KPixmap& contrast(KPixmap& pixmap, int c);
  196.  
  197.     /**
  198.      * Dithers a pixmap using Floyd-Steinberg dithering for low-color
  199.      * situations.
  200.      *
  201.      * @param pixmap The pixmap to process.
  202.      * @param palette The color palette to use.
  203.      * @param size The size of the palette.
  204.      * @return Returns the pixmap(), provided for convenience.
  205.      */
  206.     static KPixmap& dither(KPixmap &pixmap, const QColor *palette, int size);
  207.  
  208.     /**
  209.      * Calculate a 'selected' pixmap, for instance a selected icon
  210.      * on the desktop.
  211.      * @param pixmap the pixmap to select
  212.      * @param col the selected color, usually from QColorGroup::highlight().
  213.      */
  214.     static KPixmap selectedPixmap( const KPixmap &pixmap, const QColor &col );
  215. };
  216.  
  217.  
  218. #endif
  219.