Java 类java.awt.image.Kernel 实例源码

项目:incubator-netbeans    文件:HeapView.java   
public HeapView() {
    // Configure structures needed for rendering drop shadow.
    int kw = KERNEL_SIZE, kh = KERNEL_SIZE;
    float blurFactor = BLUR_FACTOR;
    float[] kernelData = new float[kw * kh];
    for (int i = 0; i < kernelData.length; i++) {
        kernelData[i] = blurFactor;
    }
    blur = new ConvolveOp(new Kernel(kw, kh, kernelData));
    format = new MessageFormat("{0,choice,0#{0,number,0.0}|999<{0,number,0}}/{1,choice,0#{1,number,0.0}|999<{1,number,0}}MB");
    heapSizeText = "";
    // Enable mouse events. This is the equivalent to adding a mouse
    // listener.
    enableEvents(AWTEvent.MOUSE_EVENT_MASK);
    setToolTipText(NbBundle.getMessage(GarbageCollectAction.class, "CTL_GC"));
    updateUI();
}
项目:GIFKR    文件:ConvolutionFilter.java   
@Override
public final BufferedImage apply(BufferedImage img) {

    float[][] matrix = getMatrix();
    float[] data = getKernelData(matrix);
    if(normalize)
        normalize(data); 
    scale(data);
    if(isZero(data))
        return new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);

    Kernel k = new Kernel(matrix[0].length, matrix.length, data);
    ConvolveOp op = new ConvolveOp(k, ConvolveOp.EDGE_NO_OP, null);

    BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
    img2.getGraphics().drawImage(img, 0, 0, null);

    return op.filter(img2, null);
}
项目:OpenJSharp    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:ChessBot    文件:ChessBoardUtils.java   
public static BufferedImage blur(BufferedImage src) {
    BufferedImage bufferedImage = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);

    int s1 = 7;
    int s2 = 7;
    float level = .1f / 9f;

    float[] filter = new float[s1 * s2];

    for (int i = 0; i < s1 * s2; i++) {
        filter[i] = level;
    }

    Kernel kernel = new Kernel(s1, s2, filter);
    BufferedImageOp op = new ConvolveOp(kernel);
    bufferedImage = op.filter(src, null);

    return bufferedImage;
}
项目:jdk8u-jdk    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:openjdk-jdk10    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:openjdk9    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:LibZ    文件:Sprite.java   
/**
 * Blur the image
 * @param amount
 */
public void effect_blur(int amount) { // TODO
    int radius = amount;
    int size = radius * 2 + 1;
    float weight = 1.0f / (size * size);
    float[] data = new float[size * size];

    for (int i = 0; i < data.length; i++) {
        data[i] = weight;
    }

    Kernel kernel = new Kernel(size, size, data);
    ConvolveOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
    image = op.filter(image, null);

}
项目:vortex    文件:GaussianBlur.java   
public static Image getBlurredImg(BufferedImage img) {
    final int kernel_size = 15;
    float[] blurKernel = new float[kernel_size * kernel_size];
    final float blurPeakHeight = 0.35f;
    double[][] sigma = new double[2][2];
    sigma[0] = new double[]{1.2, 0.0};
    sigma[1] = new double[]{0.0, 1.2};

    double mid = (kernel_size / 2.0);
    float cent = (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{mid, mid});

    for (int i = 0; i < blurKernel.length; i++) {
        int x = i / kernel_size;
        int y = i % kernel_size;
        blurKernel[i] = blurPeakHeight * (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{x, y}) / cent;
    }

    ConvolveOp op = new ConvolveOp(new Kernel(kernel_size, kernel_size, blurKernel));

    return op.filter(img, null);

}
项目:vortex    文件:GaussianBlur.java   
public static Image getBlurredImg(BufferedImage img) {
    final int kernel_size = 15;
    float[] blurKernel = new float[kernel_size * kernel_size];
    final float blurPeakHeight = 0.35f;
    double[][] sigma = new double[2][2];
    sigma[0] = new double[]{1.2, 0.0};
    sigma[1] = new double[]{0.0, 1.2};

    double mid = (kernel_size / 2.0);
    float cent = (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{mid, mid});

    for (int i = 0; i < blurKernel.length; i++) {
        int x = i / kernel_size;
        int y = i % kernel_size;
        blurKernel[i] = blurPeakHeight * (float) MultiNormalDist.density(new double[]{mid, mid}, sigma, new double[]{x, y}) / cent;
    }

    ConvolveOp op = new ConvolveOp(new Kernel(kernel_size, kernel_size, blurKernel));

    return op.filter(img, null);

}
项目:pumpernickel    文件:GaussianFilter.java   
/**
 * Make a Gaussian blur kernel.
 */
public static Kernel makeKernel(float radius) {
    int r = (int)Math.ceil(radius);
    int rows = r*2+1;
    float[] matrix = new float[rows];
    float sigma = radius/3;
    float sigma22 = 2*sigma*sigma;
    float sigmaPi2 = 2*ImageMath.PI*sigma;
    float sqrtSigmaPi2 = (float)Math.sqrt(sigmaPi2);
    float radius2 = radius*radius;
    float total = 0;
    int index = 0;
    for (int row = -r; row <= r; row++) {
        float distance = row*row;
        if (distance > radius2)
            matrix[index] = 0;
        else
            matrix[index] = (float)Math.exp(-(distance)/sigma22) / sqrtSigmaPi2;
        total += matrix[index];
        index++;
    }
    for (int i = 0; i < rows; i++)
        matrix[i] /= total;

    return new Kernel(rows, 1, matrix);
}
项目:jdk8u_jdk    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:lookaside_java-1.8.0-openjdk    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:iSeleda    文件:SmartBlurFilter.java   
@Override
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    int width = src.getWidth();
    int height = src.getHeight();

    if (dst == null) {
        dst = createCompatibleDestImage(src, null);
    }

    int[] inPixels = new int[width * height];
    int[] outPixels = new int[width * height];
    getRGB(src, 0, 0, width, height, inPixels);

    Kernel kernel = GaussianFilter.makeKernel(hRadius);
    thresholdBlur(kernel, inPixels, outPixels, width, height, true);
    thresholdBlur(kernel, outPixels, inPixels, height, width, true);

    setRGB(dst, 0, 0, width, height, inPixels);
    return dst;
}
项目:vintagetg    文件:GenLayerBlurAll.java   
@Override
public int[] getInts(int xCoord, int zCoord, int sizeX, int sizeZ) {
    int margin = 10;

    xCoord -= margin;
    zCoord -= margin;
    sizeX += 2*margin;
    sizeZ += 2*margin;

    int[] inInts = this.parent.getInts(xCoord, zCoord, sizeX, sizeZ);
    int[] outInts = IntCache.getIntCache(inInts.length);

    Kernel kernel = makeKernel(radius);

    for (int i = 0; i < iterations; i++) {
        gaussBlurGrayScale(kernel, inInts, outInts, sizeX, sizeZ);
        gaussBlurGrayScale(kernel, outInts, inInts, sizeZ, sizeX);
    }

    return cutMargins(inInts, sizeX, sizeZ, margin);
}
项目:PasswordSafe    文件:ConvolveFilter.java   
/**
 * Convolve a block of pixels.
 * @param kernel the kernel
 * @param inPixels the input pixels
 * @param outPixels the output pixels
 * @param width the width
 * @param height the height
 * @param alpha include alpha channel
 * @param edgeAction what to do at the edges
 */
public static void convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
{
    if(kernel.getHeight() == 1)
    {
        convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction);
    }
    else if(kernel.getWidth() == 1)
    {
        convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction);
    }
    else
    {
        convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction);
    }
}
项目:AvoinApotti    文件:Logic.java   
public static BufferedImage blurImage(BufferedImage image) 
{
    float ninth = 1.0f/9.0f;
    float[] blurKernel = {
            ninth, ninth, ninth,
            ninth, ninth, ninth,
            ninth, ninth, ninth
    };

    Map<RenderingHints.Key, Object> map = new HashMap<RenderingHints.Key, Object>();
    map.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    map.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    map.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    RenderingHints hints = new RenderingHints(map);
    BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel), ConvolveOp.EDGE_NO_OP, hints);

    return op.filter(image, null);
}
项目:Lucee    文件:GaussianFilter.java   
/**
 * Make a Gaussian blur kernel.
    * @param radius the blur radius
    * @return the kernel
 */
public static Kernel makeKernel(float radius) {
    int r = (int)Math.ceil(radius);
    int rows = r*2+1;
    float[] matrix = new float[rows];
    float sigma = radius/3;
    float sigma22 = 2*sigma*sigma;
    float sigmaPi2 = 2*ImageMath.PI*sigma;
    float sqrtSigmaPi2 = (float)Math.sqrt(sigmaPi2);
    float radius2 = radius*radius;
    float total = 0;
    int index = 0;
    for (int row = -r; row <= r; row++) {
        float distance = row*row;
        if (distance > radius2)
            matrix[index] = 0;
        else
            matrix[index] = (float)Math.exp(-(distance)/sigma22) / sqrtSigmaPi2;
        total += matrix[index];
        index++;
    }
    for (int i = 0; i < rows; i++)
        matrix[i] /= total;

    return new Kernel(rows, 1, matrix);
}
项目:Lucee4    文件:SmartBlurFilter.java   
public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
      int width = src.getWidth();
      int height = src.getHeight();

      if ( dst == null )
          dst = createCompatibleDestImage( src, null );

      int[] inPixels = new int[width*height];
      int[] outPixels = new int[width*height];
      getRGB( src, 0, 0, width, height, inPixels );

Kernel kernel = GaussianFilter.makeKernel(hRadius);
thresholdBlur( kernel, inPixels, outPixels, width, height, true );
thresholdBlur( kernel, outPixels, inPixels, height, width, true );

      setRGB( dst, 0, 0, width, height, inPixels );
      return dst;
  }
项目:Lucee4    文件:ImageFilterKernel.java   
public static Object call(PageContext pc, double width, double height, Object oData) throws PageException {

    float[] data=null;
    if(oData instanceof float[])
        data=(float[]) oData;
    else if(Decision.isNativeArray(oData)) {
        data=toFloatArray(pc,oData);
    }
    else if(Decision.isArray(oData)) {
        data=toFloatArray(pc,Caster.toNativeArray(oData));
    }
    else 
        throw new FunctionException(pc, "", 3, "data", "cannot cast data to a float array");

    return new Kernel(Caster.toIntValue(width),Caster.toIntValue(height),data);
}
项目:infobip-open-jdk-8    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:jdk8u-dev-jdk    文件:BufferedBufImgOps.java   
private static void enableConvolveOp(RenderQueue rq,
                                     SurfaceData srcData,
                                     ConvolveOp cop)
{
    // assert rq.lock.isHeldByCurrentThread();
    boolean edgeZero =
        cop.getEdgeCondition() == ConvolveOp.EDGE_ZERO_FILL;
    Kernel kernel = cop.getKernel();
    int kernelWidth = kernel.getWidth();
    int kernelHeight = kernel.getHeight();
    int kernelSize = kernelWidth * kernelHeight;
    int sizeofFloat = 4;
    int totalBytesRequired = 4 + 8 + 12 + (kernelSize * sizeofFloat);

    RenderBuffer buf = rq.getBuffer();
    rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
    buf.putInt(ENABLE_CONVOLVE_OP);
    buf.putLong(srcData.getNativeOps());
    buf.putInt(edgeZero ? 1 : 0);
    buf.putInt(kernelWidth);
    buf.putInt(kernelHeight);
    buf.put(kernel.getKernelData(null));
}
项目:webcamstudio    文件:SmartBlurFilter.java   
@Override
  public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
      int width = src.getWidth();
      int height = src.getHeight();

      if ( dst == null ) {
          dst = createCompatibleDestImage( src, null );
      }

      int[] inPixels = new int[width*height];
      int[] outPixels = new int[width*height];
      getRGB( src, 0, 0, width, height, inPixels );

Kernel kernel = GaussianFilter.makeKernel(hRadius);
thresholdBlur( kernel, inPixels, outPixels, width, height, true );
thresholdBlur( kernel, outPixels, inPixels, height, width, true );

      setRGB( dst, 0, 0, width, height, inPixels );
      return dst;
  }
项目:Lucee    文件:SmartBlurFilter.java   
@Override
public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
       int width = src.getWidth();
       int height = src.getHeight();

       if ( dst == null )
           dst = createCompatibleDestImage( src, null );

       int[] inPixels = new int[width*height];
       int[] outPixels = new int[width*height];
       getRGB( src, 0, 0, width, height, inPixels );

    Kernel kernel = GaussianFilter.makeKernel(hRadius);
    thresholdBlur( kernel, inPixels, outPixels, width, height, true );
    thresholdBlur( kernel, outPixels, inPixels, height, width, true );

       setRGB( dst, 0, 0, width, height, inPixels );
       return dst;
   }
项目:Lucee    文件:ImageFilterKernel.java   
public static Object call(PageContext pc, double width, double height, Object oData) throws PageException {

    float[] data=null;
    if(oData instanceof float[])
        data=(float[]) oData;
    else if(Decision.isNativeArray(oData)) {
        data=toFloatArray(pc,oData);
    }
    else if(Decision.isArray(oData)) {
        data=toFloatArray(pc,Caster.toNativeArray(oData));
    }
    else 
        throw new FunctionException(pc, "", 3, "data", "cannot cast data to a float array");

    return new Kernel(Caster.toIntValue(width),Caster.toIntValue(height),data);
}
项目:trashjam2017    文件:ShadowEffect.java   
/**
 * Apply blurring to the generate image
 * 
 * @param image The image to be blurred
 */
private void blur(BufferedImage image) {
    float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1];
    Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix);
    Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints);
    ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints);
    BufferedImage scratchImage = EffectUtil.getScratchImage();
    for (int i = 0; i < blurPasses; i++) {
        gaussianOp1.filter(image, scratchImage);
        gaussianOp2.filter(scratchImage, image);
    }
}
项目:incubator-netbeans    文件:ConvolveWidget.java   
/**
 * Creates a convolve widget with a specified ColvolveOp.
 * @param scene the scene
 * @param convolveOp the convolve operation
 */
public ConvolveWidget (Scene scene, ConvolveOp convolveOp) {
    super (scene);
    this.convolveOp = convolveOp;
    Kernel kernel = convolveOp.getKernel ();
    setBorder (BorderFactory.createEmptyBorder (kernel.getWidth (), kernel.getHeight ()));
}
项目:Progetto-C    文件:ShadowEffect.java   
/**
 * Apply blurring to the generate image
 * 
 * @param image The image to be blurred
 */
private void blur(BufferedImage image) {
    float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1];
    Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix);
    Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints);
    ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints);
    BufferedImage scratchImage = EffectUtil.getScratchImage();
    for (int i = 0; i < blurPasses; i++) {
        gaussianOp1.filter(image, scratchImage);
        gaussianOp2.filter(scratchImage, image);
    }
}
项目:oscm    文件:ImageProducer.java   
/**
 * @param bimage
 */
private static BufferedImage blurImage(final BufferedImage bimage) {
    float[] fs = new float[] { 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f,
            1f / 9f, 1f / 9f, 1f / 9f, 1f / 9f };
    final Kernel kernel = new Kernel(3, 3, fs);
    final BufferedImageOp op = new ConvolveOp(kernel);
    return op.filter(bimage, null);
}
项目:BaseClient    文件:ShadowEffect.java   
/**
 * Apply blurring to the generate image
 * 
 * @param image The image to be blurred
 */
private void blur(BufferedImage image) {
    float[] matrix = GAUSSIAN_BLUR_KERNELS[blurKernelSize - 1];
    Kernel gaussianBlur1 = new Kernel(matrix.length, 1, matrix);
    Kernel gaussianBlur2 = new Kernel(1, matrix.length, matrix);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    ConvolveOp gaussianOp1 = new ConvolveOp(gaussianBlur1, ConvolveOp.EDGE_NO_OP, hints);
    ConvolveOp gaussianOp2 = new ConvolveOp(gaussianBlur2, ConvolveOp.EDGE_NO_OP, hints);
    BufferedImage scratchImage = EffectUtil.getScratchImage();
    for (int i = 0; i < blurPasses; i++) {
        gaussianOp1.filter(image, scratchImage);
        gaussianOp2.filter(scratchImage, image);
    }
}
项目:Svg2AndroidXml    文件:AssetUtil.java   
/**
 * Applies a gaussian blur of the given radius to the given {@link BufferedImage} using a kernel
 * convolution.
 *
 * @param source The source image.
 * @param radius The blur radius, in pixels.
 * @return A new, blurred image, or the source image if no blur is performed.
 */
public static BufferedImage blurredImage(BufferedImage source, double radius) {
    if (radius == 0) {
        return source;
    }
    final int r = (int) Math.ceil(radius);
    final int rows = r * 2 + 1;
    final float[] kernelData = new float[rows * rows];
    final double sigma = radius / 3;
    final double sigma22 = 2 * sigma * sigma;
    final double sqrtPiSigma22 = Math.sqrt(Math.PI * sigma22);
    final double radius2 = radius * radius;
    double total = 0;
    int index = 0;
    double distance2;
    int x, y;
    for (y = -r; y <= r; y++) {
        for (x = -r; x <= r; x++) {
            distance2 = 1.0 * x * x + 1.0 * y * y;
            if (distance2 > radius2) {
                kernelData[index] = 0;
            } else {
                kernelData[index] = (float) (Math.exp(-distance2 / sigma22) / sqrtPiSigma22);
            }
            total += kernelData[index];
            ++index;
        }
    }
    for (index = 0; index < kernelData.length; index++) {
        kernelData[index] /= total;
    }
    // We first pad the image so the kernel can operate at the edges.
    BufferedImage paddedSource = paddedImage(source, r);
    BufferedImage blurredPaddedImage = operatedImage(paddedSource, new ConvolveOp(
            new Kernel(rows, rows, kernelData), ConvolveOp.EDGE_ZERO_FILL, null));
    return blurredPaddedImage.getSubimage(r, r, source.getWidth(), source.getHeight());
}
项目:OpenJSharp    文件:BufferedBufImgOps.java   
/**************************** ConvolveOp support ****************************/

    public static boolean isConvolveOpValid(ConvolveOp cop) {
        Kernel kernel = cop.getKernel();
        int kw = kernel.getWidth();
        int kh = kernel.getHeight();
        // REMIND: we currently can only handle 3x3 and 5x5 kernels,
        //         but hopefully this is just a temporary restriction;
        //         see native shader comments for more details
        if (!(kw == 3 && kh == 3) && !(kw == 5 && kh == 5)) {
            return false;
        }
        return true;
    }
项目:jdk8u-jdk    文件:BufferedBufImgOps.java   
/**************************** ConvolveOp support ****************************/

    public static boolean isConvolveOpValid(ConvolveOp cop) {
        Kernel kernel = cop.getKernel();
        int kw = kernel.getWidth();
        int kh = kernel.getHeight();
        // REMIND: we currently can only handle 3x3 and 5x5 kernels,
        //         but hopefully this is just a temporary restriction;
        //         see native shader comments for more details
        if (!(kw == 3 && kh == 3) && !(kw == 5 && kh == 5)) {
            return false;
        }
        return true;
    }
项目:jdk8u-jdk    文件:EdgeNoOpCrash.java   
private static ConvolveOp createConvolveOp(int edgeHint) {
    final int kw = 3;
    final int kh = 3;
    float[] kdata = new float[kw * kh];
    float v = 1f / kdata.length;
    Arrays.fill(kdata, v);

    Kernel k = new Kernel(kw, kh, kdata);
    ConvolveOp op = new ConvolveOp(k, edgeHint, null);

    return op;
}
项目:jdk8u-jdk    文件:OpCompatibleImageTest.java   
public OpCompatibleImageTest() {
    final Kernel kernel = new Kernel(3, 3,
            new float[] {
        1f/9f, 1f/9f, 1f/9f,
        1f/9f, 1f/9f, 1f/9f,
        1f/9f, 1f/9f, 1f/9f});
    op = new ConvolveOp(kernel);
}
项目:jdk8u-jdk    文件:MlibOpsTest.java   
private static BufferedImageOp getConvolveOp() {
    int kw = 3;
    int kh = 3;
    int size = kw * kh;
    float[] kdata = new float[size];
    Arrays.fill(kdata, 1.0f / size);

    Kernel k  = new Kernel(kw, kh, kdata);
    return new ConvolveOp(k);
}
项目:jdk8u-jdk    文件:SamePackingTypeTest.java   
private static BufferedImageOp createTestOp() {
    final int size = 1;
    final float v = 1f / (size * size);
    final float[] k_data = new float[size * size];
    Arrays.fill(k_data, v);

    Kernel k = new Kernel(size, size, k_data);
    return new ConvolveOp(k);
}
项目:openjdk-jdk10    文件:BufferedBufImgOps.java   
/**************************** ConvolveOp support ****************************/

    public static boolean isConvolveOpValid(ConvolveOp cop) {
        Kernel kernel = cop.getKernel();
        int kw = kernel.getWidth();
        int kh = kernel.getHeight();
        // REMIND: we currently can only handle 3x3 and 5x5 kernels,
        //         but hopefully this is just a temporary restriction;
        //         see native shader comments for more details
        if (!(kw == 3 && kh == 3) && !(kw == 5 && kh == 5)) {
            return false;
        }
        return true;
    }
项目:openjdk-jdk10    文件:EdgeNoOpCrash.java   
private static ConvolveOp createConvolveOp(int edgeHint) {
    final int kw = 3;
    final int kh = 3;
    float[] kdata = new float[kw * kh];
    float v = 1f / kdata.length;
    Arrays.fill(kdata, v);

    Kernel k = new Kernel(kw, kh, kdata);
    ConvolveOp op = new ConvolveOp(k, edgeHint, null);

    return op;
}
项目:openjdk-jdk10    文件:OpCompatibleImageTest.java   
public OpCompatibleImageTest() {
    final Kernel kernel = new Kernel(3, 3,
            new float[] {
        1f/9f, 1f/9f, 1f/9f,
        1f/9f, 1f/9f, 1f/9f,
        1f/9f, 1f/9f, 1f/9f});
    op = new ConvolveOp(kernel);
}