Functions

qxtflowview_p.cpp File Reference

#include "qxtflowview_p.h"

Go to the source code of this file.

Functions

static QRgb blendColor (QRgb c1, QRgb c2, int blend)
static QImage * prepareSurface (const QImage *slideImage, int w, int h, QRgb bgcolor, QxtFlowView::ReflectionEffect reflectionEffect)

Function Documentation

static QRgb blendColor ( QRgb  c1,
QRgb  c2,
int  blend 
) [static]

Definition at line 346 of file qxtflowview_p.cpp.

Referenced by prepareSurface().

{
    int r = qRed(c1) * blend / 256 + qRed(c2) * (256 - blend) / 256;
    int g = qGreen(c1) * blend / 256 + qGreen(c2) * (256 - blend) / 256;
    int b = qBlue(c1) * blend / 256 + qBlue(c2) * (256 - blend) / 256;
    return qRgb(r, g, b);
}
static QImage* prepareSurface ( const QImage *  slideImage,
int  w,
int  h,
QRgb  bgcolor,
QxtFlowView::ReflectionEffect  reflectionEffect 
) [static]

Definition at line 355 of file qxtflowview_p.cpp.

References blendColor(), QxtFlowView::BlurredReflection, and QxtFlowView::NoReflection.

{
#ifdef PICTUREFLOW_QT4
    Qt::TransformationMode mode = Qt::SmoothTransformation;
    QImage img = slideImage->scaled(w, h, Qt::IgnoreAspectRatio, mode);
#endif
#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2)
    QImage img = slideImage->smoothScale(w, h);
#endif

    // slightly larger, to accommodate for the reflection
    int hs = h * 2;
    int hofs = h / 3;

    // offscreen buffer: black is sweet
#ifdef PICTUREFLOW_QT4
    QImage* result = new QImage(hs, w, QImage::Format_RGB32);
#endif
#if defined(PICTUREFLOW_QT3) || defined(PICTUREFLOW_QT2)
    QImage* result = new QImage;
    result->create(hs, w, 32);
#endif
    result->fill(bgcolor);

    // transpose the image, this is to speed-up the rendering
    // because we process one column at a time
    // (and much better and faster to work row-wise, i.e in one scanline)
    for (int x = 0; x < w; x++)
        for (int y = 0; y < h; y++)
            result->setPixel(hofs + y, x, img.pixel(x, y));

    if (reflectionEffect != QxtFlowView::NoReflection)
    {
        // create the reflection
        int ht = hs - h - hofs;
        int hte = ht;
        for (int x = 0; x < w; x++)
            for (int y = 0; y < ht; y++)
            {
                QRgb color = img.pixel(x, img.height() - y - 1);
                result->setPixel(h + hofs + y, x, blendColor(color, bgcolor, 128*(hte - y) / hte));
            }

        if (reflectionEffect == QxtFlowView::BlurredReflection)
        {
            // blur the reflection everything first
            // Based on exponential blur algorithm by Jani Huhtanen
            QRect rect(hs / 2, 0, hs / 2, w);
            rect &= result->rect();

            int r1 = rect.top();
            int r2 = rect.bottom();
            int c1 = rect.left();
            int c2 = rect.right();

            int bpl = result->bytesPerLine();
            int rgba[4];
            unsigned char* p;

            // how many times blur is applied?
            // for low-end system, limit this to only 1 loop
            for (int loop = 0; loop < 2; loop++)
            {
                for (int col = c1; col <= c2; col++)
                {
                    p = result->scanLine(r1) + col * 4;
                    for (int i = 0; i < 3; i++)
                        rgba[i] = p[i] << 4;

                    p += bpl;
                    for (int j = r1; j < r2; j++, p += bpl)
                        for (int i = 0; i < 3; i++)
                            p[i] = (rgba[i] += (((p[i] << 4) - rgba[i])) >> 1) >> 4;
                }

                for (int row = r1; row <= r2; row++)
                {
                    p = result->scanLine(row) + c1 * 4;
                    for (int i = 0; i < 3; i++)
                        rgba[i] = p[i] << 4;

                    p += 4;
                    for (int j = c1; j < c2; j++, p += 4)
                        for (int i = 0; i < 3; i++)
                            p[i] = (rgba[i] += (((p[i] << 4) - rgba[i])) >> 1) >> 4;
                }

                for (int col = c1; col <= c2; col++)
                {
                    p = result->scanLine(r2) + col * 4;
                    for (int i = 0; i < 3; i++)
                        rgba[i] = p[i] << 4;

                    p -= bpl;
                    for (int j = r1; j < r2; j++, p -= bpl)
                        for (int i = 0; i < 3; i++)
                            p[i] = (rgba[i] += (((p[i] << 4) - rgba[i])) >> 1) >> 4;
                }

                for (int row = r1; row <= r2; row++)
                {
                    p = result->scanLine(row) + c2 * 4;
                    for (int i = 0; i < 3; i++)
                        rgba[i] = p[i] << 4;

                    p -= 4;
                    for (int j = c1; j < c2; j++, p -= 4)
                        for (int i = 0; i < 3; i++)
                            p[i] = (rgba[i] += (((p[i] << 4) - rgba[i])) >> 1) >> 4;
                }
            }

            // overdraw to leave only the reflection blurred (but not the actual image)
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                    result->setPixel(hofs + y, x, img.pixel(x, y));
        }
    }

    return result;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines