MCPcopy Create free account
hub / github.com/Theverat/NormalmapGenerator / load

Method load

src_gui/mainwindow.cpp:171–274  ·  view source on GitHub ↗

load the image specified in the url

Source from the content-addressed store, hash-verified

169
170//load the image specified in the url
171bool MainWindow::load(QUrl url) {
172 if(!url.isValid()) {
173 throw "[load] invalid url!";
174 return false;
175 }
176
177 QFileInfo file(url.toLocalFile());
178
179 if(file.isDir()) {
180 loadAllFromDir(url);
181 return false;
182 }
183
184 ui->statusBar->showMessage("loading Image: " + url.fileName());
185
186 //load the image
187 input = QImage(url.toLocalFile());
188
189 if(input.isNull()) {
190 QString errorMessage("Image not loaded!");
191
192 if(file.suffix().toLower() == "tga") {
193 errorMessage.append("\nOnly uncompressed TGA files are supported.");
194 }
195 else {
196 errorMessage.append("\nMost likely the image format is not supported.");
197 }
198
199 ui->statusBar->showMessage("Error: Image " + url.fileName() + " NOT loaded!", 5000);
200 QMessageBox::information(this, "Error while loading image", errorMessage);
201 return false;
202 }
203
204 //store the path the image was loaded from (for saving later)
205 if(exportPath.isEmpty())
206 setExportPath(url.adjusted(QUrl::RemoveFilename));
207 loadedImagePath = url;
208
209 //enable ui buttons
210 ui->pushButton_calcNormal->setEnabled(true);
211 ui->pushButton_calcSpec->setEnabled(true);
212 ui->pushButton_calcDisplace->setEnabled(true);
213 ui->pushButton_calcSsao->setEnabled(true);
214 ui->spinBox_normalmapSize->setEnabled(true);
215 enableAutoupdate(true);
216
217 //extract R/G/B/A channels
218 const int h = ui->label_channelRed->height();
219 QImage inputSmall(input.scaled(h, h, Qt::KeepAspectRatio));
220 IntensityMap red(inputSmall, IntensityMap::MAX, true, false, false, false);
221 IntensityMap green(inputSmall, IntensityMap::MAX, false, true, false, false);
222 IntensityMap blue(inputSmall, IntensityMap::MAX, false, false, true, false);
223 IntensityMap alpha(inputSmall, IntensityMap::MAX, false, false, false, true);
224 ui->label_channelRGBA->setPixmap(QPixmap::fromImage(inputSmall));
225 ui->label_channelRed->setPixmap(QPixmap::fromImage(red.convertToQImage()));
226 ui->label_channelGreen->setPixmap(QPixmap::fromImage(green.convertToQImage()));
227 ui->label_channelBlue->setPixmap(QPixmap::fromImage(blue.convertToQImage()));
228 ui->label_channelAlpha->setPixmap(QPixmap::fromImage(alpha.convertToQImage()));

Callers

nothing calls this directly

Calls 2

convertToQImageMethod · 0.80
setValueMethod · 0.80

Tested by

no test coverage detected