-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecompressor.java
More file actions
53 lines (40 loc) · 994 Bytes
/
Decompressor.java
File metadata and controls
53 lines (40 loc) · 994 Bytes
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
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Decompressor {
static class Pixel {
int r, g, b, data;
public Pixel (int data) {
r = (data & 0xFF0000) >> 16;
g = (data & 0x00FF00) >> 8;
b = data & 0x0000FF;
}
void setPixel (int x, int y, BufferedImage img) {
img.setRGB(y, x, data);
}
}
public static void main (String[] args) throws IOException {
BufferedImage img = null;
FileWriter output = null;
try {
output = new FileWriter(args[1]);
img = ImageIO.read(new File(args[0]));
for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
Pixel p = new Pixel (img.getRGB(x,y));
if (p.r != 0)
output.write(p.r);
if (p.g != 0)
output.write(p.g);
if (p.b != 0)
output.write(p.b);
}
}
} finally {
if (output != null)
output.close();
}
}
}