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;
  }