Beispiel #1
0
  public ImagePanel(Kdu_coords viewSize) throws KduException {
    int width = Math.min(viewSize.Get_x(), 1600);
    int height = Math.min(viewSize.Get_y(), 1200);

    setPreferredSize(new Dimension(width, height));

    getInputMap().put(KeyStroke.getKeyStroke("UP"), "pressedUpArrow");
    getActionMap()
        .put(
            "pressedUpArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
    getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "pressedDownArrow");
    getActionMap()
        .put(
            "pressedDownArrow",
            new AbstractAction() {
              public void actionPerformed(ActionEvent evt) {
                // placeholder
              }
            });
  }
Beispiel #2
0
  public Haikdu(String filename) {
    try {
      familySource.Open(filename);
      int success = wrappedSource.Open(familySource, true);
      if (success < 0) {
        familySource.Close();
        wrappedSource.Close();
        rawSource = new Kdu_simple_file_source(filename);
      }

      if (rawSource != null) compositor.Create(rawSource);
      else compositor.Create(wrappedSource);

      int numThreads = Kdu_global.Kdu_get_num_processors();
      threadEnv.Create();
      for (int thread = 1; thread < numThreads; thread++)
        if (!threadEnv.Add_thread()) numThreads = thread;
      compositor.Set_thread_env(threadEnv, null);

      compositor.Add_ilayer(0, new Kdu_dims(), new Kdu_dims());
      compositor.Set_scale(false, false, false, 0.050f);

      // Determine dimensions for the rendered result and start processing.
      compositor.Get_total_composition_dims(viewDims);
      viewSize = viewDims.Access_size();

      // Construct Swing frame
      imagePanel = new ImagePanel(viewSize);
      addWindowListener(
          new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
              System.exit(0);
            }
          });
      getContentPane().add("Center", imagePanel);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      pack();
      setTitle("Haikdu");
      setVisible(true);
      repaint();

      Kdu_coords displaySize = new Kdu_coords(imagePanel.getWidth(), imagePanel.getHeight());
      if (viewSize.Get_x() > displaySize.Get_x()) viewSize.Set_x(displaySize.Get_y());
      if (viewSize.Get_y() > displaySize.Get_y()) viewSize.Set_y(displaySize.Get_y());
      compositor.Set_buffer_surface(viewDims);
      compositorBuffer = compositor.Get_composition_buffer(viewDims);
    } catch (KduException e) {
      System.err.printf("Caught exception during Kdu object construction: %s\n", e.getMessage());
    }

    render();
  }
Beispiel #3
0
  public void render() {
    try {
      int regionBufferSize = 0;
      int[] regionBuffer = null;
      Kdu_dims newRegion = new Kdu_dims();

      long kduRenderStart = System.nanoTime();

      while (compositor.Process(100000, newRegion)) {
        Kdu_coords newOffset = newRegion.Access_pos();
        Kdu_coords newSize = newRegion.Access_size();

        newOffset.Subtract(viewDims.Access_pos());

        int newPixels = newSize.Get_x() * newSize.Get_y();
        if (newPixels == 0) continue;
        else if (newPixels > regionBufferSize) {
          regionBufferSize = newPixels;
          regionBuffer = new int[regionBufferSize];
        }

        compositorBuffer.Get_region(newRegion, regionBuffer);
        imagePanel.putRegion(
            viewSize.Get_x(),
            viewSize.Get_y(),
            newSize.Get_x(),
            newSize.Get_y(),
            newOffset.Get_x(),
            newOffset.Get_y(),
            regionBuffer);
      }

      long kduRenderEnd = System.nanoTime();

      System.out.printf(
          "Processed using %d concurrent threads of execution in %.4fms\n",
          threadEnv.Get_num_threads(), (kduRenderEnd - kduRenderStart) * 1e-6);
      imagePanel.repaint();
    } catch (KduException e) {
      System.err.printf(
          "Caught exception '%s'; code '%s'\n",
          e.getMessage(), Integer.toHexString(e.Get_kdu_exception_code()));
    }
  }