1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dishevelled.iconbundle.impl;
25
26 import java.awt.Color;
27
28 import java.awt.image.Raster;
29 import java.awt.image.WritableRaster;
30
31
32
33
34
35
36 final class SelectionRasterOp
37 extends AbstractRasterOp
38 {
39
40 private static final int PIXEL_ARRAY_SIZE = 4;
41
42
43 private static final int WHITE = 255;
44
45
46 private final Color selectionColor;
47
48
49
50
51
52
53
54
55 public SelectionRasterOp(final Color selectionColor)
56 {
57 this.selectionColor = selectionColor;
58 }
59
60
61
62 public WritableRaster filter(final Raster src, final WritableRaster dest)
63 {
64 if (selectionColor != null)
65 {
66 float[] pixel = new float[PIXEL_ARRAY_SIZE];
67 float[] selection = selectionColor.getColorComponents(new float[PIXEL_ARRAY_SIZE]);
68
69 for (int x = 0, w = src.getWidth(); x < w; x++)
70 {
71 for (int y = 0, h = src.getHeight(); y < h; y++)
72 {
73 pixel = src.getPixel(x, y, pixel);
74 pixel[0] = Math.min(pixel[0], selection[0] * WHITE);
75 pixel[1] = Math.min(pixel[1], selection[1] * WHITE);
76 pixel[2] = Math.min(pixel[2], selection[2] * WHITE);
77
78 dest.setPixel(x, y, pixel);
79 }
80 }
81 }
82 return dest;
83 }
84 }