! \internal This method is used to colorize a single data value given in \a position, to colors. The data range that shall be used for mapping the data value to the gradient is passed in \a range. \a logarithmic indicates whether the data value shall be mapped to a color logarithmically. If an entire array of data values shall be converted, rather use \ref colorize, for better performa
| 16836 | QImage::Format_ARGB32_Premultiplied). |
| 16837 | */ |
| 16838 | QRgb QCPColorGradient::color(double position, const QCPRange &range, bool logarithmic) |
| 16839 | { |
| 16840 | // If you change something here, make sure to also adapt ::colorize() |
| 16841 | if (mColorBufferInvalidated) |
| 16842 | updateColorBuffer(); |
| 16843 | |
| 16844 | const bool skipNanCheck = mNanHandling == nhNone; |
| 16845 | if (!skipNanCheck && std::isnan(position)) |
| 16846 | { |
| 16847 | switch(mNanHandling) |
| 16848 | { |
| 16849 | case nhLowestColor: return mColorBuffer.first(); |
| 16850 | case nhHighestColor: return mColorBuffer.last(); |
| 16851 | case nhTransparent: return qRgba(0, 0, 0, 0); |
| 16852 | case nhNanColor: return mNanColor.rgba(); |
| 16853 | case nhNone: return qRgba(0, 0, 0, 0); // shouldn't happen |
| 16854 | } |
| 16855 | } |
| 16856 | |
| 16857 | const double posToIndexFactor = !logarithmic ? (mLevelCount-1)/range.size() : (mLevelCount-1)/qLn(range.upper/range.lower); |
| 16858 | int index = int((!logarithmic ? position-range.lower : qLn(position/range.lower)) * posToIndexFactor); |
| 16859 | if (!mPeriodic) |
| 16860 | { |
| 16861 | index = qBound(0, index, mLevelCount-1); |
| 16862 | } else |
| 16863 | { |
| 16864 | index %= mLevelCount; |
| 16865 | if (index < 0) |
| 16866 | index += mLevelCount; |
| 16867 | } |
| 16868 | return mColorBuffer.at(index); |
| 16869 | } |
| 16870 | |
| 16871 | /*! |
| 16872 | Clears the current color stops and loads the specified \a preset. A preset consists of predefined |
no test coverage detected