-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageLayer.java
More file actions
executable file
·136 lines (110 loc) · 2.94 KB
/
ImageLayer.java
File metadata and controls
executable file
·136 lines (110 loc) · 2.94 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package bric.Image;
public class ImageLayer {
private int[][] image;
private int width;
private int height;
ColorType color;
public ImageLayer(int[] src, int w, int h, ColorType c) {
image = new int[h][w];
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
image[i][j] = src[i * w + j];
}
}
width = w;
height = h;
color = c;
}
public ImageLayer(int[][] src, int w, int h, ColorType c) {
image = src;
width = w;
height = h;
color = c;
}
public ImageLayer(int w, int h, ColorType c) {
image = new int[h][w];
width = w;
height = h;
color = c;
}
public int[][] getImage() {
return image;
}
public void setImage(int[][] i) {
image = i;
}
public void setImage(int[] src) {
// TODO: check dimensions
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
image[i][j] = src[i * width + j];
}
}
}
public void clearImage() {
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
image[i][j] = 0;
}
}
}
public int getPixel(int r, int c) {
return image[r][c];
}
public void setPixel(int r, int c, int val) {
image[r][c] = val;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int[] getDimension() {
int[] dim = {width, height};
return dim;
}
public ColorType getColor() {
return color;
}
public void setColor(ColorType c) {
color = c;
}
public int[] toArray() {
int[] r = new int[width * height];
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
r[i * width + j] = image[i][j];
}
}
return r;
}
public ImageLayer convolve(Filter f) {
return f.convolve(this);
}
public ImageLayer threshhold(int thresh) {
ImageLayer tImg = new ImageLayer(width, height, color);
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
int val = image[i][j];
if (val > thresh)
tImg.setPixel(i, j, val);
}
}
return tImg;
}
public void writeImageToFile(String fp) {
ExampleIO e = new ExampleIO(image, "w", fp, color.toString());
Thread t = new Thread(e);
t.start();
}
public void show() {
System.out.println(color.toString());
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
System.out.printf(" %03d", image[i][j]);
}
System.out.println();
}
}
}