AlbumWidget::AlbumWidget(QWidget* parent) : QWidget(parent) { qRegisterMetaType<QImage > ("QImage"); connect(&m_cd, SIGNAL(renderedImage(QImage)), this, SLOT(updatePixmap(QImage))); resize(300, 300); }
FluidWidget::FluidWidget(QWidget *parent) : QWidget(parent) { qRegisterMetaType<QImage>("QImage"); connect(&thread, SIGNAL(renderedImage(QImage)), this, SLOT(updatePixmap(QImage))); setWindowTitle(tr("Fluid")); #ifndef QT_NO_CURSOR setCursor(Qt::CrossCursor); #endif resize(1024, 1024); }
MandelbrotWidget::MandelbrotWidget(QWidget *parent) : QWidget(parent) { qRegisterMetaType<QImage>("QImage"); connect(&thread, SIGNAL(renderedImage(QImage)), this, SLOT(updatePixmap(QImage))); setWindowTitle(tr("White Noise")); resize(500, 400); QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(simulate())); timer->start(40); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { exporting = false; ui->setupUi(this); connect(this, SIGNAL(renderedImage(QList<QImage>)), ui->widget, SLOT(updatePixmap(QList<QImage>))); ui->outDir->setText(QDir::homePath()); exporting = false; ui->widget->scaleBox = ui->scale; tabifyDockWidget(ui->dockPreferences, ui->dockExport); ui->dockPreferences->raise(); pattern = QPixmap(20,20); QPainter painter(&pattern); #define BRIGHT 190 #define SHADOW 150 painter.fillRect(0,0,10,10,QColor(SHADOW,SHADOW,SHADOW)); painter.fillRect(10,0,10,10,QColor(BRIGHT,BRIGHT,BRIGHT)); painter.fillRect(10,10,10,10,QColor(SHADOW,SHADOW,SHADOW)); painter.fillRect(0,10,10,10,QColor(BRIGHT,BRIGHT,BRIGHT)); setAcceptDrops(true); }
static int transitionGetImage(mlt_frame aFrame, uint8_t **image, mlt_image_format *format, int *width, int *height, int /*writable*/) { int error = 0; mlt_frame bFrame = mlt_frame_pop_frame(aFrame); mlt_transition transition = (mlt_transition)mlt_frame_pop_service(aFrame); mlt_position position = mlt_transition_get_position(transition, aFrame); mlt_position length = mlt_transition_get_length(transition); // Get the aFrame image, we will write our output to it *format = mlt_image_rgb24; if ((error = mlt_frame_get_image(aFrame, image, format, width, height, 1)) != 0) return error; // Get the bFrame image, we won't write to it uint8_t *bImage = NULL; int bWidth = 0, bHeight = 0; if ((error = mlt_frame_get_image(bFrame, &bImage, format, &bWidth, &bHeight, 0)) != 0) return error; { // Scope the lock MLTWebVfx::ServiceLocker locker(MLT_TRANSITION_SERVICE(transition)); if (!locker.initialize(*width, *height)) return 1; MLTWebVfx::ServiceManager* manager = locker.getManager(); WebVfx::Image renderedImage(*image, *width, *height, *width * *height * WebVfx::Image::BytesPerPixel); manager->setImageForName(manager->getSourceImageName(), &renderedImage); WebVfx::Image targetImage(bImage, bWidth, bHeight, bWidth * bHeight * WebVfx::Image::BytesPerPixel); manager->setImageForName(manager->getTargetImageName(), &targetImage); manager->render(&renderedImage, position, length); } return error; }
BarcodeGenerator::BarcodeGenerator(QWidget* parent, const char* name) : QDialog(parent), paintBarcodeTimer(NULL) { ui.setupUi(this); setObjectName(name); setModal(true); connect(&thread, SIGNAL(renderedImage(QString)),this, SLOT(updatePreview(QString))); /* * We extract the barcode information from the BWIPP metadata which looks like this: * * % --BEGIN ENCODER gs1-128-- * % --REQUIRES preamble raiseerror renlinear code128-- * % --DESC: GS1-128 * % --EXAM: (01)95012345678903(3103)000123 * % --EXOP: includetext * % --RNDR: renlinear * */ QFile f(ScPaths::instance().shareDir() + QString("/plugins/barcode.ps")); if(!f.open(QIODevice::ReadOnly)) { qDebug()<<"Barcodegenerator unable to open "<<f.fileName(); return; } QTextStream ts(&f); QString bwipp = ts.readAll(); f.close(); QRegExp rx( "[\\r\\n]+% --BEGIN (RESOURCE|RENDERER|ENCODER) ([\\w-]+)--[\\r\\n]+" "(.*[\\r\\n]+)?" "(%%BeginResource.*[\\r\\n]+)" "% --END \\1 \\2--[\\r\\n]+"); rx.setMinimal(true); int pos = 0; while ( (pos = rx.indexIn(bwipp, pos)) != -1 ) { int len=rx.matchedLength(); QString restype=rx.cap(1); QString resname=rx.cap(2); QString reshead=rx.cap(3); QString resbody=rx.cap(4); resbodys[resname]=resbody; if (restype=="ENCODER") { QRegExp rxhead( "% --REQUIRES (.*)--[\\r\\n]+" "% --DESC:(.*)[\\r\\n]+" "% --EXAM:(.*)[\\r\\n]+" "% --EXOP:(.*)[\\r\\n]+" "% --RNDR:(.*)[\\r\\n]+" ); rxhead.indexIn(reshead); resreqs[resname]=rxhead.cap(1).trimmed(); resdescs[resname]=rxhead.cap(2).trimmed(); resexams[resname]=rxhead.cap(3).trimmed(); resexops[resname]=rxhead.cap(4).trimmed(); resrndrs[resname]=rxhead.cap(5).trimmed(); encoderlist.append(resname); } pos+=len; } foreach (const QString& enc, encoderlist) map[resdescs[enc]] = BarcodeType(enc, resexams[enc], resexops[enc]); /* * Ultimately all of this static data about the capabilities of each barcode * encoder will be replaced by data read from the barcode.ps metadata, when * such data exists... * */ // Content for the version and ecc combos resvers["qrcode"]="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,38,39,40"; resecls["qrcode"]="L,Q,M,H"; resvers["gs1qrcode"]=resvers["qrcode"]; resecls["gs1qrcode"]=resecls["qrcode"]; resvers["hibcqrcode"]=resvers["qrcode"]; resecls["hibcqrcode"]=resecls["qrcode"]; resvers["microqrcode"]="M1,M2,M3,M4"; resecls["microqrcode"]="L,Q,M,H"; resvers["datamatrix"]="10x10,12x12,14x14,16x16,18x18,20x20,22x22,24x24,26x26,32x32,36x36,40x40,44x44,48x48,52x52,64x64,72x72,80x80,88x88,96x96,104x104,120x120,132x132,144x144,8x18,8x32,12x26,12x36,16x36,16x48"; resecls["datamatrix"]=""; resvers["gs1datamatrix"]=resvers["datamatrix"]; resecls["gs1datamatrix"]=resvers["datamatrix"]; resvers["hibcdatamatrix"]=resvers["datamatrix"]; resecls["hibcdatamatrix"]=resecls["datamatrix"]; resvers["azteccode"]="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"; resvlbl["azteccode"]="Layers"; resecls["azteccode"]="5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95"; resvers["azteccodecompact"]="1,2,3,4"; resvlbl["azteccodecompact"]=resvlbl["azteccode"]; resecls["azteccodecompact"]=resecls["azteccode"]; resvers["pdf417"]="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"; resvlbl["pdf417"]="Columns"; resecls["pdf417"]="1,2,3,4,5"; resvers["pdf417compact"]=resvers["pdf417"]; resvlbl["pdf417compact"]=resvlbl["pdf417"]; resecls["pdf417compact"]=resecls["pdf417"]; resvers["hibcpdf417"]=resvers["pdf417"]; resvlbl["hibcpdf417"]=resvlbl["pdf417"]; resecls["hibcpdf417"]=resecls["pdf417"]; resvers["micropdf417"]="1x11,1x14,1x17,1x20,1x24,1x28,2x8,2x11,2x14,2x17,2x20,2x23,2x26,3x6,3x8,3x10,3x12,3x15,3x20,3x26,3x32,3x38,3x44,4x4,4x6,4x8,4x10,4x12,4x15,4x20,4x26,4x32,4x38,4x44"; resecls["micropdf417"]=""; resvers["hibcmicropdf417"]=resvers["micropdf417"]; resecls["hibcmicropdf417"]=resecls["micropdf417"]; resvers["hanxin"]="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,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84"; resecls["hanxin"]="L1,L2,L3,L4"; // Which options checkboxes are enabled for each encoder QStringList includetextAvail=encoderlist; foreach (const QString& enc, includetextAvail) resincludetextAvail[enc]=true; QStringList guardwhitespaceAvail; guardwhitespaceAvail << "ean13" << "ean8" << "isbn" << "ismn" << "issn" << "ean13composite" << "ean8composite"; foreach (const QString& enc, guardwhitespaceAvail) resguardwhitespaceAvail[enc]=true; QStringList includecheckAvail; includecheckAvail << "bc412" << "channelcode" << "code11" << "code2of5" << "coop2of5" << "datalogic2of5" << "iata2of5" << "industrial2of5" << "matrix2of5" << "code39" << "code39ext" << "code93" << "code93ext" << "interleaved2of5" << "msi" << "rationalizedCodabar"; foreach (const QString& enc, includecheckAvail) resincludecheckAvail[enc]=true; QStringList includecheckintextAvail; includecheckintextAvail << "bc412" << "code11" << "code2of5" << "coop2of5" << "datalogic2of5" << "iata2of5" << "industrial2of5" << "matrix2of5" << "code39" << "code39ext" << "interleaved2of5" << "japanpost" << "msi" << "planet" << "plessey" << "postnet" << "rationalizedCodabar" << "royalmail"; foreach (const QString& enc, includecheckintextAvail) resincludecheckintextAvail[enc]=true; QStringList parseAvail; parseAvail << "azteccode" << "azteccodecompact" << "codablockf" << "hibccodablockf" << "code128" << "hibccode128" << "code16k" << "code39ext" << "code49" << "code93ext" << "codeone" << "datamatrix" << "hibcdatamatrix" << "maxicode" << "micropdf417" << "hibcmicropdf417" << "pdf417" << "hibcpdf417" << "pdf417compact" << "posicode" << "qrcode" << "hibcqrcode" << "microqrcode" << "telepen" << "hanxin"; foreach (const QString& enc, parseAvail) resparseAvail[enc]=true; QStringList parsefncAvail; parsefncAvail << "codablockf" << "code128" << "code16k" << "code49" << "code93" << "codeone" << "datamatrix" << "posicode" << "qrcode" << "microqrcode"; foreach (const QString& enc, parsefncAvail) resparsefncAvail[enc]=true; // Building up the bcFamilyCombo grouping the formats for readablity ui.bcFamilyCombo->addItem(tr("Select a barcode family")); // to prevent 1st gs call ui.bcFamilyCombo->insertSeparator(999); // Building up the bcCombo grouping the formats for readablity ui.bcCombo->addItem(tr("Select a barcode format")); // to prevent 1st gs call ui.bcCombo->insertSeparator(999); QString familyName; QStringList bcNames; bcNames << "EAN-13" << "EAN-8" << "UPC-A" << "UPC-E" << "ISBN" << "ISMN" << "ISSN"; familyName = tr("Point of Sale"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "GS1-14" << "GS1 Data Matrix" << "GS1 QR Code" << "GS1-128" << "ITF-14" << "SSCC-18"; familyName = tr("Supply Chain"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "QR Code" << "Micro QR Code" << "Data Matrix" << "Aztec Code" << "Compact Aztec Code" << "Aztec Runes" << "PDF417" << "Compact PDF417" << "MicroPDF417" << "Han Xin Code"; familyName = tr("Two-dimensional symbols"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "Code 128" << "Code 39" << "Code 39 Extended" << "Code 93" << "Code 93 Extended" << "Interleaved 2 of 5 (ITF)"; familyName = tr("One-dimensional symbols"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "GS1 DataBar Omnidirectional" << "GS1 DataBar Stacked Omnidirectional" << "GS1 DataBar Expanded" << "GS1 DataBar Expanded Stacked" << "GS1 DataBar Truncated" << "GS1 DataBar Stacked" << "GS1 DataBar Limited"; familyName = tr("GS1 DataBar family"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "AusPost 4 State Customer Code" << "Deutsche Post Identcode" << "Deutsche Post Leitcode" << "Japan Post 4 State Customer Code" << "Royal Dutch TPG Post KIX" << "Royal Mail 4 State Customer Code" << "USPS Intelligent Mail" << "USPS PLANET" << "USPS POSTNET"; familyName = tr("Postal symbols"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "Italian Pharmacode" << "Pharmaceutical Binary Code" << "Two-track Pharmacode" << "Pharmazentralnummer (PZN)" << "HIBC Codablock F" << "HIBC Code 128" << "HIBC Code 39" << "HIBC Data Matrix" << "HIBC MicroPDF417" << "HIBC PDF417" << "HIBC QR Code"; familyName = tr("Pharmaceutical symbols"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "Code 11" << "Codabar" << "Code 25" << "COOP 2 of 5" << "Datalogic 2 of 5" << "IATA 2 of 5" << "Industrial 2 of 5" << "Matrix 2 of 5" << "MSI Modified Plessey" << "Plessey UK" << "PosiCode" << "Telepen" << "Telepen Numeric"<< "Code 16K" << "Codablock F" << "Code 49" << "Code One"; familyName = tr("Less-used symbols"); familyList.append(familyName); familyItems.insert(familyName, bcNames); bcNames.clear(); bcNames << "EAN-13 Composite" << "EAN-8 Composite" << "UPC-A Composite" << "UPC-E Composite" << "GS1 DataBar Omnidirectional Composite" << "GS1 DataBar Stacked Omnidirectional Composite" << "GS1 DataBar Expanded Composite" << "GS1 DataBar Expanded Stacked Composite" << "GS1 DataBar Truncated Composite" << "GS1 DataBar Stacked Composite" << "GS1 DataBar Limited Composite" << "GS1-128 Composite"; familyName = tr("GS1 Composite symbols"); familyList.append(familyName); familyItems.insert(familyName, bcNames); ui.bcFamilyCombo->addItems(familyList); /* * End of the hard-coded data * */ guiColor = ui.codeEdit->palette().color(QPalette::Window); ui.okButton->setText(CommonStrings::tr_OK); ui.cancelButton->setText(CommonStrings::tr_Cancel); ui.resetButton->setIcon(IconManager::instance()->loadIcon("u_undo16.png")); if (ScCore->primaryMainWindow()->doc->PageColors.contains("Black")) { lnColor = ScCore->primaryMainWindow()->doc->PageColors["Black"]; txtColor = ScCore->primaryMainWindow()->doc->PageColors["Black"]; ui.linesLabel->setToolTip("Black"); ui.txtLabel->setToolTip("Black"); } else { ui.linesLabel->setToolTip("n.a."); ui.txtLabel->setToolTip("n.a."); } if (ScCore->primaryMainWindow()->doc->PageColors.contains("White")) { bgColor = ScCore->primaryMainWindow()->doc->PageColors["White"]; ui.bgLabel->setToolTip("White"); } else ui.bgLabel->setToolTip("n.a."); paintColorSample(ui.linesLabel, lnColor); paintColorSample(ui.txtLabel, txtColor); paintColorSample(ui.bgLabel, bgColor); paintBarcodeTimer=new QTimer(this); paintBarcodeTimer->setSingleShot(true); connect(paintBarcodeTimer, SIGNAL(timeout()), this, SLOT(paintBarcode())); connect(ui.bcFamilyCombo, SIGNAL(activated(QString)), this, SLOT(bcFamilyComboChanged())); connect(ui.bcCombo, SIGNAL(activated(QString)), this, SLOT(bcComboChanged())); connect(ui.bgColorButton, SIGNAL(clicked()), this, SLOT(bgColorButton_pressed())); connect(ui.lnColorButton, SIGNAL(clicked()), this, SLOT(lnColorButton_pressed())); connect(ui.txtColorButton, SIGNAL(clicked()), this, SLOT(txtColorButton_pressed())); connect(ui.okButton, SIGNAL(clicked()), this, SLOT(okButton_pressed())); connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancelButton_pressed())); connect(ui.codeEdit, SIGNAL(textChanged(QString)), this, SLOT(codeEdit_textChanged(QString))); connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetButton_clicked())); bcComboChanged(); }
// process video data void CaptureThread::run() { while (devam) { mutex.lock(); do { FD_ZERO(&fds); FD_SET(fd, &fds); /* Timeout. */ tv.tv_sec = 2; tv.tv_usec = 0; r = select(fd + 1, &fds, NULL, NULL, &tv); } while ((r == -1 && (errno = EINTR))); if (r == -1) { kDebug() << "select"; quit(); return; } CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; xioctl(fd, VIDIOC_DQBUF, &buf); if (v4lconvert_convert(v4lconvert_data, &src_fmt, &fmt, (unsigned char*)buffers[buf.index].start, buf.bytesused, dst_buf, fmt.fmt.pix.sizeimage) < 0) { if (errno != EAGAIN) kDebug() << "v4l_convert"; } unsigned char* asil=(unsigned char*)malloc(fmt.fmt.pix.sizeimage+qstrlen(header)); memmove(asil, dst_buf, fmt.fmt.pix.sizeimage); memmove(asil+qstrlen(header), asil, fmt.fmt.pix.sizeimage); memcpy(asil,header,qstrlen(header)); QImage *qq=new QImage(); if(qq->loadFromData(asil,fmt.fmt.pix.sizeimage+qstrlen(header), "PPM")){ QTransform outTransform; if(Settings::mirror()){ // scaling x * -1 - making the output image mirror. outTransform.scale(-1, 1); } if(Settings::flip()){ // flipping y * -1 outTransform.scale(1, -1); } emit renderedImage(qq->transformed(outTransform)); } free(asil); delete qq; if (delay>0) { this->msleep(delay); } xioctl(fd, VIDIOC_QBUF, &buf); di++; mutex.unlock(); } }
void MainWindow::packerUpdate() { int i; quint64 area = 0; packer.sortOrder = ui->sortOrder->currentIndex(); packer.border.t = ui->borderTop->value(); packer.border.l = ui->borderLeft->value(); packer.border.r = ui->borderRight->value(); packer.border.b = ui->borderBottom->value(); packer.trim = ui->trim->currentIndex(); packer.merge = ui->merge->isChecked(); packer.mergeBF = false; packer.rotate = ui->rotationStrategy->currentIndex(); int textureWidth = ui->textureW->value(), textureHeight = ui->textureH->value(); int heuristic = ui->comboHeuristic->currentIndex(); QString outDir = ui->outDir->text(); QString outFile = ui->outFile->text(); QString outFormat = ui->outFormat->currentText(); bool previewWithImages =ui->previewWithImages->isChecked(); packer.pack(heuristic, textureWidth, textureHeight); QList<QImage> textures; for (i = 0; i < packer.bins.size(); i++) { QImage texture(packer.bins.at(i).width(), packer.bins.at(i).height(), QImage::Format_ARGB32); texture.fill(Qt::transparent); textures << texture; } if(exporting) { for(int j = 0; j < textures.count(); j++) { QString outputFile = outDir; outputFile += QDir::separator(); outputFile += outFile; if(textures.count() > 1) outputFile += QString("_") + QString::number(j + 1); outputFile += ".atlas"; QString imgFile = outFile; if(textures.count() > 1) imgFile += QString("_") + QString::number(j + 1); imgFile += "."; imgFile += outFormat.toLower(); QFile positionsFile(outputFile); if (!positionsFile.open(QIODevice::WriteOnly | QIODevice::Text)) QMessageBox::critical(0, tr("Error"), tr("Cannot create file ") + outputFile); else { QTextStream out(&positionsFile); out << "textures: " << imgFile << "\n"; for (i = 0; i < packer.images.size(); i++) { if(packer.images.at(i).textureId != j) continue; QPoint pos(packer.images.at(i).pos.x() + packer.border.l, packer.images.at(i).pos.y() + packer.border.t); QSize size, sizeOrig; QRect crop; sizeOrig = packer.images.at(i).size; if(!packer.trim) { size = packer.images.at(i).size; crop = QRect(0,0,size.width(),size.height()); } else { size = packer.images.at(i).crop.size(); crop = packer.images.at(i).crop; } if(packer.images.at(i).rotated) { size.transpose(); crop = QRect(packer.images.at(i).size.height() - crop.y() - crop.height(), crop.x(), crop.height(), crop.width()); } out << (((packerData*)(packer.images.at(i).id))->listItem)->text() << "\t" << pos.x() << "\t" << pos.y() << "\t" << crop.width() << "\t" << crop.height() << "\t" << crop.x() << "\t" << crop.y() << "\t" << sizeOrig.width() << "\t" << sizeOrig.height() << "\t" << (packer.images.at(i).rotated ? "r" : "") << "\n"; } } } } for (i = 0; i < packer.images.size(); i++) { if(packer.images.at(i).pos == QPoint(999999, 999999)) { (((packerData*)(packer.images.at(i).id))->listItem)->setForeground(Qt::red); continue; } (((packerData*)(packer.images.at(i).id))->listItem)->setForeground(Qt::black); if(packer.images.at(i).duplicateId != NULL && packer.merge) { continue; } QPoint pos(packer.images.at(i).pos.x() + packer.border.l, packer.images.at(i).pos.y() + packer.border.t); QSize size; QRect crop; if(!packer.trim) { size = packer.images.at(i).size; crop = QRect(0,0,size.width(),size.height()); } else { size = packer.images.at(i).crop.size(); crop = packer.images.at(i).crop; } QImage img; if((exporting || previewWithImages)) img = QImage(((packerData*)(packer.images.at(i).id))->path); if(packer.images.at(i).rotated) { QTransform myTransform; myTransform.rotate(90); img = img.transformed(myTransform); size.transpose(); crop = QRect(packer.images.at(i).size.height() - crop.y() - crop.height(), crop.x(), crop.height(), crop.width()); } if(packer.images.at(i).textureId < packer.bins.size()) { QPainter p(&textures.operator [](packer.images.at(i).textureId)); if(!exporting) p.fillRect(pos.x(), pos.y(), size.width(), size.height(), pattern); if(previewWithImages || exporting) { p.drawImage(pos.x(), pos.y(), img, crop.x(), crop.y(), crop.width(), crop.height()); } else if(!exporting) p.drawRect(pos.x(), pos.y(), size.width() - 1, size.height() - 1); } } for(int i = 0; i < textures.count(); i++) area += textures.at(i).width() * textures.at(i).height(); float percent = (((float)packer.area / (float)area) * 100.0f); float percent2 = (float)(((float)packer.neededArea / (float)area) * 100.0f ); ui->preview->setText(tr("Preview: ") + QString::number(percent) + QString("% filled, ") + (packer.missingImages == 0 ? QString::number(packer.missingImages) + tr(" images missed,") : QString("<font color=red><b>") + QString::number(packer.missingImages) + tr(" images missed,") + "</b></font>") + " " + QString::number(packer.mergedImages) + tr(" images merged, needed area: ") + QString::number(percent2) + "%."); if(exporting) { const char * format = qPrintable(outFormat); for(int i = 0; i < textures.count(); i++) { QString imgdirFile; imgdirFile = outDir; imgdirFile += QDir::separator(); imgdirFile += outFile; if(textures.count() > 1) imgdirFile += QString("_") + QString::number(i + 1); imgdirFile += "."; imgdirFile += outFormat.toLower(); if(outFormat == "JPG") { int res = textures.at(i).save(imgdirFile, format, 100); } else { int res = textures.at(i).save(imgdirFile); } } QMessageBox::information(0, tr("Done"), tr("Your atlas successfully saved in ") + outDir); exporting = false; } else emit renderedImage(textures); }
void RenderThread::run() { struct timeval t0,t1; forever { mutex.lock(); QSize resultSize = this->resultSize; double scaleFactor = this->scaleFactor; double centerX = this->centerX; double centerY = this->centerY; mutex.unlock(); int halfWidth = resultSize.width() / 2; int halfHeight = resultSize.height() / 2; QImage image(resultSize, QImage::Format_RGB32); const int NumPasses = 8; int pass = 0; while (pass < NumPasses) { gettimeofday(&t0,NULL); const int MaxIterations = (1 << (2 * pass + 6)) + 32; const int Limit = 4; bool allBlack = true; for (int y = -halfHeight; y < halfHeight; ++y) { if (restart) break; if (abort) return; uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y + halfHeight)); double ay = centerY + (y * scaleFactor); for (int x = -halfWidth; x < halfWidth; ++x) { double ax = centerX + (x * scaleFactor); double a1 = ax; double b1 = ay; int numIterations = 0; do { ++numIterations; double a2 = (a1 * a1) - (b1 * b1) + ax; double b2 = (2 * a1 * b1) + ay; if ((a2 * a2) + (b2 * b2) > Limit) break; ++numIterations; a1 = (a2 * a2) - (b2 * b2) + ax; b1 = (2 * a2 * b2) + ay; if ((a1 * a1) + (b1 * b1) > Limit) break; } while (numIterations < MaxIterations); if (numIterations < MaxIterations) { *scanLine++ = colormap[numIterations % ColormapSize]; allBlack = false; } else { *scanLine++ = qRgb(0, 0, 0); } } } gettimeofday(&t1,NULL); std::cout << "[Renderthread] pass " << pass << " done [" << diffmsec(t1,t0) << "ms]\n"; if (allBlack && pass == 0) { pass = 4; } else { if (!restart) emit renderedImage(image, scaleFactor); ++pass; } } mutex.lock(); if (!restart) condition.wait(&mutex); restart = false; mutex.unlock(); } }
/** * function to download image form last.fm/api * sends one request to obtain album info from * witch parses link to image to download. * Then updates Qpixmap member in AlbumWidget instance.s */ void CoverDownloader::download() { HttpClientSocket httpSocket("ws.audioscrobbler.com", 80); if (m_artist.empty() || m_albumName.empty()) { Logger::getInstance()->log(httpSocket.getSocketId(), "BOTH ARTIST AND ALBUM MUST BE SET", LOG_LEVEL_ERROR); return; } std::string albumTitle = CoverDownloader::escapeStrings(m_albumName); std::string artistName = CoverDownloader::escapeStrings(m_artist); std::string req = "GET /2.0/?method=album.getinfo&api_key="; req += API_KEY; req += "&artist="; req += artistName; req += "&album="; req += albumTitle; req += " HTTP/1.1\r\nHost: ws.audioscrobbler.com\r\n\r\n"; std::cout << "REQUEST: " << req << std::endl; if (!httpSocket.sendRequest(req)) { Logger::getInstance()->log(httpSocket.getSocketId(), "REQUEST WAS NOT SUCCESSFULLY SENT.", LOG_LEVEL_ERROR); return; } std::string response = httpSocket.getResponse(); if (response.size() < 10) { Logger::getInstance()->log(httpSocket.getSocketId(), "RESPONSE HAS INVALID SIZE", LOG_LEVEL_ERROR); return; } std::cout << "RESPONSE: " << response << std::endl; size_t pos1 = response.find("<image size=\"extralarge\">"); size_t pos2 = response.find("</image>", pos1); if (pos1 == response.npos || pos2 <= pos1) return; std::string url = response.substr(pos1 + 25, pos2 - pos1 - 25); std::cout << "URL: " << url << std::endl; if (url.length() < 5) { Logger::getInstance()->log(httpSocket.getSocketId(), "PARSED URL IS INVALID", LOG_LEVEL_ERROR); return; } std::string filename = m_artist + "_" + m_albumName; std::string path = "cache/" + filename + url.substr(url.length() - 4); saveImage(url, path); QImage* image = getImage(QString::fromStdString(filename)); if (image != NULL) { Q_EMIT renderedImage(*image); } else { Logger::getInstance()->log(httpSocket.getSocketId(), "COULD NOT LOAD IMAGE", LOG_LEVEL_ERROR); } }
//! [3] void MandelbrotRenderer::run() { qDebug() << "MandelbrotRenderer::run()"; forever { mutex.lock(); QSize resultSize = this->resultSize; double scaleFactor = this->scaleFactor; double centerX = this->centerX; double centerY = this->centerY; mutex.unlock(); //! [3] //! [4] int halfWidth = resultSize.width() / 2; //! [4] //! [5] int halfHeight = resultSize.height() / 2; QImage image(resultSize, QImage::Format_RGB32); const int NumPasses = 8; int pass = 0; while (pass < NumPasses) { const int MaxIterations = (1 << (2 * pass + 6)) + 32; const int Limit = 4; bool allBlack = true; for (int y = -halfHeight; y < halfHeight; ++y) { if (restart) break; if (abort) return; uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y + halfHeight)); double ay = centerY + (y * scaleFactor); for (int x = -halfWidth; x < halfWidth; ++x) { double ax = centerX + (x * scaleFactor); double a1 = ax; double b1 = ay; int numIterations = 0; do { ++numIterations; double a2 = (a1 * a1) - (b1 * b1) + ax; double b2 = (2 * a1 * b1) + ay; if ((a2 * a2) + (b2 * b2) > Limit) break; ++numIterations; a1 = (a2 * a2) - (b2 * b2) + ax; b1 = (2 * a2 * b2) + ay; if ((a1 * a1) + (b1 * b1) > Limit) break; } while (numIterations < MaxIterations); if (numIterations < MaxIterations) { *scanLine++ = colormap[numIterations % ColormapSize]; allBlack = false; } else { *scanLine++ = qRgb(0, 0, 0); } } } if (allBlack && pass == 0) { pass = 4; } else { if (!restart) emit renderedImage(image, scaleFactor); //! [5] //! [6] ++pass; } //! [6] //! [7] } //! [7] //! [8] mutex.lock(); //! [8] //! [9] if (!restart) condition.wait(&mutex); restart = false; mutex.unlock(); } }