Beispiel #1
0
  public static void main(String[] args) {
    try {
      // non-throwing message printer
      Kdu_sysout_message sysout = new Kdu_sysout_message(false);
      // exception-throwing message printer
      Kdu_sysout_message syserr = new Kdu_sysout_message(true);
      // non-throwing formatted printer
      Kdu_message_formatter formattedSysout = new Kdu_message_formatter(sysout);
      // throwing formatted printer
      Kdu_message_formatter formattedSyserr = new Kdu_message_formatter(syserr);

      Kdu_global.Kdu_customize_warnings(formattedSysout);
      Kdu_global.Kdu_customize_errors(formattedSyserr);
    } catch (KduException e) {
      System.err.printf("Exception during Kdu stream tie: %s\n", e.getMessage());
    }

    if (args.length != 1) {
      System.err.println("You must supply a filename (JP2, JPX or raw code-stream)");
      System.exit(0);
    }

    final String filename = args[0];

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            Haikdu app = new Haikdu(filename);
          }
        });
  }
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();
  }
  private static Kdu_coords getReferenceExpansion(
      int reference_component, Kdu_channel_mapping channels, Kdu_codestream codestream)
      throws KduException {

    int c;
    Kdu_coords ref_subs = new Kdu_coords();
    Kdu_coords subs = new Kdu_coords();
    codestream.Get_subsampling(reference_component, ref_subs);
    Kdu_coords min_subs = new Kdu_coords();
    min_subs.Assign(ref_subs);

    for (c = 0; c < channels.Get_num_channels(); c++) {
      codestream.Get_subsampling(channels.Get_source_component(c), subs);
      if (subs.Get_x() < min_subs.Get_x()) min_subs.Set_x(subs.Get_x());
      if (subs.Get_y() < min_subs.Get_y()) min_subs.Set_y(subs.Get_y());
    }

    Kdu_coords expansion = new Kdu_coords();
    expansion.Set_x(ref_subs.Get_x() / min_subs.Get_x());
    expansion.Set_y(ref_subs.Get_y() / min_subs.Get_y());

    for (c = 0; c < channels.Get_num_channels(); c++) {
      codestream.Get_subsampling(channels.Get_source_component(c), subs);
      if ((((subs.Get_x() * expansion.Get_x()) % ref_subs.Get_x()) != 0)
          || (((subs.Get_y() * expansion.Get_y()) % ref_subs.Get_y()) != 0)) {
        Kdu_global.Kdu_print_error(
            "The supplied JP2 file contains color channels "
                + "whose sub-sampling factors are not integer "
                + "multiples of one another.");
        codestream.Apply_input_restrictions(
            0, 1, 0, 0, null, Kdu_global.KDU_WANT_OUTPUT_COMPONENTS);
        channels.Configure(codestream);
        expansion = new Kdu_coords(1, 1);
      }
    }
    return expansion;
  }