Package gov.lanl.adore.djatoka

Examples of gov.lanl.adore.djatoka.DjatokaException


    try {
      in = IOUtils.createTempTiff(bi);
      compressImage(in.getAbsolutePath(), output, params);
    } catch (IOException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    } catch (Exception e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    } finally {
      if (in != null)
        in.delete();
    }
  }
View Full Code Here


      out = File.createTempFile("tmp", ".jp2");
      compressImage(in.getAbsolutePath(), out.getAbsolutePath(), params);
      IOUtils.copyStream(new FileInputStream(out), output);
    } catch (IOException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    } catch (Exception e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    }

    if (in != null)
      in.delete();
    if (out != null)
View Full Code Here

        params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
        dim = null;
      }
    } catch (IOException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    }

    compressImage(inputFile.getAbsolutePath(), output, params);

    if (inputFile != null)
View Full Code Here

        params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
        dim = null;
      }
    } catch (IOException e1) {
      logger.error("Unexpected file format; expecting uncompressed TIFF",e1);
      throw new DjatokaException("Unexpected file format; expecting uncompressed TIFF");
    }

    String out = STDOUT;
    File winOut = null;
    if (isWindows) {
      try {
        winOut = File.createTempFile("pipe_", ".jp2");
      } catch (IOException e) {
        logger.error(e,e);
        throw new DjatokaException(e);
      }
      out = winOut.getAbsolutePath();
    }

    String command = getKduCompressCommand(inputFile.getAbsolutePath(),
        out, params);
    logger.debug("compressCommand: " + command);
    Runtime rt = Runtime.getRuntime();
    try {
      final Process process = rt.exec(command, envParams, new File(env));
      if (out.equals(STDOUT)) {
        IOUtils.copyStream(process.getInputStream(), output);
      } else if (isWindows) {
        FileInputStream fis = new FileInputStream(out);
        IOUtils.copyStream(fis, output);
        fis.close();
      }
      process.waitFor();
      if (process != null) {
        String errorCheck = null;
        try {
          errorCheck = new String(IOUtils.getByteArray(process.getErrorStream()));
        } catch (Exception e1) {
          logger.error(e1,e1);
        }
        process.getInputStream().close();
        process.getOutputStream().close();
        process.getErrorStream().close();
        process.destroy();
        if (errorCheck != null)
          throw new DjatokaException(errorCheck);
      }
    } catch (IOException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    } catch (InterruptedException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    }

    if (inputFile != null)
      inputFile.delete();
    if (winOut != null)
View Full Code Here

      try {
        inputFile = IOUtils.createTempTiff(input);
        tmp = true;
        input = inputFile.getAbsolutePath();
      } catch (Exception e) {
        throw new DjatokaException("Unrecognized file format: " + e.getMessage());
      }
    }

    if (params.getLevels() == 0) {
      ImageRecord dim = ImageRecordUtils.getImageDimensions(inputFile.getAbsolutePath());
      params.setLevels(ImageProcessingUtils.getLevelCount(dim.getWidth(), dim.getHeight()));
      dim = null;
    }

    File outFile = new File(output);
    String command = getKduCompressCommand(new File(input)
        .getAbsolutePath(), outFile.getAbsolutePath(), params);
    Runtime rt = Runtime.getRuntime();
    try {
      final Process process = rt.exec(command, envParams, new File(env));
      process.waitFor();
      if (process != null) {
        String errorCheck = null;
        try {
          errorCheck = new String(IOUtils.getByteArray(process.getErrorStream()));
        } catch (Exception e1) {
        }
        process.getInputStream().close();
        process.getOutputStream().close();
        process.getErrorStream().close();
        process.destroy();
        if (errorCheck != null && !errorCheck.equals(""))
          throw new DjatokaException(errorCheck);
      }
    } catch (IOException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    } catch (InterruptedException e) {
      logger.error(e,e);
      throw new DjatokaException(e);
    } finally {
      if (tmp)
        inputFile.delete();
    }
   
    if (!outFile.getAbsolutePath().equals(STDOUT) && !outFile.exists())
      throw new DjatokaException("Unknown error occurred during processing.");
  }
View Full Code Here

   * @throws DjatokaException
   */
    @Override
  public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
    if ((r.getImageFile() == null || !new File(r.getImageFile()).exists()) && r.getObject() == null)
      throw new DjatokaException("Image Does Not Exist: " + r.toString());
   
        try {
            /*
            JPEGImageDecoder decoder = null;
            if (r.getImageFile() != null && new File(r.getImageFile()).exists()) {
                decoder = JPEGCodec.createJPEGDecoder(new FileInputStream(r.getImageFile()));
            } else {
                decoder = JPEGCodec.createJPEGDecoder((InputStream) r.getObject());
            }
            BufferedImage bi = decoder.decodeAsBufferedImage();
            */
            BufferedImage bi = null;
            if (r.getImageFile() != null && new File(r.getImageFile()).exists()) {
                bi = ImageIO.read(new File(r.getImageFile()));
            } else {
                bi = ImageIO.read((InputStream) r.getObject());
            }
            if (bi == null)
                return null;

            r.setWidth(bi.getWidth());
            r.setHeight(bi.getHeight());

            int minLevels = 3; //FIXME
            int djatokaLevels = ImageProcessingUtils.getLevelCount(r.getWidth(), r.getHeight(), 128);
            r.setDWTLevels((djatokaLevels < minLevels) ? minLevels : djatokaLevels);
            r.setLevels((djatokaLevels < minLevels) ? minLevels : djatokaLevels);

            r.setBitDepth(bi.getColorModel().getPixelSize());
            r.setNumChannels(bi.getColorModel().getNumColorComponents());
//            r.setCompositingLayerCount(frames[0]);
    } catch (Exception e) {
      throw new DjatokaException(e);
    }

    return r;
  }
View Full Code Here

    return r;
  }

    public final ImageRecord getMetadata(BufferedImage bi) throws DjatokaException {
    if (bi == null)
      throw new DjatokaException("Image Does Not Exist");

        try {
            ImageRecord r = new ImageRecord();

      r.setWidth(bi.getWidth());
      r.setHeight(bi.getHeight());

            int minLevels = 5;
      r.setDWTLevels(minLevels); //FIXME
            int djatokaLevels = ImageProcessingUtils.getLevelCount(r.getWidth(), r.getHeight());
            r.setLevels((djatokaLevels > minLevels) ? minLevels : djatokaLevels);

            r.setBitDepth(bi.getColorModel().getPixelSize());
            r.setNumChannels(bi.getColorModel().getNumColorComponents());
//            r.setCompositingLayerCount(frames[0]);
            return r;
    } catch (Exception e) {
      throw new DjatokaException(e);
    }
  }
View Full Code Here

      return process(input.getImageFile(), params);
    else if (input.getObject() != null
        && (input.getObject() instanceof InputStream))
      return process((InputStream) input.getObject(), params);
    else
      throw new DjatokaException(
          "File not defined and Input Object Type "
              + input.getObject().getClass().getName()
              + " is not supported");
  }
View Full Code Here

            if ((token = st.nextToken()).contains(".")) {
                dims.add(Double.parseDouble(token));
            } else {
                int t = Integer.parseInt(token);
                if (r.getHeight() < t) {
                    throw new DjatokaException("Region inset out of bounds: " + t + ">" + r.getHeight());
                }
                dims.add(Double.parseDouble(token) / r.getHeight());
            }
            // left
            if ((token = st.nextToken()).contains(".")) {
                dims.add(Double.parseDouble(token));
            } else {
                int t = Integer.parseInt(token);
                if (r.getWidth() < t) {
                    throw new DjatokaException("Region inset out of bounds: " + t + ">" + r.getWidth());
                }
                dims.add(Double.parseDouble(token) / r.getWidth());
            }
            // height
            if ((token = st.nextToken()).contains(".")) {
View Full Code Here

   * @return a populated ImageRecord object
   * @throws DjatokaException
   */
  public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
    if (!new File(r.getImageFile()).exists())
      throw new DjatokaException("Image Does Not Exist");
   
    Jp2_source inputSource = new Jp2_source();
    Kdu_compressed_source kduIn = null;
    Jp2_family_src jp2_family_in = new Jp2_family_src();
    Jp2_locator loc = new Jp2_locator();

    try {
      jp2_family_in.Open(r.getImageFile(), true);
      inputSource.Open(jp2_family_in, loc);
      inputSource.Read_header();
      kduIn = inputSource;
      Kdu_codestream codestream = new Kdu_codestream();
      codestream.Create(kduIn);
      Kdu_channel_mapping channels = new Kdu_channel_mapping();
      if (inputSource.Exists())
        channels.Configure(inputSource, false);
      else
        channels.Configure(codestream);
      int ref_component = channels.Get_source_component(0);
      int minLevels = codestream.Get_min_dwt_levels();
      int minLayers= codestream.Get_max_tile_layers();
      Kdu_dims image_dims = new Kdu_dims();
      codestream.Get_dims(ref_component, image_dims);
      Kdu_coords imageSize = image_dims.Access_size();
     
      r.setWidth(imageSize.Get_x());
      r.setHeight(imageSize.Get_y());
      r.setDWTLevels(minLevels);

      channels.Native_destroy();
      if (codestream.Exists())
        codestream.Destroy();
      kduIn.Native_destroy();
      inputSource.Native_destroy();
      jp2_family_in.Native_destroy();
    } catch (KduException e) {
      throw new DjatokaException(e);
    }

    return r;
  }
View Full Code Here

TOP

Related Classes of gov.lanl.adore.djatoka.DjatokaException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.