WebImage.cc 2.9 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 34 35 36 37
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Definition of the class WebImage.
 *
 *   @author Lionel Heng <hengli@student.ethz.ch>
 *
 */

#include "WebImage.h"

#include <QFile>
#include <QGLWidget>

WebImage::WebImage()
38 39 40 41 42
 : mState(WebImage::UNINITIALIZED)
 , mSourceURL("")
 , mImage(0)
 , mLastReference(0)
 , mSyncFlag(false)
43 44 45 46 47 48 49
{

}

void
WebImage::clear(void)
{
50 51 52 53
    mImage.reset();
    mSourceURL.clear();
    mState = WebImage::UNINITIALIZED;
    mLastReference = 0;
54 55 56 57 58
}

WebImage::State
WebImage::getState(void) const
{
59
    return mState;
60 61 62 63 64
}

void
WebImage::setState(State state)
{
65
    mState = state;
66 67 68 69 70
}

const QString&
WebImage::getSourceURL(void) const
{
71
    return mSourceURL;
72 73 74 75 76
}

void
WebImage::setSourceURL(const QString& url)
{
77
    mSourceURL = url;
78 79
}

80
uchar*
81 82
WebImage::getImageData(void) const
{
83
    return mImage->scanLine(0);
84 85 86 87 88 89
}

bool
WebImage::setData(const QByteArray& data)
{
    QImage tempImage;
90 91 92 93 94
    if (tempImage.loadFromData(data))
    {
        if (mImage.isNull())
        {
            mImage.reset(new QImage);
95
        }
96
        *mImage = QGLWidget::convertToGLFormat(tempImage);
97 98

        return true;
99 100 101
    }
    else
    {
102 103 104 105 106 107 108 109
        return false;
    }
}

bool
WebImage::setData(const QString& filename)
{
    QImage tempImage;
110 111 112 113 114
    if (tempImage.load(filename))
    {
        if (mImage.isNull())
        {
            mImage.reset(new QImage);
115
        }
116
        *mImage = QGLWidget::convertToGLFormat(tempImage);
117 118

        return true;
119 120 121
    }
    else
    {
122 123 124 125
        return false;
    }
}

126
int
127 128
WebImage::getWidth(void) const
{
129
    return mImage->width();
130 131
}

132
int
133 134
WebImage::getHeight(void) const
{
135
    return mImage->height();
136 137
}

138
int
139 140
WebImage::getByteCount(void) const
{
141
    return mImage->byteCount();
142 143
}

144
quint64
145 146
WebImage::getLastReference(void) const
{
147
    return mLastReference;
148 149 150
}

void
151
WebImage::setLastReference(quint64 value)
152
{
153
    mLastReference = value;
154 155 156 157 158
}

bool
WebImage::getSyncFlag(void) const
{
159
    return mSyncFlag;
160 161 162 163 164
}

void
WebImage::setSyncFlag(bool onoff)
{
165
    mSyncFlag = onoff;
166
}