Package java.awt.image.renderable

Examples of java.awt.image.renderable.ParameterBlock


    com.sun.media.jai.codec.ImageDecoder oDecoder;
    RenderedImage oRenderedImg;
    javax.media.jai.PlanarImage oPlI;
    javax.media.jai.PlanarImage oScI;
    ParameterBlock oBlk;
    com.sun.media.jai.codec.ImageEncoder oImgEnc;
    String sInputURI;
    InputStream oInputStream;
    URL oURI;

    if (DebugFile.trace) {
      DebugFile.writeln("Begin Image.drawJAIImage([OutputStream], " + String.valueOf(iThumbWidth) + "," + String.valueOf(iThumbHeight) + "," + String.valueOf(fQuality) + ")");
      DebugFile.incIdent();
    }

    sInputURI = getString(DB.path_image);

    if (sInputURI.startsWith("http://") || sInputURI.startsWith("https://")) {

      if (DebugFile.trace) DebugFile.writeln("new URL(" + sInputURI + ")");

      oURI = new URL(sInputURI);
      oInputStream = oURI.openStream();
    }
    else {
      if (DebugFile.trace) DebugFile.writeln("new FileInputStream(" + sInputURI + ")");

      try {
        oInputStream = new FileInputStream(sInputURI);
      } catch (FileNotFoundException fnf) {
        if (DebugFile.trace) DebugFile.decIdent();
        throw new FileNotFoundException(fnf.getMessage());
      }
    }

    oDecoder = com.sun.media.jai.codec.ImageCodec.createImageDecoder(getImageCodec(), oInputStream, null);

    oRenderedImg = oDecoder.decodeAsRenderedImage();

    if (getImageType().equals("gif")) {
      // Increase color depth to 16M RGB
      try {
        javax.media.jai.ImageLayout layout = new javax.media.jai.ImageLayout();

        ColorModel cm = new ComponentColorModel (ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                                 new int[] {8,8,8}, false, false,
                                                 Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
        layout.setColorModel(cm);
        layout.setSampleModel(cm.createCompatibleSampleModel(oRenderedImg.getWidth(),oRenderedImg.getHeight()));
        RenderingHints hints = new RenderingHints(javax.media.jai.JAI.KEY_IMAGE_LAYOUT, layout);
        javax.media.jai.ParameterBlockJAI pb = new javax.media.jai.ParameterBlockJAI( "format" );
        pb.addSource( oRenderedImg );
        oRenderedImg = javax.media.jai.JAI.create( "format", pb, hints );
      } catch (IllegalArgumentException iae) {
        if (DebugFile.trace) DebugFile.writeln(iae.getMessage() + " " + oRenderedImg.getColorModel().getClass().getName() + " " + oRenderedImg.getSampleModel().getClass().getName());
      }
      // End increase color depth
    } // gif

    oPlI = javax.media.jai.PlanarImage.wrapRenderedImage(oRenderedImg);

    int iImageWidth = oPlI.getWidth();
    int iImageHeight = oPlI.getHeight();

    if (DebugFile.trace) DebugFile.writeln("image width " + String.valueOf(iImageWidth));
    if (DebugFile.trace) DebugFile.writeln("image height " + String.valueOf(iImageHeight));

    float thumbRatio = ((float) iThumbWidth) / ((float) iThumbHeight);

    if (DebugFile.trace) DebugFile.writeln("thumb ratio " + String.valueOf(thumbRatio));

    float imageRatio = ((float) iImageWidth) / ((float) iImageHeight);

    if (DebugFile.trace) DebugFile.writeln("image ratio " + String.valueOf(imageRatio));

    if (thumbRatio < imageRatio)
      iThumbHeight = (int)(iThumbWidth / imageRatio);
    else
      iThumbWidth = (int)(iThumbHeight * imageRatio);

    float scaleW = ((float) iThumbWidth) / ((float) iImageWidth);

    if (DebugFile.trace) DebugFile.writeln("scale width " + String.valueOf(scaleW));

    float scaleH = ((float) iThumbHeight) / ((float) iImageHeight);

    if (DebugFile.trace) DebugFile.writeln("scale height " + String.valueOf(scaleH));

    oBlk = new ParameterBlock();

    oBlk.addSource(oPlI);

    oBlk.add(scaleW);
    oBlk.add(scaleH);
    oBlk.add(0.0f);
    oBlk.add(0.0f);
    oBlk.add(new javax.media.jai.InterpolationBilinear());

    if (DebugFile.trace) DebugFile.writeln("JAI.create (\"scale\", [ParameterBlock], null)");

    oScI = javax.media.jai.JAI.create("scale", oBlk, null); // scale image NOW !

View Full Code Here


              (int) pixelBounds.getHeight());
          imageLayout.setTileWidth(tileWidth);
          imageLayout.setTileHeight(tileHeight);

          // create the mosaic image
          ParameterBlock pbMosaic = new ParameterBlock();
          pbMosaic.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
          for (RenderedImage renderedImage : images) {
            pbMosaic.addSource(renderedImage);
          }
          RenderedOp mosaic = JAI.create("mosaic", pbMosaic, new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
              imageLayout));
          try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

                .getHeight());
            imageLayout.setTileWidth(imageWidth);
            imageLayout.setTileHeight(imageHeight);

            // create the mosaic image
            ParameterBlock pbMosaic = new ParameterBlock();
            pbMosaic.add(MosaicDescriptor.MOSAIC_TYPE_OVERLAY);
            for (RenderedImage renderedImage : images) {
              pbMosaic.addSource(renderedImage);
            }
            RenderedOp mosaic = JAI.create("mosaic", pbMosaic, new RenderingHints(JAI.KEY_IMAGE_LAYOUT,
                imageLayout));
            try {
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

   * @return rotated image
   */
  public static BufferedImage rotateImage(Image inputImage, int degrees) {
    BufferedImage retVal = null;
    RenderedImage ri = JAI.create("awtImage", inputImage);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(ri);
    TransposeType rotOp = null;
    RenderedOp op = null;
    if (degrees == 90) {
      rotOp = TransposeDescriptor.ROTATE_90;
    } else if (degrees == 180) {
      rotOp = TransposeDescriptor.ROTATE_180;
    } else if (degrees == 270) {
      rotOp = TransposeDescriptor.ROTATE_270;
    }
    if (rotOp != null) {
      // use Transpose operation
      pb.add(rotOp);
      op = JAI.create("transpose", pb);
    } else {
      // setup "normal" rotation
      pb.add(ri.getWidth() / 2.0f);
      pb.add(ri.getHeight() / 2.0f);
      pb.add((float) Math.toRadians(degrees));
      pb.add(new InterpolationNearest());
      op = JAI.create("Rotate", pb, null);
    }
    PlanarImage myPlanar = op.createInstance();
    retVal = myPlanar.getAsBufferedImage();
    return retVal;
View Full Code Here

      op.setOperationName((String)newValue);

  } else if (propName.equals("parameterblock")) {

      ParameterBlock newPB = (ParameterBlock)newValue;
      Vector newSrcs = newPB.getSources();
      newPB.removeSources();

      JAIRMIUtil.checkServerParameters(newPB, nodes);

      Vector replacedSources =
    JAIRMIUtil.replaceIdWithSources(newSrcs,
            nodes,
            op.getOperationName(),
            op.getRenderingHints());
      newPB.setSources(replacedSources);

      op.setParameterBlock(newPB);

      // Remove the newly created sinks of the srcs in the newPB
      Vector newSources = newPB.getSources();
            if(newSources != null && newSources.size() > 0) {
                Iterator it = newSources.iterator();
                while(it.hasNext()) {
                    Object src = it.next();
                    if(src instanceof PlanarImage) {
View Full Code Here

        if(opNode instanceof RenderedOp &&
           name.equalsIgnoreCase("roi")) {
            RenderedOp op = (RenderedOp)opNode;

            ParameterBlock pb = op.getParameterBlock();

            // Retrieve the rendered source image and its ROI.
            RenderedImage src = pb.getRenderedSource(0);
            Object property = src.getProperty("ROI");
            if (property == null ||
                property.equals(java.awt.Image.UndefinedProperty) ||
                !(property instanceof ROI)) {
                return java.awt.Image.UndefinedProperty;
            }
            ROI srcROI = (ROI)property;

            // Retrieve the Interpolation object.
            Interpolation interp = (Interpolation)pb.getObjectParameter(1);

            // Determine the effective source bounds.
            Rectangle srcBounds = null;
            PlanarImage dst = op.getRendering();
            if (dst instanceof GeometricOpImage &&
                ((GeometricOpImage)dst).getBorderExtender() == null) {
                srcBounds =
                    new Rectangle(src.getMinX() + interp.getLeftPadding(),
                                  src.getMinY() + interp.getTopPadding(),
                                  src.getWidth() - interp.getWidth() + 1,
                                  src.getHeight() - interp.getHeight() + 1);
            } else {
                srcBounds = new Rectangle(src.getMinX(),
            src.getMinY(),
            src.getWidth(),
            src.getHeight());
            }

            // If necessary, clip the ROI to the effective source bounds.
            if (!srcBounds.contains(srcROI.getBounds())) {
                srcROI = srcROI.intersect(new ROIShape(srcBounds));
            }

            // Retrieve the AffineTransform object.
            AffineTransform transform =
                (AffineTransform)pb.getObjectParameter(0);

            // Create the transformed ROI.
            ROI dstROI = srcROI.transform((AffineTransform)transform);

            // Retrieve the destination bounds.
View Full Code Here

                                RenderingHints hints) {
        /* Get ImageLayout and TileCache from RenderingHints. */
        ImageLayout layout = RIFUtil.getImageLayoutHint(hints);
       

        if (!MediaLibAccessor.isMediaLibCompatible(new ParameterBlock())) {
            return null;
        }

        RenderedImage source = args.getRenderedSource(0);
        EnumeratedParameter scalingType =
            (EnumeratedParameter)args.getObjectParameter(0);
        EnumeratedParameter dataNature =
            (EnumeratedParameter)args.getObjectParameter(1);

        boolean isComplexSource =
            !dataNature.equals(DFTDescriptor.REAL_TO_COMPLEX);
        int numSourceBands = source.getSampleModel().getNumBands();

        // Use the two-dimensional mediaLib DFT if possible: it supports
        // only data which have a single component (real or complex)
        // per pixel and which have dimensions which are equal to a positive
        // power of 2.
        if(((isComplexSource && numSourceBands == 2) ||
            (!isComplexSource && numSourceBands == 1)) &&
           MlibDFTOpImage.isAcceptableSampleModel(source.getSampleModel())) {
            // If necessary, pad the source to ensure that
            // both dimensions are positive powers of 2.
            int sourceWidth = source.getWidth();
            int sourceHeight = source.getHeight();
            if(!MathJAI.isPositivePowerOf2(sourceWidth) ||
               !MathJAI.isPositivePowerOf2(sourceHeight)) {
                ParameterBlock pb = new ParameterBlock();
                pb.addSource(source);
                pb.add(0);
                pb.add(MathJAI.nextPositivePowerOf2(sourceWidth) -
                       sourceWidth);
                pb.add(0);
                pb.add(MathJAI.nextPositivePowerOf2(sourceHeight) -
                       sourceHeight);
                pb.add(BorderExtender.createInstance(BorderExtender.BORDER_ZERO));
                source = JAI.create("border", pb);
            }

            return new MlibDFTOpImage(source, hints, layout, dataNature,
                                      false, scalingType);
View Full Code Here

  // call to the super constructor, then honor that now.
  if (preferencesSet)
      super.setNegotiationPreferences(negPref);

  // Create a RenderedOp on the server for this operation.
  ParameterBlock newPB = (ParameterBlock)paramBlock.clone();
  newPB.removeSources();

  // Check to see whether any of the parameters are images
  JAIRMIUtil.checkClientParameters(newPB, serverName);

  try {
View Full Code Here

    oldValue = event.getOldValue();
    newValue = event.getNewValue();

      } else if (propName.equals("parameterblock")) {

    ParameterBlock oldPB = (ParameterBlock)event.getOldValue();
    Vector oldSrcs = oldPB.getSources();
    oldPB.removeSources();

    ParameterBlock newPB = (ParameterBlock)event.getNewValue();
    Vector newSrcs = newPB.getSources();
    newPB.removeSources();

    // XXX Check serverName is correct thing to pass
    JAIRMIUtil.checkClientParameters(oldPB, serverName);
    JAIRMIUtil.checkClientParameters(newPB, serverName);

    oldPB.setSources(JAIRMIUtil.replaceSourcesWithId(oldSrcs,
                 serverName));
    newPB.setSources(JAIRMIUtil.replaceSourcesWithId(newSrcs,
                 serverName));

    oldValue = oldPB;
    newValue = newPB;
View Full Code Here

  if (preferencesSet)
      super.setNegotiationPreferences(negPref);

  // Create a RenderableOp on the server for this operation.

  ParameterBlock newPB = (ParameterBlock)paramBlock.clone();
  newPB.removeSources();

  // XXX Since checking to see whether any of the parameters are images
  // causes problems with the "renderable" operator (the RenderedOp
  // downsampler chain needs to be sent to the server as a RenderedOp,
  // and checkClientParameters would make it a RenderedImage), we do
View Full Code Here

TOP

Related Classes of java.awt.image.renderable.ParameterBlock

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.