Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
 public void cleanup() {
   try {
     if (compositor != null) compositor.Native_destroy();
     threadEnv.Destroy();
     threadEnv.Native_destroy();
     wrappedSource.Native_destroy();
     familySource.Native_destroy();
     if (rawSource != null) rawSource.Native_destroy();
   } catch (KduException e) {
     System.err.printf("Exception on Kdu object cleanup: %s\n", e.getMessage());
   }
 }