| 46 | |
| 47 | template<int operation(int, int)> |
| 48 | static QImage changeImage(const QImage &image, int value) |
| 49 | { |
| 50 | QImage im = image; |
| 51 | im.detach(); |
| 52 | if (im.colorCount() == 0) /* truecolor */ |
| 53 | { |
| 54 | if (im.format() != QImage::Format_RGB32) /* just in case */ |
| 55 | im = im.convertToFormat(QImage::Format_RGB32); |
| 56 | int table[256]; |
| 57 | for (int i = 0; |
| 58 | i < 256; |
| 59 | ++i) |
| 60 | table[i] = operation(i, value); |
| 61 | if (im.hasAlphaChannel()) { |
| 62 | for (int y = 0; |
| 63 | y < im.height(); |
| 64 | ++y) { |
| 65 | QRgb *line = reinterpret_cast<QRgb *>(im.scanLine(y)); |
| 66 | for (int x = 0; |
| 67 | x < im.width(); |
| 68 | ++x) |
| 69 | line[x] = qRgba(changeUsingTable(qRed(line[x]), table), |
| 70 | changeUsingTable(qGreen(line[x]), table), |
| 71 | changeUsingTable(qBlue(line[x]), table), |
| 72 | changeUsingTable(qAlpha(line[x]), table)); |
| 73 | } |
| 74 | } else { |
| 75 | for (int y = 0; |
| 76 | y < im.height(); |
| 77 | ++y) { |
| 78 | QRgb *line = reinterpret_cast<QRgb *>(im.scanLine(y)); |
| 79 | for (int x = 0; |
| 80 | x < im.width(); |
| 81 | ++x) |
| 82 | line[x] = qRgb(changeUsingTable(qRed(line[x]), table), |
| 83 | changeUsingTable(qGreen(line[x]), table), |
| 84 | changeUsingTable(qBlue(line[x]), table)); |
| 85 | } |
| 86 | } |
| 87 | } else { |
| 88 | QVector<QRgb> colors = im.colorTable(); |
| 89 | for (int i = 0; |
| 90 | i < im.colorCount(); |
| 91 | ++i) |
| 92 | colors[i] = qRgb(operation(qRed(colors[i]), value), |
| 93 | operation(qGreen(colors[i]), value), |
| 94 | operation(qBlue(colors[i]), value)); |
| 95 | im.setColorTable(colors); |
| 96 | } |
| 97 | return im; |
| 98 | } |
| 99 | |
| 100 | // brightness is multiplied by 100 in order to avoid floating point numbers |
| 101 | QImage changeBrightness(const QImage &image, int brightness) |
nothing calls this directly
no test coverage detected