Reputation: 11
I was trying to implement a floyd-steinberg dithering program by using png++
but the only thing that happens to output.png
is that it becomes grayscale rather than applying dithering
#include <iostream>
#include "lib/png.hpp"
#include <cmath>
png::image< png::gray_pixel > image("input.png");
int h = image.get_height();
int w = image.get_width();
int main() {
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
double o = image[y][x];
int n = std::round(o);
image[y][x] = n;
double error = o - n;
if (x+1 < w) {image[y ][x+1] += error * 7/16.0;}
if (y+1 < h && x-1 >= 0) {image[y+1][x-1] += error * 3/16.0;}
if (y+1 < h) {image[y+1][x ] += error * 5/16.0;}
if (x+1 < w && y+1 < h) {image[y+1][x+1] += error * 1/16.0;}
}
}
image.write("output.png");
return 0;
}
And I'm very confused I don't know what to do...
I tried to make a separate image variable, but didn't work either
Upvotes: 0
Views: 48