TextureDataControlFilePNG.cc 1.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University         //
// All rights reserved.                                                       //
////////////////////////////////////////////////////////////////////////////////

#include <ACGL/OpenGL/Controller/TextureDataControlFilePNG.hh>
#include <ACGL/OpenGL/Controller/TextureDataControlFileFactory.hh>

#include <QtGui/QImage>
#include <QtOpenGL/QGLWidget>

using namespace ACGL;
using namespace ACGL::OpenGL;

bool TextureDataControlFilePNG::load(SharedTextureData& texture) const
{
    QImage image = QImage(QString(getFullFilePath().c_str()));

    if(image.isNull())
    {
        ACGL::Utils::error() << "Loading image " << getFullFilePath() << " has failed!" << std::endl;
        return false;
    }

    image = QGLWidget::convertToGLFormat(image);
    GLubyte *pImageData = new GLubyte[image.byteCount()];
    memcpy(pImageData, image.bits(), image.byteCount());
    texture->setData(pImageData);
    texture->setWidth(image.width());
    texture->setHeight(image.height());
    return true;
}

34
35
36
37
38
39
40
int_t TextureDataControlFilePNG::registerType(void)
{
    sTypeID = TextureDataControlFileFactory::the()->registerType("png", &TextureDataControlFilePNG::creator);
    return sTypeID;
}

int_t TextureDataControlFilePNG::sTypeID = -1;