-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter.java
More file actions
48 lines (42 loc) · 1.28 KB
/
Filter.java
File metadata and controls
48 lines (42 loc) · 1.28 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
/*
* A superclass that contains basic functionality for all filers,
* and a method (modifyPixels()) which should be overridden by each of the
* specific Filter subclasses
* We could make this class abstract - but as that is not an AP CS-A topic, it is written
* as a concrete (normal, not abstract) class.
*/
public class Filter
{
/**
* Modify the image according to your algorithm
*
* @param theImage The image to modify
*/
Pixel[][] data;
public void filter(PixelImage theImage)
{
data = theImage.getData();
if (data != null)
{
modifyPixels();
theImage.setData(data);
}
}
//protected is not tested on the AP exam, but means that it can only be accessed by this class and its subclasses
//give access to the 2D array of Pixels to the subclasses
protected Pixel[][] getData()
{
return data;
}
//allow the 2D array of Pixels to be replaced by the subclasses
protected void setData(Pixel[][] data)
{
this.data = data;
}
//override this method in the subclasses
protected void modifyPixels()
{
//the default filter does nothing.
//override this method in your child classes, to do something.
}
}