#include "qimage.h"
#include "qdatastream.h"
#include "qbuffer.h"
#include "qmap.h"
#include "qmatrix.h"
#include "qimagereader.h"
#include "qimagewriter.h"
#include "qstringlist.h"
#include "qvariant.h"
#include <ctype.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <private/qdrawhelper_p.h>
#include <private/qpixmap_p.h>
#include <qhash.h>
#include <qpaintengine.h>
Include dependency graph for qimage.cpp:
Go to the source code of this file.
Classes | |
struct | QImageData |
struct | QRgbMap |
Defines | |
#define | MAX_R 5 |
#define | MAX_G 5 |
#define | MAX_B 5 |
#define | INDEXOF(r, g, b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b)) |
#define | DITHER(p, m) ((uchar) ((p * (m) + 127) / 255)) |
#define | DITHER(p, d, m) ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) >> 16)) |
#define | PIX(x, y) (*((QRgb*)scanLine(y)+x) & 0x00ffffff) |
#define | IWX_MSB(b) |
#define | IWX_LSB(b) |
#define | IWX_PIX(b) |
Typedefs | |
typedef void(*) | _qt_image_cleanup_hook (int) |
typedef void(*) | Image_Converter (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
Functions | |
static ushort | qt_convRgbTo16 (QRgb c) |
static QRgb | qt_conv16ToRgb (ushort c) |
static void | pnmscale (const QImage &src, QImage &dst) |
static QImage | smoothScaled (const QImage &src, int w, int h) |
static QImage | rotated90 (const QImage &src) |
static QImage | rotated180 (const QImage &src) |
static QImage | rotated270 (const QImage &src) |
Q_GUI_EXPORT qint64 | qt_image_id (const QImage &image) |
const QVector< QRgb > * | qt_image_colortable (const QImage &image) |
int | qt_defaultDpi () |
int | qimage_next_serial_number () |
static int | depthForFormat (QImage::Format format) |
const uchar * | qt_get_bitflip_array () |
bool | qt_read_xpm_image_or_array (QIODevice *device, const char *const *source, QImage &image) |
static void | convert_ARGB_to_ARGB_PM (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | convert_ARGB_PM_to_ARGB (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | convert_ARGB_PM_to_RGB (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | swap_bit_order (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | mask_alpha_converter (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static QVector< QRgb > | fix_color_table (const QVector< QRgb > &ctbl, QImage::Format format) |
static void | dither_to_Mono (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags, bool fromalpha) |
static void | convert_X_to_Mono (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) |
static void | convert_ARGB_PM_to_Mono (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) |
static void | convert_RGB_to_Indexed8 (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) |
static void | convert_ARGB_PM_to_Indexed8 (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) |
static void | convert_ARGB_to_Indexed8 (QImageData *dst, const QImageData *src, Qt::ImageConversionFlags flags) |
static void | convert_Indexed8_to_X32 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | convert_Mono_to_X32 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | convert_Mono_to_Indexed8 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | convert_16_to_32 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static void | convert_32_to_16 (QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
static int | pixel_distance (QRgb p1, QRgb p2) |
static int | closestMatch (QRgb pixel, const QVector< QRgb > &clut) |
static QImage | convertWithPalette (const QImage &src, QImage::Format format, const QVector< QRgb > &clut) |
QDataStream & | operator<< (QDataStream &s, const QImage &image) |
QDataStream & | operator>> (QDataStream &s, QImage &image) |
bool | qt_xForm_helper (const QMatrix &trueMat, int xoffset, int type, int depth, uchar *dptr, int dbpl, int p_inc, int dHeight, const uchar *sptr, int sbpl, int sWidth, int sHeight) |
Variables | |
Q_GUI_EXPORT _qt_image_cleanup_hook | qt_image_cleanup_hook = 0 |
QBasicAtomic | qimage_serial_number = Q_ATOMIC_INIT(1) |
static const uchar | bitflip [256] |
static const Image_Converter | converter_map [QImage::NImageFormats][QImage::NImageFormats] |
#define DITHER | ( | p, | |||
d, | |||||
m | ) | ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) >> 16)) |
#define DITHER | ( | p, | |||
m | ) | ((uchar) ((p * (m) + 127) / 255)) |
Referenced by convert_RGB_to_Indexed8().
#define INDEXOF | ( | r, | |||
g, | |||||
b | ) | (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b)) |
Referenced by convert_RGB_to_Indexed8().
#define IWX_LSB | ( | b | ) |
Value:
if (trigx < maxws && trigy < maxhs) { \ if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \ (1 << ((trigx>>12)&7))) \ *dptr |= b; \ } \ trigx += m11; \ trigy += m12;
Definition at line 4822 of file qimage.cpp.
Referenced by qt_xForm_helper().
#define IWX_MSB | ( | b | ) |
Value:
if (trigx < maxws && trigy < maxhs) { \ if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \ (1 << (7-((trigx>>12)&7)))) \ *dptr |= b; \ } \ trigx += m11; \ trigy += m12;
Definition at line 4813 of file qimage.cpp.
Referenced by qt_xForm_helper().
#define IWX_PIX | ( | b | ) |
Value:
if (trigx < maxws && trigy < maxhs) { \ if ((*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & \ (1 << (7-((trigx>>12)&7)))) == 0) \ *dptr &= ~b; \ } \ trigx += m11; \ trigy += m12;
Definition at line 4831 of file qimage.cpp.
Referenced by qt_xForm_helper().
#define MAX_B 5 |
Referenced by convert_RGB_to_Indexed8().
#define MAX_G 5 |
Referenced by convert_RGB_to_Indexed8().
#define MAX_R 5 |
Referenced by convert_RGB_to_Indexed8().
#define PIX | ( | x, | |||
y | ) | (*((QRgb*)scanLine(y)+x) & 0x00ffffff) |
Referenced by QImage::createHeuristicMask().
typedef void(*) _qt_image_cleanup_hook(int) |
Definition at line 73 of file qimage.cpp.
typedef void(*) Image_Converter(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags) |
Definition at line 1965 of file qimage.cpp.
static int closestMatch | ( | QRgb | pixel, | |
const QVector< QRgb > & | clut | |||
) | [inline, static] |
Definition at line 3012 of file qimage.cpp.
References QVector< T >::at(), i, pixel_distance(), and QVector< T >::size().
Referenced by convertWithPalette().
03012 { 03013 int idx = 0; 03014 int current_distance = INT_MAX; 03015 for (int i=0; i<clut.size(); ++i) { 03016 int dist = pixel_distance(pixel, clut.at(i)); 03017 if (dist < current_distance) { 03018 current_distance = dist; 03019 idx = i; 03020 } 03021 } 03022 return idx; 03023 }
Here is the call graph for this function:
static void convert_16_to_32 | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2769 of file qimage.cpp.
References QImageData::bytes_per_line, QImageData::data, QImageData::format, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_RGB16, QImage::Format_RGB32, QImageData::height, p, qt_conv16ToRgb(), QImageData::width, and y.
Referenced by QImage::convertToFormat().
02770 { 02771 Q_ASSERT(src->format == QImage::Format_RGB16); 02772 Q_ASSERT(dest->format == QImage::Format_RGB32 02773 || dest->format == QImage::Format_ARGB32_Premultiplied 02774 || dest->format == QImage::Format_ARGB32); 02775 Q_ASSERT(src->width == dest->width); 02776 Q_ASSERT(src->height == dest->height); 02777 02778 int w = src->width; 02779 const uchar *src_data = src->data; 02780 uchar *dest_data = dest->data; 02781 for (int y = 0; y < src->height; y++) { 02782 uint *p = (uint *)dest_data; 02783 const ushort *b = (ushort*)src_data; 02784 uint *end = p + w; 02785 02786 while (p < end) 02787 *p++ = qt_conv16ToRgb(*b++); 02788 02789 src_data += src->bytes_per_line; 02790 dest_data += dest->bytes_per_line; 02791 } 02792 }
Here is the call graph for this function:
static void convert_32_to_16 | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2795 of file qimage.cpp.
References QImageData::bytes_per_line, QImageData::data, QImageData::format, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_RGB16, QImage::Format_RGB32, QImageData::height, p, qt_convRgbTo16(), QImageData::width, and y.
Referenced by QImage::convertToFormat().
02796 { 02797 Q_ASSERT(dest->format == QImage::Format_RGB16); 02798 Q_ASSERT(src->format == QImage::Format_RGB32 02799 || src->format == QImage::Format_ARGB32_Premultiplied 02800 || src->format == QImage::Format_ARGB32); 02801 Q_ASSERT(src->width == dest->width); 02802 Q_ASSERT(src->height == dest->height); 02803 02804 int w = src->width; 02805 const uchar *src_data = src->data; 02806 uchar *dest_data = dest->data; 02807 for (int y = 0; y < src->height; y++) { 02808 ushort *p = (ushort *)dest_data; 02809 const uint *b = (const uint*)src_data; 02810 ushort *end = p + w; 02811 02812 while (p < end) 02813 *p++ = qt_convRgbTo16(*b++); 02814 02815 src_data += src->bytes_per_line; 02816 dest_data += dest->bytes_per_line; 02817 } 02818 }
Here is the call graph for this function:
static void convert_ARGB_PM_to_ARGB | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 1986 of file qimage.cpp.
References QImageData::bytes_per_line, QImageData::data, QImageData::format, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImageData::height, INV_PREMUL, QImageData::nbytes, QColor::QRgb(), and QImageData::width.
Referenced by convert_ARGB_PM_to_Indexed8(), and convert_ARGB_PM_to_Mono().
01987 { 01988 Q_ASSERT(src->format == QImage::Format_ARGB32_Premultiplied); 01989 Q_ASSERT(dest->format == QImage::Format_ARGB32); 01990 Q_ASSERT(src->width == dest->width); 01991 Q_ASSERT(src->height == dest->height); 01992 Q_ASSERT(src->nbytes == dest->nbytes); 01993 Q_ASSERT(src->bytes_per_line == dest->bytes_per_line); 01994 01995 const QRgb *src_data = (QRgb *) src->data; 01996 const QRgb *end = src_data + (src->nbytes>>2); 01997 QRgb *dest_data = (QRgb *) dest->data; 01998 while (src_data < end) { 01999 *dest_data = INV_PREMUL(*src_data); 02000 ++src_data; 02001 ++dest_data; 02002 } 02003 }
Here is the call graph for this function:
static void convert_ARGB_PM_to_Indexed8 | ( | QImageData * | dst, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | flags | |||
) | [static] |
Definition at line 2645 of file qimage.cpp.
References convert_ARGB_PM_to_ARGB(), convert_RGB_to_Indexed8(), QImageData::create(), QImage::Format_ARGB32, QImageData::height, and QImageData::width.
02646 { 02647 QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32); 02648 convert_ARGB_PM_to_ARGB(tmp, src, flags); 02649 convert_RGB_to_Indexed8(dst, tmp, flags); 02650 delete tmp; 02651 }
Here is the call graph for this function:
static void convert_ARGB_PM_to_Mono | ( | QImageData * | dst, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | flags | |||
) | [static] |
Definition at line 2357 of file qimage.cpp.
References convert_ARGB_PM_to_ARGB(), QImageData::create(), dither_to_Mono(), QImage::Format_ARGB32, QImageData::height, and QImageData::width.
02358 { 02359 QImageData *tmp = QImageData::create(QSize(src->width, src->height), QImage::Format_ARGB32); 02360 convert_ARGB_PM_to_ARGB(tmp, src, flags); 02361 dither_to_Mono(dst, tmp, flags, false); 02362 delete tmp; 02363 }
Here is the call graph for this function:
static void convert_ARGB_PM_to_RGB | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2005 of file qimage.cpp.
References QImageData::bytes_per_line, QImageData::data, QImageData::format, QImage::Format_ARGB32_Premultiplied, QImage::Format_RGB32, QImageData::height, INV_PREMUL, QImageData::nbytes, QColor::QRgb(), and QImageData::width.
02006 { 02007 Q_ASSERT(src->format == QImage::Format_ARGB32_Premultiplied); 02008 Q_ASSERT(dest->format == QImage::Format_RGB32); 02009 Q_ASSERT(src->width == dest->width); 02010 Q_ASSERT(src->height == dest->height); 02011 Q_ASSERT(src->nbytes == dest->nbytes); 02012 Q_ASSERT(src->bytes_per_line == dest->bytes_per_line); 02013 02014 const QRgb *src_data = (QRgb *) src->data; 02015 const QRgb *end = src_data + (src->nbytes>>2); 02016 QRgb *dest_data = (QRgb *) dest->data; 02017 while (src_data < end) { 02018 *dest_data = 0xff000000 | INV_PREMUL(*src_data); 02019 ++src_data; 02020 ++dest_data; 02021 } 02022 }
Here is the call graph for this function:
static void convert_ARGB_to_ARGB_PM | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 1967 of file qimage.cpp.
References QImageData::bytes_per_line, QImageData::data, QImageData::format, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImageData::height, QImageData::nbytes, PREMUL(), QColor::QRgb(), and QImageData::width.
01968 { 01969 Q_ASSERT(src->format == QImage::Format_ARGB32); 01970 Q_ASSERT(dest->format == QImage::Format_ARGB32_Premultiplied); 01971 Q_ASSERT(src->width == dest->width); 01972 Q_ASSERT(src->height == dest->height); 01973 Q_ASSERT(src->nbytes == dest->nbytes); 01974 Q_ASSERT(src->bytes_per_line == dest->bytes_per_line); 01975 01976 const QRgb *src_data = (QRgb *) src->data; 01977 const QRgb *end = src_data + (src->nbytes>>2); 01978 QRgb *dest_data = (QRgb *) dest->data; 01979 while (src_data < end) { 01980 *dest_data = PREMUL(*src_data); 01981 ++src_data; 01982 ++dest_data; 01983 } 01984 }
Here is the call graph for this function:
static void convert_ARGB_to_Indexed8 | ( | QImageData * | dst, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | flags | |||
) | [static] |
Definition at line 2653 of file qimage.cpp.
References convert_RGB_to_Indexed8().
02654 { 02655 convert_RGB_to_Indexed8(dst, src, flags); 02656 }
Here is the call graph for this function:
static void convert_Indexed8_to_X32 | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2658 of file qimage.cpp.
References QVector< T >::at(), QImageData::bytes_per_line, QImageData::colortable, QImageData::data, fix_color_table(), QImageData::format, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Indexed8, QImage::Format_RGB32, QImageData::height, p, QImageData::width, and y.
02659 { 02660 Q_ASSERT(src->format == QImage::Format_Indexed8); 02661 Q_ASSERT(dest->format == QImage::Format_RGB32 02662 || dest->format == QImage::Format_ARGB32 02663 || dest->format == QImage::Format_ARGB32_Premultiplied); 02664 Q_ASSERT(src->width == dest->width); 02665 Q_ASSERT(src->height == dest->height); 02666 02667 QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format); 02668 02669 int w = src->width; 02670 const uchar *src_data = src->data; 02671 uchar *dest_data = dest->data; 02672 for (int y = 0; y < src->height; y++) { 02673 uint *p = (uint *)dest_data; 02674 const uchar *b = src_data; 02675 uint *end = p + w; 02676 02677 while (p < end) 02678 *p++ = colorTable.at(*b++); 02679 02680 src_data += src->bytes_per_line; 02681 dest_data += dest->bytes_per_line; 02682 } 02683 }
Here is the call graph for this function:
static void convert_Mono_to_Indexed8 | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2727 of file qimage.cpp.
References QImageData::bytes_per_line, QImageData::colortable, QImageData::data, QImageData::format, QImage::Format_Indexed8, QImage::Format_Mono, QImage::Format_MonoLSB, QImageData::height, p, QVector< T >::resize(), QVector< T >::size(), QImageData::width, and y.
02728 { 02729 Q_ASSERT(src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB); 02730 Q_ASSERT(dest->format == QImage::Format_Indexed8); 02731 Q_ASSERT(src->width == dest->width); 02732 Q_ASSERT(src->height == dest->height); 02733 02734 QVector<QRgb> ctbl = src->colortable; 02735 if (ctbl.size() > 2) { 02736 ctbl.resize(2); 02737 } else if (ctbl.size() < 2) { 02738 if (ctbl.size() == 0) 02739 ctbl << 0xff000000; 02740 ctbl << 0xffffffff; 02741 } 02742 dest->colortable = ctbl; 02743 02744 02745 const uchar *src_data = src->data; 02746 uchar *dest_data = dest->data; 02747 if (src->format == QImage::Format_Mono) { 02748 for (int y = 0; y < dest->height; y++) { 02749 register uchar *p = dest_data; 02750 for (int x = 0; x < dest->width; x++) 02751 *p++ = (src_data[x>>3] >> (7 - (x & 7))) & 1; 02752 src_data += src->bytes_per_line; 02753 dest_data += dest->bytes_per_line; 02754 } 02755 } else { 02756 for (int y = 0; y < dest->height; y++) { 02757 register uchar *p = dest_data; 02758 for (int x = 0; x < dest->width; x++) 02759 *p++ = (src_data[x>>3] >> (x & 7)) & 1; 02760 src_data += src->bytes_per_line; 02761 dest_data += dest->bytes_per_line; 02762 } 02763 } 02764 }
Here is the call graph for this function:
static void convert_Mono_to_X32 | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2685 of file qimage.cpp.
References QVector< T >::at(), QImageData::bytes_per_line, QImageData::colortable, QImageData::data, fix_color_table(), QImageData::format, QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Mono, QImage::Format_MonoLSB, QImage::Format_RGB32, QImageData::height, p, QVector< T >::size(), QImageData::width, and y.
02686 { 02687 Q_ASSERT(src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB); 02688 Q_ASSERT(dest->format == QImage::Format_RGB32 02689 || dest->format == QImage::Format_ARGB32 02690 || dest->format == QImage::Format_ARGB32_Premultiplied); 02691 Q_ASSERT(src->width == dest->width); 02692 Q_ASSERT(src->height == dest->height); 02693 02694 QVector<QRgb> colorTable = fix_color_table(src->colortable, dest->format); 02695 02696 // Default to black / white colors 02697 if (colorTable.size() < 2) { 02698 if (colorTable.size() == 0) 02699 colorTable << 0xff000000; 02700 colorTable << 0xffffffff; 02701 } 02702 02703 const uchar *src_data = src->data; 02704 uchar *dest_data = dest->data; 02705 if (src->format == QImage::Format_Mono) { 02706 for (int y = 0; y < dest->height; y++) { 02707 register uint *p = (uint *)dest_data; 02708 for (int x = 0; x < dest->width; x++) 02709 *p++ = colorTable.at((src_data[x>>3] >> (7 - (x & 7))) & 1); 02710 02711 src_data += src->bytes_per_line; 02712 dest_data += dest->bytes_per_line; 02713 } 02714 } else { 02715 for (int y = 0; y < dest->height; y++) { 02716 register uint *p = (uint *)dest_data; 02717 for (int x = 0; x < dest->width; x++) 02718 *p++ = colorTable.at((src_data[x>>3] >> (x & 7)) & 1); 02719 02720 src_data += src->bytes_per_line; 02721 dest_data += dest->bytes_per_line; 02722 } 02723 } 02724 }
Here is the call graph for this function:
static void convert_RGB_to_Indexed8 | ( | QImageData * | dst, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | flags | |||
) | [static] |
Definition at line 2380 of file qimage.cpp.
References b, QImageData::bytes_per_line, QImageData::colortable, QImageData::data, Qt::DiffuseDither, DITHER, Qt::Dither_Mask, Qt::DitherMode_Mask, QImageData::format, QImage::Format_ARGB32, QImage::Format_Indexed8, QImage::Format_RGB32, QImageData::height, i, INDEXOF, QVector< T >::isEmpty(), m, MAX_B, MAX_G, MAX_R, p, Qt::PreferDither, QColor::qBlue(), QColor::qGreen(), qMax(), qMin(), QColor::qRed(), QColor::QRgb(), QColor::qRgb(), QVector< T >::resize(), rgb, s, QVector< T >::size(), Qt::ThresholdDither, used, QImageData::width, x, and y.
Referenced by convert_ARGB_PM_to_Indexed8(), and convert_ARGB_to_Indexed8().
02381 { 02382 Q_ASSERT(src->format == QImage::Format_RGB32 || src->format == QImage::Format_ARGB32); 02383 Q_ASSERT(dst->format == QImage::Format_Indexed8); 02384 Q_ASSERT(src->width == dst->width); 02385 Q_ASSERT(src->height == dst->height); 02386 02387 bool do_quant = (flags & Qt::DitherMode_Mask) == Qt::PreferDither 02388 || src->format == QImage::Format_ARGB32; 02389 uint alpha_mask = src->format == QImage::Format_RGB32 ? 0xff000000 : 0; 02390 02391 const int tablesize = 997; // prime 02392 QRgbMap table[tablesize]; 02393 int pix=0; 02394 02395 if (!dst->colortable.isEmpty()) { 02396 QVector<QRgb> ctbl = dst->colortable; 02397 dst->colortable.resize(256); 02398 // Preload palette into table. 02399 // Almost same code as pixel insertion below 02400 for (int i = 0; i < dst->colortable.size(); ++i) { 02401 // Find in table... 02402 QRgb p = ctbl.at(i) | alpha_mask; 02403 int hash = p % tablesize; 02404 for (;;) { 02405 if (table[hash].used()) { 02406 if (table[hash].rgb == p) { 02407 // Found previous insertion - use it 02408 break; 02409 } else { 02410 // Keep searching... 02411 if (++hash == tablesize) hash = 0; 02412 } 02413 } else { 02414 // Cannot be in table 02415 Q_ASSERT (pix != 256); // too many colors 02416 // Insert into table at this unused position 02417 dst->colortable[pix] = p; 02418 table[hash].pix = pix++; 02419 table[hash].rgb = p; 02420 break; 02421 } 02422 } 02423 } 02424 } 02425 02426 if ((flags & Qt::DitherMode_Mask) != Qt::PreferDither) { 02427 dst->colortable.resize(256); 02428 const uchar *src_data = src->data; 02429 uchar *dest_data = dst->data; 02430 for (int y = 0; y < src->height; y++) { // check if <= 256 colors 02431 const QRgb *s = (const QRgb *)src_data; 02432 uchar *b = dest_data; 02433 for (int x = 0; x < src->width; ++x) { 02434 QRgb p = s[x] | alpha_mask; 02435 int hash = p % tablesize; 02436 for (;;) { 02437 if (table[hash].used()) { 02438 if (table[hash].rgb == (p)) { 02439 // Found previous insertion - use it 02440 break; 02441 } else { 02442 // Keep searching... 02443 if (++hash == tablesize) hash = 0; 02444 } 02445 } else { 02446 // Cannot be in table 02447 if (pix == 256) { // too many colors 02448 do_quant = true; 02449 // Break right out 02450 x = src->width; 02451 y = src->height; 02452 } else { 02453 // Insert into table at this unused position 02454 dst->colortable[pix] = p; 02455 table[hash].pix = pix++; 02456 table[hash].rgb = p; 02457 } 02458 break; 02459 } 02460 } 02461 *b++ = table[hash].pix; // May occur once incorrectly 02462 } 02463 src_data += src->bytes_per_line; 02464 dest_data += dst->bytes_per_line; 02465 } 02466 } 02467 int numColors = do_quant ? 256 : pix; 02468 02469 dst->colortable.resize(numColors); 02470 02471 if (do_quant) { // quantization needed 02472 02473 #define MAX_R 5 02474 #define MAX_G 5 02475 #define MAX_B 5 02476 #define INDEXOF(r,g,b) (((r)*(MAX_G+1)+(g))*(MAX_B+1)+(b)) 02477 02478 for (int rc=0; rc<=MAX_R; rc++) // build 6x6x6 color cube 02479 for (int gc=0; gc<=MAX_G; gc++) 02480 for (int bc=0; bc<=MAX_B; bc++) 02481 dst->colortable[INDEXOF(rc,gc,bc)] = 0xff000000 | qRgb(rc*255/MAX_R, gc*255/MAX_G, bc*255/MAX_B); 02482 02483 const uchar *src_data = src->data; 02484 uchar *dest_data = dst->data; 02485 if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) { 02486 for (int y = 0; y < src->height; y++) { 02487 const QRgb *p = (const QRgb *)src_data; 02488 const QRgb *end = p + src->width; 02489 uchar *b = dest_data; 02490 02491 while (p < end) { 02492 #define DITHER(p,m) ((uchar) ((p * (m) + 127) / 255)) 02493 *b++ = 02494 INDEXOF( 02495 DITHER(qRed(*p), MAX_R), 02496 DITHER(qGreen(*p), MAX_G), 02497 DITHER(qBlue(*p), MAX_B) 02498 ); 02499 #undef DITHER 02500 p++; 02501 } 02502 src_data += src->bytes_per_line; 02503 dest_data += dst->bytes_per_line; 02504 } 02505 } else if ((flags & Qt::Dither_Mask) == Qt::DiffuseDither) { 02506 int* line1[3]; 02507 int* line2[3]; 02508 int* pv[3]; 02509 line1[0] = new int[src->width]; 02510 line2[0] = new int[src->width]; 02511 line1[1] = new int[src->width]; 02512 line2[1] = new int[src->width]; 02513 line1[2] = new int[src->width]; 02514 line2[2] = new int[src->width]; 02515 pv[0] = new int[src->width]; 02516 pv[1] = new int[src->width]; 02517 pv[2] = new int[src->width]; 02518 02519 int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian); 02520 for (int y = 0; y < src->height; y++) { 02521 const uchar* q = src_data; 02522 const uchar* q2 = y < src->height - 1 ? q + src->bytes_per_line : src->data; 02523 uchar *b = dest_data; 02524 for (int chan = 0; chan < 3; chan++) { 02525 int *l1 = (y&1) ? line2[chan] : line1[chan]; 02526 int *l2 = (y&1) ? line1[chan] : line2[chan]; 02527 if (y == 0) { 02528 for (int i = 0; i < src->width; i++) 02529 l1[i] = q[i*4+chan+endian]; 02530 } 02531 if (y+1 < src->height) { 02532 for (int i = 0; i < src->width; i++) 02533 l2[i] = q2[i*4+chan+endian]; 02534 } 02535 // Bi-directional error diffusion 02536 if (y&1) { 02537 for (int x = 0; x < src->width; x++) { 02538 int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0); 02539 int err = l1[x] - pix * 255 / 5; 02540 pv[chan][x] = pix; 02541 02542 // Spread the error around... 02543 if (x + 1< src->width) { 02544 l1[x+1] += (err*7)>>4; 02545 l2[x+1] += err>>4; 02546 } 02547 l2[x]+=(err*5)>>4; 02548 if (x>1) 02549 l2[x-1]+=(err*3)>>4; 02550 } 02551 } else { 02552 for (int x = src->width; x-- > 0;) { 02553 int pix = qMax(qMin(5, (l1[x] * 5 + 128)/ 255), 0); 02554 int err = l1[x] - pix * 255 / 5; 02555 pv[chan][x] = pix; 02556 02557 // Spread the error around... 02558 if (x > 0) { 02559 l1[x-1] += (err*7)>>4; 02560 l2[x-1] += err>>4; 02561 } 02562 l2[x]+=(err*5)>>4; 02563 if (x + 1 < src->width) 02564 l2[x+1]+=(err*3)>>4; 02565 } 02566 } 02567 } 02568 if (endian) { 02569 for (int x = 0; x < src->width; x++) { 02570 *b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]); 02571 } 02572 } else { 02573 for (int x = 0; x < src->width; x++) { 02574 *b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]); 02575 } 02576 } 02577 src_data += src->bytes_per_line; 02578 dest_data += dst->bytes_per_line; 02579 } 02580 delete [] line1[0]; 02581 delete [] line2[0]; 02582 delete [] line1[1]; 02583 delete [] line2[1]; 02584 delete [] line1[2]; 02585 delete [] line2[2]; 02586 delete [] pv[0]; 02587 delete [] pv[1]; 02588 delete [] pv[2]; 02589 } else { // OrderedDither 02590 for (int y = 0; y < src->height; y++) { 02591 const QRgb *p = (const QRgb *)src_data; 02592 const QRgb *end = p + src->width; 02593 uchar *b = dest_data; 02594 02595 int x = 0; 02596 while (p < end) { 02597 uint d = qt_bayer_matrix[y & 15][x & 15] << 8; 02598 02599 #define DITHER(p, d, m) ((uchar) ((((256 * (m) + (m) + 1)) * (p) + (d)) >> 16)) 02600 *b++ = 02601 INDEXOF( 02602 DITHER(qRed(*p), d, MAX_R), 02603 DITHER(qGreen(*p), d, MAX_G), 02604 DITHER(qBlue(*p), d, MAX_B) 02605 ); 02606 #undef DITHER 02607 02608 p++; 02609 x++; 02610 } 02611 src_data += src->bytes_per_line; 02612 dest_data += dst->bytes_per_line; 02613 } 02614 } 02615 02616 if (src->format != QImage::Format_RGB32 02617 && src->format != QImage::Format_RGB16) { 02618 const int trans = 216; 02619 Q_ASSERT(dst->colortable.size() > trans); 02620 dst->colortable[trans] = 0; 02621 QImageData *mask = QImageData::create(QSize(src->width, src->height), QImage::Format_Mono); 02622 dither_to_Mono(mask, src, flags, true); 02623 uchar *dst_data = dst->data; 02624 const uchar *mask_data = mask->data; 02625 for (int y = 0; y < src->height; y++) { 02626 for (int x = 0; x < src->width ; x++) { 02627 if (!(mask_data[x>>3] & (0x80 >> (x & 7)))) 02628 dst_data[x] = trans; 02629 } 02630 mask_data += mask->bytes_per_line; 02631 dst_data += dst->bytes_per_line; 02632 } 02633 dst->has_alpha_clut = true; 02634 delete mask; 02635 } 02636 02637 #undef MAX_R 02638 #undef MAX_G 02639 #undef MAX_B 02640 #undef INDEXOF 02641 02642 } 02643 }
Here is the call graph for this function:
static void convert_X_to_Mono | ( | QImageData * | dst, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | flags | |||
) | [static] |
Definition at line 2352 of file qimage.cpp.
References dither_to_Mono().
02353 { 02354 dither_to_Mono(dst, src, flags, false); 02355 }
Here is the call graph for this function:
static QImage convertWithPalette | ( | const QImage & | src, | |
QImage::Format | format, | |||
const QVector< QRgb > & | clut | |||
) | [static] |
Definition at line 3025 of file qimage.cpp.
References closestMatch(), QImage::Format_Indexed8, QImage::height(), QHash< Key, T >::insert(), QColor::QRgb(), QVector< T >::resize(), QImage::scanLine(), QImage::setColorTable(), QImage::size(), QString::SkipEmptyParts, QString::split(), QImage::text(), value, QHash< Key, T >::value(), QImage::width(), and y.
Referenced by QImage::convertToFormat().
03026 { 03027 QImage dest(src.size(), format); 03028 dest.setColorTable(clut); 03029 03030 #if !defined(QT_NO_IMAGE_TEXT) 03031 QString textsKeys = src.text(); 03032 QStringList textKeyList = textsKeys.split("\n", QString::SkipEmptyParts); 03033 foreach (QString textKey, textKeyList) { 03034 QStringList textKeySplitted = textKey.split(": "); 03035 dest.setText(textKeySplitted[0], textKeySplitted[1]); 03036 } 03037 #endif // !QT_NO_IMAGE_TEXT 03038 03039 int h = src.height(); 03040 int w = src.width(); 03041 03042 QHash<QRgb, int> cache; 03043 03044 if (format == QImage::Format_Indexed8) { 03045 for (int y=0; y<h; ++y) { 03046 QRgb *src_pixels = (QRgb *) src.scanLine(y); 03047 uchar *dest_pixels = (uchar *) dest.scanLine(y); 03048 for (int x=0; x<w; ++x) { 03049 int src_pixel = src_pixels[x]; 03050 int value = cache.value(src_pixel, -1); 03051 if (value == -1) { 03052 value = closestMatch(src_pixel, clut); 03053 cache.insert(src_pixel, value); 03054 } 03055 dest_pixels[x] = (uchar) value; 03056 } 03057 } 03058 } else { 03059 QVector<QRgb> table = clut; 03060 table.resize(2); 03061 for (int y=0; y<h; ++y) { 03062 QRgb *src_pixels = (QRgb *) src.scanLine(y); 03063 for (int x=0; x<w; ++x) { 03064 int src_pixel = src_pixels[x]; 03065 int value = cache.value(src_pixel, -1); 03066 if (value == -1) { 03067 value = closestMatch(src_pixel, table); 03068 cache.insert(src_pixel, value); 03069 } 03070 dest.setPixel(x, y, value); 03071 } 03072 } 03073 } 03074 03075 return dest; 03076 }
Here is the call graph for this function:
static int depthForFormat | ( | QImage::Format | format | ) | [static] |
Definition at line 193 of file qimage.cpp.
References QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Indexed8, QImage::Format_Invalid, QImage::Format_Mono, QImage::Format_MonoLSB, QImage::Format_RGB16, QImage::Format_RGB32, and QImage::NImageFormats.
Referenced by QImage::convertToFormat(), and QImage::QImage().
00194 { 00195 int depth = 0; 00196 switch(format) { 00197 case QImage::Format_Invalid: 00198 case QImage::NImageFormats: 00199 Q_ASSERT(false); 00200 case QImage::Format_Mono: 00201 case QImage::Format_MonoLSB: 00202 depth = 1; 00203 break; 00204 case QImage::Format_Indexed8: 00205 depth = 8; 00206 break; 00207 case QImage::Format_RGB32: 00208 case QImage::Format_ARGB32: 00209 case QImage::Format_ARGB32_Premultiplied: 00210 depth = 32; 00211 break; 00212 case QImage::Format_RGB16: 00213 depth = 16; 00214 break; 00215 } 00216 return depth; 00217 }
static void dither_to_Mono | ( | QImageData * | dst, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | flags, | |||
bool | fromalpha | |||
) | [static] |
Definition at line 2081 of file qimage.cpp.
References Qt::AlphaDither_Mask, QVector< T >::append(), QVector< T >::at(), bitflip, QImageData::bytes_per_line, QVector< T >::clear(), QImageData::colortable, d, QImageData::data, QImageData::depth, Qt::DiffuseAlphaDither, Qt::Dither_Mask, QImageData::format, QImage::Format_Mono, QImage::Format_MonoLSB, Qt::gray, QImageData::height, i, j, m, QImageData::nbytes, Qt::OrderedAlphaDither, Qt::OrderedDither, p, QColor::qGray(), qt_bayer_matrix, QVector< T >::size(), Qt::ThresholdDither, QImageData::width, x, and y.
Referenced by convert_ARGB_PM_to_Mono(), convert_X_to_Mono(), and QImage::createAlphaMask().
02083 { 02084 Q_ASSERT(src->width == dst->width); 02085 Q_ASSERT(src->height == dst->height); 02086 Q_ASSERT(dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB); 02087 02088 dst->colortable.clear(); 02089 dst->colortable.append(0xffffffff); 02090 dst->colortable.append(0xff000000); 02091 02092 enum { Threshold, Ordered, Diffuse } dithermode; 02093 02094 if (fromalpha) { 02095 if ((flags & Qt::AlphaDither_Mask) == Qt::DiffuseAlphaDither) 02096 dithermode = Diffuse; 02097 else if ((flags & Qt::AlphaDither_Mask) == Qt::OrderedAlphaDither) 02098 dithermode = Ordered; 02099 else 02100 dithermode = Threshold; 02101 } else { 02102 if ((flags & Qt::Dither_Mask) == Qt::ThresholdDither) 02103 dithermode = Threshold; 02104 else if ((flags & Qt::Dither_Mask) == Qt::OrderedDither) 02105 dithermode = Ordered; 02106 else 02107 dithermode = Diffuse; 02108 } 02109 02110 int w = src->width; 02111 int h = src->height; 02112 int d = src->depth; 02113 uchar gray[256]; // gray map for 8 bit images 02114 bool use_gray = (d == 8); 02115 if (use_gray) { // make gray map 02116 if (fromalpha) { 02117 // Alpha 0x00 -> 0 pixels (white) 02118 // Alpha 0xFF -> 1 pixels (black) 02119 for (int i = 0; i < src->colortable.size(); i++) 02120 gray[i] = (255 - (src->colortable.at(i) >> 24)); 02121 } else { 02122 // Pixel 0x00 -> 1 pixels (black) 02123 // Pixel 0xFF -> 0 pixels (white) 02124 for (int i = 0; i < src->colortable.size(); i++) 02125 gray[i] = qGray(src->colortable.at(i)); 02126 } 02127 } 02128 02129 uchar *dst_data = dst->data; 02130 int dst_bpl = dst->bytes_per_line; 02131 const uchar *src_data = src->data; 02132 int src_bpl = src->bytes_per_line; 02133 02134 switch (dithermode) { 02135 case Diffuse: { 02136 int *line1 = new int[w]; 02137 int *line2 = new int[w]; 02138 int bmwidth = (w+7)/8; 02139 02140 int *b1, *b2; 02141 int wbytes = w * (d/8); 02142 register const uchar *p = src->data; 02143 const uchar *end = p + wbytes; 02144 b2 = line2; 02145 if (use_gray) { // 8 bit image 02146 while (p < end) 02147 *b2++ = gray[*p++]; 02148 } else { // 32 bit image 02149 if (fromalpha) { 02150 while (p < end) { 02151 *b2++ = 255 - (*(uint*)p >> 24); 02152 p += 4; 02153 } 02154 } else { 02155 while (p < end) { 02156 *b2++ = qGray(*(uint*)p); 02157 p += 4; 02158 } 02159 } 02160 } 02161 for (int y=0; y<h; y++) { // for each scan line... 02162 int *tmp = line1; line1 = line2; line2 = tmp; 02163 bool not_last_line = y < h - 1; 02164 if (not_last_line) { // calc. grayvals for next line 02165 p = src->data + (y+1)*src->bytes_per_line; 02166 end = p + wbytes; 02167 b2 = line2; 02168 if (use_gray) { // 8 bit image 02169 while (p < end) 02170 *b2++ = gray[*p++]; 02171 } else { // 24 bit image 02172 if (fromalpha) { 02173 while (p < end) { 02174 *b2++ = 255 - (*(uint*)p >> 24); 02175 p += 4; 02176 } 02177 } else { 02178 while (p < end) { 02179 *b2++ = qGray(*(uint*)p); 02180 p += 4; 02181 } 02182 } 02183 } 02184 } 02185 02186 int err; 02187 uchar *p = dst->data + y*dst->bytes_per_line; 02188 memset(p, 0, bmwidth); 02189 b1 = line1; 02190 b2 = line2; 02191 int bit = 7; 02192 for (int x=1; x<=w; x++) { 02193 if (*b1 < 128) { // black pixel 02194 err = *b1++; 02195 *p |= 1 << bit; 02196 } else { // white pixel 02197 err = *b1++ - 255; 02198 } 02199 if (bit == 0) { 02200 p++; 02201 bit = 7; 02202 } else { 02203 bit--; 02204 } 02205 if (x < w) 02206 *b1 += (err*7)>>4; // spread error to right pixel 02207 if (not_last_line) { 02208 b2[0] += (err*5)>>4; // pixel below 02209 if (x > 1) 02210 b2[-1] += (err*3)>>4; // pixel below left 02211 if (x < w) 02212 b2[1] += err>>4; // pixel below right 02213 } 02214 b2++; 02215 } 02216 } 02217 delete [] line1; 02218 delete [] line2; 02219 } break; 02220 case Ordered: { 02221 02222 memset(dst->data, 0, dst->nbytes); 02223 if (d == 32) { 02224 for (int i=0; i<h; i++) { 02225 const uint *p = (const uint *)src_data; 02226 const uint *end = p + w; 02227 uchar *m = dst_data; 02228 int bit = 7; 02229 int j = 0; 02230 if (fromalpha) { 02231 while (p < end) { 02232 if ((*p++ >> 24) >= qt_bayer_matrix[j++&15][i&15]) 02233 *m |= 1 << bit; 02234 if (bit == 0) { 02235 m++; 02236 bit = 7; 02237 } else { 02238 bit--; 02239 } 02240 } 02241 } else { 02242 while (p < end) { 02243 if ((uint)qGray(*p++) < qt_bayer_matrix[j++&15][i&15]) 02244 *m |= 1 << bit; 02245 if (bit == 0) { 02246 m++; 02247 bit = 7; 02248 } else { 02249 bit--; 02250 } 02251 } 02252 } 02253 dst_data += dst_bpl; 02254 src_data += src_bpl; 02255 } 02256 } else 02257 /* (d == 8) */ { 02258 for (int i=0; i<h; i++) { 02259 const uchar *p = src_data; 02260 const uchar *end = p + w; 02261 uchar *m = dst_data; 02262 int bit = 7; 02263 int j = 0; 02264 while (p < end) { 02265 if ((uint)gray[*p++] < qt_bayer_matrix[j++&15][i&15]) 02266 *m |= 1 << bit; 02267 if (bit == 0) { 02268 m++; 02269 bit = 7; 02270 } else { 02271 bit--; 02272 } 02273 } 02274 dst_data += dst_bpl; 02275 src_data += src_bpl; 02276 } 02277 } 02278 } break; 02279 default: { // Threshold: 02280 memset(dst->data, 0, dst->nbytes); 02281 if (d == 32) { 02282 for (int i=0; i<h; i++) { 02283 const uint *p = (const uint *)src_data; 02284 const uint *end = p + w; 02285 uchar *m = dst_data; 02286 int bit = 7; 02287 if (fromalpha) { 02288 while (p < end) { 02289 if ((*p++ >> 24) >= 128) 02290 *m |= 1 << bit; // Set mask "on" 02291 if (bit == 0) { 02292 m++; 02293 bit = 7; 02294 } else { 02295 bit--; 02296 } 02297 } 02298 } else { 02299 while (p < end) { 02300 if (qGray(*p++) < 128) 02301 *m |= 1 << bit; // Set pixel "black" 02302 if (bit == 0) { 02303 m++; 02304 bit = 7; 02305 } else { 02306 bit--; 02307 } 02308 } 02309 } 02310 dst_data += dst_bpl; 02311 src_data += src_bpl; 02312 } 02313 } else 02314 if (d == 8) { 02315 for (int i=0; i<h; i++) { 02316 const uchar *p = src_data; 02317 const uchar *end = p + w; 02318 uchar *m = dst_data; 02319 int bit = 7; 02320 while (p < end) { 02321 if (gray[*p++] < 128) 02322 *m |= 1 << bit; // Set mask "on"/ pixel "black" 02323 if (bit == 0) { 02324 m++; 02325 bit = 7; 02326 } else { 02327 bit--; 02328 } 02329 } 02330 dst_data += dst_bpl; 02331 src_data += src_bpl; 02332 } 02333 } 02334 } 02335 } 02336 02337 if (dst->format == QImage::Format_MonoLSB) { 02338 // need to swap bit order 02339 uchar *sl = dst->data; 02340 int bpl = (dst->width + 7) * dst->depth / 8; 02341 int pad = dst->bytes_per_line - bpl; 02342 for (int y=0; y<dst->height; ++y) { 02343 for (int x=0; x<bpl; ++x) { 02344 *sl = bitflip[*sl]; 02345 ++sl; 02346 } 02347 sl += pad; 02348 } 02349 } 02350 }
Here is the call graph for this function:
static QVector<QRgb> fix_color_table | ( | const QVector< QRgb > & | ctbl, | |
QImage::Format | format | |||
) | [static] |
Definition at line 2061 of file qimage.cpp.
References QVector< T >::at(), QImage::Format_ARGB32_Premultiplied, QImage::Format_RGB32, i, PREMUL(), QColor::qAlpha(), and QVector< T >::size().
Referenced by convert_Indexed8_to_X32(), and convert_Mono_to_X32().
02062 { 02063 QVector<QRgb> colorTable = ctbl; 02064 if (format == QImage::Format_RGB32) { 02065 // check if the color table has alpha 02066 for (int i = 0; i < colorTable.size(); ++i) 02067 if (qAlpha(colorTable.at(i) != 0xff)) 02068 colorTable[i] = colorTable.at(i) | 0xff000000; 02069 } else if (format == QImage::Format_ARGB32_Premultiplied) { 02070 // check if the color table has alpha 02071 for (int i = 0; i < colorTable.size(); ++i) 02072 colorTable[i] = PREMUL(colorTable.at(i)); 02073 } 02074 return colorTable; 02075 }
Here is the call graph for this function:
static void mask_alpha_converter | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2045 of file qimage.cpp.
References QImageData::data, QImageData::height, QImageData::nbytes, and QImageData::width.
02046 { 02047 Q_ASSERT(src->width == dest->width); 02048 Q_ASSERT(src->height == dest->height); 02049 Q_ASSERT(src->nbytes == dest->nbytes); 02050 02051 const uint *src_data = (const uint *)src->data; 02052 const uint *end = (const uint *)(src->data + src->nbytes); 02053 uint *dest_data = (uint *)dest->data; 02054 while (src_data < end) { 02055 *dest_data = *src_data | 0xff000000; 02056 ++src_data; 02057 ++dest_data; 02058 } 02059 }
QDataStream& operator<< | ( | QDataStream & | s, | |
const QImage & | image | |||
) | [related] |
Definition at line 4255 of file qimage.cpp.
04256 { 04257 if (s.version() >= 5) { 04258 if (image.isNull()) { 04259 s << (qint32) 0; // null image marker 04260 return s; 04261 } else { 04262 s << (qint32) 1; 04263 // continue ... 04264 } 04265 } 04266 QImageWriter writer(s.device(), s.version() == 1 ? "bmp" : "png"); 04267 writer.write(image); 04268 return s; 04269 }
QDataStream& operator>> | ( | QDataStream & | s, | |
QImage & | image | |||
) | [related] |
static int pixel_distance | ( | QRgb | p1, | |
QRgb | p2 | |||
) | [inline, static] |
Definition at line 2998 of file qimage.cpp.
References QColor::qAlpha(), QColor::qBlue(), QColor::qGreen(), and QColor::qRed().
Referenced by closestMatch().
02998 { 02999 int r1 = qRed(p1); 03000 int g1 = qGreen(p1); 03001 int b1 = qBlue(p1); 03002 int a1 = qAlpha(p1); 03003 03004 int r2 = qRed(p2); 03005 int g2 = qGreen(p2); 03006 int b2 = qBlue(p2); 03007 int a2 = qAlpha(p2); 03008 03009 return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2); 03010 }
Here is the call graph for this function:
Definition at line 5223 of file qimage.cpp.
References a, QImage::convertToFormat(), QImage::format(), g, QImage::hasAlphaChannel(), QImage::height(), QColor::qAlpha(), QColor::qBlue(), QColor::qGreen(), QColor::qRed(), QColor::QRgb(), QColor::qRgb(), QColor::qRgba(), row, QImage::scanLine(), and QImage::width().
Referenced by smoothScaled().
05224 { 05225 QRgb* xelrow = 0; 05226 QRgb* tempxelrow = 0; 05227 register QRgb* xP; 05228 register QRgb* nxP; 05229 int rows, cols, rowsread, newrows, newcols; 05230 register int row, col, needtoreadrow; 05231 const uchar maxval = 255; 05232 double xscale, yscale; 05233 long sxscale, syscale; 05234 register long fracrowtofill, fracrowleft; 05235 long* as; 05236 long* rs; 05237 long* gs; 05238 long* bs; 05239 int rowswritten = 0; 05240 05241 cols = src.width(); 05242 rows = src.height(); 05243 newcols = dst.width(); 05244 newrows = dst.height(); 05245 05246 long SCALE; 05247 long HALFSCALE; 05248 05249 if (cols > 4096) 05250 { 05251 SCALE = 4096; 05252 HALFSCALE = 2048; 05253 } 05254 else 05255 { 05256 int fac = 4096; 05257 05258 while (cols * fac > 4096) 05259 { 05260 fac /= 2; 05261 } 05262 05263 SCALE = fac * cols; 05264 HALFSCALE = fac * cols / 2; 05265 } 05266 05267 xscale = (double) newcols / (double) cols; 05268 yscale = (double) newrows / (double) rows; 05269 05270 sxscale = (long)(xscale * SCALE); 05271 syscale = (long)(yscale * SCALE); 05272 05273 if ( newrows != rows ) /* shortcut Y scaling if possible */ 05274 tempxelrow = new QRgb[cols]; 05275 05276 if ( src.hasAlphaChannel() ) { 05277 dst = dst.convertToFormat(src.format()); 05278 as = new long[cols]; 05279 for ( col = 0; col < cols; ++col ) 05280 as[col] = HALFSCALE; 05281 } else { 05282 as = 0; 05283 } 05284 rs = new long[cols]; 05285 gs = new long[cols]; 05286 bs = new long[cols]; 05287 rowsread = 0; 05288 fracrowleft = syscale; 05289 needtoreadrow = 1; 05290 for ( col = 0; col < cols; ++col ) 05291 rs[col] = gs[col] = bs[col] = HALFSCALE; 05292 fracrowtofill = SCALE; 05293 05294 for ( row = 0; row < newrows; ++row ) { 05295 /* First scale Y from xelrow into tempxelrow. */ 05296 if ( newrows == rows ) { 05297 /* shortcut Y scaling if possible */ 05298 tempxelrow = xelrow = (QRgb*)src.scanLine(rowsread++); 05299 } else { 05300 while ( fracrowleft < fracrowtofill ) { 05301 if ( needtoreadrow && rowsread < rows ) 05302 xelrow = (QRgb*)src.scanLine(rowsread++); 05303 for ( col = 0, xP = xelrow; col < cols; ++col, ++xP ) { 05304 if (as) { 05305 as[col] += fracrowleft * qAlpha( *xP ); 05306 rs[col] += fracrowleft * qRed( *xP ) * qAlpha( *xP ) / 255; 05307 gs[col] += fracrowleft * qGreen( *xP ) * qAlpha( *xP ) / 255; 05308 bs[col] += fracrowleft * qBlue( *xP ) * qAlpha( *xP ) / 255; 05309 } else { 05310 rs[col] += fracrowleft * qRed( *xP ); 05311 gs[col] += fracrowleft * qGreen( *xP ); 05312 bs[col] += fracrowleft * qBlue( *xP ); 05313 } 05314 } 05315 fracrowtofill -= fracrowleft; 05316 fracrowleft = syscale; 05317 needtoreadrow = 1; 05318 } 05319 /* Now fracrowleft is >= fracrowtofill, so we can produce a row. */ 05320 if ( needtoreadrow && rowsread < rows ) { 05321 xelrow = (QRgb*)src.scanLine(rowsread++); 05322 needtoreadrow = 0; 05323 } 05324 register long a=0; 05325 for ( col = 0, xP = xelrow, nxP = tempxelrow; 05326 col < cols; ++col, ++xP, ++nxP ) 05327 { 05328 register long r, g, b; 05329 05330 if ( as ) { 05331 r = rs[col] + fracrowtofill * qRed( *xP ) * qAlpha( *xP ) / 255; 05332 g = gs[col] + fracrowtofill * qGreen( *xP ) * qAlpha( *xP ) / 255; 05333 b = bs[col] + fracrowtofill * qBlue( *xP ) * qAlpha( *xP ) / 255; 05334 a = as[col] + fracrowtofill * qAlpha( *xP ); 05335 if ( a ) { 05336 r = r * 255 / a * SCALE; 05337 g = g * 255 / a * SCALE; 05338 b = b * 255 / a * SCALE; 05339 } 05340 } else { 05341 r = rs[col] + fracrowtofill * qRed( *xP ); 05342 g = gs[col] + fracrowtofill * qGreen( *xP ); 05343 b = bs[col] + fracrowtofill * qBlue( *xP ); 05344 } 05345 r /= SCALE; 05346 if ( r > maxval ) r = maxval; 05347 g /= SCALE; 05348 if ( g > maxval ) g = maxval; 05349 b /= SCALE; 05350 if ( b > maxval ) b = maxval; 05351 if ( as ) { 05352 a /= SCALE; 05353 if ( a > maxval ) a = maxval; 05354 *nxP = qRgba( (int)r, (int)g, (int)b, (int)a ); 05355 as[col] = HALFSCALE; 05356 } else { 05357 *nxP = qRgb( (int)r, (int)g, (int)b ); 05358 } 05359 rs[col] = gs[col] = bs[col] = HALFSCALE; 05360 } 05361 fracrowleft -= fracrowtofill; 05362 if ( fracrowleft == 0 ) { 05363 fracrowleft = syscale; 05364 needtoreadrow = 1; 05365 } 05366 fracrowtofill = SCALE; 05367 } 05368 05369 /* Now scale X from tempxelrow into dst and write it out. */ 05370 if ( newcols == cols ) { 05371 /* shortcut X scaling if possible */ 05372 memcpy(dst.scanLine(rowswritten++), tempxelrow, newcols*4); 05373 } else { 05374 register long a, r, g, b; 05375 register long fraccoltofill, fraccolleft = 0; 05376 register int needcol; 05377 05378 nxP = (QRgb*)dst.scanLine(rowswritten++); 05379 fraccoltofill = SCALE; 05380 a = r = g = b = HALFSCALE; 05381 needcol = 0; 05382 for ( col = 0, xP = tempxelrow; col < cols; ++col, ++xP ) { 05383 fraccolleft = sxscale; 05384 while ( fraccolleft >= fraccoltofill ) { 05385 if ( needcol ) { 05386 ++nxP; 05387 a = r = g = b = HALFSCALE; 05388 } 05389 if ( as ) { 05390 r += fraccoltofill * qRed( *xP ) * qAlpha( *xP ) / 255; 05391 g += fraccoltofill * qGreen( *xP ) * qAlpha( *xP ) / 255; 05392 b += fraccoltofill * qBlue( *xP ) * qAlpha( *xP ) / 255; 05393 a += fraccoltofill * qAlpha( *xP ); 05394 if ( a ) { 05395 r = r * 255 / a * SCALE; 05396 g = g * 255 / a * SCALE; 05397 b = b * 255 / a * SCALE; 05398 } 05399 } else { 05400 r += fraccoltofill * qRed( *xP ); 05401 g += fraccoltofill * qGreen( *xP ); 05402 b += fraccoltofill * qBlue( *xP ); 05403 } 05404 r /= SCALE; 05405 if ( r > maxval ) r = maxval; 05406 g /= SCALE; 05407 if ( g > maxval ) g = maxval; 05408 b /= SCALE; 05409 if ( b > maxval ) b = maxval; 05410 if (as) { 05411 a /= SCALE; 05412 if ( a > maxval ) a = maxval; 05413 *nxP = qRgba( (int)r, (int)g, (int)b, (int)a ); 05414 } else { 05415 *nxP = qRgb( (int)r, (int)g, (int)b ); 05416 } 05417 fraccolleft -= fraccoltofill; 05418 fraccoltofill = SCALE; 05419 needcol = 1; 05420 } 05421 if ( fraccolleft > 0 ) { 05422 if ( needcol ) { 05423 ++nxP; 05424 a = r = g = b = HALFSCALE; 05425 needcol = 0; 05426 } 05427 if (as) { 05428 a += fraccolleft * qAlpha( *xP ); 05429 r += fraccolleft * qRed( *xP ) * qAlpha( *xP ) / 255; 05430 g += fraccolleft * qGreen( *xP ) * qAlpha( *xP ) / 255; 05431 b += fraccolleft * qBlue( *xP ) * qAlpha( *xP ) / 255; 05432 } else { 05433 r += fraccolleft * qRed( *xP ); 05434 g += fraccolleft * qGreen( *xP ); 05435 b += fraccolleft * qBlue( *xP ); 05436 } 05437 fraccoltofill -= fraccolleft; 05438 } 05439 } 05440 if ( fraccoltofill > 0 ) { 05441 --xP; 05442 if (as) { 05443 a += fraccolleft * qAlpha( *xP ); 05444 r += fraccoltofill * qRed( *xP ) * qAlpha( *xP ) / 255; 05445 g += fraccoltofill * qGreen( *xP ) * qAlpha( *xP ) / 255; 05446 b += fraccoltofill * qBlue( *xP ) * qAlpha( *xP ) / 255; 05447 if ( a ) { 05448 r = r * 255 / a * SCALE; 05449 g = g * 255 / a * SCALE; 05450 b = b * 255 / a * SCALE; 05451 } 05452 } else { 05453 r += fraccoltofill * qRed( *xP ); 05454 g += fraccoltofill * qGreen( *xP ); 05455 b += fraccoltofill * qBlue( *xP ); 05456 } 05457 } 05458 if ( ! needcol ) { 05459 r /= SCALE; 05460 if ( r > maxval ) r = maxval; 05461 g /= SCALE; 05462 if ( g > maxval ) g = maxval; 05463 b /= SCALE; 05464 if ( b > maxval ) b = maxval; 05465 if (as) { 05466 a /= SCALE; 05467 if ( a > maxval ) a = maxval; 05468 *nxP = qRgba( (int)r, (int)g, (int)b, (int)a ); 05469 } else { 05470 *nxP = qRgb( (int)r, (int)g, (int)b ); 05471 } 05472 } 05473 } 05474 } 05475 05476 if ( newrows != rows && tempxelrow )// Robust, tempxelrow might be 0 1 day 05477 delete [] tempxelrow; 05478 if ( as ) // Avoid purify complaint 05479 delete [] as; 05480 if ( rs ) // Robust, rs might be 0 one day 05481 delete [] rs; 05482 if ( gs ) // Robust, gs might be 0 one day 05483 delete [] gs; 05484 if ( bs ) // Robust, bs might be 0 one day 05485 delete [] bs; 05486 }
Here is the call graph for this function:
int qimage_next_serial_number | ( | ) |
Definition at line 156 of file qimage.cpp.
References id, qimage_serial_number, and QBasicAtomic::testAndSet().
Referenced by QImageData::QImageData().
00157 { 00158 register int id; 00159 for (;;) { 00160 id = qimage_serial_number; 00161 if (qimage_serial_number.testAndSet(id, id + 1)) 00162 break; 00163 } 00164 return id; 00165 }
Here is the call graph for this function:
static QRgb qt_conv16ToRgb | ( | ushort | c | ) | [inline, static] |
Definition at line 58 of file qimage.cpp.
References QColor::QRgb().
Referenced by QImage::allGray(), convert_16_to_32(), and QImage::pixel().
00059 { 00060 QRgb r = (((c) << 3) & 0xf8) 00061 | (((c) << 5) & 0xfc00) 00062 | (((c) << 8) & 0xf80000); 00063 r |= (r >> 5) & 0x70007; 00064 r |= (r >> 6) & 0x300; 00065 return r | 0xff000000; 00066 }
Here is the call graph for this function:
static ushort qt_convRgbTo16 | ( | QRgb | c | ) | [inline, static] |
Definition at line 51 of file qimage.cpp.
Referenced by convert_32_to_16(), and QImage::setPixel().
00052 { 00053 return ((c >> 8) & 0xf800) 00054 | ((c >> 5) & 0x07e) 00055 | ((c >> 3) & 0x1f); 00056 }
int qt_defaultDpi | ( | ) |
Definition at line 119 of file qfont.cpp.
Referenced by QPicture::exec(), generateWavyPath(), getPixmapSize(), QTextDocumentLayoutPrivate::indent(), QTextDocumentLayoutPrivate::layoutBlock(), QGLPixelBuffer::metric(), QGLFramebufferObject::metric(), QPicture::metric(), QTextDocument::print(), QFontMetrics::QFontMetrics(), QFontMetricsF::QFontMetricsF(), QImageData::QImageData(), and QPdfBaseEnginePrivate::QPdfBaseEnginePrivate().
00120 { 00121 if (!qt_is_gui_used) 00122 return 75; 00123 00124 int dpi; 00125 #ifdef Q_WS_X11 00126 dpi = QX11Info::appDpiY(); 00127 #elif defined(Q_WS_WIN) 00128 dpi = GetDeviceCaps(shared_dc,LOGPIXELSY); 00129 #elif defined(Q_WS_MAC) 00130 short hr; 00131 short mdpi; 00132 ScreenRes(&hr, &mdpi); 00133 dpi = int(mdpi); 00134 #elif defined(Q_WS_QWS) 00135 if (!qt_screen) 00136 return 72; 00137 QScreen *screen = qt_screen; 00138 const QList<QScreen*> subScreens = qt_screen->subScreens(); 00139 if (!subScreens.isEmpty()) 00140 screen = subScreens.at(0); 00141 dpi = qRound(screen->height() / double(screen->physicalHeight() / 25.4)); 00142 #endif // Q_WS_X11 00143 00144 return dpi; 00145 }
const uchar* qt_get_bitflip_array | ( | ) |
Definition at line 148 of file qimage.cpp.
References QImage::Format_Indexed8, and image.
Referenced by QSpanData::initTexture().
00149 { 00150 return (image.d->format <= QImage::Format_Indexed8 && !image.d->colortable.isEmpty()) ? &image.d->colortable : 0; 00151 }
Definition at line 143 of file qimage.cpp.
References image.
Referenced by QGLContextPrivate::bindTexture(), and QPdfEngine::drawImage().
Definition at line 1009 of file qxpmhandler.cpp.
References buf, cpp(), h, image, index, read_xpm_body(), read_xpm_header(), QIODevice::readLine(), QIODevice::ungetChar(), and w.
Referenced by QImage::QImage().
01010 { 01011 QByteArray buf(200, 0); 01012 QByteArray state; 01013 01014 int cpp, ncols, w, h, index = 0; 01015 01016 if (device) { 01017 // "/* XPM */" 01018 int readBytes; 01019 if ((readBytes = device->readLine(buf.data(), buf.size())) < 0) 01020 return false; 01021 01022 if (buf.indexOf("/* XPM") != 0) { 01023 while (readBytes > 0) { 01024 device->ungetChar(buf.at(readBytes - 1)); 01025 --readBytes; 01026 } 01027 return false; 01028 }// bad magic 01029 } 01030 01031 if (!read_xpm_header(device, source, index, state, &cpp, &ncols, &w, &h)) 01032 return false; 01033 01034 return read_xpm_body(device, source, index, state, cpp, ncols, w, h, image); 01035 }
Here is the call graph for this function:
bool qt_xForm_helper | ( | const QMatrix & | trueMat, | |
int | xoffset, | |||
int | type, | |||
int | depth, | |||
uchar * | dptr, | |||
int | dbpl, | |||
int | p_inc, | |||
int | dHeight, | |||
const uchar * | sptr, | |||
int | sbpl, | |||
int | sWidth, | |||
int | sHeight | |||
) |
Definition at line 4839 of file qimage.cpp.
References QMatrix::dx(), QMatrix::dy(), IWX_LSB, IWX_MSB, IWX_PIX, QMatrix::m11(), QMatrix::m12(), QMatrix::m21(), QMatrix::m22(), qRound(), QT_XFORM_TYPE_LSBFIRST, QT_XFORM_TYPE_MSBFIRST, and y.
Referenced by QImage::transformed().
04842 { 04843 int m11 = qRound(trueMat.m11()*4096.0); 04844 int m12 = qRound(trueMat.m12()*4096.0); 04845 int m21 = qRound(trueMat.m21()*4096.0); 04846 int m22 = qRound(trueMat.m22()*4096.0); 04847 int dx = qRound(trueMat.dx()*4096.0); 04848 int dy = qRound(trueMat.dy()*4096.0); 04849 04850 int m21ydx = dx + (xoffset<<16); 04851 int m22ydy = dy; 04852 uint trigx; 04853 uint trigy; 04854 uint maxws = sWidth<<12; 04855 uint maxhs = sHeight<<12; 04856 04857 for (int y=0; y<dHeight; y++) { // for each target scanline 04858 trigx = m21ydx; 04859 trigy = m22ydy; 04860 uchar *maxp = dptr + dbpl; 04861 if (depth != 1) { 04862 switch (depth) { 04863 case 8: // 8 bpp transform 04864 while (dptr < maxp) { 04865 if (trigx < maxws && trigy < maxhs) 04866 *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12)); 04867 trigx += m11; 04868 trigy += m12; 04869 dptr++; 04870 } 04871 break; 04872 04873 case 16: // 16 bpp transform 04874 while (dptr < maxp) { 04875 if (trigx < maxws && trigy < maxhs) 04876 *((ushort*)dptr) = *((ushort *)(sptr+sbpl*(trigy>>12) + 04877 ((trigx>>12)<<1))); 04878 trigx += m11; 04879 trigy += m12; 04880 dptr++; 04881 dptr++; 04882 } 04883 break; 04884 04885 case 24: // 24 bpp transform 04886 while (dptr < maxp) { 04887 if (trigx < maxws && trigy < maxhs) { 04888 const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3); 04889 dptr[0] = p2[0]; 04890 dptr[1] = p2[1]; 04891 dptr[2] = p2[2]; 04892 } 04893 trigx += m11; 04894 trigy += m12; 04895 dptr += 3; 04896 } 04897 break; 04898 04899 case 32: // 32 bpp transform 04900 while (dptr < maxp) { 04901 if (trigx < maxws && trigy < maxhs) 04902 *((uint*)dptr) = *((uint *)(sptr+sbpl*(trigy>>12) + 04903 ((trigx>>12)<<2))); 04904 trigx += m11; 04905 trigy += m12; 04906 dptr += 4; 04907 } 04908 break; 04909 04910 default: { 04911 return false; 04912 } 04913 } 04914 } else { 04915 switch (type) { 04916 case QT_XFORM_TYPE_MSBFIRST: 04917 while (dptr < maxp) { 04918 IWX_MSB(128); 04919 IWX_MSB(64); 04920 IWX_MSB(32); 04921 IWX_MSB(16); 04922 IWX_MSB(8); 04923 IWX_MSB(4); 04924 IWX_MSB(2); 04925 IWX_MSB(1); 04926 dptr++; 04927 } 04928 break; 04929 case QT_XFORM_TYPE_LSBFIRST: 04930 while (dptr < maxp) { 04931 IWX_LSB(1); 04932 IWX_LSB(2); 04933 IWX_LSB(4); 04934 IWX_LSB(8); 04935 IWX_LSB(16); 04936 IWX_LSB(32); 04937 IWX_LSB(64); 04938 IWX_LSB(128); 04939 dptr++; 04940 } 04941 break; 04942 # if defined(Q_WS_WIN) 04943 case QT_XFORM_TYPE_WINDOWSPIXMAP: 04944 while (dptr < maxp) { 04945 IWX_PIX(128); 04946 IWX_PIX(64); 04947 IWX_PIX(32); 04948 IWX_PIX(16); 04949 IWX_PIX(8); 04950 IWX_PIX(4); 04951 IWX_PIX(2); 04952 IWX_PIX(1); 04953 dptr++; 04954 } 04955 break; 04956 # endif 04957 } 04958 } 04959 m21ydx += m21; 04960 m22ydy += m22; 04961 dptr += p_inc; 04962 } 04963 return true; 04964 }
Here is the call graph for this function:
Definition at line 5549 of file qimage.cpp.
References image.
Referenced by QImage::transformed().
05549 { 05550 return image.mirrored(true, true); 05551 }
Definition at line 5554 of file qimage.cpp.
References QImage::bits(), QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Indexed8, QImage::Format_RGB32, image, QColor::QRgb(), QImage::setColorTable(), QImage::setPixel(), and y.
Referenced by QImage::transformed().
05554 { 05555 QImage out(image.height(), image.width(), image.format()); 05556 if (image.numColors() > 0) 05557 out.setColorTable(image.colorTable()); 05558 int w = image.width(); 05559 int h = image.height(); 05560 switch (image.format()) { 05561 case QImage::Format_RGB32: 05562 case QImage::Format_ARGB32: 05563 case QImage::Format_ARGB32_Premultiplied: 05564 { 05565 QRgb *dst = (QRgb *) out.bits(); 05566 for (int y=0; y<h; ++y) { 05567 const QRgb *src = (const QRgb *) image.scanLine(y); 05568 for (int x=0; x<w; ++x) 05569 dst[y + (w-x-1)*h] = *src++; 05570 } 05571 } 05572 break; 05573 case QImage::Format_Indexed8: 05574 { 05575 uchar *dst = out.bits(); 05576 for (int y=0; y<h; ++y) { 05577 const uchar *src = image.scanLine(y); 05578 for (int x=0; x<w; ++x) { 05579 dst[y + (w-x-1)*h] = *src++; 05580 } 05581 } 05582 } 05583 break; 05584 default: 05585 for (int y=0; y<h; ++y) { 05586 if (image.numColors()) 05587 for (int x=0; x<w; ++x) 05588 out.setPixel(y, w-x-1, image.pixelIndex(x, y)); 05589 else 05590 for (int x=0; x<w; ++x) 05591 out.setPixel(y, w-x-1, image.pixel(x, y)); 05592 } 05593 break; 05594 } 05595 return out; 05596 }
Here is the call graph for this function:
Definition at line 5504 of file qimage.cpp.
References QImage::bits(), QImage::Format_ARGB32, QImage::Format_ARGB32_Premultiplied, QImage::Format_Indexed8, QImage::Format_RGB32, image, QColor::QRgb(), QImage::setColorTable(), QImage::setPixel(), and y.
Referenced by QImage::transformed().
05504 { 05505 QImage out(image.height(), image.width(), image.format()); 05506 if (image.numColors() > 0) 05507 out.setColorTable(image.colorTable()); 05508 int w = image.width(); 05509 int h = image.height(); 05510 switch (image.format()) { 05511 case QImage::Format_RGB32: 05512 case QImage::Format_ARGB32: 05513 case QImage::Format_ARGB32_Premultiplied: 05514 { 05515 QRgb *dst = (QRgb *) out.bits(); 05516 for (int y=0; y<h; ++y) { 05517 const QRgb *src = (const QRgb *) image.scanLine(y); 05518 for (int x=0; x<w; ++x) 05519 dst[x*h + h-y-1] = *src++; 05520 } 05521 } 05522 break; 05523 case QImage::Format_Indexed8: 05524 { 05525 uchar *dst = out.bits(); 05526 for (int y=0; y<h; ++y) { 05527 const uchar *src = image.scanLine(y); 05528 for (int x=0; x<w; ++x) { 05529 dst[x*h + h-y-1] = *src++; 05530 } 05531 } 05532 } 05533 break; 05534 default: 05535 for (int y=0; y<h; ++y) { 05536 if (image.numColors()) 05537 for (int x=0; x<w; ++x) 05538 out.setPixel(h-y-1, x, image.pixelIndex(x, y)); 05539 else 05540 for (int x=0; x<w; ++x) 05541 out.setPixel(h-y-1, x, image.pixel(x, y)); 05542 } 05543 break; 05544 } 05545 return out; 05546 }
Here is the call graph for this function:
Definition at line 5489 of file qimage.cpp.
References QImage::convertToFormat(), QImage::format(), QImage::Format_ARGB32, QImage::Format_RGB32, QImage::hasAlphaChannel(), and pnmscale().
Referenced by QImage::transformed().
05489 { 05490 QImage::Format sf = src.format(); 05491 QImage source = src; 05492 if (sf != QImage::Format_RGB32 && sf != QImage::Format_ARGB32) { 05493 if (src.hasAlphaChannel()) 05494 source = src.convertToFormat(QImage::Format_ARGB32); 05495 else 05496 source = src.convertToFormat(QImage::Format_RGB32); 05497 } 05498 QImage dest(w, h, source.format()); 05499 pnmscale(source, dest); 05500 return dest; 05501 }
Here is the call graph for this function:
static void swap_bit_order | ( | QImageData * | dest, | |
const QImageData * | src, | |||
Qt::ImageConversionFlags | ||||
) | [static] |
Definition at line 2024 of file qimage.cpp.
References bitflip, QImageData::bytes_per_line, QImageData::colortable, QImageData::data, QImageData::format, QImage::Format_Mono, QImage::Format_MonoLSB, QImageData::height, QImageData::nbytes, and QImageData::width.
02025 { 02026 Q_ASSERT(src->format == QImage::Format_Mono || src->format == QImage::Format_MonoLSB); 02027 Q_ASSERT(dest->format == QImage::Format_Mono || dest->format == QImage::Format_MonoLSB); 02028 Q_ASSERT(src->width == dest->width); 02029 Q_ASSERT(src->height == dest->height); 02030 Q_ASSERT(src->nbytes == dest->nbytes); 02031 Q_ASSERT(src->bytes_per_line == dest->bytes_per_line); 02032 02033 dest->colortable = src->colortable; 02034 02035 const uchar *src_data = src->data; 02036 const uchar *end = src->data + src->nbytes; 02037 uchar *dest_data = dest->data; 02038 while (src_data < end) { 02039 *dest_data = bitflip[*src_data]; 02040 ++src_data; 02041 ++dest_data; 02042 } 02043 }
const uchar bitflip[256] [static] |
Initial value:
{ 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255 }
Definition at line 704 of file qimage.cpp.
Referenced by dither_to_Mono(), qt_get_bitflip_array(), and swap_bit_order().
const Image_Converter converter_map[QImage::NImageFormats][QImage::NImageFormats] [static] |
Definition at line 2837 of file qimage.cpp.
QBasicAtomic qimage_serial_number = Q_ATOMIC_INIT(1) |
Q_GUI_EXPORT _qt_image_cleanup_hook qt_image_cleanup_hook = 0 |
Definition at line 74 of file qimage.cpp.
Referenced by QGLContextPrivate::bindTexture(), QGLContext::~QGLContext(), and QImageData::~QImageData().