/**
   * performs the creation of a <tt>ImageGridCoverage</tt> from the source assigned to this reader.
   *
   * @param parameters
   * @throws IOException
   */
  private GridCoverage performECW(GeneralParameterValueIm[] parameters) throws IOException {

    BufferedImage bi = null;
    CoverageOffering co = null;
    Object[] o = null;

    ECWReader ecwFile = null;
    try {
      String s = ((File) source).getName();
      ecwFile = new ECWReader(s);

      // get the requested dimension in pixels
      int reqWidth = 0;
      int reqHeight = 0;
      for (int i = 0; i < parameters.length; i++) {
        OperationParameterIm op = (OperationParameterIm) parameters[i].getDescriptor();
        String name = op.getName();
        if (name.equalsIgnoreCase("WIDTH")) {
          Object vo = op.getDefaultValue();
          reqWidth = ((Integer) vo).intValue();
        } else if (name.equalsIgnoreCase("HEIGHT")) {
          Object vo = op.getDefaultValue();
          reqHeight = ((Integer) vo).intValue();
        }
      }

      // calculate image region of interest
      o = getECWImageRegion(reqWidth, reqHeight);
      Envelope envl = (Envelope) o[1];

      Rectangle rect = (Rectangle) o[0];
      bi = ecwFile.getBufferedImage(envl, rect.width, rect.height);

      // create a coverage description that matches the sub image (coverage)
      // for this a new LonLatEnvelope must be set
      co = (CoverageOffering) description.clone();
      co.setLonLatEnvelope((LonLatEnvelope) o[2]);

    } catch (Exception e) {
      e.printStackTrace();
      throw new IOException(StringTools.stackTraceToString(e));
    } finally {
      // free the ECW cache memory
      if (ecwFile != null) {
        ecwFile.close();
      }
    }

    return new ImageGridCoverage(co, (Envelope) o[1], bi);
  }
  /**
   * performs the creation of a <tt>ImageGridCoverage</tt> from the source assigned to this reader.
   *
   * @throws IOException
   * @throws ParameterNotFoundException
   */
  private GridCoverage performImage() throws ParameterNotFoundException, IOException {

    BufferedImage bi = readImage();

    // get image rectangle of interrest, envelope and lonlatenvelope
    Object[] o = getImageRegion(bi.getWidth(), bi.getHeight());
    Rectangle rect = (Rectangle) o[0];
    // return null if the result GC would have a width or height of zero
    if (rect.width == 0 || rect.height == 0) {
      return null;
    }
    bi = bi.getSubimage(rect.x, rect.y, rect.width, rect.height);

    // create a coverage description that matches the sub image (coverage)
    // for this a new LonLatEnvelope must be set
    CoverageOffering co = (CoverageOffering) description.clone();
    co.setLonLatEnvelope((LonLatEnvelope) o[2]);

    return new ImageGridCoverage(co, (Envelope) o[1], bi);
  }