Skip to content

Instantly share code, notes, and snippets.

@kashimAstro
Created February 19, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kashimAstro/98d4f9ea30c31a0bfd95 to your computer and use it in GitHub Desktop.
Save kashimAstro/98d4f9ea30c31a0bfd95 to your computer and use it in GitHub Desktop.
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