Changeset 8729 in josm for trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
- Timestamp:
- 2015-09-04T10:32:05+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r8723 r8729 20 20 import java.awt.image.ConvolveOp; 21 21 import java.awt.image.Kernel; 22 import java.awt.image.LookupOp; 23 import java.awt.image.ShortLookupTable; 22 24 import java.text.AttributedCharacterIterator; 23 25 import java.text.AttributedString; … … 75 77 protected double dy = 0.0; 76 78 79 protected GammaImageProcessor gammaImageProcessor = new GammaImageProcessor(); 80 77 81 private final ImageryAdjustAction adjustAction = new ImageryAdjustAction(this); 78 82 … … 92 96 } 93 97 addImageProcessor(createSharpener(PROP_SHARPEN_LEVEL.get())); 98 addImageProcessor(gammaImageProcessor); 94 99 } 95 100 … … 247 252 BufferedImageOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); 248 253 return createImageProcessor(op, false); 254 } 255 256 /** 257 * An image processor which adjusts the gamma value of an image. 258 */ 259 public static class GammaImageProcessor implements ImageProcessor { 260 private double gamma = 1; 261 final short[] gammaChange = new short[256]; 262 private LookupOp op3 = new LookupOp(new ShortLookupTable(0, new short[][]{gammaChange, gammaChange, gammaChange}), null); 263 private LookupOp op4 = new LookupOp(new ShortLookupTable(0, new short[][]{gammaChange, gammaChange, gammaChange, gammaChange}), null); 264 265 /** 266 * Returns the currently set gamma value. 267 */ 268 public double getGamma() { 269 return gamma; 270 } 271 272 /** 273 * Sets a new gamma value, {@code 1} stands for no correction. 274 */ 275 public void setGamma(double gamma) { 276 this.gamma = gamma; 277 for (int i = 0; i < 256; i++) { 278 gammaChange[i] = (short) (255 * Math.pow(i / 255., gamma)); 279 } 280 } 281 282 private LookupOp getOp(int bands) { 283 if (gamma == 1) { 284 return null; 285 } else if (bands == 3) { 286 return op3; 287 } else if (bands == 4) { 288 return op4; 289 } else { 290 return null; 291 } 292 } 293 294 @Override 295 public BufferedImage process(BufferedImage image) { 296 final LookupOp op = getOp(image.getRaster().getNumBands()); 297 final BufferedImage to = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB); 298 return op == null ? image : op.filter(image, to); 299 } 300 } 301 302 /** 303 * Returns the currently set gamma value. 304 */ 305 public double getGamma() { 306 return gammaImageProcessor.getGamma(); 307 } 308 309 /** 310 * Sets a new gamma value, {@code 1} stands for no correction. 311 */ 312 public void setGamma(double gamma) { 313 gammaImageProcessor.setGamma(gamma); 249 314 } 250 315
Note:
See TracChangeset
for help on using the changeset viewer.
