void diff_images(QImage *image1, QImage *image2, QString fileName) { // TODO: Check images size QImage* image3 = new QImage(image1->size(), QImage::Format_RGB32); for (int i = 0; i < image1->size().width(); i++) { for (int j = 0; j < image1->size().height(); j++) { int p1 = qGray(image1->pixel(i,j)); int p2 = qGray(image2->pixel(i,j)); int p3 = p1-p2; double fSigma = 0.4 * 25.0; double diff = (static_cast<double>(p3)+ fSigma) * 255.0 / (2.0 * fSigma); if (diff < 0.0) diff = 0; if (diff > 255.5) diff = 255; p3 = diff; image3->setPixel(i,j,qRgb(p3,p3,p3)); } } QImageWriter* imageDiff = new QImageWriter(); imageDiff->setFileName(fileName); imageDiff->write(*image3); delete image3; delete imageDiff; }
void GraphicColumnWidget::slotExportToTiff() { QString fn = QFileDialog::getSaveFileName(this, tr("Export Profile To Tiff..."), QDir::currentPath(), tr("TIFF Files (*.tif *.tiff *.Tif *.TIF *.TIFF *.Tiff)")); if (fn.isEmpty()) { return; } QImageWriter w; w.setFileName(fn); w.setFormat("TIFF"); QImage img(QSize((int)(_scene->width()), (int)(_scene->height())), QImage::Format_RGB32); QPainter painter(&img); painter.setRenderHint(QPainter::Antialiasing); _scene->render(&painter); painter.end(); if (w.write(img)) { QMessageBox::information(this, tr("Export Completed"), tr("Profile exported to <b>%1</b>.").arg(fn)); } else { QMessageBox::critical(this, tr("Export Failed"), tr("Could not export Profile: %1").arg(w.errorString())); } }
QStringList MainWindow::do_run_jobs(QMap<QString, rc_map> &jobs) { QStringList failed, succeeded; QString propaganda = QString("Generated by Morning Star v%1").arg(mos_version); this->setEnabled(false); for(QMap<QString, rc_map>::const_iterator k = jobs.begin(); k != jobs.end(); ++k) { QImage rc; QImageWriter out; out.setFormat("png"); out.setFileName(k.key()); out.setText("", propaganda); if(rc_image(this->img_original_, rc, k.value()) && out.write(rc)) { succeeded.push_back(out.fileName()); } else { failed.push_back(out.fileName()); } } this->setEnabled(true); if(failed.isEmpty() != true) { throw failed; } return succeeded; }
void MainWindow::exportImage() { QVector<CPoint> centroids = nGas.getCentroids(); QVector<KPoint> points = nGas.getPoints(); QImage image(imageSize,QImage::Format_RGB32); QProgressDialog progress(this); progress.setWindowTitle("Self-organizing maps"); progress.setLabelText("Generating file..."); progress.setModal(true); progress.show(); int k = 0; for(int i=0;i<image.width();i++) { progress.setValue(((double)i / (double)image.width()) * 100); if(progress.wasCanceled()) return; for(int j=0;j<image.height();j++) { for(int d=0;d<centroids.size();d++) centroids[d].setDistance(Centroids::countDistance(centroids[d],points[k])); qSort(centroids.begin(),centroids.end(),SortByDistance()); image.setPixel(i,j,qRgb(centroids[0].paramAt(0),centroids[1].paramAt(1),centroids[2].paramAt(2))); k++; } } progress.setValue(100); QGraphicsScene* scene = new QGraphicsScene(this); ui->graphicsView_2->setScene(scene); scene->addPixmap(QPixmap::fromImage(image.scaled(ui->graphicsView->width()*0.95,ui->graphicsView->height()*0.95))); ui->graphicsView_2->show(); QImageWriter writer; writer.setFileName(QFileDialog::getSaveFileName(this,tr("Open image"),"C:\\Users\\GiBSoN\\Desktop",tr("Image files (*.jpg *.png)"))); writer.setFormat("jpg"); writer.setCompression(10); writer.write(image); }
void River::generateImages(QVector<QImage> &images, QVector<QString> & stockNames, QMutex &imageMutex, Statistics & stats) { imageMutex.lock(); #pragma omp parallel { #pragma omp for for(int imageIndex = 0; imageIndex < NUM_IMAGES; imageIndex++){ QColor color("black"); images[imageIndex].fill(color.rgb()); } #pragma omp for for(int i = 0; i < p.getSize(); i++){ if(!p.hasWater[i]) { continue; } int x = p.pxcor[i]; int y = p.pycor[i]; QColor macroColor = getHeatMapColor(p.macro[i], stats.avgMacro, stats.maxMacro); QColor phytoColor = getHeatMapColor(p.phyto[i], stats.avgPhyto, stats.maxPhyto); QColor herbivoreColor = getHeatMapColor(p.herbivore[i], stats.avgHerbivore, stats.maxHerbivore); QColor waterDecompColor = getHeatMapColor(p.waterdecomp[i], stats.avgWaterDecomp, stats.maxWaterDecomp); QColor sedDecompColor = getHeatMapColor(p.seddecomp[i], stats.avgSedDecomp, stats.maxSedDecomp); QColor sedConsumerColor = getHeatMapColor(p.sedconsumer[i], stats.avgSedConsumer, stats.maxSedConsumer); QColor consumColor = getHeatMapColor(p.consumer[i], stats.avgConsum, stats.maxConsum); QColor DOCColor = getHeatMapColor(p.DOC[i], stats.avgDOC, stats.maxDOC); QColor POCColor = getHeatMapColor(p.POC[i], stats.avgPOC, stats.maxPOC); QColor detritusColor = getHeatMapColor(p.detritus[i], stats.avgDetritus, stats.maxDetritus); images[STOCK_MACRO].setPixel( x, y, macroColor.rgb()); images[STOCK_PHYTO].setPixel(x, y, phytoColor.rgb()); images[STOCK_HERBIVORE].setPixel(x, y, herbivoreColor.rgb()); images[STOCK_WATERDECOMP].setPixel( x, y, waterDecompColor.rgb()); images[STOCK_SEDDECOMP].setPixel(x, y, sedDecompColor.rgb()); images[STOCK_SEDCONSUMER].setPixel(x, y, sedConsumerColor.rgb()); images[STOCK_CONSUMER].setPixel(x, y, consumColor.rgb()); images[STOCK_DOC].setPixel(x, y, DOCColor.rgb()); images[STOCK_POC].setPixel(x, y, POCColor.rgb()); images[STOCK_DETRITUS].setPixel(x, y, detritusColor.rgb()); int patchCarbon = p.macro[i] + p.phyto[i] + p.herbivore[i] + p.waterdecomp[i] + p.seddecomp[i] + p.sedconsumer[i] + p.consumer[i] + p.DOC[i] + p.POC[i] + p.detritus[i]; QColor allCarbonColor = getHeatMapColor(patchCarbon, stats.avgCarbon, stats.maxCarbon); images[STOCK_ALL_CARBON].setPixel(x, y, allCarbonColor.rgb()); } //Due to the layout of the hydrofiles, the river will appear upside down if we don't flip it. #pragma omp for for(int imageIndex = 0; imageIndex < NUM_IMAGES; imageIndex++){ images[imageIndex] = images[imageIndex].mirrored(false,true); } } imageMutex.unlock(); QImageWriter writer; writer.setFormat("png"); for(int i = 0; i < NUM_IMAGES; i++){ QString date_time_str = QDateTime::currentDateTime().toString("_MMM_d_H_mm_ss"); QString fileName = "./results/images/" + stockNames[i] + date_time_str + ".png"; writer.setFileName(fileName); writer.write(images[i]); } }
// // save image in the opengl texture into file // bool frag_pane::saveImage( const QString strFile ) { bool bRetCode = false; QImageWriter writer; int nWidth, nHeight; int k, iRow, i, j, iRed, iGreen, iBlue; QImage *img = NULL; GLubyte *image = NULL; if( !validImageProc( ) ) { goto PIX_EXIT; } if( !_out_fbo ) { goto PIX_EXIT; } nWidth = _out_fbo->size().width( ); nHeight = _out_fbo->size().height( ); // get the buffer into texture _out_fbo->bind( ); glEnable( GL_TEXTURE_2D ); glViewport( 0, 0, nWidth, nHeight ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0.0, nWidth, 0.0, nHeight, -1.0, 1.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); glBindTexture( GL_TEXTURE_2D, _out_fbo->texture( ) ); image = new GLubyte[nHeight*nWidth*4]; if( !image ) { qDebug() << "ERROR! Memory Allocation Failed."; goto PIX_EXIT; } glReadPixels( 0, 0, nWidth, nHeight, GL_RGB, GL_UNSIGNED_BYTE, image ); // *** create image *** img = new QImage( nWidth, nHeight, QImage::Format_RGB888 ); if( !img ) { qDebug() << "ERROR! Failed to Create QImage."; goto PIX_EXIT; } for( i = 0; i < nHeight; i++ ) { iRow = nHeight - i - 1; for( j = 0 ; j < nWidth ; j++ ) { k = i * nWidth + j; iRed = (int)image[k*3]; iGreen = (int)image[k*3+1]; iBlue = (int)image[k*3+2]; img->setPixel( j, iRow, qRgb( iRed, iGreen, iBlue ) ); } } // save the image writer.setFileName( strFile ); if( !writer.canWrite( ) ) { qDebug() << "ERROR! Can't write to this file " << strFile; goto PIX_EXIT; } if( !writer.write( *img ) ) { qDebug() << "ERROR! Failed to read image " << strFile; goto PIX_EXIT; } _out_fbo->release( ); // --- DONE --- bRetCode = true; PIX_EXIT: if( image ) { delete[] image; image = NULL; } if( img ) { delete img; img = NULL; } return bRetCode; }
QImage* nlm_filter(QImage* image, QSize size, int d, int ld, double sigma) { int pW = size.width()+d-(d%2!=0?1:0); int pH = size.height()+d-(d%2!=0?1:0); QImage* imageFiltered = new QImage(pW, pH, QImage::Format_RGB32); QImage* tmpImage1 = new QImage(pW, pH, QImage::Format_RGB32); nlm_increse_image(image, imageFiltered, size, d); double** redArray = new double*[pW]; double** greenArray = new double*[pW]; double** blueArray = new double*[pW]; double** redArrayOutput = new double*[pW]; double** greenArrayOutput = new double*[pW]; double** blueArrayOutput = new double*[pW]; createColorArrays(redArray, greenArray, blueArray, imageFiltered, pW, pH); createColorArrays(redArrayOutput, greenArrayOutput, blueArrayOutput, tmpImage1, pW, pH); #ifdef MTHREADING QFuture<void> prRed = QtConcurrent::run( processColorArray, redArray, redArrayOutput, FilterParam(QSize(pW, pH), d, ld, sigma) ); QFuture<void> prGreen = QtConcurrent::run( processColorArray, greenArray, greenArrayOutput, FilterParam(QSize(pW, pH), d, ld, sigma) ); QFuture<void> prBlue = QtConcurrent::run( processColorArray, blueArray, blueArrayOutput, FilterParam(QSize(pW, pH), d, ld, sigma) ); prRed.waitForFinished(); prGreen.waitForFinished(); prBlue.waitForFinished(); #else processColorArray(redArray, redArrayOutput, FilterParam(QSize(pW, pH), d, ld, sigma)); processColorArray(greenArray, greenArrayOutput, FilterParam(QSize(pW, pH), d, ld, sigma)); processColorArray(blueArray, blueArrayOutput, FilterParam(QSize(pW, pH), d, ld, sigma)); #endif QImage* tmpImage = new QImage(size, QImage::Format_RGB32); createImageFromColors(redArrayOutput, greenArrayOutput, blueArrayOutput, tmpImage, pW, pH, d); deleteColorsArrays(redArray, greenArray, blueArray, pW); deleteColorsArrays(redArrayOutput, greenArrayOutput, blueArrayOutput, pW); QImageWriter* writer = new QImageWriter(); writer->setFileName("tmp.png"); writer->write(*tmpImage); delete tmpImage1; delete imageFiltered; return tmpImage; }
/** * @return Path to the thumbnail of the given DXF file. If no thumbnail exists, one is * created in the user's home. If no thumbnail can be created, an empty string is returned. */ QString QG_LibraryWidget::getPathToPixmap(const QString& dir, const QString& dxfFile, const QString& dxfPath) { // the thumbnail must be created in the user's home. #if QT_VERSION < 0x040400 QString iconCacheLocation = emu_qt44_storageLocationData() + QDir::separator() + "iconCache" + QDir::separator(); #elif QT_VERSION >= 0x050000 QString iconCacheLocation=QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QDir::separator() + "iconCache" + QDir::separator(); #else QString iconCacheLocation=QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QDir::separator() + "iconCache" + QDir::separator(); #endif RS_DEBUG->print("QG_LibraryWidget::getPathToPixmap: " "dir: '%s' dxfFile: '%s' dxfPath: '%s'", dir.toLatin1().data(), dxfFile.toLatin1().data(), dxfPath.toLatin1().data()); // List of all directories that contain part libraries: QStringList directoryList = RS_SYSTEM->getDirectoryList("library"); directoryList.prepend(iconCacheLocation); QStringList::Iterator it; QFileInfo fiDxf(dxfPath); QString itemDir; QString pngPath; // look in all possible system directories for PNG files // in the current library path: for (it=directoryList.begin(); it!=directoryList.end(); ++it) { itemDir = (*it)+dir; pngPath = itemDir + QDir::separator() + fiDxf.baseName() + ".png"; RS_DEBUG->print("QG_LibraryWidget::getPathToPixmap: checking: '%s'", pngPath.toLatin1().data()); QFileInfo fiPng(pngPath); // the thumbnail exists: if (fiPng.isFile()) { RS_DEBUG->print("QG_LibraryWidget::getPathToPixmap: dxf date: %s, png date: %s", fiDxf.lastModified().toString().toLatin1().data(), fiPng.lastModified().toString().toLatin1().data()); if (fiPng.lastModified() > fiDxf.lastModified()) { RS_DEBUG->print("QG_LibraryWidget::getPathToPixmap: thumbnail found: '%s'", pngPath.toLatin1().data()); return pngPath; } else { RS_DEBUG->print("QG_LibraryWidget::getPathToPixmap: thumbnail needs to be updated: '%s'", pngPath.toLatin1().data()); } } } // create all directories needed: RS_SYSTEM->createPaths(iconCacheLocation + dir); // QString foo=iconCacheLocation + dir + QDir::separator() + fiDxf.baseName() + ".png"; pngPath = iconCacheLocation + dir + QDir::separator() + fiDxf.baseName() + ".png"; QPixmap* buffer = new QPixmap(128,128); RS_PainterQt painter(buffer); painter.setBackground(RS_Color(255,255,255)); painter.eraseRect(0,0, 128,128); RS_StaticGraphicView gv(128,128, &painter); RS_Graphic graphic; if (graphic.open(dxfPath, RS2::FormatUnknown)) { gv.setContainer(&graphic); gv.zoomAuto(false); // gv.drawEntity(&graphic, true); for (RS_Entity* e=graphic.firstEntity(RS2::ResolveAll); e; e=graphic.nextEntity(RS2::ResolveAll)) { if (e->rtti() != RS2::EntityHatch){ RS_Pen pen = e->getPen(); pen.setColor(Qt::black); e->setPen(pen); } gv.drawEntity(&painter, e); } QImageWriter iio; QImage img; img = buffer->toImage(); img = img.scaled(64,64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); // iio.setImage(img); iio.setFileName(pngPath); iio.setFormat("PNG"); if (!iio.write(img)) { pngPath = ""; RS_DEBUG->print(RS_Debug::D_ERROR, "QG_LibraryWidget::getPathToPixmap: Cannot write thumbnail: '%s'", pngPath.toLatin1().data()); } } else { RS_DEBUG->print(RS_Debug::D_ERROR, "QG_LibraryWidget::getPathToPixmap: Cannot open file: '%s'", dxfPath.toLatin1().data()); } // GraphicView deletes painter painter.end(); delete buffer; return pngPath; }