summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qdrawhelper_p.h2
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp53
-rw-r--r--src/gui/painting/qpdf.cpp13
-rw-r--r--src/gui/painting/qpdf_p.h2
4 files changed, 39 insertions, 31 deletions
diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h
index 45a3174734..e537c343bb 100644
--- a/src/gui/painting/qdrawhelper_p.h
+++ b/src/gui/painting/qdrawhelper_p.h
@@ -335,6 +335,8 @@ struct QSpanData
QGradientData gradient;
QTextureData texture;
};
+ QExplicitlySharedDataPointer<const QSharedData> cachedGradient;
+
void init(QRasterBuffer *rb, const QRasterPaintEngine *pe);
void setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode);
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 0edd9125a3..df96a993e3 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -2283,6 +2283,8 @@ void QRasterPaintEngine::drawImage(const QRectF &r, const QImage &img, const QRe
= QRectF(sr.x() + clippedTargetRect.x() - r.x(), sr.y() + clippedTargetRect.y() - r.y(),
clippedTargetRect.width(), clippedTargetRect.height()).toRect();
+ clippedSourceRect = clippedSourceRect.intersected(img.rect());
+
uint dbpl = d->rasterBuffer->bytesPerLine();
uint sbpl = img.bytesPerLine();
@@ -4147,7 +4149,8 @@ void QRasterBuffer::flushToARGBImage(QImage *target) const
class QGradientCache
{
- struct CacheInfo
+public:
+ struct CacheInfo : public QSharedData
{
inline CacheInfo(QGradientStops s, int op, QGradient::InterpolationMode mode) :
stops(qMove(s)), opacity(op), interpolationMode(mode) {}
@@ -4158,12 +4161,9 @@ class QGradientCache
QGradient::InterpolationMode interpolationMode;
};
- typedef QMultiHash<quint64, CacheInfo> QGradientColorTableHash;
-
-public:
- typedef QPair<const QRgb *, const QRgba64 *> ColorBufferPair;
+ typedef QMultiHash<quint64, QExplicitlySharedDataPointer<const CacheInfo> > QGradientColorTableHash;
- inline ColorBufferPair getBuffer(const QGradient &gradient, int opacity) {
+ inline QExplicitlySharedDataPointer<const CacheInfo> getBuffer(const QGradient &gradient, int opacity) {
quint64 hash_val = 0;
const QGradientStops stops = gradient.stops();
@@ -4177,10 +4177,9 @@ public:
return addCacheElement(hash_val, gradient, opacity);
else {
do {
- const CacheInfo &cache_info = it.value();
- if (cache_info.stops == stops && cache_info.opacity == opacity && cache_info.interpolationMode == gradient.interpolationMode())
- return qMakePair(reinterpret_cast<const QRgb *>(cache_info.buffer32),
- reinterpret_cast<const QRgba64 *>(cache_info.buffer64));
+ const QExplicitlySharedDataPointer<const CacheInfo> &cache_info = it.value();
+ if (cache_info->stops == stops && cache_info->opacity == opacity && cache_info->interpolationMode == gradient.interpolationMode())
+ return cache_info;
++it;
} while (it != cache.constEnd() && it.key() == hash_val);
// an exact match for these stops and opacity was not found, create new cache
@@ -4194,18 +4193,16 @@ protected:
inline void generateGradientColorTable(const QGradient& g,
QRgba64 *colorTable,
int size, int opacity) const;
- ColorBufferPair addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) {
+ QExplicitlySharedDataPointer<const CacheInfo> addCacheElement(quint64 hash_val, const QGradient &gradient, int opacity) {
if (cache.size() == maxCacheSize()) {
// may remove more than 1, but OK
cache.erase(cache.begin() + (qrand() % maxCacheSize()));
}
- CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode());
- generateGradientColorTable(gradient, cache_entry.buffer64, paletteSize(), opacity);
+ QExplicitlySharedDataPointer<CacheInfo> cache_entry(new CacheInfo (gradient.stops(), opacity, gradient.interpolationMode()));
+ generateGradientColorTable(gradient, cache_entry->buffer64, paletteSize(), opacity);
for (int i = 0; i < GRADIENT_STOPTABLE_SIZE; ++i)
- cache_entry.buffer32[i] = cache_entry.buffer64[i].toArgb32();
- CacheInfo &cache_value = cache.insert(hash_val, cache_entry).value();
- return qMakePair(reinterpret_cast<const QRgb *>(cache_value.buffer32),
- reinterpret_cast<const QRgba64 *>(cache_value.buffer64));
+ cache_entry->buffer32[i] = cache_entry->buffer64[i].toArgb32();
+ return cache.insert(hash_val, cache_entry).value();
}
QGradientColorTableHash cache;
@@ -4424,6 +4421,7 @@ Q_GUI_EXPORT extern QImage qt_imageForBrush(int brushStyle, bool invert);
void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode compositionMode)
{
Qt::BrushStyle brushStyle = qbrush_style(brush);
+ cachedGradient.reset();
switch (brushStyle) {
case Qt::SolidPattern: {
type = Solid;
@@ -4440,9 +4438,10 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
const QLinearGradient *g = static_cast<const QLinearGradient *>(brush.gradient());
gradient.alphaColor = !brush.isOpaque() || alpha != 256;
- QGradientCache::ColorBufferPair colorBuffers = qt_gradient_cache()->getBuffer(*g, alpha);
- gradient.colorTable64 = colorBuffers.second;
- gradient.colorTable32 = colorBuffers.first;
+ QExplicitlySharedDataPointer<const QGradientCache::CacheInfo> cacheInfo = qt_gradient_cache()->getBuffer(*g, alpha);
+ cachedGradient = cacheInfo;
+ gradient.colorTable32 = cacheInfo->buffer32;
+ gradient.colorTable64 = cacheInfo->buffer64;
gradient.spread = g->spread();
@@ -4461,9 +4460,10 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
const QRadialGradient *g = static_cast<const QRadialGradient *>(brush.gradient());
gradient.alphaColor = !brush.isOpaque() || alpha != 256;
- QGradientCache::ColorBufferPair colorBuffers = qt_gradient_cache()->getBuffer(*g, alpha);
- gradient.colorTable64 = colorBuffers.second;
- gradient.colorTable32 = colorBuffers.first;
+ QExplicitlySharedDataPointer<const QGradientCache::CacheInfo> cacheInfo = qt_gradient_cache()->getBuffer(*g, alpha);
+ cachedGradient = cacheInfo;
+ gradient.colorTable32 = cacheInfo->buffer32;
+ gradient.colorTable64 = cacheInfo->buffer64;
gradient.spread = g->spread();
@@ -4486,9 +4486,10 @@ void QSpanData::setup(const QBrush &brush, int alpha, QPainter::CompositionMode
const QConicalGradient *g = static_cast<const QConicalGradient *>(brush.gradient());
gradient.alphaColor = !brush.isOpaque() || alpha != 256;
- QGradientCache::ColorBufferPair colorBuffers = qt_gradient_cache()->getBuffer(*g, alpha);
- gradient.colorTable64 = colorBuffers.second;
- gradient.colorTable32 = colorBuffers.first;
+ QExplicitlySharedDataPointer<const QGradientCache::CacheInfo> cacheInfo = qt_gradient_cache()->getBuffer(*g, alpha);
+ cachedGradient = cacheInfo;
+ gradient.colorTable32 = cacheInfo->buffer32;
+ gradient.colorTable64 = cacheInfo->buffer64;
gradient.spread = QGradient::RepeatSpread;
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index d246c96da6..84e18a64dd 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -1924,7 +1924,7 @@ int QPdfEnginePrivate::writeCompressed(const char *src, int len)
}
int QPdfEnginePrivate::writeImage(const QByteArray &data, int width, int height, int depth,
- int maskObject, int softMaskObject, bool dct)
+ int maskObject, int softMaskObject, bool dct, bool isMono)
{
int image = addXrefEntry(-1);
xprintf("<<\n"
@@ -1934,8 +1934,13 @@ int QPdfEnginePrivate::writeImage(const QByteArray &data, int width, int height,
"/Height %d\n", width, height);
if (depth == 1) {
- xprintf("/ImageMask true\n"
- "/Decode [1 0]\n");
+ if (!isMono) {
+ xprintf("/ImageMask true\n"
+ "/Decode [1 0]\n");
+ } else {
+ xprintf("/BitsPerComponent 1\n"
+ "/ColorSpace /DeviceGray\n");
+ }
} else {
xprintf("/BitsPerComponent 8\n"
"/ColorSpace %s\n", (depth == 32) ? "/DeviceRGB" : "/DeviceGray");
@@ -2453,7 +2458,7 @@ int QPdfEnginePrivate::addImage(const QImage &img, bool *bitmap, qint64 serial_n
memcpy(rawdata, image.constScanLine(y), bytesPerLine);
rawdata += bytesPerLine;
}
- object = writeImage(data, w, h, d, 0, 0);
+ object = writeImage(data, w, h, d, 0, 0, false, is_monochrome(img.colorTable()));
} else {
QByteArray softMaskData;
bool dct = false;
diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h
index cb1a91e09f..a6aa2940c8 100644
--- a/src/gui/painting/qpdf_p.h
+++ b/src/gui/painting/qpdf_p.h
@@ -295,7 +295,7 @@ private:
int streampos;
int writeImage(const QByteArray &data, int width, int height, int depth,
- int maskObject, int softMaskObject, bool dct = false);
+ int maskObject, int softMaskObject, bool dct = false, bool isMono = false);
void writePage();
int addXrefEntry(int object, bool printostr = true);