Skip to content

Commit 0e8a801

Browse files
committed
filter(): implement POSTERIZE
1 parent 90adec8 commit 0e8a801

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/Processing.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,11 @@ void PApplet::filter(int mode, float param) {
27472747
else if (mode==INVERT) { buf[i*4]=255-r; buf[i*4+1]=255-g; buf[i*4+2]=255-b; }
27482748
else if (mode==THRESHOLD) { unsigned char t=(grey>param*255)?255:0; buf[i*4]=buf[i*4+1]=buf[i*4+2]=t; }
27492749
else if (mode==OPAQUE) { buf[i*4+3]=255; }
2750+
else if (mode==POSTERIZE) {
2751+
int levels = ::std::max(2,(int)param);
2752+
auto post = [levels](int v){ return (int)((int)(v*(levels-1)/255.0f+0.5f)*255/(levels-1)); };
2753+
buf[i*4]=post(r); buf[i*4+1]=post(g); buf[i*4+2]=post(b);
2754+
}
27502755
}
27512756
} else if (mode == BLUR) {
27522757
int radius = ::std::max(1,(int)param);

0 commit comments

Comments
 (0)