Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
C++ Floyd-Steinberg 24bit RGB color
unsigned char * floydSteinberg(unsigned char * source, int w, int h){
unsigned char * newSource;
for(int i=0; i<(h*3); i++){
for(int j=0; j<w; j++) {
int ci = i*w+j;
int cc = source[ci];
int rc = (cc<128?0:255);
int err = cc-rc;
source[ci] = rc;
if(j+1<w) source[ci+1] += (err*7)>>4;
if(i+1==h) continue;
if(j >0) source[ci+w-1] += (err*3)>>4;
source[ci+w] += (err*5)>>4;
if(j+1<w) source[ci+w+1] += (err*1)>>4;
newSource = source;
return newSource;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.