Created
May 10, 2013 17:05
-
-
Save donSchoe/5555799 to your computer and use it in GitHub Desktop.
wo is der fehler?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* dither() */ | |
float p11 = image[w * y + x]; | |
float sw11 = 1.f; | |
if(p11 < 0.5) sw11 = 0.f; | |
float qe = p11 - sw11; | |
image[ w * y + x ] = sw11; | |
image[ w * y + _clamp(0, w, (x + 1))] += 7.f * qe / 16.f; | |
image[_clamp(0, h, (w * (y + 1))) + _clamp(0, w, (x - 1))] += 3.f * qe / 16.f; //@TODO: Not applied, why? | |
image[_clamp(0, h, (w * (y + 1))) + x ] += 5.f * qe / 16.f; //@TODO: Not applied, why? | |
image[_clamp(0, h, (w * (y + 1))) + _clamp(0, w, (x + 1))] += 1.f * qe / 16.f; //@TODO: Not applied, why? | |
/* initialize() */ | |
// Creates a 1d float array with gray values of an image | |
float * imagef = new float[w * h]; | |
for(int y = 0; y < h; ++y) | |
for(int x = 0; x < w; ++x) { | |
QColor c11(m_image->pixel(x, y)); | |
imagef[w * y + x] = c11.valueF(); | |
} | |
// Applies Floyd-Steinberg dither | |
for(int y = 0; y < h; ++y) | |
for(int x = 0; x < w; ++x) | |
dither(imagef, x, y, w, h); | |
// Draws dithered image from float array | |
for(int y = 0; y < h; ++y) | |
for(int x = 0; x < w; ++x) { | |
QColor c11; | |
float value = _clamp(0.f, 1.f, imagef[w * y + x]); | |
c11.setRgbF(value, value, value); | |
image.setPixel(x, y, c11.rgb()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment