⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qimage.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        }    }    image.d->dpmx = dotsPerMeterX();    image.d->dpmy = dotsPerMeterY();    image.d->offset = offset();    image.d->has_alpha_clut = d->has_alpha_clut;#ifndef QT_NO_IMAGE_TEXT    image.d->text_lang = d->text_lang;#endif    return image;}/*!    \fn bool QImage::isNull() const    Returns true if it is a null image, otherwise returns false.    A null image has all parameters set to zero and no allocated data.*/bool QImage::isNull() const{    return !d;}/*!    \fn int QImage::width() const    Returns the width of the image.    \sa {QImage#Image Information}{Image Information}*/int QImage::width() const{    return d ? d->width : 0;}/*!    \fn int QImage::height() const    Returns the height of the image.    \sa {QImage#Image Information}{Image Information}*/int QImage::height() const{    return d ? d->height : 0;}/*!    \fn QSize QImage::size() const    Returns the size of the image, i.e. its width() and height().    \sa {QImage#Image Information}{Image Information}*/QSize QImage::size() const{    return d ? QSize(d->width, d->height) : QSize();}/*!    \fn QRect QImage::rect() const    Returns the enclosing rectangle (0, 0, width(), height()) of the    image.    \sa {QImage#Image Information}{Image Information}*/QRect QImage::rect() const{    return d ? QRect(0, 0, d->width, d->height) : QRect();}/*!    Returns the depth of the image.    The image depth is the number of bits used to encode a single    pixel, also called bits per pixel (bpp) or bit planes of an image.    The supported depths are 1, 8 and 32.    \sa convertToFormat(), {QImage#Image Formats}{Image Formats},    {QImage#Image Information}{Image Information}*/int QImage::depth() const{    return d ? d->depth : 0;}/*!    \fn int QImage::numColors() const    Returns the size of the color table for the image.    Notice that numColors() returns 0 for 32-bpp images because these    images do not use color tables, but instead encode pixel values as    ARGB quadruplets.    \sa setNumColors(), {QImage#Image Information}{Image Information}*/int QImage::numColors() const{    return d ? d->colortable.size() : 0;}#ifdef QT3_SUPPORT/*!    \fn QImage::Endian QImage::bitOrder() const    Returns the bit order for the image. If it is a 1-bpp image, this    function returns either QImage::BigEndian or    QImage::LittleEndian. Otherwise, this function returns    QImage::IgnoreEndian.    Use the format() function instead for the monochrome formats. For    non-monochrome formats the bit order is irrelevant.*//*!    Returns a pointer to the scanline pointer table. This is the    beginning of the data block for the image.    Use the bits() or scanLine() function instead.*/uchar **QImage::jumpTable(){    if (!d)        return 0;    detach();    if (!d->jumptable) {        d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));        uchar *data = d->data;        int height = d->height;        uchar **p = d->jumptable;        while (height--) {            *p++ = data;            data += d->bytes_per_line;        }    }    return d->jumptable;}/*!    \overload*/const uchar * const *QImage::jumpTable() const{    if (!d)        return 0;    if (!d->jumptable) {        d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *));        uchar *data = d->data;        int height = d->height;        uchar **p = d->jumptable;        while (height--) {            *p++ = data;            data += d->bytes_per_line;        }    }    return d->jumptable;}#endif/*!    Sets the color table used to translate color indexes to QRgb    values, to the specified \a colors.    \sa colorTable(), setColor(), {QImage#Image Transformations}{Image    Transformations}*/void QImage::setColorTable(const QVector<QRgb> colors){    if (!d)        return;    detach();    d->colortable = colors;    d->has_alpha_clut = false;    for (int i = 0; i < d->colortable.size(); ++i)        d->has_alpha_clut |= (qAlpha(d->colortable.at(i)) != 255);}/*!    Returns a list of the colors contained in the image's color table,    or an empty list if the image does not have a color table    \sa setColorTable(), numColors(), color()*/QVector<QRgb> QImage::colorTable() const{    return d ? d->colortable : QVector<QRgb>();}/*!    Returns the number of bytes occupied by the image data.    \sa bytesPerLine(), bits(), {QImage#Image Information}{Image    Information}*/int QImage::numBytes() const{    return d ? d->nbytes : 0;}/*!    Returns the number of bytes per image scanline.    This is equivalent to numBytes()/ height().    \sa scanLine()*/int QImage::bytesPerLine() const{    return (d && d->height) ? d->nbytes / d->height : 0;}/*!    Returns the color in the color table at index \a i. The first    color is at index 0.    The colors in an image's color table are specified as ARGB    quadruplets (QRgb). Use the qAlpha(), qRed(), qGreen(), and    qBlue() functions to get the color value components.    \sa setColor(), pixelIndex(), {QImage#Pixel Manipulation}{Pixel    Manipulation}*/QRgb QImage::color(int i) const{    Q_ASSERT(i < numColors());    return d ? d->colortable.at(i) : QRgb(uint(-1));}/*!    \fn void QImage::setColor(int index, QRgb colorValue)    Sets the color at the given \a index in the color table, to the    given to \a colorValue.    The color value is an ARGB quadruplet.    \sa color(), setColorTable(), {QImage#Pixel Manipulation}{Pixel    Manipulation}*/void QImage::setColor(int i, QRgb c){    detach();    Q_ASSERT(i < numColors());    d->colortable[i] = c;    d->has_alpha_clut |= (qAlpha(c) != 255);}/*!    Returns a pointer to the pixel data at the scanline with index \a    i. The first scanline is at index 0.    The scanline data is aligned on a 32-bit boundary.    \warning If you are accessing 32-bpp image data, cast the returned    pointer to \c{QRgb*} (QRgb has a 32-bit size) and use it to    read/write the pixel value. You cannot use the \c{uchar*} pointer    directly, because the pixel format depends on the byte order on    the underlying platform. Use qRed(), qGreen(), qBlue(), and    qAlpha() to access the pixels.    \sa bytesPerLine(), bits(), {QImage#Pixel Manipulation}{Pixel    Manipulation}*/uchar *QImage::scanLine(int i){    detach();    Q_ASSERT(i >= 0 && i < height());    return d->data + i * d->bytes_per_line;}/*!    \overload*/const uchar *QImage::scanLine(int i) const{    Q_ASSERT(i >= 0 && i < height());    return d->data + i * d->bytes_per_line;}/*!    Returns a pointer to the first pixel data. This is equivalent to    scanLine(0).    \sa scanLine(), numBytes()*/uchar *QImage::bits(){    if (!d)        return 0;    detach();    return d->data;}/*!    \overload*/const uchar *QImage::bits() const{    return d ? d->data : 0;}/*!    \fn void QImage::reset()    Resets all image parameters and deallocates the image data.    Assign a null image instead.    \oldcode        QImage image;        image.reset();    \newcode        QImage image;        image = QImage();    \endcode*//*!    \fn void QImage::fill(uint pixelValue)    Fills the entire image with the given \a pixelValue.    If the depth of this image is 1, only the lowest bit is used. If    you say fill(0), fill(2), etc., the image is filled with 0s. If    you say fill(1), fill(3), etc., the image is filled with 1s. If    the depth is 8, the lowest 8 bits are used and if the depth is 16    the lowest 16 bits are used.    Note: QImage::pixel() returns the color of the pixel at the given    coordinates while QColor::pixel() returns the pixel value of the    underlying window system (essentially an index value), so normally    you will want to use QImage::pixel() to use a color from an    existing image or QColor::rgb() to use a specific color.    \sa depth(), {QImage#Image Transformations}{Image Transformations}*/void QImage::fill(uint pixel){    if (!d)        return;    detach();    if (d->depth == 1 || d->depth == 8) {        if (d->depth == 1) {            if (pixel & 1)                pixel = 0xffffffff;            else                pixel = 0;        } else {            pixel &= 0xff;        }        memset(d->data, pixel, d->nbytes);        return;    } else if (d->depth == 16) {        pixel = (pixel << 16) | (pixel & 0xffff);    }    if (d->format == Format_RGB32)        pixel |= 0xff000000;    if (pixel == 0 || pixel == 0xffffffff) {        memset(d->data, (pixel & 0xff), d->nbytes);    } else {        uint *data = (uint *)d->data;        uint *end = (uint *)(d->data + d->nbytes);        while (data < end)            *data++ = pixel;    }}/*!    Inverts all pixel values in the image.    The given invert \a mode only have a meaning when the image's    depth is 32. The default \a mode is InvertRgb, which leaves the    alpha channel unchanged. If the \a mode is InvertRgba, the alpha    bits are also inverted.    Inverting an 8-bit image means to replace all pixels using color    index \e i with a pixel using color index 255 minus \e i. The same    is the case for a 1-bit image. Note that the color table is \e not    changed.    \sa {QImage#Image Transformations}{Image Transformations}*/void QImage::invertPixels(InvertMode mode){    if (!d)        return;    detach();    if (depth() != 32) {        // number of used bytes pr line        int bpl = (d->width * d->depth + 7) / 8;        int pad = d->bytes_per_line - bpl;        uchar *sl = d->data;        for (int y=0; y<d->height; ++y) {            for (int x=0; x<bpl; ++x)                *sl++ ^= 0xff;            sl += pad;        }    } else {        quint32 *p = (quint32*)d->data;        quint32 *end = (quint32*)(d->data + d->nbytes);        uint xorbits = (mode == InvertRgba) ? 0xffffffff : 0x00ffffff;        while (p < end)            *p++ ^= xorbits;    }}/*!    \fn void QImage::invertPixels(bool invertAlpha)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -