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

📄 qscreen_qws.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    const quint8 tailMask = (1 << (pixelsPerByte - tailWidth)) - 1;    const int width8 = (width - alignWidth) / pixelsPerByte;    dest += y * stride + x / pixelsPerByte;    stride -= (doAlign + width8);    for (int j = 0; j < height; ++j) {        if (doAlign) {            *dest = (*dest & ~alignMask) | (value & alignMask);            ++dest;        }        if (width8) {            qt_memfill<quint8>(dest, value, width8);            dest += width8;        }        if (doTail)            *dest = (*dest & tailMask) | (value & ~tailMask);        dest += stride;    }}static void solidFill_mono(QScreen *screen, const QColor &color,                           const QRegion &region){    quint8 *dest = reinterpret_cast<quint8*>(screen->base());    const quint8 c8 = (qGray(color.rgba()) >> 7) * 0xff;    const int stride = screen->linestep();    const QVector<QRect> rects = region.rects();    for (int i = 0; i < rects.size(); ++i) {        const QRect r = rects.at(i);        qt_rectfill_mono(dest, c8, r.x(), r.y(), r.width(), r.height(),                         stride);    }}#endif // QT_QWS_DEPTH_1void qt_solidFill_setup(QScreen *screen, const QColor &color,                        const QRegion &region){    switch (screen->depth()) {#ifdef QT_QWS_DEPTH_32    case 32:        screen->d_ptr->solidFill = solidFill_template<quint32>;        break;#endif#ifdef QT_QWS_DEPTH_24    case 24:        screen->d_ptr->solidFill = solidFill_template<quint24>;        break;#endif#ifdef QT_QWS_DEPTH_18    case 18:        screen->d_ptr->solidFill = solidFill_template<quint18>;        break;#endif#ifdef QT_QWS_DEPTH_16    case 16:        screen->d_ptr->solidFill = solidFill_template<quint16>;        break;#endif#ifdef QT_QWS_DEPTH_8    case 8:        screen->d_ptr->solidFill = solidFill_template<quint8>;        break;#endif#ifdef QT_QWS_DEPTH_4    case 4:        screen->d_ptr->solidFill = solidFill_gray4;        break;#endif#ifdef QT_QWS_DEPTH_1    case 1:        screen->d_ptr->solidFill = solidFill_mono;        break;#endif     default:        qFatal("solidFill_setup(): Screen depth %d not supported!",               screen->depth());        screen->d_ptr->solidFill = 0;        break;    }    screen->d_ptr->solidFill(screen, color, region);}template <typename DST, typename SRC>static void blit_template(QScreen *screen, const QImage &image,                          const QPoint &topLeft, const QRegion &region){    DST *dest = reinterpret_cast<DST*>(screen->base());    const SRC *src = reinterpret_cast<const SRC*>(image.bits());    const int screenStride = screen->linestep();    const int imageStride = image.bytesPerLine();    const QVector<QRect> rects = region.rects();    for (int i = 0; i < rects.size(); ++i) {        const QRect r = rects.at(i);        qt_rectconvert<DST, SRC>(dest,                                 src + r.y() * imageStride / sizeof(SRC) + r.x(),                                 r.x() + topLeft.x(), r.y() + topLeft.y(),                                 r.width(), r.height(),                                 screenStride, imageStride);    }}#ifdef QT_QWS_DEPTH_32static void blit_32(QScreen *screen, const QImage &image,                    const QPoint &topLeft, const QRegion &region){    switch (image.format()) {    case QImage::Format_RGB32:    case QImage::Format_ARGB32:    case QImage::Format_ARGB32_Premultiplied:        blit_template<quint32, quint32>(screen, image, topLeft, region);        return;#ifdef QT_QWS_DEPTH_16    case QImage::Format_RGB16:        blit_template<quint32, quint16>(screen, image, topLeft, region);        return;#endif    default:        qCritical("blit_16(): Image format %d not supported!", image.format());    }}#endif // QT_QWS_DEPTH_32#ifdef QT_QWS_DEPTH_16static void blit_16(QScreen *screen, const QImage &image,                    const QPoint &topLeft, const QRegion &region){    switch (image.format()) {    case QImage::Format_RGB32:    case QImage::Format_ARGB32:    case QImage::Format_ARGB32_Premultiplied:        blit_template<quint16, quint32>(screen, image, topLeft, region);        return;    case QImage::Format_RGB16:        blit_template<quint16, quint16>(screen, image, topLeft, region);        return;    default:        qCritical("blit_16(): Image format %d not supported!", image.format());    }}#if Q_BYTE_ORDER == Q_BIG_ENDIANclass quint16LE{public:    inline quint16LE(quint32 v) {        data = ((v & 0xff00) >> 8) | ((v & 0x00ff) << 8);    }    inline quint16LE(int v) {        data = ((v & 0xff00) >> 8) | ((v & 0x00ff) << 8);    }    inline quint16LE(quint16 v) {        data = ((v & 0xff00) >> 8) | ((v & 0x00ff) << 8);    }private:    quint16 data;};static void blit_16_bigToLittleEndian(QScreen *screen, const QImage &image,                                      const QPoint &topLeft,                                      const QRegion &region){    switch (image.format()) {    case QImage::Format_RGB32:    case QImage::Format_ARGB32:    case QImage::Format_ARGB32_Premultiplied:        blit_template<quint16LE, quint32>(screen, image, topLeft, region);        return;    case QImage::Format_RGB16:        blit_template<quint16LE, quint16>(screen, image, topLeft, region);        return;    default:        qCritical("blit_16_bigToLittleEndian(): Image format %d not supported!", image.format());    }}#endif // Q_BIG_ENDIAN#endif // QT_QWS_DEPTH_16#ifdef QT_QWS_DEPTH_8static void blit_8(QScreen *screen, const QImage &image,                   const QPoint &topLeft, const QRegion &region){    switch (image.format()) {    case QImage::Format_RGB32:    case QImage::Format_ARGB32:    case QImage::Format_ARGB32_Premultiplied:        blit_template<quint8, quint32>(screen, image, topLeft, region);        return;    case QImage::Format_RGB16:        blit_template<quint8, quint16>(screen, image, topLeft, region);        return;    default:        qCritical("blit_8(): Image format %d not supported!", image.format());    }}#endif // QT_QWS_DEPTH_8#ifdef QT_QWS_DEPTH_4struct qgray4 { quint8 dummy; } Q_PACKED;template <typename SRC>static inline quint8 qt_convertToGray4(SRC color);template <>static inline quint8 qt_convertToGray4(quint32 color){    return qGray(color) >> 4;}template <>static inline quint8 qt_convertToGray4(quint16 color){    const int r = (color & 0xf800) >> 11;    const int g = (color & 0x07e0) >> 6; // only keep 5 bit    const int b = (color & 0x001f);    return (r * 11 + g * 16 + b * 5) >> 6;}template <typename SRC>static inline void qt_rectconvert_gray4(qgray4 *dest4, const SRC *src,                                        int x, int y, int width, int height,                                        int dstStride, int srcStride){    const int pixelsPerByte = 2;    quint8 *dest8 = reinterpret_cast<quint8*>(dest4)                    + y * dstStride + x / pixelsPerByte;    const int doAlign = x & 1;    const int doTail = (width - doAlign) & 1;    const int width8 = (width - doAlign) / pixelsPerByte;    const int count8 = (width8 + 3) / 4;    srcStride = srcStride / sizeof(SRC) - width;    dstStride -= (width8 + doAlign);    for (int i = 0; i < height; ++i) {        if (doAlign) {            *dest8 = (*dest8 & 0xf0) | qt_convertToGray4<SRC>(*src++);            ++dest8;        }        if (count8) {            int n = count8;            switch (width8 & 0x03) // duff's device            {            case 0: do { *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4                                    | qt_convertToGray4<SRC>(src[1]);                         src += 2;            case 3:      *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4                                    | qt_convertToGray4<SRC>(src[1]);                         src += 2;            case 2:      *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4                                    | qt_convertToGray4<SRC>(src[1]);                         src += 2;            case 1:      *dest8++ = qt_convertToGray4<SRC>(src[0]) << 4                                    | qt_convertToGray4<SRC>(src[1]);                         src += 2;            } while (--n > 0);            }        }        if (doTail)            *dest8 = qt_convertToGray4<SRC>(*src++) << 4 | (*dest8 & 0x0f);        dest8 += dstStride;        src += srcStride;    }}template <>void qt_rectconvert(qgray4 *dest, const quint32 *src,                    int x, int y, int width, int height,                    int dstStride, int srcStride){    qt_rectconvert_gray4<quint32>(dest, src, x, y, width, height,                                  dstStride, srcStride);}template <>void qt_rectconvert(qgray4 *dest, const quint16 *src,                    int x, int y, int width, int height,                    int dstStride, int srcStride){    qt_rectconvert_gray4<quint16>(dest, src, x, y, width, height,                                  dstStride, srcStride);}static void blit_4(QScreen *screen, const QImage &image,                   const QPoint &topLeft, const QRegion &region){    switch (image.format()) {    case QImage::Format_ARGB32_Premultiplied:        blit_template<qgray4, quint32>(screen, image, topLeft, region);        return;    case QImage::Format_RGB16:        blit_template<qgray4, quint16>(screen, image, topLeft, region);        return;    default:        qCritical("blit_4(): Image format %d not supported!", image.format());    }}#endif // QT_QWS_DEPTH_4#ifdef QT_QWS_DEPTH_1struct qmono { quint8 dummy; } Q_PACKED;template <typename SRC>static inline quint8 qt_convertToMono(SRC color);template <>static inline quint8 qt_convertToMono(quint32 color){    return qGray(color) >> 7;}template <>static inline quint8 qt_convertToMono(quint16 color){    return (qGray(qt_colorConvert<quint32, quint16>(color, 0)) >> 7);}template <typename SRC>static inline void qt_rectconvert_mono(qmono *dest, const SRC *src,                                       int x, int y, int width, int height,                                       int dstStride, int srcStride){    const int pixelsPerByte = 8;    quint8 *dest8 = reinterpret_cast<quint8*>(dest)                    + y * dstStride + x / pixelsPerByte;    const int alignWidth = qMin(width, (8 - (x & 7)) & 7);    const int doAlign = (alignWidth > 0 ? 1 : 0);    const int alignStart = pixelsPerByte - 1 - (x & 7);    const int alignStop = alignStart - (alignWidth - 1);    const quint8 alignMask = ((1 << alignWidth) - 1) << alignStop;    const int tailWidth = (width - alignWidth) & 7;    const int doTail = (tailWidth > 0 ? 1 : 0);    const quint8 tailMask = (1 << (pixelsPerByte - tailWidth)) - 1;    const int width8 = (width - alignWidth) / pixelsPerByte;    srcStride = srcStride / sizeof(SRC) - (width8 * 8 + alignWidth);    dstStride -= (width8 + doAlign);    for (int j = 0;  j < height; ++j) {        if (doAlign) {            quint8 d = *dest8 & ~alignMask;            for (int i = alignStart; i >= alignStop; --i)                d |= qt_convertToMono<SRC>(*src++) << i;            *dest8++ = d;        }        for (int i = 0; i < width8; ++i) {            *dest8 = (qt_convertToMono<SRC>(src[0]) << 7)                     | (qt_convertToMono<SRC>(src[1]) << 6)                     | (qt_convertToMono<SRC>(src[2]) << 5)                     | (qt_convertToMono<SRC>(src[3]) << 4)                     | (qt_convertToMono<SRC>(src[4]) << 3)                     | (qt_convertToMono<SRC>(src[5]) << 2)                     | (qt_convertToMono<SRC>(src[6]) << 1)                     | (qt_convertToMono<SRC>(src[7]));            src += 8;            ++dest8;        }        if (doTail) {            quint8 d = *dest8 & tailMask;            switch (tailWidth) {            case 7: d |= qt_convertToMono<SRC>(src[6]) << 1;            case 6: d |= qt_convertToMono<SRC>(src[5]) << 2;            case 5: d |= qt_convertToMono<SRC>(src[4]) << 3;            case 4: d |= qt_convertToMono<SRC>(src[3]) << 4;            case 3: d |= qt_convertToMono<SRC>(src[2]) << 5;            case 2: d |= qt_convertToMono<SRC>(src[1]) << 6;            case 1: d |= qt_convertToMono<SRC>(src[0]) << 7;            }            *dest8 = d;        }        dest8 += dstStride;        src += srcStride;    }}template <>void qt_rectconvert(qmono *dest, const quint32 *src,                    int x, int y, int width, int height,                    int dstStride, int srcStride){    qt_rectconvert_mono<quint32>(dest, src, x, y, width, height,                                 dstStride, srcStride);}template <>void qt_rectconvert(qmono *dest, const quint16 *src,                    int x, int y, int width, int height,                    int dstStride, int srcStride){    qt_rectconvert_mono<quint16>(dest, src, x, y, width, height,                                 dstStride, srcStride);}static void blit_1(QScreen *screen, const QImage &image,                   const QPoint &topLeft, const QRegion &region){    switch (image.format()) {    case QImage::Format_ARGB32_Premultiplied:        blit_template<qmono, quint32>(screen, image, topLeft, region);        return;    case QImage::Format_RGB16:        blit_template<qmono, quint16>(screen, image, topLeft, region);        return;    default:        qCritical("blit_1(): Image format %d not supported!", image.format());    }}#endif // QT_QWS_DEPTH_1#ifdef QT_QWS_DEPTH_GENERICstatic void blit_rgb(QScreen *screen, const QImage &image,                     const QPoint &topLeft, const QRegion &region){    switch (image.format()) {    case QImage::Format_ARGB32_Premultiplied:        blit_template<qrgb, quint32>(screen, image, topLeft, region);        return;    case QImage::Format_RGB16:        blit_template<qrgb, quint16>(screen, image, topLeft, region);        return;    default:        qCritical("blit_rgb(): Image format %d not supported!", image.format());    }}void qt_set_generic_blit(QScreen *screen, int bpp,                         int len_red, int len_green, int len_blue, int len_alpha,                         int off_red, int off_green, int off_blue, int off_alpha){    qrgb::bpp = bpp / 8;    qrgb::len_red = len_red;

⌨️ 快捷键说明

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