Logo Search packages:      
Sourcecode: qt4-x11 version File versions

void QImage::setPixel ( int  x,
int  y,
uint  index_or_rgb 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the pixel index or color at (x, y) to index_or_rgb.

Definition at line 3598 of file qimage.cpp.

References detach(), format(), height(), scanLine(), and width().

Referenced by createMaskFromColor(), BasicToolsPlugin::filterImage(), and setPixel().

{
    if (!d || x < 0 || x >= width() || y < 0 || y >= height()) {
        qWarning("QImage::setPixel: coordinate (%d,%d) out of range", x, y);
        return;
    }
    detach();
    uchar * s = scanLine(y);
    const quint32p p = quint32p::fromRawData(index_or_rgb);
    switch(d->format) {
    case Format_Mono:
    case Format_MonoLSB:
        if (index_or_rgb > 1) {
            qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
        } else if (format() == Format_MonoLSB) {
            if (index_or_rgb==0)
                *(s + (x >> 3)) &= ~(1 << (x & 7));
            else
                *(s + (x >> 3)) |= (1 << (x & 7));
        } else {
            if (index_or_rgb==0)
                *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
            else
                *(s + (x >> 3)) |= (1 << (7-(x & 7)));
        }
        break;
    case Format_Indexed8:
        if (index_or_rgb > (uint)d->colortable.size()) {
            qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
            return;
        }
        s[x] = index_or_rgb;
        break;
    case Format_RGB32:
        //make sure alpha is 255, we depend on it in qdrawhelper for cases
        // when image is set as a texture pattern on a qbrush
        ((uint *)s)[x] = uint(255 << 24) | index_or_rgb;
        break;
    case Format_ARGB32:
    case Format_ARGB32_Premultiplied:
        ((uint *)s)[x] = index_or_rgb;
        break;
    case Format_RGB16:
        ((quint16 *)s)[x] = qt_colorConvert<quint16, quint32p>(p, 0);
        break;
    case Format_ARGB8565_Premultiplied:
        ((qargb8565*)s)[x] = qt_colorConvert<qargb8565, quint32p>(p, 0);
        break;
    case Format_RGB666:
        ((qrgb666*)s)[x] = qt_colorConvert<qrgb666, quint32p>(p, 0);
        break;
    case Format_ARGB6666_Premultiplied:
        ((qargb6666*)s)[x] = qt_colorConvert<qargb6666, quint32p>(p, 0);
        break;
    case Format_RGB555:
        ((qrgb555*)s)[x] = qt_colorConvert<qrgb555, quint32p>(p, 0);
        break;
    case Format_ARGB8555_Premultiplied:
        ((qargb8555*)s)[x] = qt_colorConvert<qargb8555, quint32p>(p, 0);
        break;
    case Format_RGB888:
        ((qrgb888*)s)[x] = qt_colorConvert<qrgb888, quint32p>(p, 0);
        break;
    case Format_RGB444:
        ((qrgb444*)s)[x] = qt_colorConvert<qrgb444, quint32p>(p, 0);
        break;
    case Format_ARGB4444_Premultiplied:
        ((qargb4444*)s)[x] = qt_colorConvert<qargb4444, quint32p>(p, 0);
        break;
    case Format_Invalid:
    case NImageFormats:
        Q_ASSERT(false);
    }
}


Generated by  Doxygen 1.6.0   Back to index