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 |
|
|
|
|
| 81.2% |
Uncovered Elements: 6 (32) |
Complexity: 8 |
Complexity Density: 0.4 |
|
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 |
16 |
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 |
|
|
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
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 |
26 |
if (loaded == null) { |
74 |
0 |
throw new ImagingException("Could not load image for " + filterParams); |
75 |
|
} |
76 |
|
|
77 |
26 |
int imageType = ImageUtil.getImageType(loaded); |
78 |
26 |
final BufferedImage img = new BufferedImage(loaded.getWidth(), loaded.getHeight(), imageType); |
79 |
|
|
80 |
26 |
final Graphics2D g = img.createGraphics(); |
81 |
|
|
82 |
26 |
if (backgroundColor != null) { |
83 |
1 |
g.setColor(backgroundColor); |
84 |
1 |
g.fill(new Rectangle(0, 0, img.getWidth(), img.getHeight())); |
85 |
|
} |
86 |
26 |
g.drawImage(loaded, null, 0, 0); |
87 |
|
|
88 |
|
|
89 |
26 |
g.dispose(); |
90 |
26 |
return img; |
91 |
|
} |
92 |
|
|
93 |
|
protected abstract BufferedImage loadSource(P filterParams) throws ImagingException; |
94 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
95 |
19 |
protected BufferedImage doReadAndClose(InputStream inputStream) throws IOException, ImagingException {... |
96 |
19 |
if (inputStream == null) { |
97 |
0 |
throw new IOException("No input"); |
98 |
|
} |
99 |
19 |
try { |
100 |
19 |
return imageDecoder.read(inputStream); |
101 |
|
} finally { |
102 |
19 |
inputStream.close(); |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
106 |
|
public ImageDecoder getImageDecoder() {... |
107 |
|
return imageDecoder; |
108 |
|
} |
109 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
110 |
|
public void setImageDecoder(ImageDecoder imageDecoder) {... |
111 |
|
this.imageDecoder = imageDecoder; |
112 |
|
} |
113 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
114 |
|
public Color getBackgroundColor() {... |
115 |
|
return backgroundColor; |
116 |
|
} |
117 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
118 |
|
public void setBackgroundColor(Color backgroundColor) {... |
119 |
|
this.backgroundColor = backgroundColor; |
120 |
|
} |
121 |
|
} |