Browse code

Initial commit

haywalk authored on 30/03/2021 00:52:54
Showing 6 changed files

1 1
new file mode 100755
2 2
Binary files /dev/null and b/PixelPoke.class differ
3 3
new file mode 100755
... ...
@@ -0,0 +1,76 @@
1
+/*
2
+ * PixelPoke by Hayden Walker, for the AP Computer Science Principles final project
3
+ * 26 March 2021
4
+ */
5
+
6
+import java.awt.image.*;
7
+import java.io.*;
8
+import javax.imageio.*;
9
+
10
+public class PixelPoke {
11
+	public static void main(String[] args) throws IOException {
12
+		// Create variables to store names of input and output files
13
+		String inputFileName = "";
14
+		String outputFileName = "";
15
+		
16
+		// See what was passed in as a command line argument or piped
17
+		if(args.length == 2) {
18
+			// If user specified an input file and output file, use those
19
+			inputFileName = args[0];
20
+			outputFileName = args[1];
21
+		} else if(args.length == 1) {
22
+			// If user only specified input, overwrite it.
23
+			inputFileName = args[0];
24
+			outputFileName = inputFileName;
25
+		} else {
26
+			// If no arguments given, take filename from pipeline
27
+			BufferedReader pipeInput = new BufferedReader(new InputStreamReader(System.in));
28
+			String[] pipeArgs = pipeInput.readLine().split(" ");
29
+			// Use variables depending on input length
30
+			switch(pipeArgs.length){
31
+				case 1: 
32
+					inputFileName = pipeArgs[0];
33
+					outputFileName = inputFileName;
34
+					break;
35
+				case 2:
36
+					inputFileName = pipeArgs[0];
37
+					outputFileName = pipeArgs[1];
38
+					break;
39
+				default:
40
+					System.out.println("Invalid arguments\nUsage: negative [inputfile.jpg] [outputfile.jpg]");
41
+					System.exit(1);
42
+			}
43
+		}
44
+		
45
+		// Create input and output files
46
+		File inputFile = new File(inputFileName);
47
+		File outputFile = new File(outputFileName);
48
+		
49
+		// Create a new buffered image
50
+		BufferedImage img = null;
51
+				
52
+		// Read the input file
53
+		try {
54
+			img = ImageIO.read(inputFile);
55
+		} catch(IOException e) {
56
+			System.out.println("Invalid arguments\nUsage: negative [inputfile.jpg] [outputfile.jpg]");
57
+			System.exit(1);
58
+		}
59
+		
60
+		// Get the dimensions of the image
61
+		int width = img.getWidth();
62
+		int height = img.getHeight();
63
+		
64
+		// Iterate through each row of the image
65
+		for(int row = 0; row < height; row++) {
66
+			// Iterate through each column
67
+			for(int column = 0; column < width; column++){
68
+				// Invert each pixel by subtracting its current colour value from that of white
69
+				img.setRGB(column, row, 0xFFFFFF - img.getRGB(column, row));
70
+			}
71
+		}
72
+		
73
+		// Write the modified image to the output file
74
+		ImageIO.write(img, "jpg", outputFile);
75
+	}
76
+}
0 77
new file mode 100755
... ...
@@ -0,0 +1,5 @@
1
+# PixelPoke
2
+
3
+This is a simple program that, when run, will take in an image file as an argument and create an inverted version of that image.
4
+
5
+Usage (in the directory with the .class file): `$ java PixelPoke [input.jpg] [output.jpg]` or if you follow the instructions in `pkg/`, you can use `$ negative [input.jpg] [output.jpg]`.
0 6
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+If you put these two files somewhere in your path, you can run this program from anywhere, on any file. Make sure it's executable. Usage: `$ negative [input.jpg] [output.jpg]`
0 2
new file mode 100755
... ...
@@ -0,0 +1,4 @@
1
+#!/bin/sh
2
+DIRECTORY=`dirname $0`
3
+
4
+java -jar $DIRECTORY/negative.jar $1 $2
0 5
new file mode 100644
1 6
Binary files /dev/null and b/pkg/negative.jar differ