Exemplo n.º 1
0
    Jp2ExeOpImage(BandInfo bandInfo, MultiLevelModel imageModel, int level) throws IOException {
      super(
          DataBuffer.TYPE_USHORT,
          bandInfo.imageLayout.width,
          bandInfo.imageLayout.height,
          getTileDim(bandInfo, level),
          null,
          ResolutionLevel.create(imageModel, level));

      final File resolvedFile = bandInfo.imageFile.getCanonicalFile();
      if (!resolvedFile.exists()) {
        throw new FileNotFoundException("File not found: " + bandInfo.imageFile);
      }

      if (resolvedFile.getParentFile() == null) {
        throw new IOException("Can't determine package directory");
      }

      final File cacheDir =
          new File(
              new File(SystemUtils.getApplicationDataDir(), "jopenjpeg/cache"),
              resolvedFile.getParentFile().getName());
      cacheDir.mkdirs();
      if (!cacheDir.exists() || !cacheDir.isDirectory() || !cacheDir.canWrite()) {
        throw new IOException("Can't access package cache directory");
      }

      this.bandInfo = bandInfo;
      this.imageFile = resolvedFile;
      this.cacheDir = cacheDir;
      this.openFiles = new HashMap<File, Jp2File>();
      this.locks = new HashMap<File, Object>();
    }
Exemplo n.º 2
0
    @Override
    protected RenderedImage createImage(int level) {
      RasterDataNode rdn = getRasterDataNode();
      NetcdfFile lock = ctx.getNetcdfFile();
      final Object object = ctx.getProperty(Constants.Y_FLIPPED_PROPERTY_NAME);
      boolean isYFlipped = object instanceof Boolean && (Boolean) object;
      int dataBufferType = ImageManager.getDataBufferType(rdn.getDataType());
      int sourceWidth = (int) (rdn.getSceneRasterWidth() / scaleFactor);
      int sourceHeight = (int) (rdn.getSceneRasterHeight() / scaleFactor);
      ResolutionLevel resolutionLevel = ResolutionLevel.create(getModel(), level);
      Dimension tileSize = getPreferredTileSize(rdn);

      RenderedImage netcdfImg;
      if (variable.getDataType() == DataType.LONG) {
        if (rdn.getName().endsWith("_lsb")) {
          netcdfImg =
              NetcdfOpImage.createLsbImage(
                  variable,
                  imageOrigin,
                  isYFlipped,
                  lock,
                  dataBufferType,
                  sourceWidth,
                  sourceHeight,
                  tileSize,
                  resolutionLevel);
        } else {
          netcdfImg =
              NetcdfOpImage.createMsbImage(
                  variable,
                  imageOrigin,
                  isYFlipped,
                  lock,
                  dataBufferType,
                  sourceWidth,
                  sourceHeight,
                  tileSize,
                  resolutionLevel);
        }
      } else {
        netcdfImg =
            new NetcdfOpImage(
                variable,
                imageOrigin,
                isYFlipped,
                lock,
                dataBufferType,
                sourceWidth,
                sourceHeight,
                tileSize,
                resolutionLevel);
      }

      return ScaleDescriptor.create(
          netcdfImg,
          scaleFactor,
          scaleFactor,
          0.5f,
          0.5f,
          Interpolation.getInstance(Interpolation.INTERP_NEAREST),
          null);
    }