1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.imagery;
|
---|
3 |
|
---|
4 | import java.util.Arrays;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.concurrent.CopyOnWriteArrayList;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.gui.layer.ImageProcessor;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * This class holds the filter settings for an imagery layer.
|
---|
12 | * @author Michael Zangl
|
---|
13 | * @since 10547
|
---|
14 | */
|
---|
15 | public class ImageryFilterSettings {
|
---|
16 |
|
---|
17 | protected GammaImageProcessor gammaImageProcessor = new GammaImageProcessor();
|
---|
18 | protected SharpenImageProcessor sharpenImageProcessor = new SharpenImageProcessor();
|
---|
19 | protected ColorfulImageProcessor collorfulnessImageProcessor = new ColorfulImageProcessor();
|
---|
20 | private final List<FilterChangeListener> filterChangeListeners = new CopyOnWriteArrayList<>();
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Returns the currently set gamma value.
|
---|
24 | * @return the currently set gamma value
|
---|
25 | */
|
---|
26 | public double getGamma() {
|
---|
27 | return gammaImageProcessor.getGamma();
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Sets a new gamma value, {@code 1} stands for no correction.
|
---|
32 | * @param gamma new gamma value
|
---|
33 | */
|
---|
34 | public void setGamma(double gamma) {
|
---|
35 | gammaImageProcessor.setGamma(gamma);
|
---|
36 | fireListeners();
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Gets the current sharpen level.
|
---|
41 | * @return The sharpen level.
|
---|
42 | */
|
---|
43 | public double getSharpenLevel() {
|
---|
44 | return sharpenImageProcessor.getSharpenLevel();
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Sets the sharpen level for the layer.
|
---|
49 | * <code>1</code> means no change in sharpness.
|
---|
50 | * Values in range 0..1 blur the image.
|
---|
51 | * Values above 1 are used to sharpen the image.
|
---|
52 | * @param sharpenLevel The sharpen level.
|
---|
53 | */
|
---|
54 | public void setSharpenLevel(double sharpenLevel) {
|
---|
55 | sharpenImageProcessor.setSharpenLevel((float) sharpenLevel);
|
---|
56 | fireListeners();
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Gets the colorfulness of this image.
|
---|
61 | * @return The colorfulness
|
---|
62 | */
|
---|
63 | public double getColorfulness() {
|
---|
64 | return collorfulnessImageProcessor.getColorfulness();
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Sets the colorfulness of this image.
|
---|
69 | * 0 means grayscale.
|
---|
70 | * 1 means normal colorfulness.
|
---|
71 | * Values greater than 1 are allowed.
|
---|
72 | * @param colorfulness The colorfulness.
|
---|
73 | */
|
---|
74 | public void setColorfulness(double colorfulness) {
|
---|
75 | collorfulnessImageProcessor.setColorfulness(colorfulness);
|
---|
76 | fireListeners();
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Gets the image processors for this setting.
|
---|
81 | * @return The processors in the order in which they should be applied.
|
---|
82 | */
|
---|
83 | public List<ImageProcessor> getProcessors() {
|
---|
84 | return Arrays.asList(collorfulnessImageProcessor, gammaImageProcessor, sharpenImageProcessor);
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Adds a filter change listener
|
---|
89 | * @param l The listener
|
---|
90 | */
|
---|
91 | public void addFilterChangeListener(FilterChangeListener l) {
|
---|
92 | filterChangeListeners.add(l);
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Removes a filter change listener
|
---|
97 | * @param l The listener
|
---|
98 | */
|
---|
99 | public void removeFilterChangeListener(FilterChangeListener l) {
|
---|
100 | filterChangeListeners.remove(l);
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void fireListeners() {
|
---|
104 | for (FilterChangeListener l : filterChangeListeners) {
|
---|
105 | l.filterChanged();
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * A listener that listens to filter changes
|
---|
111 | * @author Michael Zangl
|
---|
112 | */
|
---|
113 | public interface FilterChangeListener {
|
---|
114 | /**
|
---|
115 | * Invoked when the filter is changed.
|
---|
116 | */
|
---|
117 | void filterChanged();
|
---|
118 | }
|
---|
119 | }
|
---|