-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter.java
More file actions
97 lines (83 loc) · 2.86 KB
/
Filter.java
File metadata and controls
97 lines (83 loc) · 2.86 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class Filter {
// http://msdn.microsoft.com/en-us/library/dd183374(VS.85).aspx
// Lifted from the official Microsoft documentation for how .bmp metadata is attached to the header
public static class BITMAPFILEHEADER {
short bfType;
int bfSize;
short bfReserved1;
short bfReserved2;
int bfOffBits;
public BITMAPFILEHEADER(byte[] data) {
ByteBuffer buffer = ByteBuffer.wrap(data);
buffer.order(ByteOrder.LITTLE_ENDIAN);
bfType = buffer.getShort();
bfSize = buffer.getInt();
bfReserved1 = buffer.getShort();
bfReserved2 = buffer.getShort();
bfOffBits = buffer.getInt();
}
}
// http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx
public static class BITMAPINFOHEADER {
int biSize;
public int biWidth;
public int biHeight;
short biPlanes;
short biBitCount;
int biCompression;
int biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
int biClrUsed;
int biClrImportant;
public BITMAPINFOHEADER(byte[] data) {
ByteBuffer buffer = ByteBuffer.wrap(data);
buffer.order(ByteOrder.LITTLE_ENDIAN);
biSize = buffer.getInt();
biWidth = buffer.getInt();
biHeight = buffer.getInt();
biPlanes = buffer.getShort();
biBitCount = buffer.getShort();
biCompression = buffer.getInt();
biSizeImage = buffer.getInt();
biXPelsPerMeter = buffer.getInt();
biYPelsPerMeter = buffer.getInt();
biClrUsed = buffer.getInt();
biClrImportant = buffer.getInt();
}
}
// Creates a class to contain RGB values similar to how the Pair class was implemented from the homework.
public static class RGBTRIPLE {
public byte rgbtBlue;
public byte rgbtGreen;
public byte rgbtRed;
// NEEDS COMMENTS
public byte luminanceGrey;
public RGBTRIPLE(byte blue, byte green, byte red) {
rgbtBlue = blue;
rgbtGreen = green;
rgbtRed = red;
// NEEDS COMMENTS
luminanceGrey = (byte) (0.29 * rgbtRed + .589 * rgbtGreen + .114 * rgbtRed);
}
// NEEDS COMMENTS
public int getLumninanceGrey(){
return luminanceGrey;
}
// NEEDS COMMENTS
public void setWhite(){
rgbtRed = 0;
rgbtGreen = 0;
rgbtBlue = 0;
}
// NEEDS COMMENTS
public void setBlack(){
rgbtRed = (byte) 255;
rgbtGreen = (byte) 255;
rgbtBlue = (byte) 255;
}
}
public void applyFilter(int height, int width, RGBTRIPLE[][] image, String randB, String randG, String randR){};
}