~phablet-team/+junk/filters-unit-tests

« back to all changes in this revision

Viewing changes to backend/modules/Filters/halide_transform.cpp

  • Committer: Ugo Riboni
  • Date: 2015-03-22 09:35:11 UTC
  • mfrom: (176.1.77 trunk)
  • Revision ID: ugo.riboni@canonical.com-20150322093511-tjdc5mkjvh8cpv3c
MergeĀ upstreamĀ changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    }
67
67
}
68
68
 
 
69
bool HalideTransform::updating() const
 
70
{
 
71
    return m_updateTimer.isValid();
 
72
}
 
73
 
69
74
HalideImage* HalideTransform::input() const
70
75
{
71
76
    return m_input;
75
80
{
76
81
    if (input != m_input) {
77
82
        if (m_input) {
78
 
            QObject::disconnect(m_input, SIGNAL(bufferChanged()), this, SLOT(onInputChanged()));
 
83
            QObject::disconnect(m_input, SIGNAL(dataChanged()), this, SLOT(onInputChanged()));
79
84
        }
80
85
 
81
86
        m_input = input;
82
87
 
83
88
        if (m_input) {
84
 
            QObject::connect(m_input, SIGNAL(bufferChanged()), this, SLOT(onInputChanged()));
 
89
            QObject::connect(m_input, SIGNAL(dataChanged()), this, SLOT(onInputChanged()));
 
90
            if (m_functions.isEmpty()) {
 
91
                if (m_input) {
 
92
                    m_output->setData(m_input->data());
 
93
                }
 
94
            }
85
95
        }
86
96
 
87
97
        Q_EMIT inputChanged();
 
98
        onInputChanged();
88
99
    }
89
100
}
90
101
 
91
102
void HalideTransform::onInputChanged()
92
103
{
93
 
    if (!m_functions.isEmpty()) {
 
104
    if (m_functions.isEmpty()) {
 
105
        if (m_input) {
 
106
            m_output->setData(m_input->data());
 
107
        }
 
108
    } else {
94
109
        m_functions.first()->setDirty(true);
95
110
    }
96
111
}
115
130
 
116
131
void HalideTransform::doUpdate(bool outputImageRequired)
117
132
{
118
 
    if (m_functions.length() == 0) {
 
133
    if (m_functions.isEmpty()) {
 
134
        if (m_input) {
 
135
            m_output->setData(m_input->data());
 
136
        }
119
137
        return;
120
138
    }
121
139
 
122
140
    Q_FOREACH(HalideFunction* function, m_functions) {
123
141
        if (!function->allPropertiesValid()) {
 
142
            function->setDirty(false);
124
143
            qWarning() << "doUpdate(): missing parameters for Halide function.";
125
144
            return;
126
145
        }
127
146
    }
128
147
 
 
148
    // if first function has an "input" property, verify that
 
149
    // either it is set to a valid image or HalideTransform::input is
 
150
    QVariant inputProperty = m_functions.first()->property("input");
 
151
    bool hasInputProperty = inputProperty.isValid();
 
152
    if (hasInputProperty) {
 
153
        HalideImage* value = inputProperty.value<HalideImage*>();
 
154
        if (!value || !value->data()->buffer.defined()) {
 
155
            if (!m_input || !m_input->data()->buffer.defined()) {
 
156
                m_functions.first()->setDirty(false);
 
157
                qWarning() << "HalideTransform's input does not have a valid image.";
 
158
                return;
 
159
            }
 
160
        }
 
161
    }
 
162
 
129
163
    if (!m_renderer || !m_renderer->isReady()) {
130
164
        return;
131
165
    }
136
170
    }
137
171
 
138
172
    m_updateTimer.start();
 
173
    Q_EMIT updatingChanged();
139
174
    m_renderer->apply(m_input, m_functions, m_output, outputImageRequired);
140
175
 
141
176
    qDebug() << QString("\"%1\" applied in %2 ms (%3x%4)")
144
179
                .arg(m_output->size().width())
145
180
                .arg(m_output->size().height()).toLocal8Bit().constData();
146
181
    m_updateTimer.invalidate();
 
182
    Q_EMIT updatingChanged();
147
183
}
148
184
 
149
185
bool HalideTransform::saveToFile(QString fileName)
151
187
    doUpdate(true);
152
188
    QString directory = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
153
189
    QString filePath = directory + "/" + fileName;
154
 
    bool success = m_output->image().rgbSwapped().save(filePath);
 
190
    bool success = m_output->data()->image.rgbSwapped().save(filePath);
155
191
    if (!success) {
156
192
        qWarning() << "Failed to save image to file:" << filePath;
157
193
    }