/*
 * @(#) ConvolveOpFactory.java 1.0 99/10/4
 * Copyright (c) 1999 Larry Rodrigues
 */
package com.vistech.imagedata;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class ConvolveOpFactory {

   public static ConvolveOp getBlurOp(){
      float blurmatrix[] = {0.0625f, 0.125f, 0.0625f,
                          0.125f, 0.25f, 0.125f,
                          0.0625f, 0.125f, 0.0625f};
      Kernel blurKernel = new Kernel(3,3,blurmatrix);
      return getConvolveOp( blurKernel);
   }

   public static ConvolveOp getSharpOp(){
      float sharpMatrix[] = {-1.0f, -1.0f, -1.0f,
                             -1.0f, 9.0f, -1.0f,
                             -1.0f, -1.0f, -1.0f};
      Kernel sharpKernel = new Kernel (3,3, sharpMatrix);
      return getConvolveOp( sharpKernel);
   }

    public static ConvolveOp getSobelVertOp(){
      float sbvMatrix[] = {-1.0f, -2.0f, -1.0f,
                            0.0f,  0.0f,  0.0f,
                            1.0f,  2.0f,  1.0f};
       Kernel kernel = new Kernel (3,3, sbvMatrix);
       return getConvolveOp(kernel);
    }

    public static ConvolveOp getSobelHorizOp(){
      float sbhMatrix[] = {1.0f, -0.0f, -1.0f,
                           2.0f,  0.0f, -2.0f,
                           1.0f,  0.0f, -1.0f};
       Kernel kernel = new Kernel (3,3, sbhMatrix);
       return getConvolveOp(kernel);
    }

    public static ConvolveOp getRobertsHorizOp(){
      float rbhMatrix[] = {0.0f, 0.0f, -1.0f,
                           0.0f,  1.0f, 0.0f,
                           0.0f,  0.0f, 0.0f};

       Kernel kernel = new Kernel (3,3, rbhMatrix);
       return getConvolveOp(kernel);
    }

    public static ConvolveOp getRobertsVertOp(){
       float rbvMatrix[] = {-1.0f, 0.0f, 0.0f,
                           0.0f,  1.0f, 0.0f,
                           0.0f,  0.0f, 0.0f};
       Kernel kernel = new Kernel (3,3, rbvMatrix);
       return getConvolveOp(kernel);
    }

    public static ConvolveOp getConvolveOp(Kernel kernel) {

      RenderingHints hints =
                     new RenderingHints(RenderingHints.KEY_RENDERING,
                                        RenderingHints.VALUE_RENDER_QUALITY);
      ConvolveOp op = new ConvolveOp( kernel,
                                      ConvolveOp.EDGE_NO_OP,
                                      hints);
      return op;
   }



   public static BufferedImage createDestImage(BufferedImage srcImage, ConvolveOp op){
      BufferedImage destImage = op.createCompatibleDestImage(srcImage,
                                                  srcImage.getColorModel());
      destImage = op.filter(srcImage, destImage);
      return destImage;
   }

}
