1 /*******************************************************************************
2 * Copyright (c) 2020 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.scenegraph.g2d.color;
14 import java.awt.Color;
16 public class RGBAColorFilter implements ColorFilter {
18 private double r, g, b, a;
20 public RGBAColorFilter(double r, double g, double b, double a) {
28 public Color filter(Color c) {
29 int avg = (c.getRed() + c.getGreen() + c.getBlue()) / 3;
30 int R = Math.min(255, (int)(avg * r));
31 int G = Math.min(255, (int)(avg * g));
32 int B = Math.min(255, (int)(avg * b));
33 int A = Math.min(255, (int)(c.getAlpha() * a));
34 Color c2 = new Color(R, G, B, A);
39 public int hashCode() {
43 temp = Double.doubleToLongBits(a);
44 result = prime * result + (int) (temp ^ (temp >>> 32));
45 temp = Double.doubleToLongBits(b);
46 result = prime * result + (int) (temp ^ (temp >>> 32));
47 temp = Double.doubleToLongBits(g);
48 result = prime * result + (int) (temp ^ (temp >>> 32));
49 temp = Double.doubleToLongBits(r);
50 result = prime * result + (int) (temp ^ (temp >>> 32));
55 public boolean equals(Object obj) {
60 if (getClass() != obj.getClass())
62 RGBAColorFilter other = (RGBAColorFilter) obj;
63 if (Double.doubleToLongBits(a) != Double.doubleToLongBits(other.a))
65 if (Double.doubleToLongBits(b) != Double.doubleToLongBits(other.b))
67 if (Double.doubleToLongBits(g) != Double.doubleToLongBits(other.g))
69 if (Double.doubleToLongBits(r) != Double.doubleToLongBits(other.r))