Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KPixmap (./kdelibs/kdecore/kpixmap.h:55)
class KPixmap : public QPixmap
{
public:
enum ColorMode { Auto, Color, Mono, LowColor, WebColor };
enum GradientMode { Horizontal, Vertical, Diagonal, CrossDiagonal };
/**
* Create a null pixmap.
*/
KPixmap() : QPixmap() {};
/**
* Destroy the pixmap.
*/
~KPixmap() {};
/**
* Copy the QPixmap @p pix.
*/
KPixmap(const QPixmap& pix);
/**
* Convert an image and sets this pixmap.
*
* The conversion_flags argument is a bitwise-OR from the
* following choices. The options marked (default) are the
* choice if no other choice from the list is included (they
* are zero):
*
* Color/Mono preference
*
* @li WebColor - If the image has depth 1 and contains
* only black and white pixels then the pixmap becomes monochrome. If
* the pixmap has a depth of 8 bits per pixel then the Netscape
* palette is used for the pixmap color table.
* @li LowColor - If the image has depth 1 and contains only black and
* white pixels then the pixmap becomes monochrome. If the pixmap has a
* depth of 8 bits per pixel and the image does not posess a color table
* that matches the Icon palette a 3x3x3 color cube is used for the
* pixmap color table.
* @li AutoColor (default) - If the image has depth 1 and contains
* only black and white pixels, then the pixmap becomes
* monochrome.
* @li ColorOnly - The pixmap is dithered/converted to the native
* display depth.
* @li MonoOnly - The pixmap becomes monochrome. If necessary, it
* is dithered using the chosen dithering algorithm.
*
* Dithering mode preference, for RGB channels
*
* @li DiffuseDither (default) - A high quality dither.
* @li OrderedDither - A faster more ordered dither.
* @li ThresholdDither - No dithering, closest color is used.
*
* Dithering mode preference, for alpha channel
*
* @li DiffuseAlphaDither - A high quality dither.
* @li OrderedAlphaDither - A faster more ordered dither.
* @li ThresholdAlphaDither (default) - No dithering.
*
* Color matching versus dithering preference
*
* @li PreferDither - Always dither 32-bit images when the image
* is being converted to 8-bits. This is the default when
* converting to a pixmap.
* @li AvoidDither - Only dither 32-bit images if the image has
* more than 256 colours and it is being converted to 8-bits.
* This is the default when an image is converted for the
* purpose of saving to a file.
*
* Passing 0 for @p conversion_flags gives all the default
* options.
* @return @p true if successful.
**/
bool convertFromImage( const QImage &img, int conversion_flags );
/**
* This is an overloaded member function, provided for
* convenience. It differs from the above function only in
* what argument(s) it accepts.
**/
bool convertFromImage( const QImage &img, ColorMode mode = WebColor );
/**
* Loads a pixmap from the file @p fileName.
*
* If format is specified, the loader attempts to read the
* pixmap using the specified format. If format is not
* specified (default), the loader reads a few bytes from the
* header to guess the file format.
*
* See the @ref convertFromImage() documentation for a description
* of the conversion_flags argument.
*
* The @ref QImageIO documentation lists the supported image
* formats and explains how to add extra formats.
*
* @return @p true if successful, or false if the pixmap
* could not be loaded.
**/
bool load( const QString& fileName, const char *format,
int conversion_flags );
/**
* This is an overloaded member function, provided for
* convenience. It differs from the above function only in
* what argument(s) it accepts.
**/
bool load( const QString& fileName,
const char *format = 0,
ColorMode mode = WebColor );
/**
* Returns true if the image posesses a color table that
* matches the Icon palette or false otherwise.
*
* An image with one color not found in the Icon palette is
* considered to be a match, since this extra color may be a
* transparent background.
**/
bool checkColorTable(const QImage &image);
private:
KPixmapPrivate *d;
};
kdelibs'KPixmap::load() (./kdelibs/kdecore/kpixmap.cpp:188)
bool KPixmap::load( const QString& fileName, const char *format,
int conversion_flags )
{
QImageIO io( fileName, format );
bool result = io.read();
if ( result ) {
detach();
result = convertFromImage( io.image(), conversion_flags );
}
return result;
}
kdelibs'KPixmap::load() (./kdelibs/kdecore/kpixmap.cpp:202)
bool KPixmap::load( const QString& fileName, const char *format,
ColorMode mode )
{
int conversion_flags = 0;
switch (mode) {
case Color:
conversion_flags |= ColorOnly;
break;
case Mono:
conversion_flags |= MonoOnly;
break;
case LowColor:
conversion_flags |= LowOnly;
break;
case WebColor:
conversion_flags |= WebOnly;
break;
default:
break;// Nothing.
}
return load( fileName, format, conversion_flags );
}
kdelibs'KPixmap::convertFromImage() (./kdelibs/kdecore/kpixmap.cpp:225)
bool KPixmap::convertFromImage( const QImage &img, ColorMode mode )
{
int conversion_flags = 0;
switch (mode) {
case Color:
conversion_flags |= ColorOnly;
break;
case Mono:
conversion_flags |= MonoOnly;
break;
case LowColor:
conversion_flags |= LowOnly;
break;
case WebColor:
conversion_flags |= WebOnly;
break;
default:
break; // Nothing.
}
return convertFromImage( img, conversion_flags );
}
kdelibs'KPixmap::convertFromImage() (./kdelibs/kdecore/kpixmap.cpp:247)
bool KPixmap::convertFromImage( const QImage &img, int conversion_flags )
{
if ( img.isNull() ) {
#if defined(CHECK_NULL)
warning( "KPixmap::convertFromImage: Cannot convert a null image" );
#endif
return false;
}
detach(); // detach other references
int dd = defaultDepth();
// If color mode not one of KPixmaps extra modes nothing to do
if ( ( conversion_flags & KColorMode_Mask ) != LowOnly &&
( conversion_flags & KColorMode_Mask ) != WebOnly ) {
return QPixmap::convertFromImage ( img, conversion_flags );
}
// If the default pixmap depth is not 8bpp, KPixmap color modes have no
// effect. Ignore them and use AutoColor instead.
if ( dd > 8 ) {
if ( ( conversion_flags & KColorMode_Mask ) == LowOnly ||
( conversion_flags & KColorMode_Mask ) == WebOnly )
conversion_flags = (conversion_flags & ~KColorMode_Mask) | Auto;
return QPixmap::convertFromImage ( img, conversion_flags );
}
if ( ( conversion_flags & KColorMode_Mask ) == LowOnly ) {
// Here we skimp a little on the possible conversion modes
// Don't offer ordered or threshold dither of RGB channels or
// diffuse or ordered dither of alpha channel. It hardly seems
// worth the effort for this specialised mode.
// If image uses icon palette don't dither it.
if( img.numColors() > 0 && img.numColors() <=40 ) {
if ( checkColorTable( img ) )
return QPixmap::convertFromImage( img, QPixmap::Auto );
}
QBitmap mask;
bool isMask = false;
QImage image = img.convertDepth(32);
QImage tImage( image.width(), image.height(), 8, 256 );
if( img.hasAlphaBuffer() ) {
image.setAlphaBuffer( true );
tImage.setAlphaBuffer( true );
isMask = mask.convertFromImage( img.createAlphaMask() );
}
kdither_32_to_8( &image, &tImage );
if( QPixmap::convertFromImage( tImage ) ) {
if ( isMask ) QPixmap::setMask( mask );
return true;
} else
return false;
} else {
QImage image = img.convertDepth( 32 );
image.setAlphaBuffer( img.hasAlphaBuffer() );
conversion_flags = (conversion_flags & ~ColorMode_Mask) | Auto;
return QPixmap::convertFromImage ( image, conversion_flags );
}
}
kdelibs'KPixmap::checkColorTable() (./kdelibs/kdecore/kpixmap.cpp:315)
bool KPixmap::checkColorTable( const QImage &image )
{
int i = 0;
if (kpixmap_iconPalette == 0) {
kpixmap_iconPalette = new QColor[40];
// Standard palette
kpixmap_iconPalette[i++] = red;
kpixmap_iconPalette[i++] = green;
kpixmap_iconPalette[i++] = blue;
kpixmap_iconPalette[i++] = cyan;
kpixmap_iconPalette[i++] = magenta;
kpixmap_iconPalette[i++] = yellow;
kpixmap_iconPalette[i++] = darkRed;
kpixmap_iconPalette[i++] = darkGreen;
kpixmap_iconPalette[i++] = darkBlue;
kpixmap_iconPalette[i++] = darkCyan;
kpixmap_iconPalette[i++] = darkMagenta;
kpixmap_iconPalette[i++] = darkYellow;
kpixmap_iconPalette[i++] = white;
kpixmap_iconPalette[i++] = lightGray;
kpixmap_iconPalette[i++] = gray;
kpixmap_iconPalette[i++] = darkGray;
kpixmap_iconPalette[i++] = black;
// Pastels
kpixmap_iconPalette[i++] = QColor( 255, 192, 192 );
kpixmap_iconPalette[i++] = QColor( 192, 255, 192 );
kpixmap_iconPalette[i++] = QColor( 192, 192, 255 );
kpixmap_iconPalette[i++] = QColor( 255, 255, 192 );
kpixmap_iconPalette[i++] = QColor( 255, 192, 255 );
kpixmap_iconPalette[i++] = QColor( 192, 255, 255 );
// Reds
kpixmap_iconPalette[i++] = QColor( 64, 0, 0 );
kpixmap_iconPalette[i++] = QColor( 192, 0, 0 );
// Oranges
kpixmap_iconPalette[i++] = QColor( 255, 128, 0 );
kpixmap_iconPalette[i++] = QColor( 192, 88, 0 );
kpixmap_iconPalette[i++] = QColor( 255, 168, 88 );
kpixmap_iconPalette[i++] = QColor( 255, 220, 168 );
// Blues
kpixmap_iconPalette[i++] = QColor( 0, 0, 192 );
// Turquoise
kpixmap_iconPalette[i++] = QColor( 0, 64, 64 );
kpixmap_iconPalette[i++] = QColor( 0, 192, 192 );
// Yellows
kpixmap_iconPalette[i++] = QColor( 64, 64, 0 );
kpixmap_iconPalette[i++] = QColor( 192, 192, 0 );
// Greens
kpixmap_iconPalette[i++] = QColor( 0, 64, 0 );
kpixmap_iconPalette[i++] = QColor( 0, 192, 0 );
// Purples
kpixmap_iconPalette[i++] = QColor( 192, 0, 192 );
// Greys
kpixmap_iconPalette[i++] = QColor( 88, 88, 88 );
kpixmap_iconPalette[i++] = QColor( 48, 48, 48 );
kpixmap_iconPalette[i++] = QColor( 220, 220, 220 );
}
QRgb* ctable = image.colorTable();
int ncols = image.numColors();
int j;
// Allow one failure which could be transparent background
int failures = 0;
for ( i=0; i<ncols; i++ ) {
for ( j=0; j<40; j++ ) {
if ( kpixmap_iconPalette[j].red() == qRed( ctable[i] ) &&
kpixmap_iconPalette[j].green() == qGreen( ctable[i] ) &&
kpixmap_iconPalette[j].blue() == qBlue( ctable[i] ) ) {
break;
}
}
if ( j == 40 ) {
failures ++;
}
}
return ( failures <= 1 );
}
kdelibs'KPixmap::KPixmap() (./kdelibs/kdecore/kpixmap.cpp:410)
KPixmap::KPixmap(const QPixmap& p)
: QPixmap(p)
{
}