コード例 #1
2
    public boolean saveImage(String fileName, String fileFormat) {
      QImage visibleImage = image;
      visibleImage = resizeImage(visibleImage, size());

      if (visibleImage.save(fileName, fileFormat)) {
        modified = false;
        return true;
      } else {
        return false;
      }
    }
コード例 #2
1
ファイル: Icons.java プロジェクト: perok/it1901_sheep
  private void changeIcon() {
    QIcon icon = new QIcon();

    for (int row = 0; row < imagesTable.rowCount(); ++row) {
      QTableWidgetItem item0 = imagesTable.item(row, 0);
      QTableWidgetItem item1 = imagesTable.item(row, 1);
      QTableWidgetItem item2 = imagesTable.item(row, 2);

      if (item0.checkState() == Qt.CheckState.Checked) {
        QIcon.Mode mode;
        if (item1.text().equals(tr("Normal"))) {
          mode = QIcon.Mode.Normal;
        } else if (item1.text().equals(tr("Active"))) {
          mode = QIcon.Mode.Active;
        } else if (item1.text().equals(tr("Disabled"))) {
          mode = QIcon.Mode.Disabled;
        } else {
          mode = QIcon.Mode.Selected;
        }

        QIcon.State state;
        if (item2.text().equals(tr("On"))) {
          state = QIcon.State.On;
        } else {
          state = QIcon.State.Off;
        }

        String fileName = (String) item0.data(Qt.ItemDataRole.UserRole);
        QImage image = new QImage(fileName);
        if (!image.isNull()) icon.addPixmap(QPixmap.fromImage(image), mode, state);
      }
    }

    previewArea.setIcon(icon);
  }
コード例 #3
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;
    }
コード例 #4
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  private static QImage makeShade(QImage image, boolean highlight, boolean darker) {
    double shade_alpha = 0.8;
    double shade_size = 0.2;
    double hl_pos = GOLDEN_MEAN;

    QColor shade_color = QColor.fromRgbF(0, 0, 0, shade_alpha);
    QColor transparent = darker ? QColor.fromRgbF(0, 0, 0, 0.25) : QColor.fromRgbF(0, 0, 0, 0);
    QColor hl_color = QColor.fromRgbF(1, 1, 1, 0.7);

    image = image.copy();
    QPainter p = new QPainter();
    p.begin(image);
    p.scale(image.width(), image.height());

    QLinearGradient lg = new QLinearGradient(0, 0, 1, 0);
    lg.setColorAt(0, shade_color);
    lg.setColorAt(shade_size, transparent);
    if (highlight) lg.setColorAt(hl_pos, hl_color);
    lg.setColorAt(1 - shade_size, transparent);
    lg.setColorAt(1, shade_color);
    p.fillRect(0, 0, 1, 1, new QBrush(lg));

    if (highlight) {
      QRadialGradient rg = new QRadialGradient(hl_pos, 1 - hl_pos, 0.4, hl_pos, 1 - hl_pos);
      rg.setColorAt(0, hl_color);
      rg.setColorAt(1, transparent);
      p.fillRect(0, 0, 1, 1, new QBrush(rg));
    }

    p.end();

    return image;
  }
コード例 #5
0
 @Override
 protected void resizeEvent(QResizeEvent event) {
   if (width() > image.width() || height() > image.height()) {
     int newWidth = Math.max(width() + 128, image.width());
     int newHeight = Math.max(height() + 128, image.height());
     image = resizeImage(image, new QSize(newWidth, newHeight));
     update();
   }
   super.resizeEvent(event);
 }
コード例 #6
0
    public boolean openImage(String fileName) {
      QImage loadedImage = new QImage();
      if (!loadedImage.load(fileName)) return false;

      QSize newSize = loadedImage.size().expandedTo(size());
      loadedImage = resizeImage(loadedImage, newSize);
      image = loadedImage;
      modified = false;
      update();
      return true;
    }
コード例 #7
0
    public void print() {
      QPrinter printer = new QPrinter(QPrinter.PrinterMode.HighResolution);

      QPrintDialog printDialog = new QPrintDialog(printer, this);
      if (printDialog.exec() == QDialog.DialogCode.Accepted.value()) {
        QPainter painter = new QPainter(printer);
        QRect rect = painter.viewport();
        QSize size = image.size();
        size.scale(rect.size(), Qt.AspectRatioMode.KeepAspectRatio);
        painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
        painter.setWindow(image.rect());
        painter.drawImage(0, 0, image);
        painter.end();
      }
    }
コード例 #8
0
ファイル: ImagePage.java プロジェクト: rohans/tradeinbooks
  // is the file an image suitable for displaying within a web page?
  public boolean file_is_displayable_image(String path) {
    Array<Object> info = new Array<Object>();
    boolean result = false;
    info = QImage.getimagesize(gVars.webEnv, path);

    if (empty(info)) {
      result = false;
    } else if (!Array.in_array(
        info.getValue(2),
        new Array<Object>(
            new ArrayEntry<Object>(Image.IMAGETYPE_GIF),
            new ArrayEntry<Object>(Image.IMAGETYPE_JPEG),
            new ArrayEntry<Object>(Image.IMAGETYPE_PNG)))) {
      result = false;
    } else if ((intval(info.getValue("channels")) > 0) && !equal(info.getValue("channels"), 3)) {
      // only gif, jpeg and png images can reliably be displayed
      result = false;
    } else {
      // some web browsers can't display cmyk or grayscale jpegs
      result = true;
    }

    return booleanval(
        getIncluded(PluginPage.class, gVars, gConsts)
            .apply_filters("file_is_displayable_image", result, path));
  }
コード例 #9
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  public static QImage qoffeyLogo(int size) {
    int warp = size / 5;
    QImage bg_image = null, fg_image = null;
    {
      QImage image = qtLogoImage(size, size, false);
      QImage shade = makeShade(image, false, true);
      bg_image = warpImage(shade, warp, -1);
    }
    {
      QImage image = qtLogoImage(size, size, true);
      QImage shade = makeShade(image, true, false);
      fg_image = warpImage(shade, warp, 1);
    }

    QImage cup = composeCup(bg_image, fg_image, size, warp);
    return cup.scaledToWidth(size, Qt.TransformationMode.SmoothTransformation);
  }
コード例 #10
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  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;
  }
コード例 #11
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  public void next() {
    // blur
    for (int y = 1; y < m_height; ++y) {
      int oset = y * m_width;
      //      System.out.println("y:::");
      for (int x = 1; x < m_width - 1; ++x) {
        //      int dl = m_data[oset + m_width + x - 1];
        //      int dr = m_data[oset + m_width + x + 1];
        //      int d = m_data[oset + m_width + x];
        //          m_data[oset + x] = (int) ((dl + (d * 2) + dr) / (4 + 10.0 / m_width));
        //      m_data[oset + x] = (int) ((dl + du + dr + dd) / 4);
        m_data[oset + x] =
            (((m_data[oset + x + m_width] << 2)
                        + (m_data[oset + x] << 1)
                        + (m_data[oset + x + 1])
                        + (m_data[oset + x - 1]))
                    - 7)
                >> 3;
        if (m_data[oset + x] < 0) m_data[oset + x] = 0;
        //      System.out.print(" " + m_data[oset + x]);
      }
      //      System.out.println();
    }

    // seed the last row for the next step...
    seedLastRow();

    QNativePointer np = m_image.bits();
    np.setVerificationEnabled(false);
    int ppl = m_image.bytesPerLine() / 4;
    for (int y = 0; y < m_height; ++y) {
      int oset = ppl * y;
      for (int x = 0; x < m_width; ++x) {
        int val = m_data[oset + x];
        val = val * val / (255);
        int val_2 = 0;
        np.setIntAt(oset + x, (val << 24) | (val_2 << 16) | (val_2 << 8) | (val_2));
      }
    }
  }
コード例 #12
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  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();
  }
コード例 #13
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  @Override
  protected void paintEvent(QPaintEvent e) {
    m_smoke_effect.next();

    QPainter p = new QPainter();
    p.begin(this);
    p.fillRect(rect(), new QBrush(QColor.white));
    //  p.fillRect(rect(), new QBrush(Qt.CrossPattern));

    p.drawImage(50, 80, m_logo);

    p.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform);
    QImage im = m_smoke_effect.image();
    p.drawImage(
        new QRect(50, -20, im.width(), im.height()),
        im,
        new QRect(0, (int) (im.height() * 0.60), im.width(), (int) (im.height() * 0.39)));

    p.end();
  }
コード例 #14
0
ファイル: Image.java プロジェクト: palaniyappanBala/qtjambi
  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;
  }
コード例 #15
0
ファイル: ImagePage.java プロジェクト: rohans/tradeinbooks
  // is the file a real image file?
  public boolean file_is_valid_image(String path) {
    Array<Object> size = new Array<Object>();
    size = QImage.getimagesize(gVars.webEnv, path);

    return !empty(size);
  }
コード例 #16
0
ファイル: ImagePage.java プロジェクト: rohans/tradeinbooks
  // get extended image metadata, exif or iptc as available
  public Array<Object> wp_read_image_metadata(String file) {
    Array<Object> meta = new Array<Object>();
    Array<Object> info = new Array<Object>();
    Array<Object> iptc = new Array<Object>();
    Array<Object> exif = new Array<Object>();

    if (!FileSystemOrSocket.file_exists(gVars.webEnv, file)) {
      return new Array<Object>();
    }

    new ListAssigner<Object>() {
      public Array<Object> doAssign(Array<Object> srcArray) {
        if (strictEqual(srcArray, null)) {
          return null;
        }

        wp_read_image_metadata_sourceImageType = srcArray.getValue(2);

        return srcArray;
      }
    }.doAssign(QImage.getimagesize(gVars.webEnv, file));

    // exif contains a bunch of data we'll probably never need formatted in ways that are difficult
    // to use.
    // We'll normalize it and just extract the fields that are likely to be useful.  Fractions and
    // numbers
    // are converted to floats, dates to unix timestamps, and everything else to strings.
    meta =
        new Array<Object>(
            new ArrayEntry<Object>("aperture", 0),
            new ArrayEntry<Object>("credit", ""),
            new ArrayEntry<Object>("camera", ""),
            new ArrayEntry<Object>("caption", ""),
            new ArrayEntry<Object>("created_timestamp", 0),
            new ArrayEntry<Object>("copyright", ""),
            new ArrayEntry<Object>("focal_length", 0),
            new ArrayEntry<Object>("iso", 0),
            new ArrayEntry<Object>("shutter_speed", 0),
            new ArrayEntry<Object>("title", ""));

    // read iptc first, since it might contain data not available in exif such as caption,
    // description etc
    if (true) /*Modified by Numiton*/ {
      QImage.getimagesize(gVars.webEnv, file, info);

      if (!empty(info.getValue("APP13"))) {
        iptc = new Array<Object>();

        if (!empty(iptc.getArrayValue("2#110").getValue(0))) { // credit
          meta.putValue("credit", Strings.trim(strval(iptc.getArrayValue("2#110").getValue(0))));
        } else if (!empty(iptc.getArrayValue("2#080").getValue(0))) { // byline
          meta.putValue("credit", Strings.trim(strval(iptc.getArrayValue("2#080").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#055").getValue(0))
            && !empty(iptc.getArrayValue("2#060").getValue(0))) { // created datee and time
          meta.putValue(
              "created_timestamp",
              QDateTime.strtotime(
                  strval(iptc.getArrayValue("2#055").getValue(0))
                      + " "
                      + strval(iptc.getArrayValue("2#060").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#120").getValue(0))) { // caption
          meta.putValue("caption", Strings.trim(strval(iptc.getArrayValue("2#120").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#116").getValue(0))) { // copyright
          meta.putValue("copyright", Strings.trim(strval(iptc.getArrayValue("2#116").getValue(0))));
        }

        if (!empty(iptc.getArrayValue("2#005").getValue(0))) { // title
          meta.putValue("title", Strings.trim(strval(iptc.getArrayValue("2#005").getValue(0))));
        }
      }
    }

    // fetch additional info from exif if available
    if (false
        && /*Modified by Numiton*/ Array.in_array(
            wp_read_image_metadata_sourceImageType,
            (Array)
                getIncluded(PluginPage.class, gVars, gConsts)
                    .apply_filters(
                        "wp_read_image_metadata_types",
                        new Array<Object>(
                            new ArrayEntry<Object>(Image.IMAGETYPE_JPEG),
                            new ArrayEntry<Object>(Image.IMAGETYPE_TIFF_II),
                            new ArrayEntry<Object>(Image.IMAGETYPE_TIFF_MM))))) {
      exif = new Array<Object>();

      if (!empty(exif.getValue("FNumber"))) {
        meta.putValue(
            "aperture", Math.round(wp_exif_frac2dec(strval(exif.getValue("FNumber"))), 2));
      }

      if (!empty(exif.getValue("Model"))) {
        meta.putValue("camera", Strings.trim(strval(exif.getValue("Model"))));
      }

      if (!empty(exif.getValue("DateTimeDigitized"))) {
        meta.putValue(
            "created_timestamp", wp_exif_date2ts(strval(exif.getValue("DateTimeDigitized"))));
      }

      if (!empty(exif.getValue("FocalLength"))) {
        meta.putValue("focal_length", wp_exif_frac2dec(strval(exif.getValue("FocalLength"))));
      }

      if (!empty(exif.getValue("ISOSpeedRatings"))) {
        meta.putValue("iso", exif.getValue("ISOSpeedRatings"));
      }

      if (!empty(exif.getValue("ExposureTime"))) {
        meta.putValue("shutter_speed", wp_exif_frac2dec(strval(exif.getValue("ExposureTime"))));
      }
    }

    // FIXME: try other exif libraries if available

    return (Array<Object>)
        getIncluded(PluginPage.class, gVars, gConsts)
            .apply_filters(
                "wp_read_image_metadata", meta, file, wp_read_image_metadata_sourceImageType);
  }
コード例 #17
0
ファイル: ImagePage.java プロジェクト: rohans/tradeinbooks
  /**
   * wp_generate_attachment_metadata() - Generate post Image attachment Metadata
   *
   * @package WordPress
   * @internal Missing Long Description
   * @param int $attachment_id Attachment Id to process
   * @param string $file Filepath of the Attached image
   * @return mixed Metadata for attachment
   */
  public Object wp_generate_attachment_metadata(int attachment_id, String file) {
    StdClass attachment = null;
    Array<Object> metadata = new Array<Object>();
    Array<Object> imagesize = new Array<Object>();
    Array<Object> sizes = new Array<Object>();
    Array<Object> resized = new Array<Object>();
    Object size = null;
    Array<Object> image_meta;
    attachment =
        (StdClass)
            getIncluded(PostPage.class, gVars, gConsts)
                .get_post(attachment_id, gConsts.getOBJECT(), "raw");
    metadata = new Array<Object>();

    if (QRegExPerl.preg_match(
            "!^image/!", getIncluded(PostPage.class, gVars, gConsts).get_post_mime_type(attachment))
        && file_is_displayable_image(file)) {
      imagesize = QImage.getimagesize(gVars.webEnv, file);
      metadata.putValue("width", imagesize.getValue(0));
      metadata.putValue("height", imagesize.getValue(1));
      new ListAssigner<Object>() {
        public Array<Object> doAssign(Array<Object> srcArray) {
          if (strictEqual(srcArray, null)) {
            return null;
          }

          wp_generate_attachment_metadata_uwidth = srcArray.getValue(0);
          wp_generate_attachment_metadata_uheight = srcArray.getValue(1);

          return srcArray;
        }
      }.doAssign(
          wp_shrink_dimensions(
              intval(metadata.getValue("width")), intval(metadata.getValue("height")), 128, 96));
      metadata.putValue(
          "hwstring_small",
          "height=\'"
              + strval(wp_generate_attachment_metadata_uheight)
              + "\' width=\'"
              + strval(wp_generate_attachment_metadata_uwidth)
              + "\'");
      metadata.putValue("file", file);

      // make thumbnails and other intermediate sizes
      sizes =
          new Array<Object>(new ArrayEntry<Object>("thumbnail"), new ArrayEntry<Object>("medium"));
      sizes =
          (Array<Object>)
              getIncluded(PluginPage.class, gVars, gConsts)
                  .apply_filters("intermediate_image_sizes", sizes);

      for (Map.Entry javaEntry147 : sizes.entrySet()) {
        size = javaEntry147.getValue();
        resized =
            getIncluded(MediaPage.class, gVars, gConsts)
                .image_make_intermediate_size(
                    file,
                    intval(
                        getIncluded(FunctionsPage.class, gVars, gConsts)
                            .get_option(strval(size) + "_size_w")),
                    intval(
                        getIncluded(FunctionsPage.class, gVars, gConsts)
                            .get_option(strval(size) + "_size_h")),
                    booleanval(
                        getIncluded(FunctionsPage.class, gVars, gConsts)
                            .get_option(strval(size) + "_crop")));

        if (booleanval(resized)) {
          metadata.getArrayValue("sizes").putValue(size, resized);
        }
      }

      // fetch additional metadata from exif/iptc
      image_meta = wp_read_image_metadata(file);

      if (booleanval(image_meta)) {
        metadata.putValue("image_meta", image_meta);
      }
    }

    return getIncluded(PluginPage.class, gVars, gConsts)
        .apply_filters("wp_generate_attachment_metadata", metadata);
  }
コード例 #18
0
 public void clearImage() {
   image.fill(new QColor(Qt.GlobalColor.white).rgb());
   modified = true;
   update();
 }