Exemplo n.º 1
0
 /**
  * Basic nonparametric usage of canny edge detector. No thresholding is used.
  *
  * @param original input image
  */
 public CCannyEdgeDetector(BufferedImage original) {
   size = new Dimension(original.getWidth(), original.getHeight());
   input = original.getData();
   image =
       new BufferedImage(
           (int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_RGB);
   bands = original.getSampleModel().getNumBands();
 }
Exemplo n.º 2
0
  /**
   * Binds the BufferedImage byte-stream into video memory. BufferedImage must be in 4BYTE_ABGR.
   * 4BYTE_ABGR removes endinese problems.
   */
  public Texture bind(final BufferedImage _image, final InternalFormat _format) {
    final GL3 gl = GLRenderer.getCanvas().getContext().getCurrentGL().getGL3();
    if (gl == null) {
      System.out.println("GL context doesn't exist");
      return null;
    }

    gl.glEnable(GL.GL_TEXTURE_2D);

    final int textureID = glGenTextures(gl);
    gl.glBindTexture(GL3.GL_TEXTURE_2D, textureID);

    gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_WRAP_S, GL3.GL_REPEAT);
    gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_WRAP_T, GL3.GL_REPEAT);
    gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_MAG_FILTER, GL3.GL_LINEAR);
    gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_MIN_FILTER, GL3.GL_LINEAR_MIPMAP_LINEAR);

    final int width = _image.getWidth();
    final int height = _image.getHeight();
    final int channels = _image.getSampleModel().getNumBands();
    int internalFormat = GL3.GL_RGB;

    if (gl.isExtensionAvailable("GL_EXT_abgr") == true) {
      switch (channels) {
        case 4:
          imageFormat = GL2.GL_ABGR_EXT;
          break;
        case 3:
          imageFormat = GL3.GL_BGR;
          break;
        case 1:
          imageFormat = GL3.GL_RED;
          break;
      }
    } else {
      switch (channels) {
        case 4:
          imageFormat = GL3.GL_RGBA;
          break;
        case 3:
          imageFormat = GL3.GL_RGB;
          break;
        case 1:
          imageFormat = GL3.GL_RED;
          break;
      }
    }

    gl.glPixelStorei(GL3.GL_UNPACK_ALIGNMENT, 1);
    gl.glTexImage2D(
        GL3.GL_TEXTURE_2D,
        0,
        getGLInternalFormat(channels, _format),
        width,
        height,
        0,
        imageFormat,
        GL3.GL_UNSIGNED_BYTE,
        getByteBuffer(_image));

    gl.glGenerateMipmap(GL3.GL_TEXTURE_2D);
    gl.glBindTexture(GL.GL_TEXTURE_2D, 0); // Reset to default texture

    return new Texture(new GLImage(textureID, width, height));
  }
Exemplo n.º 3
0
  public BufferedImage read(int imageIndex, ImageReadParam param) throws IOException {
    checkIndex(imageIndex);
    readHeader();

    if (iis == null) throw new IllegalStateException("input is null");

    BufferedImage img;

    clearAbortRequest();
    processImageStarted(imageIndex);

    if (param == null) param = getDefaultReadParam();

    sourceRegion = new Rectangle(0, 0, 0, 0);
    destinationRegion = new Rectangle(0, 0, 0, 0);

    computeRegions(
        param, this.width, this.height, param.getDestination(), sourceRegion, destinationRegion);

    scaleX = param.getSourceXSubsampling();
    scaleY = param.getSourceYSubsampling();

    // If the destination band is set used it
    sourceBands = param.getSourceBands();
    destBands = param.getDestinationBands();

    seleBand = (sourceBands != null) && (destBands != null);
    noTransform = destinationRegion.equals(new Rectangle(0, 0, width, height)) || seleBand;

    if (!seleBand) {
      sourceBands = new int[colorPlanes];
      destBands = new int[colorPlanes];
      for (int i = 0; i < colorPlanes; i++) destBands[i] = sourceBands[i] = i;
    }

    // If the destination is provided, then use it.  Otherwise, create new one
    bi = param.getDestination();

    // Get the image data.
    WritableRaster raster = null;

    if (bi == null) {
      if (sampleModel != null && colorModel != null) {
        sampleModel =
            sampleModel.createCompatibleSampleModel(
                destinationRegion.width + destinationRegion.x,
                destinationRegion.height + destinationRegion.y);
        if (seleBand) sampleModel = sampleModel.createSubsetSampleModel(sourceBands);
        raster = Raster.createWritableRaster(sampleModel, new Point(0, 0));
        bi = new BufferedImage(colorModel, raster, false, null);
      }
    } else {
      raster = bi.getWritableTile(0, 0);
      sampleModel = bi.getSampleModel();
      colorModel = bi.getColorModel();

      noTransform &= destinationRegion.equals(raster.getBounds());
    }

    byte bdata[] = null; // buffer for byte data

    if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE)
      bdata = (byte[]) ((DataBufferByte) raster.getDataBuffer()).getData();

    readImage(bdata);

    if (abortRequested()) processReadAborted();
    else processImageComplete();

    return bi;
  }