/** Builds a TYPE_SATURATE instance */
 public static ColorMatrixRable buildSaturate(float s) {
   ColorMatrixRable8Bit filter = new ColorMatrixRable8Bit();
   filter.type = TYPE_SATURATE;
   filter.matrix =
       new float[][] {
         {0.213f + 0.787f * s, 0.715f - 0.715f * s, 0.072f - 0.072f * s, 0, 0},
         {0.213f - 0.213f * s, 0.715f + 0.285f * s, 0.072f - 0.072f * s, 0, 0},
         {0.213f - 0.213f * s, 0.715f - 0.715f * s, 0.072f + 0.928f * s, 0, 0},
         {0, 0, 0, 1, 0}
       };
   return filter;
 }
  /**
   * Builds a TYPE_HUE_ROTATE instance.
   *
   * @param a angle, in radian
   */
  public static ColorMatrixRable buildHueRotate(float a) {
    ColorMatrixRable8Bit filter = new ColorMatrixRable8Bit();
    filter.type = TYPE_HUE_ROTATE;

    float cos = (float) Math.cos(a);
    float sin = (float) Math.sin(a);

    // System.out.println("sin : " + sin + " cos : " + cos);

    float a00 = 0.213f + cos * 0.787f - sin * 0.213f;
    float a10 = 0.213f - cos * 0.212f + sin * 0.143f;
    float a20 = 0.213f - cos * 0.213f - sin * 0.787f;

    float a01 = 0.715f - cos * 0.715f - sin * 0.715f;
    float a11 = 0.715f + cos * 0.285f + sin * 0.140f;
    float a21 = 0.715f - cos * 0.715f + sin * 0.715f;

    float a02 = 0.072f - cos * 0.072f + sin * 0.928f;
    float a12 = 0.072f - cos * 0.072f - sin * 0.283f;
    float a22 = 0.072f + cos * 0.928f + sin * 0.072f;

    filter.matrix =
        new float[][] {
          {a00, a01, a02, 0, 0},
          {a10, a11, a12, 0, 0},
          {a20, a21, a22, 0, 0},
          {0, 0, 0, 1, 0}
        };

    /*for(int i=0; i<4; i++){
    for(int j=0; j<5; j++)
        System.out.print(filter.matrix[i][j] + " ");
    System.out.println();
    }*/

    return filter;
  }
  /** Builds a TYPE_MATRIX instance */
  public static ColorMatrixRable buildMatrix(float[][] matrix) {
    if (matrix == null) {
      throw new IllegalArgumentException();
    }

    if (matrix.length != 4) {
      throw new IllegalArgumentException();
    }

    float[][] newMatrix = new float[4][];

    for (int i = 0; i < 4; i++) {
      float[] m = matrix[i];
      if (m == null) {
        throw new IllegalArgumentException();
      }
      if (m.length != 5) {
        throw new IllegalArgumentException();
      }
      newMatrix[i] = new float[5];
      for (int j = 0; j < 5; j++) {
        newMatrix[i][j] = m[j];
      }
    }

    /*for(int i=0; i<4; i++){
    for(int j=0; j<5; j++)
        System.out.print(newMatrix[i][j] + " ");
    System.out.println();
    }*/

    ColorMatrixRable8Bit filter = new ColorMatrixRable8Bit();
    filter.type = TYPE_MATRIX;
    filter.matrix = newMatrix;
    return filter;
  }
 /** Builds a TYPE_LUMINANCE_TO_ALPHA instance */
 public static ColorMatrixRable buildLuminanceToAlpha() {
   ColorMatrixRable8Bit filter = new ColorMatrixRable8Bit();
   filter.type = TYPE_LUMINANCE_TO_ALPHA;
   filter.matrix = MATRIX_LUMINANCE_TO_ALPHA;
   return filter;
 }