1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.imaging.operations.cropresize.resizers; |
35 |
|
|
36 |
|
import info.magnolia.imaging.operations.cropresize.Coords; |
37 |
|
import info.magnolia.imaging.operations.cropresize.Resizer; |
38 |
|
import info.magnolia.imaging.operations.cropresize.Size; |
39 |
|
|
40 |
|
import java.awt.Graphics2D; |
41 |
|
import java.awt.RenderingHints; |
42 |
|
import java.awt.image.BufferedImage; |
43 |
|
import java.awt.image.ColorModel; |
44 |
|
import java.awt.image.WritableRaster; |
45 |
|
import java.util.HashMap; |
46 |
|
import java.util.Map; |
47 |
|
|
48 |
|
|
49 |
|
@link |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.25 |
|
51 |
|
public class BasicResizer implements Resizer { |
52 |
|
|
53 |
|
|
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
55 |
1 |
private static final Map<String, Object> INTERPOLATION_HINTS = new HashMap<String, Object>() {{... |
56 |
1 |
put("nearest_neighbor", RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
57 |
1 |
put("bilinear", RenderingHints.VALUE_INTERPOLATION_BILINEAR); |
58 |
1 |
put("bicubic", RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
59 |
|
}}; |
60 |
|
|
61 |
|
private String interpolation = "bilinear"; |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
63 |
36 |
@Override... |
64 |
|
public BufferedImage resize(BufferedImage src, Coords srcCoords, Size targetSize) { |
65 |
36 |
final ColorModel cm = src.getColorModel(); |
66 |
36 |
final WritableRaster raster = cm.createCompatibleWritableRaster(targetSize.getWidth(), targetSize.getHeight()); |
67 |
35 |
final BufferedImage dst = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null); |
68 |
35 |
final Graphics2D g = dst.createGraphics(); |
69 |
|
|
70 |
35 |
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, getInterpolationHint()); |
71 |
|
|
72 |
35 |
g.drawImage(src, 0, 0, targetSize.getWidth(), targetSize.getHeight(), srcCoords.getX1(), srcCoords.getY1(), srcCoords.getX2(), srcCoords.getY2(), null); |
73 |
35 |
g.dispose(); |
74 |
35 |
return dst; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
41 |
protected Object getInterpolationHint() {... |
78 |
41 |
return INTERPOLATION_HINTS.get(interpolation); |
79 |
|
} |
80 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
81 |
|
public String getInterpolation() {... |
82 |
|
return interpolation; |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@see |
89 |
|
|
90 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
91 |
|
public void setInterpolation(String interpolation) {... |
92 |
|
this.interpolation = interpolation; |
93 |
|
} |
94 |
|
} |