4 #include "bitmapline.h"
7 static QImage
img2line(const QImage
&img
, int width
, int offset
)
9 Q_ASSERT(img
.format() == QImage::Format_ARGB32_Premultiplied
);
10 QImage
res(width
, img
.height(), QImage::Format_ARGB32_Premultiplied
);
11 const int srcBpl
= img
.bytesPerLine();
12 const int dstBpl
= res
.bytesPerLine();
13 const uchar
*srcBits
= img
.bits();
14 uchar
*dstBits
= res
.bits();
16 for (int i
= 0; i
< img
.height(); i
++) {
17 const uchar
*srcLine
= srcBits
+ srcBpl
* i
;
18 uchar
*dstLine
= dstBits
+ dstBpl
* i
;
22 size
= qMin(dstBpl
, srcBpl
- 4 * offset
);
23 memcpy(dstLine
, srcLine
+ 4 * offset
, size
);
26 for (int j
= dstBpl
- size
; j
> 0; j
-= srcBpl
, dstLine
+= srcBpl
)
27 memcpy(dstLine
, srcLine
, qMin(j
, srcBpl
));
30 res
.setDevicePixelRatio(img
.devicePixelRatio());
35 void BitmapLine::draw(QPainter
*painter
, const QPolygonF
&line
,
40 for (int i
= 1; i
< line
.size(); i
++) {
41 QLineF
segment(line
.at(i
-1).x(), line
.at(i
-1).y(), line
.at(i
).x(),
43 int len
= qCeil(segment
.length() * img
.devicePixelRatio());
46 painter
->translate(segment
.p1());
47 painter
->rotate(-segment
.angle());
48 painter
->drawImage(0.0, -img
.height()/2.0, img2line(img
, len
, offset
));
51 offset
= (len
+ offset
) % img
.width();
55 void BitmapLine::draw(QPainter
*painter
, const QVector
<QPolygonF
> &lines
,
58 for (int i
= 0; i
< lines
.size(); i
++)
59 draw(painter
, lines
.at(i
), img
);