Package java.awt.image

Examples of java.awt.image.BufferedImageOp


        if (bias != 0.0)
            throw new IllegalArgumentException
                ("Only bias equal to zero is supported in ConvolveMatrix.");

        BufferedImageOp op = new ConvolveOp(kernel,
                                            ConvolveOp.EDGE_NO_OP,
                                            rh);

        ColorModel cm = cr.getColorModel();

        // OK this is a bit of a cheat. We Pull the DataBuffer out of
        // The read-only raster that getData gives us. And use it to
        // build a WritableRaster.  This avoids a copy of the data.
        Raster rr = cr.getData();
        WritableRaster wr = GraphicsUtil.makeRasterWritable(rr, 0, 0);

        // Here we update the translate to account for the phase shift
        // (if any) introduced by setting targetX, targetY in SVG.
        int phaseShiftX = target.x - kernel.getXOrigin();
        int phaseShiftY = target.y - kernel.getYOrigin();
        int destX = (int)(r.getX() + phaseShiftX);
        int destY = (int)(r.getY() + phaseShiftY);

        BufferedImage destBI;
        if (!preserveAlpha) {
            // Force the data to be premultiplied since often the JDK
            // code doesn't properly premultiply the values...
            cm = GraphicsUtil.coerceData(wr, cm, true);

            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Easy case just apply the op...
            destBI = op.filter(srcBI, null);

            if (kernelHasNegValues) {
                // When the kernel has negative values it's possible
                // for the resultant image to have alpha values less
                // than the associated color values this will lead to
                // problems later when we try to display the image so
                // we fix this here.
                fixAlpha(destBI);
            }

        } else {
            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Construct a linear sRGB cm without alpha...
            cm = new DirectColorModel(ColorSpace.getInstance
                                      (ColorSpace.CS_LINEAR_RGB), 24,
                                      0x00FF0000, 0x0000FF00,
                                      0x000000FF, 0x0, false,
                                      DataBuffer.TYPE_INT);



            // Create an image with that color model
            BufferedImage tmpSrcBI = new BufferedImage
                (cm, cm.createCompatibleWritableRaster(wr.getWidth(),
                                                       wr.getHeight()),
                 cm.isAlphaPremultiplied(), null);

            // Copy the color data (no alpha) to that image
            // (dividing out alpha if needed).
            GraphicsUtil.copyData(srcBI, tmpSrcBI);

            // org.apache.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpSrcBI: ", tmpSrcBI);

            // Get a linear sRGB Premult ColorModel
            ColorModel dstCM = GraphicsUtil.Linear_sRGB_Unpre;
            // Construct out output image around that ColorModel
            destBI = new BufferedImage
                (dstCM, dstCM.createCompatibleWritableRaster(wr.getWidth(),
                                                             wr.getHeight()),
                 dstCM.isAlphaPremultiplied(), null);

            // Construct another image on the same data buffer but without
            // an alpha channel.

            // Create the Raster (note we are using 'cm' again).
            WritableRaster dstWR =
                Raster.createWritableRaster
                (cm.createCompatibleSampleModel(wr.getWidth(), wr.getHeight()),
                 destBI.getRaster().getDataBuffer(),
                 new Point(0,0));

            // Create the BufferedImage.
            BufferedImage tmpDstBI = new BufferedImage
                (cm, dstWR, cm.isAlphaPremultiplied(), null);

            // Filter between the two image without alpha.
            tmpDstBI = op.filter(tmpSrcBI, tmpDstBI);

            // org.apache.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpDstBI: ", tmpDstBI);

            // Copy the alpha channel into the result (note the color
View Full Code Here


        if (bias != 0.0)
            throw new IllegalArgumentException
                ("Only bias equal to zero is supported in ConvolveMatrix.");

        BufferedImageOp op = new ConvolveOp(kernel,
                                            ConvolveOp.EDGE_NO_OP,
                                            rh);

        ColorModel cm = cr.getColorModel();

        // OK this is a bit of a cheat. We Pull the DataBuffer out of
        // The read-only raster that getData gives us. And use it to
        // build a WritableRaster.  This avoids a copy of the data.
        Raster rr = cr.getData();
        WritableRaster wr = GraphicsUtil.makeRasterWritable(rr, 0, 0);

        // Here we update the translate to account for the phase shift
        // (if any) introduced by setting targetX, targetY in SVG.
        int phaseShiftX = target.x - kernel.getXOrigin();
        int phaseShiftY = target.y - kernel.getYOrigin();
        int destX = (int)(r.getX() + phaseShiftX);
        int destY = (int)(r.getY() + phaseShiftY);

        BufferedImage destBI;
        if (!preserveAlpha) {
            // Force the data to be premultiplied since often the JDK
            // code doesn't properly premultiply the values...
            cm = GraphicsUtil.coerceData(wr, cm, true);

            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Easy case just apply the op...
            destBI = op.filter(srcBI, null);

            if (kernelHasNegValues) {
                // When the kernel has negative values it's possible
                // for the resultant image to have alpha values less
                // than the associated color values this will lead to
                // problems later when we try to display the image so
                // we fix this here.
                fixAlpha(destBI);
            }

        } else {
            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Construct a linear sRGB cm without alpha...
            cm = new DirectColorModel(ColorSpace.getInstance
                                      (ColorSpace.CS_LINEAR_RGB), 24,
                                      0x00FF0000, 0x0000FF00,
                                      0x000000FF, 0x0, false,
                                      DataBuffer.TYPE_INT);



            // Create an image with that color model
            BufferedImage tmpSrcBI = new BufferedImage
                (cm, cm.createCompatibleWritableRaster(wr.getWidth(),
                                                       wr.getHeight()),
                 cm.isAlphaPremultiplied(), null);

            // Copy the color data (no alpha) to that image
            // (dividing out alpha if needed).
            GraphicsUtil.copyData(srcBI, tmpSrcBI);

            // org.apache.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpSrcBI: ", tmpSrcBI);

            // Get a linear sRGB Premult ColorModel
            ColorModel dstCM = GraphicsUtil.Linear_sRGB_Unpre;
            // Construct out output image around that ColorModel
            destBI = new BufferedImage
                (dstCM, dstCM.createCompatibleWritableRaster(wr.getWidth(),
                                                             wr.getHeight()),
                 dstCM.isAlphaPremultiplied(), null);

            // Construct another image on the same data buffer but without
            // an alpha channel.

            // Create the Raster (note we are using 'cm' again).
            WritableRaster dstWR =
                Raster.createWritableRaster
                (cm.createCompatibleSampleModel(wr.getWidth(), wr.getHeight()),
                 destBI.getRaster().getDataBuffer(),
                 new Point(0,0));

            // Create the BufferedImage.
            BufferedImage tmpDstBI = new BufferedImage
                (cm, dstWR, cm.isAlphaPremultiplied(), null);

            // Filter between the two image without alpha.
            tmpDstBI = op.filter(tmpSrcBI, tmpDstBI);

            // org.apache.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpDstBI: ", tmpDstBI);

            // Copy the alpha channel into the result (note the color
View Full Code Here

        if (bias != 0.0)
            throw new IllegalArgumentException
                ("Only bias equal to zero is supported in ConvolveMatrix.");

        BufferedImageOp op = new ConvolveOp(kernel,
                                            ConvolveOp.EDGE_NO_OP,
                                            rh);

        ColorModel cm = cr.getColorModel();

        // OK this is a bit of a cheat. We Pull the DataBuffer out of
        // The read-only raster that getData gives us. And use it to
        // build a WritableRaster.  This avoids a copy of the data.
        Raster rr = cr.getData();
        WritableRaster wr = GraphicsUtil.makeRasterWritable(rr, 0, 0);

        // Here we update the translate to account for the phase shift
        // (if any) introduced by setting targetX, targetY in SVG.
        int phaseShiftX = target.x - kernel.getXOrigin();
        int phaseShiftY = target.y - kernel.getYOrigin();
        int destX = (int)(r.getX() + phaseShiftX);
        int destY = (int)(r.getY() + phaseShiftY);

        BufferedImage destBI;
        if (!preserveAlpha) {
            // Force the data to be premultiplied since often the JDK
            // code doesn't properly premultiply the values...
            cm = GraphicsUtil.coerceData(wr, cm, true);

            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Easy case just apply the op...
            destBI = op.filter(srcBI, null);

            if (kernelHasNegValues) {
                // When the kernel has negative values it's possible
                // for the resultant image to have alpha values less
                // than the associated color values this will lead to
                // problems later when we try to display the image so
                // we fix this here.
                fixAlpha(destBI);
            }

        } else {
            BufferedImage srcBI;
            srcBI = new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);

            // Construct a linear sRGB cm without alpha...
            cm = new DirectColorModel(ColorSpace.getInstance
                                      (ColorSpace.CS_LINEAR_RGB), 24,
                                      0x00FF0000, 0x0000FF00,
                                      0x000000FF, 0x0, false,
                                      DataBuffer.TYPE_INT);



            // Create an image with that color model
            BufferedImage tmpSrcBI = new BufferedImage
                (cm, cm.createCompatibleWritableRaster(wr.getWidth(),
                                                       wr.getHeight()),
                 cm.isAlphaPremultiplied(), null);

            // Copy the color data (no alpha) to that image
            // (dividing out alpha if needed).
            GraphicsUtil.copyData(srcBI, tmpSrcBI);

            // org.apache.flex.forks.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpSrcBI: ", tmpSrcBI);

            // Get a linear sRGB Premult ColorModel
            ColorModel dstCM = GraphicsUtil.Linear_sRGB_Unpre;
            // Construct out output image around that ColorModel
            destBI = new BufferedImage
                (dstCM, dstCM.createCompatibleWritableRaster(wr.getWidth(),
                                                             wr.getHeight()),
                 dstCM.isAlphaPremultiplied(), null);

            // Construct another image on the same data buffer but without
            // an alpha channel.

            // Create the Raster (note we are using 'cm' again).
            WritableRaster dstWR =
                Raster.createWritableRaster
                (cm.createCompatibleSampleModel(wr.getWidth(), wr.getHeight()),
                 destBI.getRaster().getDataBuffer(),
                 new Point(0,0));

            // Create the BufferedImage.
            BufferedImage tmpDstBI = new BufferedImage
                (cm, dstWR, cm.isAlphaPremultiplied(), null);

            // Filter between the two image without alpha.
            tmpDstBI = op.filter(tmpSrcBI, tmpDstBI);

            // org.apache.flex.forks.batik.test.gvt.ImageDisplay.showImage
            //   ("tmpDstBI: ", tmpDstBI);

            // Copy the alpha channel into the result (note the color
View Full Code Here

            BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(),
                    BufferedImage.TYPE_BYTE_GRAY);
            Raster raster = img.getData();
            GraphicsUtil.copyBand(raster, cm.getNumColorComponents(), alpha.getRaster(), 0);

            BufferedImageOp op1 = new LookupOp(new ByteLookupTable(0, THRESHOLD_TABLE), null);
            BufferedImage alphat = op1.filter(alpha, null);

            BufferedImage mask;
            if (true) {
                mask = new BufferedImage(targetDim.width, targetDim.height,
                        BufferedImage.TYPE_BYTE_BINARY);
View Full Code Here

    boolean hasReassignedSrc = false;
    for (int i = 0; i < ops.length; i++) {
      long subT = -1;
      if (DEBUG)
        subT = System.currentTimeMillis();
      BufferedImageOp op = ops[i];
      // Skip null ops instead of throwing an exception.
      if (op == null)
        continue;
      if (DEBUG)
        log(1, "Applying BufferedImageOp [class=%s, toString=%s]...", op.getClass(), op.toString());
      /*
       * Must use op.getBounds instead of src.getWidth and src.getHeight
       * because we are trying to create an image big enough to hold the
       * result of this operation (which may be to scale the image
       * smaller), in that case the bounds reported by this op and the
       * bounds reported by the source image will be different.
       */
      Rectangle2D resultBounds = op.getBounds2D(src);
      // Watch out for flaky/misbehaving ops that fail to work right.
      if (resultBounds == null)
        throw new ImagingOpException(
            "BufferedImageOp ["
                    + op.toString()
                    + "] getBounds2D(src) returned null bounds for the target image; this should not happen and indicates a problem with application of this type of op.");
      /*
       * We must manually create the target image; we cannot rely on the
       * null-destination filter() method to create a valid destination
       * for us thanks to this JDK bug that has been filed for almost a
       * decade:
       * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4965606
       */
      BufferedImage dest = createOptimalImage(src, (int) Math.round(resultBounds.getWidth()),
          (int) Math.round(resultBounds.getHeight()));
      // Perform the operation, update our result to return.
      BufferedImage result = op.filter(src, dest);
      /*
       * Flush the 'src' image ONLY IF it is one of our interim temporary
       * images being used when applying 2 or more operations back to
       * back. We never want to flush the original image passed in.
       */
 
View Full Code Here

       
        if (useBlurResizingForImages &&
            bi.getType() != BufferedImage.TYPE_CUSTOM &&
            image.getWidth() >= 1.75*r.getWidth() && image.getHeight() >= 1.75*r.getHeight()){

          BufferedImageOp op;
         
          final float maxFactor = 3.5f;
          final boolean RESIZE = true;
          if (image.getWidth() > maxFactor*r.getWidth() && image.getHeight() > maxFactor*r.getHeight()){
            //First resize, otherwise we risk that we get out of heapspace
            int newHeight = (int)Math.round(maxFactor*r.getHeight());
            int newWidth = (int)Math.round(maxFactor*r.getWidth());
            if (!RESIZE) {
              newHeight = image.getHeight();
              newWidth = image.getWidth();
            }
            BufferedImage blured = new BufferedImage(newWidth,
                newHeight, bi.getType());
            Graphics2D bg = (Graphics2D) blured.getGraphics();
            bg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            bg.drawImage(bi, 0, 0, newWidth, newHeight, null);
            bi = blured;
                at = new AffineTransform(1f / bi.getWidth(), 0,
                        0, -1f / bi.getHeight(),
                        0, 1);
               
                final float weight = 1.0f/16.0f;
              final float[] blurKernel = {
                  weight, weight, weight, weight,
                  weight, weight, weight, weight,
                  weight, weight, weight, weight,
                  weight, weight, weight, weight,
              };
              op = new ConvolveOp(new Kernel(4, 4, blurKernel), ConvolveOp.EDGE_NO_OP, null);             
          }
          else {
            final float weight = 1.0f/18.0f;
            final float[] blurKernel = {
                1*weight, 2*weight, 1*weight,
                2*weight, 6*weight, 2*weight,
                1*weight, 2*weight, 1*weight
            };

            op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, null);
          }
         
          BufferedImage blured = op.createCompatibleDestImage(bi, bi.getColorModel());
         
             op.filter(bi, blured);
          bi = blured;
          isBlured = true;
        }
       
        this.g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
View Full Code Here

            BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(),
                    BufferedImage.TYPE_BYTE_GRAY);
            Raster raster = img.getData();
            GraphicsUtil.copyBand(raster, cm.getNumColorComponents(), alpha.getRaster(), 0);

            BufferedImageOp op1 = new LookupOp(new ByteLookupTable(0, THRESHOLD_TABLE), null);
            BufferedImage alphat = op1.filter(alpha, null);

            BufferedImage mask;
            if (true) {
                mask = new BufferedImage(targetDim.width, targetDim.height,
                        BufferedImage.TYPE_BYTE_BINARY);
View Full Code Here

      float yScale = 1;
      AffineTransform at = new AffineTransform();
      at.scale(xScale, yScale);
     
      // instantiate and apply affine transformation filter
      BufferedImageOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
      return bio.filter(img, null);
   }
View Full Code Here

      float yScale = (float) destHeight / img.getHeight();
      AffineTransform at = new AffineTransform();
      at.scale(xScale, yScale);
     
      // instantiate and apply affine transformation filter
      BufferedImageOp bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
      return bio.filter(img, null);
   }
View Full Code Here

      // rotate angle degrees around image center
//System.out.println("Rotate by "+angle+": "+angle * Math.PI / 180.0);      
      at.rotate(angle * Math.PI / 180.0, srcImg.getWidth() / 2.0, srcImg.getHeight() / 2.0);

      // instantiate and apply affine transformation filter
      BufferedImageOp bio;
      bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

     
      BufferedImage dest = cropImage(bio.filter(srcImg, null), (int)Math.rint(srcImg.getWidth()*scale)/cropwidth, (int)Math.rint(srcImg.getHeight()*scale)/cropHight);
     
//      File f = new File("SteeringWheel"+angle+".png");
//      System.out.println("Store file at "+f.getAbsolutePath());      
//      try {
//      ImageIO.write(dest, "png", f);
View Full Code Here

TOP

Related Classes of java.awt.image.BufferedImageOp

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.