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

📄 qimage.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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){    if (i < 0 || i >= numColors()) {        qWarning("QImage::setColor: Index out of bound %d", i);        return;    }    detach();    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).    Note that QImage uses \l{Implicit Data Sharing} {implicit data    sharing}. This function performs a deep copy of the shared pixel    data, thus ensuring that this QImage is the only one using the    current return value.    \sa scanLine(), numBytes()*/uchar *QImage::bits(){    if (!d)        return 0;    detach();    return d->data;}/*!    \overload    Note that QImage uses \l{Implicit Data Sharing} {implicit data    sharing}, but this function does \e not perform a deep copy of the    shared pixel data, because the returned data is const.*/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) {        int w = d->width;        if (d->depth == 1) {            if (pixel & 1)                pixel = 0xffffffff;            else                pixel = 0;            w = (w + 7) / 8;        } else {            pixel &= 0xff;        }        qt_rectfill<quint8>(d->data, pixel, 0, 0,                            w, d->height, d->bytes_per_line);        return;    } else if (d->depth == 16) {        qt_rectfill<quint16>(reinterpret_cast<quint16*>(d->data), pixel,                             0, 0, d->width, d->height, d->bytes_per_line);        return;    }    if (d->format == Format_RGB32)        pixel |= 0xff000000;    qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel,                      0, 0, d->width, d->height, d->bytes_per_line);}/*!    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)    Use the invertPixels() function that takes a QImage::InvertMode    parameter instead.*//*! \fn QImage::Endian QImage::systemByteOrder()    Determines the host computer byte order. Returns    QImage::LittleEndian (LSB first) or QImage::BigEndian (MSB first).    This function is no longer relevant for QImage. Use QSysInfo    instead.*/// Windows defines these#if defined(write)# undef write#endif#if defined(close)# undef close#endif#if defined(read)# undef read#endif/*!    Resizes the color table to contain \a numColors entries.    If the color table is expanded, all the extra colors will be set to    transparent (i.e qRgba(0, 0, 0, 0)).    \sa numColors(), colorTable(), {QImage#Image    Transformations}{Image Transformations}*/void QImage::setNumColors(int numColors){    if (!d) {        qWarning("QImage::setNumColors: null image");        return;    }    detach();    if (numColors == d->colortable.size())        return;    if (numColors <= 0) {                        // use no color table        d->colortable = QVector<QRgb>();        return;    }    int nc = d->colortable.size();    d->colortable.resize(numColors);    for (int i = nc; i < numColors; ++i)        d->colortable[i] = 0;}/*!    Returns the format of the image.    \sa {QImage#Image Formats}{Image Formats}*/QImage::Format QImage::format() const{    return d ? d->format : Format_Invalid;}#ifdef QT3_SUPPORT/*!    Returns true if alpha buffer mode is enabled; otherwise returns    false.    Use the hasAlphaChannel() function instead.*/bool QImage::hasAlphaBuffer() const{    return d && (d->format != Format_RGB32)        && (d->format != Format_RGB16);}/*!    Enables alpha buffer mode if \a enable is true, otherwise disables    it. The alpha buffer is used to set a mask when a QImage is    translated to a QPixmap.    If a monochrome or indexed 8-bit image has alpha channels in their    color tables they will automatically detect that they have an    alpha channel, so this function is not required.  To force alpha    channels on 32-bit images, use the convertToFormat() function.*/void QImage::setAlphaBuffer(bool enable){    if (!d        || d->format == Format_Mono        || d->format == Format_MonoLSB        || d->format == Format_Indexed8)        return;    if (enable && (d->format == Format_ARGB32 || d->format == Format_ARGB32_Premultiplied))        return;    if (!enable && d->format == Format_RGB32)        return;    detach();    d->format = (enable ? Format_ARGB32 : Format_RGB32);}/*!  \fn bool QImage::create(int width, int height, int depth, int numColors, Endian bitOrder)    Sets the image \a width, \a height, \a depth, its number of colors    (in \a numColors), and bit order. Returns true if successful, or    false if the parameters are incorrect or if memory cannot be    allocated.    The \a width and \a height is limited to 32767. \a depth must be    1, 8, or 32. If \a depth is 1, \a bitOrder must be set to    either QImage::LittleEndian or QImage::BigEndian. For other depths    \a bitOrder must be QImage::IgnoreEndian.    This function allocates a color table and a buffer for the image    data. The image data is not initialized. The image buffer is    allocated as a single block that consists of a table of scanLine()    pointers (jumpTable()) and the image data (bits()).    Use a QImage constructor instead.*/bool QImage::create(int width, int height, int depth, int numColors, Endian bitOrder){    if (d && !d->ref.deref())        delete d;    d = QImageData::create(QSize(width, height), formatFor(depth, bitOrder), numColors);    return true;}/*!    \fn bool QImage::create(const QSize& size, int depth, int numColors, Endian bitOrder)    \overload    The width and height are specified in the \a size argument.    Use a QImage constructor instead.*/bool QImage::create(const QSize& size, int depth, int numColors, QImage::Endian bitOrder){    if (d && !d->ref.deref())        delete d;    d = QImageData::create(size, formatFor(depth, bitOrder), numColors);    return true;}#endif // QT3_SUPPORT/*****************************************************************************  Internal routines for converting image depth. *****************************************************************************/typedef void (*Image_Converter)(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags);static void convert_ARGB_to_ARGB_PM(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags){    Q_ASSERT(src->format == QImage::Format_ARGB32);    Q_ASSERT(dest->format == QImage::Format_ARGB32_Premultiplied);    Q_ASSERT(src->width == dest->width);    Q_ASSERT(src->height == dest->height);    const int src_pad = (src->bytes_per_line >> 2) - src->width;    const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;    const QRgb *src_data = (QRgb *) src->data;    QRgb *dest_data = (QRgb *) dest->data;    for (int i = 0; i < src->height; ++i) {        const QRgb *end = src_data + src->width;        while (src_data < end) {            *dest_data = PREMUL(*src_data);            ++src_data;            ++dest_data;        }        src_data += src_pad;        dest_data += dest_pad;    }}static void convert_ARGB_PM_to_ARGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags){    Q_ASSERT(src->format == QImage::Format_ARGB32_Premultiplied);    Q_ASSERT(dest->format == QImage::Format_ARGB32);    Q_ASSERT(src->width == dest->width);    Q_ASSERT(src->height == dest->height);    const int src_pad = (src->bytes_per_line >> 2) - src->width;    const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;    const QRgb *src_data = (QRgb *) src->data;    QRgb *dest_data = (QRgb *) dest->data;    for (int i = 0; i < src->height; ++i) {        const QRgb *end = src_data + src->width;        while (src_data < end) {            *dest_data = INV_PREMUL(*src_data);            ++src_data;            ++dest_data;        }        src_data += src_pad;        dest_data += dest_pad;    }}static void convert_ARGB_PM_to_RGB(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags){    Q_ASSERT(src->format == QImage::Format_ARGB32_Premultiplied);    Q_ASSERT(dest->format == QImage::Format_RGB32);    Q_ASSERT(src->width == dest->width);    Q_ASSERT(src->height == dest->height);    const int src_pad = (src->bytes_per_line >> 2) - src->width;    const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;    const QRgb *src_data = (QRgb *) src->data;    QRgb *dest_data = (QRgb *) dest->data;    for (int i =

⌨️ 快捷键说明

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