| 32 | } |
| 33 | |
| 34 | QImage SpecularmapGenerator::calculateSpecmap(const QImage &input, double scale, double contrast) { |
| 35 | QImage result(input.width(), input.height(), QImage::Format_ARGB32); |
| 36 | |
| 37 | //generate contrast lookup table |
| 38 | unsigned short contrastLookup[256]; |
| 39 | double newValue = 0; |
| 40 | |
| 41 | for(int i = 0; i < 256; i++) { |
| 42 | newValue = (double)i; |
| 43 | newValue /= 255.0; |
| 44 | newValue -= 0.5; |
| 45 | newValue *= contrast; |
| 46 | newValue += 0.5; |
| 47 | newValue *= 255; |
| 48 | |
| 49 | if(newValue < 0) |
| 50 | newValue = 0; |
| 51 | if(newValue > 255) |
| 52 | newValue = 255; |
| 53 | |
| 54 | contrastLookup[i] = (unsigned short)newValue; |
| 55 | } |
| 56 | |
| 57 | // This is outside of the loop because the multipliers are the same for every pixel |
| 58 | double multiplierSum = (redMultiplier + greenMultiplier + blueMultiplier + alphaMultiplier); |
| 59 | if(multiplierSum == 0.0) |
| 60 | multiplierSum = 1.0; |
| 61 | |
| 62 | #pragma omp parallel for // OpenMP |
| 63 | //for every row of the image |
| 64 | for(int y = 0; y < result.height(); y++) { |
| 65 | QRgb *scanline = (QRgb*) result.scanLine(y); |
| 66 | |
| 67 | //for every column of the image |
| 68 | for(int x = 0; x < result.width(); x++) { |
| 69 | double intensity = 0.0; |
| 70 | |
| 71 | const QColor pxColor = QColor(input.pixel(x, y)); |
| 72 | |
| 73 | const double r = pxColor.redF() * redMultiplier; |
| 74 | const double g = pxColor.greenF() * greenMultiplier; |
| 75 | const double b = pxColor.blueF() * blueMultiplier; |
| 76 | const double a = pxColor.alphaF() * alphaMultiplier; |
| 77 | |
| 78 | if(mode == IntensityMap::AVERAGE) { |
| 79 | //take the average out of all selected channels |
| 80 | intensity = (r + g + b + a) / multiplierSum; |
| 81 | } |
| 82 | else if(mode == IntensityMap::MAX) { |
| 83 | //take the maximum out of all selected channels |
| 84 | const double tempMaxRG = std::max(r, g); |
| 85 | const double tempMaxBA = std::max(b, a); |
| 86 | intensity = std::max(tempMaxRG, tempMaxBA); |
| 87 | } |
| 88 | |
| 89 | //apply scale (brightness) |
| 90 | intensity *= scale; |
| 91 |
no outgoing calls
no test coverage detected