WebImage.cc 2.89 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
/*=====================================================================

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>
 *
 */

32 33
#include "WebImage.h"

34 35
#include <QGLWidget>

36 37
WebImage::WebImage()
    : state(WebImage::UNINITIALIZED)
38
    , sourceURL("")
39
    , image(0)
40 41 42 43 44 45 46 47 48
    , lastReference(0)
    , syncFlag(false)
{

}

void
WebImage::clear(void)
{
49
    image.reset();
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    sourceURL.clear();
    state = WebImage::UNINITIALIZED;
    lastReference = 0;
}

WebImage::State
WebImage::getState(void) const
{
    return state;
}

void
WebImage::setState(State state)
{
    this->state = state;
}

67
const QString&
68 69 70 71 72 73 74 75 76 77 78 79 80 81
WebImage::getSourceURL(void) const
{
    return sourceURL;
}

void
WebImage::setSourceURL(const QString& url)
{
    sourceURL = url;
}

const uint8_t*
WebImage::getData(void) const
{
82
    return image->scanLine(0);
83 84
}

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

        return true;
98 99 100
    }
    else
    {
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
        return false;
    }
}

bool
WebImage::setData(const QString& filename)
{
    QImage tempImage;
    if (tempImage.load(filename))
    {
        if (image.isNull())
        {
            image.reset(new QImage);
        }
        *image = QGLWidget::convertToGLFormat(tempImage);

        return true;
    }
    else
    {
        return false;
122
    }
123 124
}

125 126 127 128 129 130 131 132 133 134 135 136
int32_t
WebImage::getWidth(void) const
{
    return image->width();
}

int32_t
WebImage::getHeight(void) const
{
    return image->height();
}

137 138 139 140 141 142
int32_t
WebImage::getByteCount(void) const
{
    return image->byteCount();
}

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
uint64_t
WebImage::getLastReference(void) const
{
    return lastReference;
}

void
WebImage::setLastReference(uint64_t value)
{
    lastReference = value;
}

bool
WebImage::getSyncFlag(void) const
{
    return syncFlag;
}

void
WebImage::setSyncFlag(bool onoff)
{
    syncFlag = onoff;
}