source: josm/trunk/src/org/openstreetmap/josm/gui/layer/imagery/ColorfulImageProcessor.java@ 12597

Last change on this file since 12597 was 12597, checked in by Don-vip, 7 years ago

see #14794 - checkstyle/javadoc

  • Property svn:eol-style set to native
File size: 2.3 KB
RevLine 
[10547]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.imagery;
3
4import java.awt.image.BufferedImage;
[12594]5import java.util.Collections;
6import java.util.Map;
[10547]7
[12597]8import org.openstreetmap.josm.Main;
[10547]9import org.openstreetmap.josm.gui.layer.ImageProcessor;
[12594]10import org.openstreetmap.josm.io.session.SessionAwareReadApply;
11import org.openstreetmap.josm.tools.Utils;
[10547]12
13/**
14 * Adds or removes the colorfulness of the image.
15 *
16 * @author Michael Zangl
17 * @since 10547
18 */
[12594]19public class ColorfulImageProcessor implements ImageProcessor, SessionAwareReadApply {
[10547]20 private ColorfulFilter op;
[12594]21 private double colorfulness = 1.0;
[10547]22
23 /**
24 * Gets the colorfulness value.
25 * @return The value
26 */
27 public double getColorfulness() {
28 return colorfulness;
29 }
30
31 /**
32 * Sets the colorfulness value. Clamps it to 0+
33 * @param colorfulness The value
34 */
35 public void setColorfulness(double colorfulness) {
36 if (colorfulness < 0) {
37 this.colorfulness = 0;
38 } else {
39 this.colorfulness = colorfulness;
40 }
41
42 if (this.colorfulness < .95 || this.colorfulness > 1.05) {
43 op = new ColorfulFilter(this.colorfulness);
44 } else {
45 op = null;
46 }
47 }
48
49 @Override
50 public BufferedImage process(BufferedImage image) {
51 if (op != null) {
52 return op.filter(image, null);
53 } else {
54 return image;
55 }
56 }
57
58 @Override
[12594]59 public void applyFromPropertiesMap(Map<String, String> properties) {
60 String cStr = properties.get("colorfulness");
61 if (cStr != null) {
62 try {
63 setColorfulness(Double.parseDouble(cStr));
64 } catch (NumberFormatException e) {
[12597]65 if (Main.isTraceEnabled()) {
66 Main.trace(e);
67 }
[12594]68 }
69 }
70 }
71
72 @Override
73 public Map<String, String> toPropertiesMap() {
74 if (Utils.equalsEpsilon(colorfulness, 1.0))
75 return Collections.emptyMap();
76 else
77 return Collections.singletonMap("colorfulness", Double.toString(colorfulness));
78 }
79
80 @Override
[10547]81 public String toString() {
82 return "ColorfulImageProcessor [colorfulness=" + colorfulness + ']';
83 }
84}
Note: See TracBrowser for help on using the repository browser.