-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathSeamRemover.java
More file actions
73 lines (61 loc) · 2.67 KB
/
SeamRemover.java
File metadata and controls
73 lines (61 loc) · 2.67 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
import edu.princeton.cs.algs4.Picture;
public class SeamRemover {
public SeamRemover() {
}
public static Picture removeHorizontalSeam(Picture var0, int[] var1) {
if(var1 == null) {
throw new NullPointerException("Input seam array cannot be null.");
} else if(var0.width() == 1) {
throw new IllegalArgumentException("Image width is 1.");
} else if(var1.length != var0.width()) {
throw new IllegalArgumentException("Seam length does not match image width.");
} else {
for(int var2 = 0; var2 < var1.length - 2; ++var2) {
if(Math.abs(var1[var2] - var1[var2 + 1]) > 1) {
throw new IllegalArgumentException("Invalid seam, consecutive vertical indices are greater than one apart.");
}
}
Picture var5 = new Picture(var0.width(), var0.height() - 1);
for(int var3 = 0; var3 < var0.width(); ++var3) {
int var4;
for(var4 = 0; var4 < var1[var3]; ++var4) {
var5.set(var3, var4, var0.get(var3, var4));
}
for(var4 = var1[var3] + 1; var4 < var0.height(); ++var4) {
var5.set(var3, var4 - 1, var0.get(var3, var4));
}
}
return var5;
}
}
public static Picture removeVerticalSeam(Picture var0, int[] var1) {
if(var1 == null) {
throw new NullPointerException("Input seam array cannot be null.");
} else if(var0.height() == 1) {
throw new IllegalArgumentException("Image height is 1.");
} else if(var1.length != var0.height()) {
throw new IllegalArgumentException("Seam length does not match image height.");
} else {
for(int var2 = 0; var2 < var1.length - 2; ++var2) {
if(Math.abs(var1[var2] - var1[var2 + 1]) > 1) {
throw new IllegalArgumentException("Invalid seam, consecutive horizontal indices are greater than one apart.");
}
}
Picture var5 = new Picture(var0.width() - 1, var0.height());
for(int var3 = 0; var3 < var0.height(); ++var3) {
int var4;
for(var4 = 0; var4 < var1[var3]; ++var4) {
var5.set(var4, var3, var0.get(var4, var3));
}
for(var4 = var1[var3] + 1; var4 < var0.width(); ++var4) {
var5.set(var4 - 1, var3, var0.get(var4, var3));
}
}
return var5;
}
}
}