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

📄 qdrawhelper.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <private/qdrawhelper_p.h>#include <private/qpaintengine_raster_p.h>#include <private/qpainter_p.h>#include <private/qmath_p.h>#include <math.h>#define MASK(src, a) src = BYTE_MUL(src, a)#if defined(Q_OS_IRIX) && defined(Q_CC_GNU) && __GNUC__ == 3 && __GNUC__ < 4 && QT_POINTER_SIZE == 8#define Q_IRIX_GCC3_3_WORKAROUND//// work around http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14484//static uint gccBug(uint value) __attribute__((noinline));static uint gccBug(uint value){    return value;}#endif/*  constants and structures*/static const int fixed_scale = 1 << 16;static const int half_point = 1 << 15;static const int buffer_size = 2048;struct LinearGradientValues{    qreal dx;    qreal dy;    qreal l;    qreal off;};struct RadialGradientValues{    qreal dx;    qreal dy;    qreal a;};struct Operator;typedef uint *QT_FASTCALL (*DestFetchProc)(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length);typedef void QT_FASTCALL (*DestStoreProc)(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length);typedef const uint *QT_FASTCALL (*SourceFetchProc)(uint *buffer, const Operator *o, const QSpanData *data, int y, int x, int length);struct Operator{    QPainter::CompositionMode mode;    DestFetchProc dest_fetch;    DestStoreProc dest_store;    SourceFetchProc src_fetch;    CompositionFunctionSolid funcSolid;    CompositionFunction func;    union {        LinearGradientValues linear;        RadialGradientValues radial;//        TextureValues texture;    };};/*  Destination fetch. This is simple as we don't have to do bounds checks or  transformations*/static uint * QT_FASTCALL destFetchMono(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length){    uchar *data = (uchar *)rasterBuffer->scanLine(y);    uint *start = buffer;    const uint *end = buffer + length;    while (buffer < end) {        *buffer = data[x>>3] & (0x80 >> (x & 7)) ? 0xff000000 : 0xffffffff;        ++buffer;        ++x;    }    return start;}static uint * QT_FASTCALL destFetchMonoLsb(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length){    uchar *data = (uchar *)rasterBuffer->scanLine(y);    uint *start = buffer;    const uint *end = buffer + length;    while (buffer < end) {        *buffer = data[x>>3] & (0x1 << (x & 7)) ? 0xff000000 : 0xffffffff;        ++buffer;        ++x;    }    return start;}static uint * QT_FASTCALL destFetchRGB32(uint *, QRasterBuffer *rasterBuffer, int x, int y, int){    uint *data = (uint *)rasterBuffer->scanLine(y) + x;    // This should work without us having to fix the alpha channel manually.//     for (int i = 0; i < length; ++i)//         data[i] |= 0xff000000;    return data;}static uint * QT_FASTCALL destFetchARGB32(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length){    const uint *data = (const uint *)rasterBuffer->scanLine(y) + x;    for (int i = 0; i < length; ++i)        buffer[i] = PREMUL(data[i]);    return buffer;}static uint * QT_FASTCALL destFetchARGB32P(uint *, QRasterBuffer *rasterBuffer, int x, int y, int){    return (uint *)rasterBuffer->scanLine(y) + x;}#ifdef Q_WS_QWSstatic uint * QT_FASTCALL destFetchRGB16(uint *buffer, QRasterBuffer *rasterBuffer, int x, int y, int length){    const ushort *data = (const ushort *)rasterBuffer->scanLine(y) + x;    for (int i = 0; i < length; ++i)        buffer[i] = qConvertRgb16To32(data[i]);    return buffer;}#endifstatic const DestFetchProc destFetchProc[QImage::NImageFormats] ={    0, // Format_Invalid    destFetchMono, // Format_Mono,    destFetchMonoLsb, // Format_MonoLSB    0, // Format_Indexed8    destFetchRGB32, // Format_RGB32    destFetchARGB32, // Format_ARGB32,    destFetchARGB32P // Format_ARGB32_Premultiplied#ifdef Q_WS_QWS    ,  destFetchRGB16#endif};/*  Destination store.*/static void QT_FASTCALL destStoreMono(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length){    uchar *data = (uchar *)rasterBuffer->scanLine(y);    for (int i = 0; i < length; ++i) {        if (qGray(buffer[i]) < int(qt_bayer_matrix[y & 15][x & 15]))            data[x >> 3] |= 0x80 >> (x & 7);        else            data[x >> 3] &= ~(0x80 >> (x & 7));        ++x;    }}static void QT_FASTCALL destStoreMonoLsb(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length){    uchar *data = (uchar *)rasterBuffer->scanLine(y);    for (int i = 0; i < length; ++i) {        if (qGray(buffer[i]) < int(qt_bayer_matrix[y & 15][x & 15]))            data[x >> 3] |= 1 << (x & 7);        else            data[x >> 3] &= ~(1 << (x & 7));        ++x;    }}static void QT_FASTCALL destStoreARGB32(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length){    uint *data = (uint *)rasterBuffer->scanLine(y) + x;    for (int i = 0; i < length; ++i)        data[i] = INV_PREMUL(buffer[i]);}#ifdef Q_WS_QWSstatic void QT_FASTCALL destStoreRGB16(QRasterBuffer *rasterBuffer, int x, int y, const uint *buffer, int length){    ushort *data = (ushort *)rasterBuffer->scanLine(y) + x;    for (int i = 0; i < length; ++i)        data[i] = qConvertRgb32To16(buffer[i]);}#endifstatic const DestStoreProc destStoreProc[QImage::NImageFormats] ={    0, // Format_Invalid    destStoreMono, // Format_Mono,    destStoreMonoLsb, // Format_MonoLSB    0, // Format_Indexed8    0, // Format_RGB32    destStoreARGB32, // Format_ARGB32,    0 // Format_ARGB32_Premultiplied#ifdef Q_WS_QWS    ,  destStoreRGB16#endif};/*  Source fetches  This is a bit more complicated, as we need several fetch routines for every surface type  We need 5 fetch methods per surface type:  untransformed  transformed  transformed tiled  transformed bilinear  transformed bilinear tiled  We don't need bounds checks for untransformed, but we need them for the other ones.  The generic implementation does pixel by pixel fetches*/static uint QT_FASTCALL fetchPixel_Mono(const uchar *scanLine, int x, const QVector<QRgb> *rgb){    bool pixel = scanLine[x>>3] & (0x80 >> (x & 7));    if (rgb) return rgb->at(pixel ? 1 : 0);    return pixel ? 0xff000000 : 0xffffffff;}static uint QT_FASTCALL fetchPixel_MonoLSB(const uchar *scanLine, int x, const QVector<QRgb> *rgb){    bool pixel = scanLine[x>>3] & (0x1 << (x & 7));    if (rgb) return rgb->at(pixel ? 1 : 0);    return pixel ? 0xff000000 : 0xffffffff;}static uint QT_FASTCALL fetchPixel_Indexed8(const uchar *scanLine, int x, const QVector<QRgb> *rgb){    return rgb->at(scanLine[x]);}static uint QT_FASTCALL fetchPixel_RGB32(const uchar *scanLine, int x, const QVector<QRgb> *){    return ((const uint *)scanLine)[x] | 0xff000000;}static uint QT_FASTCALL fetchPixel_ARGB32(const uchar *scanLine, int x, const QVector<QRgb> *){    return PREMUL(((const uint *)scanLine)[x]);}static uint QT_FASTCALL fetchPixel_ARGB32_Premultiplied(const uchar *scanLine, int x, const QVector<QRgb> *){    return ((const uint *)scanLine)[x];}#ifdef Q_WS_QWSstatic uint QT_FASTCALL fetchPixel_RGB16(const uchar *scanLine, int x, const QVector<QRgb> *){    return qConvertRgb16To32(((const ushort *)scanLine)[x]);}#endiftypedef uint QT_FASTCALL (*FetchPixelProc)(const uchar *scanLine, int x, const QVector<QRgb> *);static const FetchPixelProc fetchPixelProc[QImage::NImageFormats] ={    0,    fetchPixel_Mono,    fetchPixel_MonoLSB,    fetchPixel_Indexed8,    fetchPixel_RGB32,    fetchPixel_ARGB32,    fetchPixel_ARGB32_Premultiplied#ifdef Q_WS_QWS    ,  fetchPixel_RGB16#endif};enum TextureBlendType {    BlendUntransformed,    BlendTiled,    BlendTransformed,    BlendTransformedTiled,    BlendTransformedBilinear,    BlendTransformedBilinearTiled,    NBlendTypes};static const uint * QT_FASTCALL fetch_generic(uint *buffer, const Operator *, const QSpanData *data,                                             int y, int x, int length){    FetchPixelProc fetch = fetchPixelProc[data->texture.format];    const uchar *scanLine = data->texture.scanLine(y);    for (int i = 0; i < length; ++i)        buffer[i] = fetch(scanLine, x + i, data->texture.colorTable);    return buffer;}static const uint * QT_FASTCALL fetchTransformed_generic(uint *buffer, const Operator *, const QSpanData *data,                                                         int y, int x, int length){    FetchPixelProc fetch = fetchPixelProc[data->texture.format];    int image_width = data->texture.width;    int image_height = data->texture.height;    // The increment pr x in the scanline    int fdx = (int)(data->m11 * fixed_scale);    int fdy = (int)(data->m12 * fixed_scale);    int fx = int((data->m21 * (y + 0.5)                  + data->m11 * (x + 0.5) + data->dx) * fixed_scale);    int fy = int((data->m22 * (y + 0.5)                  + data->m12 * (x + 0.5) + data->dy) * fixed_scale);    const uint *end = buffer + length;    uint *b = buffer;    while (b < end) {        int px = fx >> 16;        int py = fy >> 16;        bool out = (px < 0) || (px >= image_width)                   || (py < 0) || (py >= image_height);        const uchar *scanLine = data->texture.scanLine(py);        *b = out ? uint(0) : fetch(scanLine, px, data->texture.colorTable);        fx += fdx;        fy += fdy;        ++b;    }    return buffer;}static const uint * QT_FASTCALL fetchTransformedTiled_generic(uint *buffer, const Operator *, const QSpanData *data,                                                              int y, int x, int length){    FetchPixelProc fetch = fetchPixelProc[data->texture.format];    int image_width = data->texture.width;    int image_height = data->texture.height;    // The increment pr x in the scanline    int fdx = (int)(data->m11 * fixed_scale);    int fdy = (int)(data->m12 * fixed_scale);    int fx = int((data->m21 * (y + 0.5)                  + data->m11 * (x + 0.5) + data->dx) * fixed_scale);    int fy = int((data->m22 * (y + 0.5)                  + data->m12 * (x + 0.5) + data->dy) * fixed_scale);    const uint *end = buffer + length;    uint *b = buffer;    while (b < end) {        int px = fx >> 16;        int py = fy >> 16;        px %= image_width;        py %= image_height;        if (px < 0) px += image_width;        if (py < 0) py += image_height;        const uchar *scanLine = data->texture.scanLine(py);        *b = fetch(scanLine, px, data->texture.colorTable);        fx += fdx;        fy += fdy;        ++b;    }    return buffer;}static const uint * QT_FASTCALL fetchTransformedBilinear_generic(uint *buffer, const Operator *, const QSpanData *data,                                                                 int y, int x, int length){    FetchPixelProc fetch = fetchPixelProc[data->texture.format];    int image_width = data->texture.width;    int image_height = data->texture.height;    // The increment pr x in the scanline    int fdx = (int)(data->m11 * fixed_scale);    int fdy = (int)(data->m12 * fixed_scale);    int fx = int((data->m21 * (y + 0.5)                  + data->m11 * (x + 0.5) + data->dx) * fixed_scale);    int fy = int((data->m22 * (y + 0.5)

⌨️ 快捷键说明

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