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; |
35 |
|
|
36 |
|
import java.io.Serializable; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
|
|
| 95.2% |
Uncovered Elements: 2 (42) |
Complexity: 12 |
Complexity Density: 0.43 |
|
44 |
|
public class Size implements Serializable { |
45 |
|
private final int width; |
46 |
|
private final int height; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
44 |
public Size(int width, int height) {... |
49 |
44 |
this.width = width; |
50 |
44 |
this.height = height; |
51 |
|
} |
52 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
53 |
|
public int getWidth() {... |
54 |
|
return width; |
55 |
|
} |
56 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
57 |
|
public int getHeight() {... |
58 |
|
return height; |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 5 |
Complexity Density: 0.33 |
|
61 |
32 |
public static Size conformToCropRatio(final Coords cropCoords, final int targetWidth, final int targetHeight) {... |
62 |
32 |
final int effectiveTargetWidth, effectiveTargetHeight; |
63 |
32 |
if (targetWidth <= 0 && targetHeight <= 0) { |
64 |
3 |
effectiveTargetWidth = cropCoords.getWidth(); |
65 |
3 |
effectiveTargetHeight = cropCoords.getHeight(); |
66 |
29 |
} else if (targetWidth <= 0) { |
67 |
3 |
double ratio = (double) targetHeight / (double) cropCoords.getHeight(); |
68 |
3 |
effectiveTargetWidth = (int) (cropCoords.getWidth() * ratio); |
69 |
3 |
effectiveTargetHeight = targetHeight; |
70 |
26 |
} else if (targetHeight <= 0) { |
71 |
3 |
double ratio = (double) targetWidth / (double) cropCoords.getWidth(); |
72 |
3 |
effectiveTargetHeight = (int) (cropCoords.getHeight() * ratio); |
73 |
3 |
effectiveTargetWidth = targetWidth; |
74 |
|
} else { |
75 |
23 |
effectiveTargetWidth = targetWidth; |
76 |
23 |
effectiveTargetHeight = targetHeight; |
77 |
|
} |
78 |
|
|
79 |
32 |
return new Size(effectiveTargetWidth, effectiveTargetHeight); |
80 |
|
} |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
public static Size maxSizeComplyingWithSourceRatio(final int sourceWidth, final int sourceHeight, final int maxWidth, final int maxHeight) {... |
83 |
0 |
return maxSizeComplyingWithSourceRatio(sourceWidth, sourceHeight, maxWidth, maxHeight, true); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
86 |
12 |
public static Size maxSizeComplyingWithSourceRatio(final int sourceWidth, final int sourceHeight, final int maxWidth, final int maxHeight, final boolean expand) {... |
87 |
12 |
final double sourceRatio = (double) sourceWidth / (double) sourceHeight; |
88 |
|
|
89 |
12 |
final int tentativeWidth = maxWidth; |
90 |
12 |
final int tentativeHeight = (int) (tentativeWidth / sourceRatio); |
91 |
12 |
if (!expand && sourceWidth <= maxWidth && sourceHeight <= maxHeight) { |
92 |
1 |
return new Size(sourceWidth, sourceHeight); |
93 |
|
} |
94 |
11 |
if (tentativeHeight <= maxHeight) { |
95 |
|
|
96 |
6 |
return new Size(tentativeWidth, tentativeHeight); |
97 |
|
} else { |
98 |
|
|
99 |
5 |
final int effectiveHeight = maxHeight; |
100 |
5 |
final int effectiveWidth = (int) (effectiveHeight * sourceRatio); |
101 |
5 |
return new Size(effectiveWidth, effectiveHeight); |
102 |
|
} |
103 |
|
} |
104 |
|
} |