void ChipViewport::stretchFromCubeViewport(Stretch *newStretch, CubeViewport *cvp) { ASSERT(cvp != NULL); if (!cvp || !p_chipCube) return; // only stretch if the CubeViewport is opened to the same cube as we are, // otherwise the signal was meant for a different ChipViewport! if (cvp->cube()->fileName() == p_chipCube->fileName()) { // if user right clicked in the CubeViewport then we get a SIGNAL with a // NULL Stretch. This is used to signify that we need to restretch on our // own (go back to global). if (!newStretch) { computeStretch(p_gray.stretch, true); paintImage(); update(); } else { *p_stretch = *newStretch; p_gray.stretch = *newStretch; paintImage(); update(); } } }
TEST_C(NodeRemovalTest, nodeParameterWithoutParentCanBeUsed) { auto levelHeights = makeLevelHeights({ 0, 1, 2, 3 }); DummyMinMaxTreeImageType image(4, 1); std::shared_ptr<TreeNodeType> noParent; paintImage(image); assignPixelsToLatestNodes(image); auto nodeCopy = image.getPixelNode(2, 0); nodeCopy.setParent(noParent); image.removeNode(nodeCopy); assertThat(image.getPixelValue(0, 0)).isEqualTo(levelHeights[0]); assertThat(image.getPixelValue(1, 0)).isEqualTo(levelHeights[1]); assertThat(image.getPixelValue(2, 0)).isEqualTo(levelHeights[1]); assertThat(image.getPixelValue(3, 0)).isEqualTo(levelHeights[3]); auto& firstNode = image.getPixelNode(0, 0); auto& secondNode = image.getPixelNode(1, 0); auto& thirdNode = image.getPixelNode(2, 0); auto& fourthNode = image.getPixelNode(3, 0); verifyNode(firstNode, levelHeights[0], 0u); verifyNode(secondNode, levelHeights[1], 0u, firstNode); verifyNode(thirdNode, levelHeights[1], 0u, firstNode); verifyNode(fourthNode, levelHeights[3], 0u, secondNode); }
TEST_C(NodeRemovalTest, pixelNodeIdsAreUpdated) { auto levelHeights = makeLevelHeights({ 0, 1, 2, 3, 4, 5 }); DummyMinMaxTreeImageType image(3, 2); paintImage(image); auto repeatedLevel = image.getPixelValue(1, 0); image.setPixel(2, 0, repeatedLevel); image.assignPixelToLatestNode(0, 0); image.assignPixelToLatestNode(1, 0); image.assignPixelToNewNode(2, 0); image.assignPixelToLatestNode(0, 1); image.assignPixelToLatestNode(1, 1); image.assignPixelToLatestNode(2, 1); auto& node = image.getPixelNode(0, 1); image.removeNode(node); auto& firstNode = image.getPixelNode(0, 0); auto& secondNode = image.getPixelNode(1, 0); auto& thirdNode = image.getPixelNode(2, 0); auto& fourthNode = image.getPixelNode(0, 1); auto& fifthNode = image.getPixelNode(1, 1); auto& sixthNode = image.getPixelNode(2, 1); verifyNode(firstNode, levelHeights[0], 0u); verifyNode(secondNode, levelHeights[1], 0u, firstNode); verifyNode(thirdNode, levelHeights[1], 1u, firstNode); verifyNode(fourthNode, levelHeights[1], 1u, firstNode); verifyNode(fifthNode, levelHeights[4], 0u, fourthNode); verifyNode(sixthNode, levelHeights[5], 0u, fifthNode); }
TEST_C(NodeRemovalTest, cantRemoveNodeFromInexistentLevel) { auto levelHeights = makeLevelHeights({ 0, 1, 2, 3 }); DummyMinMaxTreeImageType image(4, 1); paintImage(image); assignPixelsToLatestNodes(image); auto fakeNode = TreeNodeType(PixelType{ 4 }, 0u); image.removeNode(fakeNode); assertThat(image.getPixelValue(0, 0)).isEqualTo(levelHeights[0]); assertThat(image.getPixelValue(1, 0)).isEqualTo(levelHeights[1]); assertThat(image.getPixelValue(2, 0)).isEqualTo(levelHeights[2]); assertThat(image.getPixelValue(3, 0)).isEqualTo(levelHeights[3]); auto& firstNode = image.getPixelNode(0, 0); auto& secondNode = image.getPixelNode(1, 0); auto& thirdNode = image.getPixelNode(2, 0); auto& fourthNode = image.getPixelNode(3, 0); verifyNode(firstNode, levelHeights[0], 0u); verifyNode(secondNode, levelHeights[1], 0u, firstNode); verifyNode(thirdNode, levelHeights[2], 0u, secondNode); verifyNode(fourthNode, levelHeights[3], 0u, thirdNode); }
void Object::exportX(int frameStart, int frameEnd, QMatrix view, QSize exportSize, QString filePath, bool antialiasing, int gradients) { QSettings settings("Pencil","Pencil"); qreal curveOpacity = (100-settings.value("curveOpacity").toInt())/100.0; // default value is 1.0 int page; page=0; for(int j = frameStart; j <= frameEnd; j=j+15) { QImage xImg(QSize(2300,3400), QImage::Format_ARGB32_Premultiplied); QPainter xPainter(&xImg); xPainter.fillRect(0,0,2300,3400,Qt::white); int y = j-1; for(int i=j;i<15+page*15 && i<=frameEnd;i++) { QRect source = QRect( QPoint(0,0) , exportSize ); QRect target = QRect ( QPoint((y%3)*800+30, (y/3)*680+50-page*3400) , QSize(640,480) ); QMatrix thumbView = view * Editor::map(source, target); xPainter.setWorldMatrix( thumbView ); xPainter.setClipRegion( thumbView.inverted().map( QRegion(target) ) ); paintImage(xPainter, i, false, curveOpacity, antialiasing, gradients); xPainter.resetMatrix(); xPainter.setClipping(false); xPainter.setPen( Qt::black ); xPainter.setFont(QFont("helvetica",50)); xPainter.drawRect( target ); xPainter.drawText(QPoint((y%3)*800+35, (y/3)*680+65-page*3400), QString::number(i)); y++; } if(filePath.endsWith(".jpg", Qt::CaseInsensitive)) { filePath = filePath.remove(".jpg", Qt::CaseInsensitive); } xImg.save(filePath+QString::number(page)+".jpg", "JPG", 60); page++; } }
TEST_C(NodeRemovalTest, parentOfNodeParameterIsNotUsed) { auto levelHeights = makeLevelHeights({ 0, 1, 2 }); DummyMinMaxTreeImageType image(3, 1); paintImage(image); assignPixelsToLatestNodes(image); auto nodeCopy = image.getPixelNode(1, 0); auto fakeParent = makeNode(0u, PixelType { 98765 }); nodeCopy.setParent(fakeParent); image.removeNode(nodeCopy); assertThat(image.getPixelValue(0, 0)).isEqualTo(levelHeights[0]); assertThat(image.getPixelValue(1, 0)).isEqualTo(levelHeights[0]); assertThat(image.getPixelValue(2, 0)).isEqualTo(levelHeights[2]); auto& firstNode = image.getPixelNode(0, 0); auto& secondNode = image.getPixelNode(1, 0); auto& thirdNode = image.getPixelNode(2, 0); verifyNode(firstNode, levelHeights[0], 0u); verifyNode(secondNode, levelHeights[0], 0u); verifyNode(thirdNode, levelHeights[2], 0u, firstNode); }
//! [3] void TabletCanvas::tabletEvent(QTabletEvent *event) { switch (event->type()) { case QEvent::TabletPress: if (!deviceDown) deviceDown = true; break; case QEvent::TabletRelease: if (deviceDown) deviceDown = false; break; case QEvent::TabletMove: polyLine[2] = polyLine[1]; polyLine[1] = polyLine[0]; polyLine[0] = event->pos(); if (deviceDown) { updateBrush(event); QPainter painter(&image); paintImage(painter, event); } break; default: break; } update(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void DREAM3DGraphicsView::updateDisplay() { // std::cout << "DREAM3DGraphicsView::updateDisplay()" << std::endl; QPainter painter; QSize pSize(0, 0); if (m_BaseImage.isNull() == false) { pSize = m_BaseImage.size(); } else { return; } QImage paintImage(pSize, QImage::Format_ARGB32_Premultiplied); QPoint point(0, 0); painter.begin(&paintImage); painter.setPen(Qt::NoPen); if (m_ImageDisplayType == EmMpm_Constants::OriginalImage) { painter.drawImage(point, m_BaseImage); } painter.end(); if (paintImage.isNull() == true) { return; } QGraphicsPixmapItem* pixItem = qgraphicsitem_cast<QGraphicsPixmapItem*> (m_ImageGraphicsItem); pixItem->setPixmap(QPixmap::fromImage(paintImage)); this->update(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void ImageGraphicsDelegate::updateGraphicsView(bool updateGraphicsScene) { if (this->m_CachedImage.isNull() == true) { return; } if (NULL != m_CurrentGraphicsItem) { m_GraphicsScene->removeItem(m_CurrentGraphicsItem); //Remove the image that is displaying m_CurrentGraphicsItem->setParentItem(NULL); // Set the parent to NULL delete m_CurrentGraphicsItem; // Delete the object } QImage dataImage; if (_zoomIndex != 3) // There was scaling and a scaled image already exists { dataImage = m_ScaledCachedImage; } else // 100% view, ie, no scaling just use the existing cached image { dataImage = m_CachedImage; } QPixmap imagePixmap; if (m_CompositeImages == true && m_OverlayImage.isNull() == false) { QImage topImage = _scaleImage(m_OverlayImage); QPainter painter; QImage paintImage(dataImage.size(), QImage::Format_ARGB32_Premultiplied); QPoint point(0, 0); painter.begin(&paintImage); // Draw the fixed Image first painter.setPen(Qt::NoPen); painter.drawImage(point, topImage); // Draw the moving image next painter.setCompositionMode(m_composition_mode); painter.drawImage(point, dataImage); painter.end(); imagePixmap = QPixmap::fromImage(paintImage); m_CompositedImage = paintImage; } else { m_CompositedImage = QImage(); imagePixmap = QPixmap::fromImage(dataImage); } m_CurrentGraphicsItem = m_GraphicsScene->addPixmap(imagePixmap); // Add the new image into the display m_CurrentGraphicsItem->setAcceptDrops(true); QRectF rect = m_CurrentGraphicsItem->boundingRect(); m_GraphicsScene->setSceneRect(rect); m_GraphicsView->setScene(m_GraphicsScene); m_GraphicsView->centerOn(m_CurrentGraphicsItem); if (updateGraphicsScene) { m_GraphicsScene->update(rect); } }
void Painter::paintImage(Image img, SDL_Point pos, Uint8 alpha) { SDL_Rect r; r.x = pos.x; r.y = pos.y; r.w = img.getSize().width; r.h = img.getSize().height; paintImage(img, r, alpha); }
void Painter::paintImage(Image img, int x, int y, Uint8 alpha) { SDL_Rect r; r.x = x; r.y = y; r.w = img.getSize().width; r.h = img.getSize().height; paintImage(img, r, alpha); }
bool Object::exportFrames( int frameStart, int frameEnd, Layer* currentLayer, QSize exportSize, QString filePath, const char* format, int quality, bool background, bool antialiasing, QProgressDialog* progress = NULL, int progressMax = 50 ) { QSettings settings( "Pencil", "Pencil" ); QString extension = ""; QString formatStr = format; if ( formatStr == "PNG" || formatStr == "png" ) { format = "PNG"; extension = ".png"; } if ( formatStr == "JPG" || formatStr == "jpg" || formatStr == "JPEG" || formatStr == "jpeg" ) { format = "JPG"; extension = ".jpg"; background = true; // JPG doesn't support transparency so we have to include the background } if ( filePath.endsWith( extension, Qt::CaseInsensitive ) ) { filePath.chop( extension.size() ); } //qDebug() << "format =" << format << "extension = " << extension; qDebug() << "Exporting frames from " << frameStart << "to" << frameEnd << "at size " << exportSize; for ( int currentFrame = frameStart; currentFrame <= frameEnd; currentFrame++ ) { if ( progress != NULL ) progress->setValue( ( currentFrame - frameStart )*progressMax / ( frameEnd - frameStart ) ); QImage tempImage( exportSize, QImage::Format_ARGB32_Premultiplied ); QPainter painter( &tempImage ); // Make sure that old frame is erased before exporting a new one tempImage.fill( 0x00000000 ); QRect viewRect = ( ( LayerCamera* )currentLayer )->getViewRect(); QTransform mapView = RectMapTransform( viewRect, QRectF( QPointF( 0, 0 ), exportSize ) ); mapView = ( ( LayerCamera* )currentLayer )->getViewAtFrame( currentFrame ) * mapView; painter.setWorldTransform( mapView ); paintImage( painter, currentFrame, background, antialiasing ); QString frameNumberString = QString::number( currentFrame ); while ( frameNumberString.length() < 4 ) { frameNumberString.prepend( "0" ); } tempImage.save( filePath + frameNumberString + extension, format, quality ); } return true; }
bool Object::exportFrames(int frameStart, int frameEnd, QMatrix view, Layer* currentLayer, QSize exportSize, QString filePath, const char* format, int quality, bool background, bool antialiasing, int gradients, QProgressDialog* progress=NULL, int progressMax=50) { QSettings settings("Pencil","Pencil"); qreal curveOpacity = (100-settings.value("curveOpacity").toInt())/100.0; // default value is 1.0 QString extension = ""; QString formatStr = format; if ( formatStr == "PNG" || formatStr == "png") { format = "PNG"; extension = ".png"; } if ( formatStr == "JPG" || formatStr == "jpg" || formatStr == "JPEG" || formatStr == "jpeg") { format = "JPG"; extension = ".jpg"; background = true; // JPG doesn't support transparency so we have to include the background } if (filePath.endsWith(extension, Qt::CaseInsensitive)) { filePath.chop(extension.size()); } //qDebug() << "format =" << format << "extension = " << extension; qDebug() << "Exporting frames from " << frameStart << "to" << frameEnd << "at size " << exportSize; for(int currentFrame = frameStart; currentFrame <= frameEnd ; currentFrame++) { if ( progress != NULL ) progress->setValue((currentFrame-frameStart)*progressMax/(frameEnd-frameStart)); QImage tempImage(exportSize, QImage::Format_ARGB32_Premultiplied); QPainter painter(&tempImage); // Make sure that old frame is erased before exporting a new one tempImage.fill(0x00000000); if (currentLayer->type == Layer::CAMERA) { QRect viewRect = ((LayerCamera*)currentLayer)->getViewRect(); QMatrix mapView = Editor::map( viewRect, QRectF(QPointF(0,0), exportSize) ); mapView = ((LayerCamera*)currentLayer)->getViewAtFrame(currentFrame) * mapView; painter.setWorldMatrix(mapView); } else { painter.setWorldMatrix(view); } paintImage(painter, currentFrame, background, curveOpacity, antialiasing, gradients); QString frameNumberString = QString::number(currentFrame); while ( frameNumberString.length() < 4) frameNumberString.prepend("0"); tempImage.save(filePath+frameNumberString+extension, format, quality); } // XXX no error handling done yet return true; }
bool Object::exportIm( int frameStart, int frameEnd, QTransform view, QSize exportSize, QString filePath, bool antialiasing ) { Q_UNUSED( frameEnd ); QImage exported( exportSize, QImage::Format_ARGB32_Premultiplied ); QPainter painter( &exported ); painter.fillRect( exported.rect(), Qt::white ); painter.setWorldTransform( view ); paintImage( painter, frameStart, false, antialiasing ); return exported.save( filePath ); }
bool Object::exportIm(int frameStart, int frameEnd, QMatrix view, QSize exportSize, QString filePath, bool antialiasing, int gradients) { Q_UNUSED(frameEnd); QSettings settings("Pencil","Pencil"); qreal curveOpacity = (100-settings.value("curveOpacity").toInt())/100.0; // default value is 1.0 QImage exported(exportSize, QImage::Format_ARGB32_Premultiplied); QPainter painter(&exported); painter.fillRect(exported.rect(), Qt::white); painter.setWorldMatrix(view); paintImage(painter, frameStart, false, curveOpacity, antialiasing, gradients); return exported.save(filePath); }
Astar::Astar(Node startingNode, Node goalNode, std::set<Node> obstacles) { pathFound = false; this->obstacles = obstacles; this->goalNode = goalNode; this->goalNode.setPaint(GOAL); this->startingNode = startingNode; this->startingNode.setPaint(START); startingNode.setCostSoFar(0); openList.insert(startingNode); execute(); setPath(); paintImage(); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void AIMImageGraphicsDelegate::updateGraphicsScene(bool update) { if (this->m_CachedImage.isNull() == true) { return; } if (NULL != m_CurrentGraphicsItem) { m_GraphicsScene->removeItem(m_CurrentGraphicsItem); //Remove the image that is displaying m_CurrentGraphicsItem->setParentItem(NULL); // Set the parent to NULL delete m_CurrentGraphicsItem; // Delete the object } QImage dataImage = _scaleImage(); QPixmap imagePixmap; if (m_CompositeImages == true && m_OverlayImage.isNull() == false) { QImage topImage = _scaleImage(m_OverlayImage); QPainter painter; QImage paintImage(dataImage.size(), QImage::Format_ARGB32_Premultiplied); QPoint point(0, 0); painter.begin(&paintImage); // Draw the fixed Image first painter.setPen(Qt::NoPen); painter.drawImage(point, topImage ); // Draw the moving image next painter.setCompositionMode(m_composition_mode); painter.drawImage(point, dataImage); painter.end(); imagePixmap = QPixmap::fromImage(paintImage); } else { imagePixmap = QPixmap::fromImage(dataImage); } m_CurrentGraphicsItem = m_GraphicsScene->addPixmap(imagePixmap); // Add the new image into the display QRectF rect = m_CurrentGraphicsItem->boundingRect(); m_GraphicsScene->setSceneRect(rect); m_GraphicsView->setScene(m_GraphicsScene); m_GraphicsView->centerOn(m_CurrentGraphicsItem); if (update) { m_GraphicsScene->update(rect); } }
bool Object::exportX( int frameStart, int frameEnd, QTransform view, QSize exportSize, QString filePath, bool antialiasing ) { QSettings settings( "Pencil", "Pencil" ); int page; page = 0; for ( int j = frameStart; j <= frameEnd; j = j + 15 ) { QImage xImg( QSize( 2300, 3400 ), QImage::Format_ARGB32_Premultiplied ); QPainter xPainter( &xImg ); xPainter.fillRect( 0, 0, 2300, 3400, Qt::white ); int y = j - 1; for ( int i = j; i < 15 + page * 15 && i <= frameEnd; i++ ) { QRect source = QRect( QPoint( 0, 0 ), exportSize ); QRect target = QRect( QPoint( ( y % 3 ) * 800 + 30, ( y / 3 ) * 680 + 50 - page * 3400 ), QSize( 640, 480 ) ); QTransform thumbView = view * RectMapTransform( source, target ); xPainter.setWorldTransform( thumbView ); xPainter.setClipRegion( thumbView.inverted().map( QRegion( target ) ) ); paintImage( xPainter, i, false, antialiasing ); xPainter.resetMatrix(); xPainter.setClipping( false ); xPainter.setPen( Qt::black ); xPainter.setFont( QFont( "helvetica", 50 ) ); xPainter.drawRect( target ); xPainter.drawText( QPoint( ( y % 3 ) * 800 + 35, ( y / 3 ) * 680 + 65 - page * 3400 ), QString::number( i ) ); y++; } if ( filePath.endsWith( ".jpg", Qt::CaseInsensitive ) ) { filePath.chop( 4 ); } if ( !xImg.save( filePath + QString::number( page ) + ".jpg", "JPG", 60 ) ) { return false; } page++; } return true; }
int expQt::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: on_maxSlider_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: on_minSlider_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: on_ROISlider_valueChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: on_Up_Clicked(); break; case 4: on_Down_Clicked(); break; case 5: on_Left_Clicked(); break; case 6: on_Right_Clicked(); break; case 7: on_Water_Clicked(); break; case 8: on_Point_Clicked(); break; case 9: paintImage((*reinterpret_cast< RGBDImage*(*)>(_a[1]))); break; default: ; } _id -= 10; } return _id; }
void ImageWidget::paint(QPainter& painter) { SYNC_WITH(imageView.console); const DebugImage* image = nullptr; RobotConsole::Images& currentImages = imageView.upperCam ? imageView.console.upperCamImages : imageView.console.lowerCamImages; RobotConsole::Images::const_iterator i = currentImages.find(imageView.background); if(i != currentImages.end()) { image = i->second.image; imageWidth = image->getImageWidth(); imageHeight = image->height; } else if(!currentImages.empty()) { imageWidth = currentImages.begin()->second.image->getImageWidth(); imageHeight = currentImages.begin()->second.image->height; } const QSize& size = painter.window().size(); float xScale = float(size.width()) / float(imageWidth); float yScale = float(size.height()) / float(imageHeight); scale = xScale < yScale ? xScale : yScale; scale *= zoom; float imageXOffset = (float(size.width()) - float(imageWidth) * scale) * 0.5f + float(offset.x()) * scale; float imageYOffset = (float(size.height()) - float(imageHeight) * scale) * 0.5f + float(offset.y()) * scale; painter.setTransform(QTransform(scale, 0, 0, scale, imageXOffset, imageYOffset)); if(image) paintImage(painter, *image); else lastImageTimeStamp = 0; paintDrawings(painter); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QImage PoleFigureMaker::generatePoleFigureImage(const PoleFigureData& config) { int imageWidth = config.imageSize[0]; int imageHeight = config.imageSize[1]; QImage image(imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied); QVector<float> xPoints = config.xData; QVector<float> yPoints = config.yData; int size = yPoints.size(); QColor white(255, 255, 255, 255); QColor black(0.25 * 255, 0.2549 * 255, 0.7961 * 255, 255); image.fill(white.rgba()); // Fill all white QRgb black_Rgba = black.rgba(); // Flip the pixels to black that came from the data xy coords for (int i = 0; i < size; ++i) { // float xp = xPoints[i]; // float yp = yPoints[i]; int xCoord = (xPoints[i] + 1) * imageWidth / 2; int yCoord = (yPoints[i] + 1) * imageHeight / 2; if (xCoord > imageWidth || yCoord > imageHeight) { qDebug() << "This is bad" << "\n"; } image.setPixel(xCoord, yCoord, black_Rgba); } // Flip the image so the (-1, -1) is in the lower left image = image.mirrored(true, false); return paintImage(config.imageSize[0], config.imageSize[1], config.label, image); }
void ViewportView::drawBackground(QPainter* painter, const QRectF& rect) { QGraphicsView::drawBackground(painter, rect); painter->beginNativePainting(); if (!gl_initialized) { initializeOpenGLFunctions(); gl_initialized = true; } glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Get bounds from all child images float zmin = INFINITY; float zmax = -INFINITY; auto m = getMatrix(); emit(getDepth(m, &zmin, &zmax)); // Paint all images emit(paintImage(m, zmin, zmax)); painter->endNativePainting(); }
TEST_C(NodeRemovalTest, treeIsUpdated) { auto levelHeights = makeLevelHeights({ 0, 1, 2, 3 }); DummyMinMaxTreeImageType image(2, 2); paintImage(image); assignPixelsToLatestNodes(image); auto& node = image.getPixelNode(0, 1); image.removeNode(node); verifyNode(image.getPixelNode(0, 0), levelHeights[0], 0u); verifyNode(image.getPixelNode(1, 0), levelHeights[1], 0u, levelHeights[0], 0u); verifyNode(image.getPixelNode(0, 1), levelHeights[1], 0u, levelHeights[0], 0u); verifyNode(image.getPixelNode(1, 1), levelHeights[3], 0u, levelHeights[1], 0u, levelHeights[0], 0u); }
void QGeomWidget::paintEvent ( QPaintEvent* /*event*/ ) { if( m_ViewerCore->hasImage() ) { m_Painter->begin( this ); switch( m_InterpolationType ) { case nn: m_Painter->setRenderHint( QPainter::NonCosmeticDefaultPen, true ); break; case lin: m_Painter->setRenderHint( QPainter::SmoothPixmapTransform, true ); break; } m_Painter->resetTransform(); if( m_ViewerCore->getSettings()->getPropertyAs<bool>( "latchSingleImage" ) ) { m_LatchOrientation = getWidgetEnsemble()->getImageVector().size() == 1; } else { m_LatchOrientation = false; } //bounding box calculation m_BoundingBox = _internal::getPhysicalBoundingBox( getWidgetEnsemble()->getImageVector(), m_PlaneOrientation ); _internal::zoomBoundingBox( m_BoundingBox, m_Translation, m_ViewerCore->getCurrentImage()->getImageProperties().physicalCoords, m_Zoom, m_PlaneOrientation, ( m_RightMouseButtonPressed && !m_LeftMouseButtonPressed ) || m_ZoomEvent || ( !m_RightMouseButtonPressed && !m_LeftMouseButtonPressed ) ); if( m_Zoom > 1 ) { m_BoundingBox[0] -= m_Translation[0]; m_BoundingBox[1] -= m_Translation[1]; } m_ZoomEvent = false; updateViewPort(); m_Painter->setWindow( m_BoundingBox[0], m_BoundingBox[1], m_BoundingBox[2], m_BoundingBox[3] ); m_Painter->setViewport( m_ViewPort[0], m_ViewPort[1], m_ViewPort[2], m_ViewPort[3] ); BOOST_FOREACH( ImageHolder::Vector::const_reference image, getWidgetEnsemble()->getImageVector() ) { if( image->getImageProperties().isVisible && image->getImageProperties().opacity != 0 ) { paintImage( image ); } } if( m_ViewerCore->hasImage() && m_ShowCrosshair ) { paintCrossHair(); } if( m_ShowLabels ) { paintLabels(); } if( m_ShowScalingOffset ) { m_Painter->resetMatrix(); m_Painter->setFont( QFont( "Chicago", 10 ) ); m_Painter->setPen( Qt::red ); std::stringstream scalingOffset; const ImageHolder::Pointer image = getWidgetEnsemble()->getImageVector().back(); scalingOffset << "Scaling: " << image->getImageProperties().scaling << " Offset: " << image->getImageProperties().offset; m_Painter->drawText( 10, 30, scalingOffset.str().c_str() ); } m_ShowScalingOffset = false; m_Painter->end(); }
bool Object::exportFrames1( ExportFrames1Parameters par ) { int frameStart = par.frameStart; int frameEnd = par.frameEnd; QTransform view = par.view; Layer* currentLayer = par.currentLayer; QSize exportSize = par.exportSize; QString filePath = par.filePath; const char* format = par.format; int quality = par.quality; bool background = par.background; bool antialiasing = par.antialiasing; QProgressDialog* progress = par.progress; int progressMax = par.progressMax; int fps = par.fps; int exportFps = par.exportFps; int frameRepeat; int frameReminder, frameReminder1; int framePutEvery, framePutEvery1; int frameSkipEvery, frameSkipEvery1; int frameNumber; int framePerSecond; QSettings settings( "Pencil", "Pencil" ); QString extension = ""; QString formatStr = format; if ( formatStr == "PNG" || formatStr == "png" ) { format = "PNG"; extension = ".png"; } if ( formatStr == "JPG" || formatStr == "jpg" || formatStr == "JPEG" ) { format = "JPG"; extension = ".jpg"; background = true; // JPG doesn't support transparency so we have to include the background } if ( filePath.endsWith( extension, Qt::CaseInsensitive ) ) { filePath.chop( extension.size() ); } //qDebug() << "format =" << format << "extension = " << extension; qDebug() << "Exporting frames from " << frameStart << "to" << frameEnd << "at size " << exportSize; convertNFrames( fps, exportFps, &frameRepeat, &frameReminder, &framePutEvery, &frameSkipEvery ); qDebug() << "fps " << fps << " exportFps " << exportFps << " frameRepeat " << frameRepeat << " frameReminder " << frameReminder << " framePutEvery " << framePutEvery << " frameSkipEvery " << frameSkipEvery; frameNumber = 0; framePerSecond = 0; frameReminder1 = frameReminder; framePutEvery1 = framePutEvery; frameSkipEvery1 = frameSkipEvery; for ( int currentFrame = frameStart; currentFrame <= frameEnd; currentFrame++ ) { if ( progress != NULL ) progress->setValue( ( currentFrame - frameStart )*progressMax / ( frameEnd - frameStart ) ); QImage tempImage( exportSize, QImage::Format_ARGB32_Premultiplied ); QPainter painter( &tempImage ); // Make sure that old frame is erased before exporting a new one tempImage.fill( 0x00000000 ); if ( currentLayer->type() == Layer::CAMERA ) { QRect viewRect = ( ( LayerCamera* )currentLayer )->getViewRect(); QTransform mapView = RectMapTransform( viewRect, QRectF( QPointF( 0, 0 ), exportSize ) ); mapView = ( ( LayerCamera* )currentLayer )->getViewAtFrame( currentFrame ) * mapView; painter.setWorldTransform( mapView ); } else { painter.setTransform( view ); } paintImage( painter, currentFrame, background, antialiasing ); frameNumber++; framePerSecond++; QString frameNumberString = QString::number( frameNumber ); while ( frameNumberString.length() < 4 ) frameNumberString.prepend( "0" ); tempImage.save( filePath + frameNumberString + extension, format, quality ); int delta = 0; if ( framePutEvery ) { framePutEvery1--; qDebug() << "-->framePutEvery1" << framePutEvery1; if ( framePutEvery1 ) { delta = 0; } else { delta = 1; framePutEvery1 = framePutEvery; } } if ( frameSkipEvery ) { frameSkipEvery1--; qDebug() << "-->frameSkipEvery1" << frameSkipEvery1; if ( frameSkipEvery1 ) { delta = 1; } else { delta = 0; frameSkipEvery1 = frameSkipEvery; } } if ( frameReminder1 ) { frameReminder1 -= delta; } else { delta = 0; } for ( int i = 0; ( i < frameRepeat - 1 + delta ) && ( framePerSecond < exportFps ); i++ ) { frameNumber++; framePerSecond++; QString frameNumberLink = QString::number( frameNumber ); while ( frameNumberLink.length() < 4 ) frameNumberLink.prepend( "0" ); tempImage.save( filePath + frameNumberLink + extension, format, quality ); } if ( framePerSecond == exportFps ) { framePerSecond = 0; frameReminder1 = frameReminder; framePutEvery1 = framePutEvery; frameSkipEvery1 = frameSkipEvery; } } // XXX no error handling yet return true; }
void ShareableBitmap::paint(WebCore::GraphicsContext& context, float scaleFactor, const IntPoint& destination, const IntRect& source) { paintImage(context.platformContext(), makeCGImageCopy().get(), scaleFactor, destination, source); }
void MoveSinglePieceAnimation::paint() { paintImage(m_pos); }
bool Object::exportFrames1(int frameStart, int frameEnd, QMatrix view, Layer* currentLayer, QSize exportSize, QString filePath, const char* format, int quality, bool background, bool antialiasing, int gradients, QProgressDialog* progress, int progressMax, int fps, int exportFps) { int frameRepeat; int frameReminder, frameReminder1; int framePutEvery, framePutEvery1; int frameSkipEvery, frameSkipEvery1; int frameNumber; int framePerSecond; QSettings settings("Pencil","Pencil"); qreal curveOpacity = (100-settings.value("curveOpacity").toInt())/100.0; // default value is 1.0 QString extension = ""; QString formatStr = format; if ( formatStr == "PNG" || formatStr == "png") { format = "PNG"; extension = ".png"; } if ( formatStr == "JPG" || formatStr == "jpg" || formatStr == "JPEG") { format = "JPG"; extension = ".jpg"; background = true; // JPG doesn't support transparency so we have to include the background } if (filePath.endsWith(extension, Qt::CaseInsensitive)) { filePath.chop(extension.size()); } //qDebug() << "format =" << format << "extension = " << extension; qDebug() << "Exporting frames from " << frameStart << "to" << frameEnd << "at size " << exportSize; convertNFrames(fps,exportFps,&frameRepeat,&frameReminder,&framePutEvery,&frameSkipEvery); qDebug() << "fps " << fps << " exportFps " << exportFps << " frameRepeat " << frameRepeat << " frameReminder " << frameReminder << " framePutEvery " << framePutEvery << " frameSkipEvery " << frameSkipEvery; frameNumber = 0; framePerSecond = 0; frameReminder1 = frameReminder; framePutEvery1 = framePutEvery; frameSkipEvery1 = frameSkipEvery; for(int currentFrame = frameStart; currentFrame <= frameEnd ; currentFrame++) { if ( progress != NULL ) progress->setValue((currentFrame-frameStart)*progressMax/(frameEnd-frameStart)); QImage tempImage(exportSize, QImage::Format_ARGB32_Premultiplied); QPainter painter(&tempImage); // Make sure that old frame is erased before exporting a new one tempImage.fill(0x00000000); if (currentLayer->type == Layer::CAMERA) { QRect viewRect = ((LayerCamera*)currentLayer)->getViewRect(); QMatrix mapView = Editor::map( viewRect, QRectF(QPointF(0,0), exportSize) ); mapView = ((LayerCamera*)currentLayer)->getViewAtFrame(currentFrame) * mapView; painter.setWorldMatrix(mapView); } else { painter.setWorldMatrix(view); } paintImage(painter, currentFrame, background, curveOpacity, antialiasing, gradients); frameNumber++; framePerSecond++; QString frameNumberString = QString::number(frameNumber); while ( frameNumberString.length() < 4) frameNumberString.prepend("0"); tempImage.save(filePath+frameNumberString+extension, format, quality); int delta = 0; if (framePutEvery) { framePutEvery1--; if (framePutEvery1) {delta = 1;} else {framePutEvery1 = framePutEvery;} } if (frameSkipEvery) { frameSkipEvery1--; if (!frameSkipEvery1) {delta = 1;} else {frameSkipEvery1 = frameSkipEvery;} } if (frameReminder1) {frameReminder1 -= delta;} else {delta = 0;} for (int i=0; (i < frameRepeat-1+delta) && (framePerSecond < exportFps); i++) { frameNumber++; framePerSecond++; QString frameNumberLink = QString::number(frameNumber); while ( frameNumberLink.length() < 4) frameNumberLink.prepend("0"); // QFile::link(filePath+frameNumberString+extension, filePath+frameNumberLink+extension+".lnk"); tempImage.save(filePath+frameNumberLink+extension, format, quality); } if (framePerSecond == exportFps) { framePerSecond = 0; frameReminder1 = frameReminder; framePutEvery1 = framePutEvery; frameSkipEvery1 = frameSkipEvery; } } // XXX no error handling yet return true; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QImage PoleFigureMaker::generateColorPoleFigureImage(const PoleFigureData& config) { int kernelWidth = config.kernelRadius[0]; int kernelHeight = config.kernelRadius[1]; int imageWidth = config.imageSize[0]; int imageHeight = config.imageSize[1]; // qDebug() << "Size: " << size << "\n"; // Generate the Kernel Weights generateKernelWeigths(kernelWidth, kernelHeight); // Allocate an array to hold the image data and initialize it to all zeros QVector<qint32> data(imageWidth * imageHeight, 1); QVector<qint32> counts(imageWidth * imageHeight, 0); QVector<float> xPoints = config.xData; QVector<float> yPoints = config.yData; int size = yPoints.size(); // Find the max count qint32 max = -2147483646; qint32 min = 2147483647; // Loop over all the data and get the x,y coords (scaled) and turn on the data pixel // This discretizes the data onto the pixel grid for (int i = 0; i < size; ++i) { int xCoord = (xPoints[i] + 1) * imageWidth / 2; int yCoord = (yPoints[i] + 1) * imageHeight / 2; data[ yCoord * imageWidth + xCoord]++; if (data[ yCoord * imageWidth + xCoord] > max) { max = data[ yCoord * imageWidth + xCoord];} if (data[ yCoord * imageWidth + xCoord] < min) { min = data[ yCoord * imageWidth + xCoord];} } // qDebug() << "Max Data[]: " << max << "\n"; qint32 value = 0; for (int yCoord = 0; yCoord < imageHeight; ++yCoord) { for (int xCoord = 0; xCoord < imageWidth; ++xCoord) { value = countPixelNeighbors(imageWidth, imageHeight, xCoord, yCoord, data, counts, kernelWidth, kernelHeight); if (value > max) { max = value;} if (value < min) { min = value;} } } value = 0; for (int yCoord = 0; yCoord < imageHeight; ++yCoord) { for (int xCoord = 0; xCoord < imageWidth; ++xCoord) { value = countPixelNeighbors(imageWidth, imageHeight, xCoord, yCoord, data, counts, kernelWidth, kernelHeight, true); } } if (max < 14) { max = 14; } QImage image (imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied); image.fill(0); qint32 numColors = max + 1; QVector<QColor> colorTable(numColors); qint32 range = max - min; float r, g, b; for (int i = 0; i < numColors; i++) { int val = min + ((float)i / numColors) * range; getColorCorrespondingTovalue(val, r, g, b, max, min); colorTable[i] = QColor(r * 255, g * 255, b * 255, 255); } // Index 0 is all white which is every pixel outside of the ODF circle colorTable[0] = QColor(255, 255, 255, 255); for (int yCoord = 0; yCoord < imageHeight; ++yCoord) { for (int xCoord = 0; xCoord < imageWidth; ++xCoord) { quint32 colorIndex = counts[yCoord * imageWidth + xCoord]; image.setPixel(xCoord, yCoord, colorTable[colorIndex].rgba()); } } // Flip the image so the (-1, -1) is in the lower left image = image.mirrored(true, false); return paintImage(config.imageSize[0], config.imageSize[1], config.label, image); }
void QRWidget::setQRData(const QString& data) { this->data = data; paintImage(); }