! Modifies colors according to gamma, luminosity threshold, white balance and brightness settings All modifications are made over extended 12bit RGB, so \code outColors \endcode will contain 12bit RGB instead of 8bit. */
| 75 | RGB instead of 8bit. |
| 76 | */ |
| 77 | void AbstractLedDevice::applyColorModifications(const QList<QRgb> &inColors, QList<StructRgb> &outColors) { |
| 78 | |
| 79 | bool isApplyWBAdjustments = m_wbAdjustments.count() == inColors.count(); |
| 80 | |
| 81 | for(int i = 0; i < inColors.count(); i++) { |
| 82 | |
| 83 | //renormalize to 12bit |
| 84 | double k = 4095/255.0; |
| 85 | outColors[i].r = qRed(inColors[i]) * k; |
| 86 | outColors[i].g = qGreen(inColors[i]) * k; |
| 87 | outColors[i].b = qBlue(inColors[i]) * k; |
| 88 | |
| 89 | if (isApplyWBAdjustments) { |
| 90 | outColors[i].r *= m_wbAdjustments[i].red; |
| 91 | outColors[i].g *= m_wbAdjustments[i].green; |
| 92 | outColors[i].b *= m_wbAdjustments[i].blue; |
| 93 | } |
| 94 | |
| 95 | PrismatikMath::gammaCorrection(m_gamma, outColors[i]); |
| 96 | } |
| 97 | |
| 98 | StructLab avgColor = PrismatikMath::toLab(PrismatikMath::avgColor(outColors)); |
| 99 | |
| 100 | for (int i = 0; i < outColors.count(); ++i) { |
| 101 | StructLab lab = PrismatikMath::toLab(outColors[i]); |
| 102 | int dl = m_luminosityThreshold - lab.l; |
| 103 | if (dl > 0) { |
| 104 | if (m_isMinimumLuminosityEnabled) { // apply minimum luminosity or dead-zone |
| 105 | // Cross-fade a and b channels to avarage value within kFadingRange, fadingFactor = (dL - fadingRange)^2 / (fadingRange^2) |
| 106 | const int kFadingRange = 5; |
| 107 | double fadingCoeff = dl < kFadingRange ? (dl - kFadingRange)*(dl - kFadingRange)/(kFadingRange*kFadingRange): 1; |
| 108 | char da = avgColor.a - lab.a; |
| 109 | char db = avgColor.b - lab.b; |
| 110 | lab.l = m_luminosityThreshold; |
| 111 | lab.a += round(da * fadingCoeff); |
| 112 | lab.b += round(db * fadingCoeff); |
| 113 | StructRgb rgb = PrismatikMath::toRgb(lab); |
| 114 | outColors[i] = rgb; |
| 115 | } else { |
| 116 | outColors[i].r = 0; |
| 117 | outColors[i].g = 0; |
| 118 | outColors[i].b = 0; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | PrismatikMath::brightnessCorrection(m_brightness, outColors[i]); |
| 123 | } |
| 124 | |
| 125 | } |
nothing calls this directly
no test coverage detected