-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comp202Photoshop.java
68 lines (66 loc) · 2.01 KB
/
Comp202Photoshop.java
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
import java.io.*;
public class Comp202Photoshop{
public static void main(String[] args){
if(args.length < 4){
System.err.println("Invalid Input. Must have 4 arguments, 8 if you wish to crop the image.");
return;
}
else{
try{
String inFileName = args[0];
String outFileName = args[1];
String format = args[2];
String operation = args[3];
Image image = ImageFileUtilities.read(inFileName);
//Modify the image
int i = 0;
while(i == 0){
if(operation.equals("-fh")){
image.flip(true);
i++;
}
else if(operation.equals("-fv")){
image.flip(false);
i++;
}
else if(operation.equals("-gs")){
image.toGrey();
i++;
}
else if(operation.equals("-cr")){
if(args.length < 8 || args.length > 8){
System.err.println("Invalid input. -cr operation must have 8 arguments.");
return;
}
else{
int startX = Integer.parseInt(args[4]);
int startY = Integer.parseInt(args[5]);
int endX = Integer.parseInt(args[6]);
int endY = Integer.parseInt(args[7]);
try{
image.crop(startX, startY, endX, endY);
i++;
}catch(IllegalArgumentException e){
System.err.println("IllegalArgumentException" + e);
return;
}
}
}
}
//Print the image in specified format
if(format.equals("pgm")){
ImageFileUtilities.writePgm(image, outFileName);
}
else if(format.equals("pnm")){
ImageFileUtilities.writePnm(image, outFileName);
}
else{
throw new IllegalArgumentException("Invalid format");
}
}catch(IOException e){
System.err.println("IOException" + e);
return;
}
}
}
}