All pastes #221040 Raw Edit

Unnamed

public text v1 · immutable
#221040 ·published 2006-10-25 13:55 UTC
rendered paste body
void GLSingleView::loadImage()
{
    loadingImage = true;

    ThumbItem *item = m_itemList.at(m_pos);
    if (!item) {
        std::cerr << "GLSingleView: The impossible happened. No item at "
                  << m_pos << std::endl;
        return;
    }

    QImage image(item->path);
    if (!image.isNull()) {

        // get screen aspect
        Display  *display;
        display = XOpenDisplay(NULL);

        int scr = DefaultScreen(display);
        int s_height_mm = DisplayHeightMM(display,scr);
        int s_width_mm = DisplayWidthMM(display,scr);
        int s_height_px = DisplayHeight(display,scr);
        int s_width_px = DisplayWidth(display,scr);

        XCloseDisplay(display);

        double aspect_h = (double)s_height_px/(double)s_height_mm;
        double aspect_w = (double)s_width_px/(double)s_width_mm;

        double scale_factor_w = 1;

        scale_factor_w = aspect_w / aspect_h;

        int a  = m_tex1First ? 0 : 1;
        TexItem& t = m_texItem[a];

        t.item     = item;
        t.angle    = 0;

        QString queryStr = "SELECT angle FROM gallerymetadata WHERE "
                           "image=\"" + item->path + "\";";
        QSqlQuery query = m_db->exec(queryStr);

        if (query.isActive()  && query.numRowsAffected() > 0)
        {
            query.next();
            t.angle = query.value(0).toInt();
        }

        t.width  = (int)round(image.width() * scale_factor_w);
        t.height = (int)round(image.height());

        if (t.angle%180 != 0) {
            int tmp  = t.width;
            t.width  = t.height;
            t.height = tmp;
        }

        QSize sz(t.width,t.height);
        sz.scale(screenwidth, screenheight, QSize::ScaleMin);

        t.cx = (float)sz.width()/(float)screenwidth;
        t.cy = (float)sz.height()/(float)screenheight;

        image = image.smoothScale(m_w, m_h);
        QImage tex = convertToGLFormat(image);

        if (t.tex) {
            glDeleteTextures(1, &t.tex);
        }

        /* create the texture */
        glGenTextures(1, &t.tex);
        glBindTexture(GL_TEXTURE_2D, t.tex);

        /* actually generate the texture */
        glTexImage2D( GL_TEXTURE_2D, 0, 3, tex.width(), tex.height(), 0,
                      GL_RGBA, GL_UNSIGNED_BYTE, tex.bits() );
        /* enable linear filtering  */
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    }

    loadingImage = false;
}