int r, g, b, a;
QRgb val;
double levels = 5.0; // posterize value 5.0
levels -= 1.0; // by following gimp code
int newRed, newGreen, newBlue;
// starting loop
for(int x=0; y<img.width(); x++)
for(int y=0; y<img.height(); y++) {
val = img.pixel(x, y);
r = qRed(val);
g = qGreen(val);
b = qBlue(val);
a = qAlpha(val);
qDebug() << "r = " << r;
qDebug() << "g = " << g;
qDebug() << "b = " << b;
// lines 21-23 from GIMP...
newRed = (rint) ( (double)r / 255.0 * levels) / levels;
newGreen = (rint) ( (double)g / 255.0 * levels) / levels;
newBlue = (rint) ( (double)b / 255.0 * levels) / levels;
qDebug() << "newRed = " << newRed;
qDebug() << "newGreen = " << newGreen;
qDebug() << "newBlue = " << newBlue;
// make picture by direct pixel operation
postherized_img.setPixel(x, y, qRgba(newRed, newGreen, newBlue, a));
}
// save the picture
postherized_img.save("/home/user/Desktop/test_posterized.jpg", "JPG", 100);
int r, g, b, a;
QRgb val;
double levels = 5.0; // posterize value 5.0
levels -= 1.0; // by following gimp code
int newRed, newGreen, newBlue;
// starting loop
for(int x=0; y<img.width(); x++)
for(int y=0; y<img.height(); y++) {
val = img.pixel(x, y);
r = qRed(val);
g = qGreen(val);
b = qBlue(val);
a = qAlpha(val);
qDebug() << "r = " << r;
qDebug() << "g = " << g;
qDebug() << "b = " << b;
// lines 21-23 from GIMP...
newRed = (rint) ( (double)r / 255.0 * levels) / levels;
newGreen = (rint) ( (double)g / 255.0 * levels) / levels;
newBlue = (rint) ( (double)b / 255.0 * levels) / levels;
qDebug() << "newRed = " << newRed;
qDebug() << "newGreen = " << newGreen;
qDebug() << "newBlue = " << newBlue;
// make picture by direct pixel operation
postherized_img.setPixel(x, y, qRgba(newRed, newGreen, newBlue, a));
}
// save the picture
postherized_img.save("/home/user/Desktop/test_posterized.jpg", "JPG", 100);
To copy to clipboard, switch view to plain text mode
Bookmarks