Exemplo n.º 1
1
    public QImage resizeImage(QImage image, QSize newSize) {
      if (image.size() == newSize) return image;

      QImage newImage = new QImage(newSize, QImage.Format.Format_RGB32);
      newImage.fill(new QColor(Qt.GlobalColor.white).rgb());
      QPainter painter = new QPainter(newImage);
      painter.drawImage(new QPoint(0, 0), image);
      painter.end();

      return newImage;
    }
Exemplo n.º 2
0
  private static QImage warpImage(QImage src, int warp, int sign) {
    int w = src.width();
    int ppl = src.bytesPerLine() / 4;
    int srch = src.height();
    int desth = srch + warp;

    QImage dest = new QImage(w, desth, QImage.Format.Format_ARGB32_Premultiplied);
    dest.fill(0);

    QNativePointer sbits = src.bits();
    QNativePointer dbits = dest.bits();

    sbits.setVerificationEnabled(false);
    dbits.setVerificationEnabled(false);

    double r = w / 2.0;

    int extra_offset = sign >= 0 ? 0 : warp;

    for (int x = 0; x < w; ++x) {
      int oset = (int) (((Math.sqrt(Math.abs(r * r - (x - r) * (x - r)))) * sign / r) * warp);
      for (int y = 0; y < srch; ++y) {
        int p = sbits.intAt(y * ppl + x);
        dbits.setIntAt(((y + oset + extra_offset) * ppl) + x, p);
      }
    }
    return dest;
  }
Exemplo n.º 3
0
  public SmokeEffect(int width, int height) {
    m_width = width;
    m_height = height;

    m_seeds = new int[16000];
    for (int i = 0; i < m_seeds.length; ++i) {
      double d = Math.random();
      m_seeds[i] = (int) (d * 255);
    }
    m_image = new QImage(width, height, QImage.Format.Format_ARGB32_Premultiplied);
    m_image.fill(0);

    m_data = new int[m_width * (m_height + 1)];
    seedLastRow();
  }
Exemplo n.º 4
0
  private static QImage composeCup(QImage bg_image, QImage fg_image, int size, int warp) {
    double coffey_alpha = 1;
    QColor dark_brown = QColor.fromRgbF(0.3, 0.15, 0, coffey_alpha);
    QColor light_brown = QColor.fromRgbF(0.66, 0.33, 0, coffey_alpha);
    QColor highlight = QColor.fromRgbF(1, 1, 0.8, coffey_alpha);
    QColor transparent = QColor.transparent;
    double highlight_pos = 0.4;
    double highlight_size = 0.05;

    QImage combined =
        new QImage(
            size + size / 2, size + warp * 2 + size / 8, QImage.Format.Format_ARGB32_Premultiplied);
    combined.fill(0);

    QPainter p = new QPainter();
    p.begin(combined);
    p.setRenderHint(QPainter.RenderHint.Antialiasing);
    p.setPen(Qt.PenStyle.NoPen);

    // draw the background
    p.drawImage(0, 0, bg_image);

    // Draw the coffey
    QRectF coffey_bounds = new QRectF(0, warp, size, 2 * warp);
    QConicalGradient cg =
        new QConicalGradient(
            coffey_bounds.width() * GOLDEN_MEAN + warp * 0.1,
            warp * 1.2 + coffey_bounds.height() / 2.0,
            -30);
    cg.setColorAt(0, dark_brown);
    cg.setColorAt(highlight_pos - highlight_size, light_brown);
    cg.setColorAt(0.4, highlight);
    cg.setColorAt(highlight_pos + highlight_size, light_brown);
    cg.setColorAt(1, dark_brown);
    p.setPen(new QPen(new QBrush(QColor.black), size * 0.01));
    p.setBrush(new QBrush(cg));
    p.drawEllipse(coffey_bounds);

    // draw the foreground
    p.drawImage(0, warp, fg_image);

    // Draw the handle
    double handle_dim = size * 0.8;
    QRectF handle_bounds = new QRectF(size - handle_dim / 2, size / 3, handle_dim, handle_dim);
    double hcx = handle_bounds.width() / 2;
    double hcy = handle_bounds.height() / 2;
    QImage handle_im =
        new QImage(handle_bounds.size().toSize(), QImage.Format.Format_ARGB32_Premultiplied);
    {
      handle_im.fill(0);
      QPainter ph = new QPainter();
      ph.begin(handle_im);
      QRadialGradient rg = new QRadialGradient(hcx, hcy, hcx, hcx, hcy + size / 30);
      double ir = 0.5;
      double or = 0.9;
      double aa = 0.02;
      double shade = 0.08;
      rg.setColorAt(ir - aa, transparent);
      rg.setColorAt(ir, QColor.fromRgbF(0, 0, 0, 1));
      rg.setColorAt(ir + shade, color_green);
      rg.setColorAt((ir + or) / 2, QColor.fromRgbF(0.8, 0.85, 0.6));
      rg.setColorAt(or - shade, color_green);
      rg.setColorAt(or, QColor.fromRgbF(0, 0, 0, 1));
      rg.setColorAt(or + aa, transparent);
      ph.setBrush(new QBrush(rg));
      ph.setPen(Qt.PenStyle.NoPen);
      ph.drawEllipse(0, 0, (int) handle_bounds.width(), (int) handle_bounds.height());

      QLinearGradient lg = new QLinearGradient(0, 0, handle_bounds.width(), 0);
      lg.setColorAt(0.42, transparent);
      lg.setColorAt(0.47, QColor.fromRgbF(0, 0, 0));
      ph.setBrush(new QBrush(lg));
      ph.setCompositionMode(QPainter.CompositionMode.CompositionMode_DestinationIn);
      ph.drawRect(0, 0, (int) handle_bounds.width(), (int) handle_bounds.height());
      ph.end();
    }
    p.drawImage(handle_bounds.topLeft(), handle_im);

    // The drop shadow...
    QRadialGradient dsg = new QRadialGradient(0, 0, 0.5, 0, 0);
    dsg.setColorAt(0, QColor.fromRgbF(0, 0, 0, .75));
    dsg.setColorAt(1, transparent);
    p.translate(size * 3 / 4, size + warp * 1.4);
    p.scale(size * 1.5, size / 2);
    p.setBrush(new QBrush(dsg));
    p.setPen(Qt.PenStyle.NoPen);
    p.setCompositionMode(QPainter.CompositionMode.CompositionMode_DestinationOver);
    p.drawEllipse(new QRectF(-0.5, -0.5, 1, 1));
    //      p.drawEllipse(new QRectF(size - size / 2, size + warp - size / 2, size, size));

    p.end();

    return combined;
  }
Exemplo n.º 5
0
 public void clearImage() {
   image.fill(new QColor(Qt.GlobalColor.white).rgb());
   modified = true;
   update();
 }