@Override
  @SuppressWarnings("AssignmentReplaceableWithOperatorAssignment")
  public int filterRGB(int x, int y, int rgb) {
    // Use NTSC conversion formula.
    int gray = (int)(0.30 * (rgb >> 16 & 0xff) +
                     0.59 * (rgb >> 8 & 0xff) +
                     0.11 * (rgb & 0xff));

    if (brightness >= 0) {
      gray = (int)((gray + brightness * 255) / (1 + brightness));
    }
    else {
      gray = (int)(gray / (1 - brightness));
    }

    if (contrast >= 0) {
      if (gray >= 127) {
        gray = (int)(gray + (255 - gray) * contrast);
      }
      else {
        gray = (int)(gray - gray * contrast);
      }
    }
    else {
      gray = (int)(127 + (gray - 127) * (contrast + 1));
    }

    int a = ((rgb >> 24) & 0xff) * alpha / 100;

    return (a << 24) | (gray << 16) | (gray << 8) | gray;
  }
@Override
  @SuppressWarnings("AssignmentReplaceableWithOperatorAssignment")
  public int filterRGB(int x, int y, int rgb)