Created
May 9, 2013 18:00
-
-
Save donSchoe/5549273 to your computer and use it in GitHub Desktop.
wo ist 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; | |
float p12 = image[w * y + _clamp(0, w, (x + 1))]; | |
float p20 = image[_clamp(0, h, (w * (y + 1))) + _clamp(0, w, (x - 1))]; | |
float p21 = image[_clamp(0, h, (w * (y + 1))) + x]; | |
float p22 = image[_clamp(0, h, (w * (y + 1))) + _clamp(0, w, (x + 1))]; | |
image[w * y + _clamp(0, w, (x + 1))] = p12 + 7 * qe / 16.f; | |
image[_clamp(0, h, (w * (y + 1))) + _clamp(0, w, (x - 1))] = p20 + 3 * qe / 16.f; | |
image[_clamp(0, h, (w * (y + 1))) + x] = p21 + 2 * qe / 16.f; | |
image[_clamp(0, h, (w * (y + 1))) + _clamp(0, w, (x + 1))] = p22 + 1 * qe / 16.f; | |
image[w * y + x] = sw11; | |
// initialize() | |
// [...] | |
float * imagef = new float[w * h]; | |
for(int y = 0; y < h; ++y) | |
for(int x = 0; x < w; ++x) { | |
QColor c11(image.pixel(x, y)); | |
imagef[y * w + x] = c11.valueF(); | |
} | |
for(int y = 0; y < h; ++y) | |
for(int x = 0; x < w; ++x) | |
dither(imagef, x, y, w, h); | |
for(int y = 0; y < h; ++y) | |
for(int x = 0; x < w; ++x) | |
{ | |
image.setPixel(x, y, imagef[w * y + x]); | |
} | |
delete imagef; | |
m_dithered = new QGraphicsPixmapItem(QPixmap::fromImage(image)); | |
// [...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
zeile 13