📄 qimage.cpp
字号:
\internal*/int QImage::devType() const{ return QInternal::Image;}/*! Returns the image as a QVariant.*/QImage::operator QVariant() const{ return QVariant(QVariant::Image, this);}/*! \internal If multiple images share common data, this image makes a copy of the data and detaches itself from the sharing mechanism, making sure that this image is the only one referring to the data. Nothing is done if there is just a single reference. \sa copy(), isDetached(), {Implicit Data Sharing}*/void QImage::detach(){ if (d) { if (qt_image_cleanup_hook_64 && d->ref == 1) qt_image_cleanup_hook_64(cacheKey()); if (d->ref != 1 || d->ro_data) *this = copy(); ++d->detach_no; }}/*! \fn QImage QImage::copy(int x, int y, int width, int height) const \overload The returned image is copied from the position (\a x, \a y) in this image, and will always have the given \a width and \a height. In areas beyond this image, pixels are set to 0.*//*! \fn QImage QImage::copy(const QRect& rectangle) const Returns a sub-area of the image as a new image. The returned image is copied from the position (\a {rectangle}.x(), \a{rectangle}.y()) in this image, and will always have the size of the given \a rectangle. In areas beyond this image, pixels are set to 0. For 32-bit RGB images, this means black; for 32-bit ARGB images, this means transparent black; for 8-bit images, this means the color with index 0 in the color table which can be anything; for 1-bit images, this means Qt::color0. If the given \a rectangle is a null rectangle the entire image is copied. \sa QImage()*/QImage QImage::copy(const QRect& r) const{ if (!d) return QImage(); if (r.isNull()) { QImage image(d->width, d->height, d->format); if (image.isNull()) return image; // Qtopia Core can create images with non-default bpl // make sure we don't crash. if (image.d->nbytes != d->nbytes) { int bpl = image.bytesPerLine(); for (int i = 0; i < height(); i++) memcpy(image.scanLine(i), scanLine(i), bpl); } else memcpy(image.bits(), bits(), d->nbytes); image.d->colortable = d->colortable; image.d->dpmx = d->dpmx; image.d->dpmy = d->dpmy; image.d->offset = d->offset; image.d->has_alpha_clut = d->has_alpha_clut;#ifndef QT_NO_IMAGE_TEXT image.d->text = d->text;#endif return image; } int x = r.x(); int y = r.y(); int w = r.width(); int h = r.height(); int dx = 0; int dy = 0; if (w <= 0 || h <= 0) return QImage(); QImage image(w, h, d->format); if (image.isNull()) return image; if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) { // bitBlt will not cover entire image - clear it. image.fill(0); if (x < 0) { dx = -x; x = 0; } if (y < 0) { dy = -y; y = 0; } } image.d->colortable = d->colortable; int pixels_to_copy = qMax(w - dx, 0); if (x > d->width) pixels_to_copy = 0; else if (pixels_to_copy > d->width - x) pixels_to_copy = d->width - x; int lines_to_copy = qMax(h - dy, 0); if (y > d->height) lines_to_copy = 0; else if (lines_to_copy > d->height - y) lines_to_copy = d->height - y; bool byteAligned = true; if (d->format == Format_Mono || d->format == Format_MonoLSB) byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7); if (byteAligned) { const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line; uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line; const int bytes_to_copy = (pixels_to_copy * d->depth) >> 3; for (int i = 0; i < lines_to_copy; ++i) { memcpy(dest, src, bytes_to_copy); src += d->bytes_per_line; dest += image.d->bytes_per_line; } } else if (d->format == Format_Mono) { const uchar *src = d->data + y * d->bytes_per_line; uchar *dest = image.d->data + dy * image.d->bytes_per_line; for (int i = 0; i < lines_to_copy; ++i) { for (int j = 0; j < pixels_to_copy; ++j) { if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7))) dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7)); else dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7)); } src += d->bytes_per_line; dest += image.d->bytes_per_line; } } else { // Format_MonoLSB Q_ASSERT(d->format == Format_MonoLSB); const uchar *src = d->data + y * d->bytes_per_line; uchar *dest = image.d->data + dy * image.d->bytes_per_line; for (int i = 0; i < lines_to_copy; ++i) { for (int j = 0; j < pixels_to_copy; ++j) { if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7))) dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7)); else dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7)); } src += d->bytes_per_line; dest += image.d->bytes_per_line; } } 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 = d->text;#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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -