-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPosterization.java
More file actions
41 lines (39 loc) · 1.09 KB
/
Posterization.java
File metadata and controls
41 lines (39 loc) · 1.09 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
public class Posterization extends ColorPixelConverter{
/* parameter of posterize */
private int levelR=4,levelG=4,levelB=4;
/* constructor */
public Posterization(){
}
public Posterization(int level){
levelR=level; levelG=level; levelB=level;
}
public Posterization(int levelR,int levelG,int levelB){
this.levelR=levelR; this.levelG=levelG; this.levelB=levelB;
}
/* posterization function */
public int functionR(int r){
int base=256/levelR;
for(int c=base;c<256;c+=base)
if(r<c) return c;
return 255;
}
public int functionG(int g){
int base=256/levelG;
for(int c=base;c<256;c+=base)
if(g<c) return c;
return 255;
}
public int functionB(int b){
int base=256/levelB;
for(int c=base;c<256;c+=base)
if(b<c) return c;
return 255;
}
/* setter of level */
public void setLevel(int level){
levelR=level; levelG=level; levelB=level;
}
public void setLevel(int levelR,int levelG,int levelB){
this.levelR=levelR; this.levelG=levelG; this.levelB=levelB;
}
}