]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/color/BWColorFilter.java
Render elements using custom color filters
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / color / BWColorFilter.java
1 /*******************************************************************************
2  * Copyright (c) 2020 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.g2d.color;
13
14 import java.awt.Color;
15
16 public class BWColorFilter implements ColorFilter {
17
18     @Override
19     public Color filter(Color c) {
20         int avg = (c.getRed() + c.getGreen() + c.getBlue()) / 3; 
21         Color c2 = new Color(avg, avg, avg, c.getAlpha());
22         return c2;
23     }
24
25     @Override
26     public int hashCode() {
27         return getClass().hashCode();
28     }
29
30     @Override
31     public boolean equals(Object obj) {
32         if (this == obj)
33             return true;
34         if (obj == null)
35             return false;
36         if (getClass() != obj.getClass())
37             return false;
38         return true;
39     }
40 }