Esempio n. 1
0
void SkBaseDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitmap,
                                        int x, int y,
                                        const SkPaint& paint) {
    SkImageFilter* filter = paint.getImageFilter();
    SkASSERT(filter);

    SkIPoint offset = SkIPoint::Make(0, 0);
    SkMatrix matrix = *draw.fMatrix;
    matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
    const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y);
    SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
    SkImageFilter::Context ctx(matrix, clipBounds, cache.get());

    sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(bitmap, &this->surfaceProps()));
    if (!srcImg) {
        return; // something disastrous happened
    }

    sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset));
    if (resultImg) {
        SkPaint tmpUnfiltered(paint);
        tmpUnfiltered.setImageFilter(nullptr);
        SkBitmap resultBM;
        if (resultImg->internal_getBM(&resultBM)) {
            // TODO: add drawSprite(SkSpecialImage) to SkDevice? (see skbug.com/5073)
            this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered);
        }
    }
}
Esempio n. 2
0
void SkBitmapDevice::drawSpecial(const SkDraw& draw, SkSpecialImage* srcImg, int x, int y,
                                 const SkPaint& paint) {
    SkASSERT(!srcImg->isTextureBacked());

    SkBitmap resultBM;

    SkImageFilter* filter = paint.getImageFilter();
    if (filter) {
        SkIPoint offset = SkIPoint::Make(0, 0);
        SkMatrix matrix = *draw.fMatrix;
        matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
        const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y);
        SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
        SkImageFilter::OutputProperties outputProperties(fBitmap.colorSpace());
        SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), outputProperties);
        
        sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
        if (resultImg) {
            SkPaint tmpUnfiltered(paint);
            tmpUnfiltered.setImageFilter(nullptr);
            if (resultImg->getROPixels(&resultBM)) {
                this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered);
            }
        }
    } else {
        if (srcImg->getROPixels(&resultBM)) {
            this->drawSprite(draw, resultBM, x, y, paint);
        }
    }
}
Esempio n. 3
0
void
ImageSearch::generateResults(const std::string& resultImageFile) {
    PNG resultImg(mainImage);
    PNGHelper resultHelper(resultImg);
    for(size_t i = 0; (i < mrl.size()); i++) {
	drawRedBox(resultHelper, mrl[i]);
    }
    resultImg.write(resultImageFile);
    std::cout << mrl << "Number of matches: " << mrl.size() << std::endl;
}
Esempio n. 4
0
void ImageOperations::colorCanny( const OpRGBImage& img,
                                  OpGrayImage& imgRet,
                                  float dThreshLow, float dThreshHigh,
                                  float dSigma )
{
  //printf("ImageOperations::colorCanny() ...\n");
  QImage qimg = img.getQtImage();

  int w = qimg.width();
  int h = qimg.height();

  //- create a YCC color-opponent image from the input image -//
  OpGrayImage imgY ( w, h );
  OpGrayImage imgC1( w, h );
  OpGrayImage imgC2( w, h );

  for (int y=0; y < h; y++)
  {
    for (int x=0; x < w; x++)
    {
      // img is the original QImage //
      uint *p = (uint *) qimg.scanLine(y) + x;

      //-- convert rgb to YCC --//
      imgY(x,y)  = (1.0/3.0)*(qRed(*p) + qGreen(*p) + qBlue(*p));
      imgC1(x,y) = 2.0*(0.5*qRed(*p) - 0.5*qGreen(*p));
      imgC2(x,y) = 2.0*(0.5*qRed(*p) + 0.5*qGreen(*p) - qBlue(*p));
    }
  }
  //-- apply the filter --//
  OpGrayImage imgDx( w, h );
  OpGrayImage imgDy( w, h );

  //-- fast gauss --//
  OpGrayImage imgYDx( w, h );
  OpGrayImage imgYDy( w, h );
  imgY.opFastGaussDxDy( dSigma, imgYDx, imgYDy );

  OpGrayImage imgC1Dx( w, h );
  OpGrayImage imgC1Dy( w, h );
  imgC1.opFastGaussDxDy( dSigma, imgC1Dx, imgC1Dy );

  OpGrayImage imgC2Dx( w, h );
  OpGrayImage imgC2Dy( w, h );
  imgC2.opFastGaussDxDy( dSigma, imgC2Dx, imgC2Dy );

  for (int y=0; y < h; y++)
  {
    for (int x=0; x < w; x++)
    {
      imgDx(x,y) = sqrt( imgYDx(x,y).value()*imgYDx(x,y).value() +
                         imgC1Dx(x,y).value()*imgC1Dx(x,y).value() +
                         imgC2Dx(x,y).value()*imgC2Dx(x,y).value() );
      imgDy(x,y) = sqrt( imgYDy(x,y).value()*imgYDy(x,y).value() +
                         imgC1Dy(x,y).value()*imgC1Dy(x,y).value() +
                         imgC2Dy(x,y).value()*imgC2Dy(x,y).value() );
    }
  }
  /*
  //-- slow gauss --//    
  OpGrayImage imgYDx  = imgY.opGaussDerivGx( m_dSigma );
  OpGrayImage imgYDy  = imgY.opGaussDerivGy( m_dSigma );
  OpGrayImage imgC1Dx = imgC1.opGaussDerivGx( m_dSigma );
  OpGrayImage imgC1Dy = imgC1.opGaussDerivGy( m_dSigma );
  OpGrayImage imgC2Dx = imgC2.opGaussDerivGx( m_dSigma );
  OpGrayImage imgC2Dy = imgC2.opGaussDerivGy( m_dSigma );

  for (int y=0; y < m_img.height(); y++)
  for (int x=0; x < m_img.width(); x++)
  {
  imgDx(x,y) = sqrt( imgYDx(x,y).value()*imgYDx(x,y).value() +
  imgC1Dx(x,y).value()*imgC1Dx(x,y).value() +
  imgC2Dx(x,y).value()*imgC2Dx(x,y).value() );
  imgDy(x,y) = sqrt( imgYDy(x,y).value()*imgYDy(x,y).value() +
  imgC1Dy(x,y).value()*imgC1Dy(x,y).value() +
  imgC2Dy(x,y).value()*imgC2Dy(x,y).value() );
  }
  */

  //-- apply the Canny operator --//
  OpGrayImage resultImg( w, h );
  imgRet = resultImg;
  imgRet = cannyEdgesDxDy( imgDx, imgDy, dThreshLow, dThreshHigh );
}
Esempio n. 5
0
void MainWindow::Private::captureFleetDetail()
{
    qDebug() << "captureFleetDetail";

    //設定確認
    checkSavePath();

    QRect captureRect = DETAIL_RECT_CAPTURE;
    QImage resultImg(captureRect.width() * 2
                     , captureRect.height() * 3
                     ,QImage::Format_ARGB32);
    resultImg.fill(Qt::transparent);
    QPainter painter(&resultImg);

    GameScreen gameScreen(ui.webView->capture());
    if (!gameScreen.isVisible(GameScreen::Ship1Part))
    {
        ui.statusBar->showMessage(tr("not in organization"), STATUS_BAR_MSG_TIME);
        return;
    }

    //開始確認
    QMessageBox::StandardButton res = QMessageBox::warning(q
                                                           , tr("Kan Memo")
                                                           , tr("Capture the fleet ditail.\nPlease wait while a cup of coffee.")
                                                           , QMessageBox::Yes | QMessageBox::Cancel);
    if(res == QMessageBox::Cancel)
        return;

    //メニュー無効
    ui.menuBar->setEnabled(false);
    ui.toolBar->setEnabled(false);

    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui.statusBar->showMessage(tr("making fleet detail"), -1);
    ui.progressBar->show();
    ui.progressBar->setValue(0);
    for (int i = 0; i < 6; i++) {
        if (!gameScreen.isVisible(static_cast<GameScreen::PartType>(GameScreen::Ship1Part + i))) break;
        gameScreen.click(ui.webView, static_cast<GameScreen::PartType>(GameScreen::Ship1Part + i), GameScreen::WaitLonger);

        QImage tmpImg = ui.webView->capture().copy(captureRect);
        painter.drawImage(captureRect.width() * (i % 2)
                          , captureRect.height() * (i / 2)
                          , tmpImg);
        ui.progressBar->setValue((i + 1) * 100 / 6);
        gameScreen.click(ui.webView, GameScreen::Ship1Part);
    }
    ui.progressBar->hide();
    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, false);
    ui.statusBar->clearMessage();

    char format[] = "jpg";
    QString path = makeFileName(QString(format));
    qDebug() << "path:" << path;

    //保存する
    ui.statusBar->showMessage(tr("saving to %1...").arg(path), STATUS_BAR_MSG_TIME);
    if(resultImg.save(path, format))
    {
        //つぶやくダイアログ
        openTweetDialog(path);
    }else{
        ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME);
    }

    //メニュー復活
    ui.menuBar->setEnabled(true);
    ui.toolBar->setEnabled(true);
}
Esempio n. 6
0
void MainWindow::Private::captureCatalog()
{
    qDebug() << "captureCatalog";

    //設定確認
    checkSavePath();

    QRect captureRect = CATALOG_RECT_CAPTURE;
    QList<QRect> shipRectList;
    {
        shipRectList << CATALOG_RECT_SHIP1
                     << CATALOG_RECT_SHIP2
                     << CATALOG_RECT_SHIP3;
    }
    QList<QRect> pageRectList;
    {
        pageRectList << CATALOG_RECT_PAGE1
                     << CATALOG_RECT_PAGE2
                     << CATALOG_RECT_PAGE3
                     << CATALOG_RECT_PAGE4
                     << CATALOG_RECT_PAGE5;
    }

    QImage resultImg(captureRect.width() * shipRectList.size()
                     , captureRect.height() * pageRectList.size()
                     ,QImage::Format_ARGB32);
    QPainter painter(&resultImg);

    QPoint currentPos = ui.webView->page()->mainFrame()->scrollPosition();
    QRect geometry = ui.webView->getGameRect();

    if (GameScreen(ui.webView->capture()).screenType() != GameScreen::CatalogScreen)
    {
        ui.webView->page()->mainFrame()->setScrollPosition(currentPos);
        ui.statusBar->showMessage(tr("not in catalog"), STATUS_BAR_MSG_TIME);
        return;
    }

    //開始確認
    QMessageBox::StandardButton res = QMessageBox::warning(q
                                                           , tr("Kan Memo")
                                                           , tr("Capture the catalog.\nPlease wait while a cup of coffee.")
                                                           , QMessageBox::Yes | QMessageBox::Cancel);
    if(res == QMessageBox::Cancel)
        return;

    //メニュー無効
    ui.menuBar->setEnabled(false);
    ui.toolBar->setEnabled(false);

    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui.statusBar->showMessage(tr("making catalog"), -1);
    ui.progressBar->show();
    ui.progressBar->setValue(0);
    for (int type = 0; type < shipRectList.size(); type++)
    {
        int tx = geometry.x()
                + (shipRectList.value(type).x() + qrand() % shipRectList.value(type).width());
        int ty = geometry.y()
                + (shipRectList.value(type).y() + qrand() % shipRectList.value(type).height());
        clickGame(QPoint(tx, ty));

        for (int page = 0; page < pageRectList.size(); page++)
        {
            int px = geometry.x()
                    + (pageRectList.value(page).x() + qrand() % pageRectList.value(page).width());
            int py = geometry.y()
                    + (pageRectList.value(page).y() + qrand() % pageRectList.value(page).height());
            clickGame(QPoint(px, py));

            QImage details = ui.webView->capture().copy(captureRect);
            painter.drawImage(captureRect.width() * type
                              , captureRect.height() * page
                              , details);

            ui.progressBar->setValue((pageRectList.size() * type + (page + 1)) * 100
                                     / (pageRectList.size() * shipRectList.size()) );
        }
    }
    ui.progressBar->hide();
    ui.webView->page()->mainFrame()->setScrollPosition(currentPos);
    ui.webView->setAttribute(Qt::WA_TransparentForMouseEvents, false);
    ui.statusBar->showMessage("", -1);

    char format[] = "jpg";
    QString path = makeFileName(QString(format));
    qDebug() << "path:" << path;

    //保存する
    ui.statusBar->showMessage(tr("saving to %1...").arg(path), STATUS_BAR_MSG_TIME);
    if(resultImg.save(path, format))
    {
        //つぶやくダイアログ
        openTweetDialog(path);
    }else{
        ui.statusBar->showMessage(tr("failed save image"), STATUS_BAR_MSG_TIME);
    }

    //メニュー復活
    ui.menuBar->setEnabled(true);
    ui.toolBar->setEnabled(true);
}