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.load; |
35 |
|
|
36 |
|
import info.magnolia.imaging.ImagingException; |
37 |
|
import info.magnolia.imaging.ParameterProvider; |
38 |
|
import info.magnolia.imaging.operations.ImageOperation; |
39 |
|
import info.magnolia.imaging.util.ImageUtil; |
40 |
|
import info.magnolia.objectfactory.Components; |
41 |
|
|
42 |
|
import java.awt.Color; |
43 |
|
import java.awt.Graphics2D; |
44 |
|
import java.awt.Rectangle; |
45 |
|
import java.awt.image.BufferedImage; |
46 |
|
import java.io.IOException; |
47 |
|
import java.io.InputStream; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
|
|
|
| 83.3% |
Uncovered Elements: 6 (36) |
Complexity: 10 |
Complexity Density: 0.45 |
|
56 |
|
public abstract class AbstractLoader<P extends ParameterProvider<?>> implements ImageOperation<P> { |
57 |
|
private ImageDecoder imageDecoder = Components.getComponentProvider().newInstance(ImageDecoder.class); |
58 |
|
private Color backgroundColor; |
59 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
60 |
17 |
protected AbstractLoader() {... |
61 |
|
} |
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
63 |
8 |
protected AbstractLoader(Color backgroundColor) {... |
64 |
8 |
this.backgroundColor = backgroundColor; |
65 |
|
} |
66 |
|
|
|
|
| 83.3% |
Uncovered Elements: 4 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
67 |
29 |
@Override... |
68 |
|
public BufferedImage apply(BufferedImage source, P filterParams) throws ImagingException { |
69 |
29 |
if (source != null) { |
70 |
0 |
throw new ImagingException("This operation currently does not support overlaying images"); |
71 |
|
} |
72 |
29 |
final BufferedImage loaded = loadSource(filterParams); |
73 |
29 |
if (loaded == null) { |
74 |
0 |
throw new ImagingException("Could not load image for " + filterParams); |
75 |
|
} |
76 |
|
|
77 |
29 |
int resolvedTargetImageType = ImageUtil.getImageType(loaded); |
78 |
|
|
79 |
29 |
if (backgroundColor != null || loaded.getType() != resolvedTargetImageType) { |
80 |
9 |
final BufferedImage img = new BufferedImage(loaded.getWidth(), loaded.getHeight(), resolvedTargetImageType); |
81 |
|
|
82 |
9 |
final Graphics2D g = img.createGraphics(); |
83 |
9 |
if (backgroundColor != null) { |
84 |
1 |
g.setColor(backgroundColor); |
85 |
1 |
g.fill(new Rectangle(0, 0, img.getWidth(), img.getHeight())); |
86 |
|
} |
87 |
9 |
g.drawImage(loaded, null, 0, 0); |
88 |
|
|
89 |
9 |
g.dispose(); |
90 |
9 |
return img; |
91 |
|
} |
92 |
20 |
return loaded; |
93 |
|
} |
94 |
|
|
95 |
|
protected abstract BufferedImage loadSource(P filterParams) throws ImagingException; |
96 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
97 |
19 |
protected BufferedImage doReadAndClose(InputStream inputStream) throws IOException, ImagingException {... |
98 |
19 |
if (inputStream == null) { |
99 |
0 |
throw new IOException("No input"); |
100 |
|
} |
101 |
19 |
try { |
102 |
19 |
return imageDecoder.read(inputStream); |
103 |
|
} finally { |
104 |
19 |
inputStream.close(); |
105 |
|
} |
106 |
|
} |
107 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
108 |
|
public ImageDecoder getImageDecoder() {... |
109 |
|
return imageDecoder; |
110 |
|
} |
111 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
112 |
|
public void setImageDecoder(ImageDecoder imageDecoder) {... |
113 |
|
this.imageDecoder = imageDecoder; |
114 |
|
} |
115 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
116 |
|
public Color getBackgroundColor() {... |
117 |
|
return backgroundColor; |
118 |
|
} |
119 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
120 |
|
public void setBackgroundColor(Color backgroundColor) {... |
121 |
|
this.backgroundColor = backgroundColor; |
122 |
|
} |
123 |
|
} |