mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Display of ink coverage
This commit is contained in:
@@ -90,6 +90,23 @@ PDFColorComponent PDFFloatBitmap::getPixelInkCoverage(size_t x, size_t y) const
|
||||
return inkCoverage;
|
||||
}
|
||||
|
||||
PDFFloatBitmap PDFFloatBitmap::getInkCoverageBitmap() const
|
||||
{
|
||||
PDFFloatBitmap result(getWidth(), getHeight(), PDFPixelFormat::createFormat(1, 0, false, true, false));
|
||||
|
||||
for (size_t y = 0; y < getHeight(); ++y)
|
||||
{
|
||||
for (size_t x = 0; x < getWidth(); ++x)
|
||||
{
|
||||
PDFColorComponent coverage = getPixelInkCoverage(x, y);
|
||||
PDFColorBuffer targetProcessColorBuffer = result.getPixel(x, y);
|
||||
targetProcessColorBuffer[0] = coverage;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const PDFColorComponent* PDFFloatBitmap::begin() const
|
||||
{
|
||||
return m_data.data();
|
||||
|
@@ -160,6 +160,10 @@ public:
|
||||
/// Returns ink coverage
|
||||
PDFColorComponent getPixelInkCoverage(size_t x, size_t y) const;
|
||||
|
||||
/// Returns ink coverage bitmap. Bitmap consists of one color channel,
|
||||
/// which consists of ink coverage.
|
||||
PDFFloatBitmap getInkCoverageBitmap() const;
|
||||
|
||||
const PDFColorComponent* begin() const;
|
||||
const PDFColorComponent* end() const;
|
||||
|
||||
|
@@ -518,4 +518,43 @@ QString PDFSysUtils::getUserName()
|
||||
return userName;
|
||||
}
|
||||
|
||||
PDFColorScale::PDFColorScale(PDFReal min, PDFReal max) :
|
||||
m_min(min),
|
||||
m_max(max)
|
||||
{
|
||||
m_colorScales = {
|
||||
Qt::blue,
|
||||
Qt::cyan,
|
||||
Qt::green,
|
||||
Qt::yellow,
|
||||
Qt::red
|
||||
};
|
||||
}
|
||||
|
||||
QColor PDFColorScale::map(PDFReal value) const
|
||||
{
|
||||
PDFReal correctedValue = qBound(m_min, value, m_max);
|
||||
PDFReal intervalValue = interpolate(correctedValue, m_min, m_max, 0.0, PDFReal(m_colorScales.size() - 1));
|
||||
PDFReal indexValue = qFloor(intervalValue);
|
||||
int index = indexValue;
|
||||
PDFReal fractionValue = intervalValue - index;
|
||||
|
||||
if (index == int(m_colorScales.size()) - 1)
|
||||
{
|
||||
--index;
|
||||
fractionValue = 1.0;
|
||||
}
|
||||
|
||||
Q_ASSERT(index + 1 < m_colorScales.size());
|
||||
|
||||
const QColor& leftValue = m_colorScales[index];
|
||||
const QColor& rightValue = m_colorScales[index + 1];
|
||||
|
||||
qreal r = (1.0 - fractionValue) * leftValue.redF() + fractionValue * rightValue.redF();
|
||||
qreal g = (1.0 - fractionValue) * leftValue.greenF() + fractionValue * rightValue.greenF();
|
||||
qreal b = (1.0 - fractionValue) * leftValue.blueF() + fractionValue * rightValue.blueF();
|
||||
|
||||
return QColor::fromRgbF(r, g, b);
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@@ -806,6 +806,21 @@ QDataStream& operator<<(QDataStream& stream, const std::set<T>& set)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// Color scale represents hot-to-cold color scale. It maps value
|
||||
/// to the color from blue trough green to red.
|
||||
class Pdf4QtLIBSHARED_EXPORT PDFColorScale
|
||||
{
|
||||
public:
|
||||
explicit PDFColorScale(PDFReal min, PDFReal max);
|
||||
|
||||
QColor map(PDFReal value) const;
|
||||
|
||||
private:
|
||||
std::vector<QColor> m_colorScales;
|
||||
PDFReal m_min;
|
||||
PDFReal m_max;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
||||
#endif // PDFUTILS_H
|
||||
|
Reference in New Issue
Block a user