本文整理汇总了C++中BitmapImage::scanLine方法的典型用法代码示例。如果您正苦于以下问题:C++ BitmapImage::scanLine方法的具体用法?C++ BitmapImage::scanLine怎么用?C++ BitmapImage::scanLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitmapImage
的用法示例。
在下文中一共展示了BitmapImage::scanLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: floodFill
// Flood fill
// ----- http://lodev.org/cgtutor/floodfill.html
void BitmapImage::floodFill(BitmapImage* targetImage,
QRect cameraRect,
QPoint point,
QRgb newColor,
int tolerance)
{
// If the point we are supposed to fill is outside the image and camera bounds, do nothing
if(!cameraRect.united(targetImage->bounds()).contains(point))
{
return;
}
// Square tolerance for use with compareColor
tolerance = static_cast<int>(qPow(tolerance, 2));
QRgb oldColor = targetImage->pixel(point);
oldColor = qRgba(qRed(oldColor), qGreen(oldColor), qBlue(oldColor), qAlpha(oldColor));
// Preparations
QList<QPoint> queue; // queue all the pixels of the filled area (as they are found)
BitmapImage* replaceImage = nullptr;
QPoint tempPoint;
QRgb newPlacedColor = 0;
QScopedPointer< QHash<QRgb, bool> > cache(new QHash<QRgb, bool>());
int xTemp = 0;
bool spanLeft = false;
bool spanRight = false;
// Extend to size of Camera
targetImage->extend(cameraRect);
replaceImage = new BitmapImage(cameraRect, Qt::transparent);
queue.append(point);
// Preparations END
while (!queue.empty())
{
tempPoint = queue.takeFirst();
point.setX(tempPoint.x());
point.setY(tempPoint.y());
xTemp = point.x();
newPlacedColor = replaceImage->constScanLine(xTemp, point.y());
while (xTemp >= targetImage->mBounds.left() &&
compareColor(targetImage->constScanLine(xTemp, point.y()), oldColor, tolerance, cache.data())) xTemp--;
xTemp++;
spanLeft = spanRight = false;
while (xTemp <= targetImage->mBounds.right() &&
compareColor(targetImage->constScanLine(xTemp, point.y()), oldColor, tolerance, cache.data()) &&
newPlacedColor != newColor)
{
// Set pixel color
replaceImage->scanLine(xTemp, point.y(), newColor);
if (!spanLeft && (point.y() > targetImage->mBounds.top()) &&
compareColor(targetImage->constScanLine(xTemp, point.y() - 1), oldColor, tolerance, cache.data())) {
queue.append(QPoint(xTemp, point.y() - 1));
spanLeft = true;
}
else if (spanLeft && (point.y() > targetImage->mBounds.top()) &&
!compareColor(targetImage->constScanLine(xTemp, point.y() - 1), oldColor, tolerance, cache.data())) {
spanLeft = false;
}
if (!spanRight && point.y() < targetImage->mBounds.bottom() &&
compareColor(targetImage->constScanLine(xTemp, point.y() + 1), oldColor, tolerance, cache.data())) {
queue.append(QPoint(xTemp, point.y() + 1));
spanRight = true;
}
else if (spanRight && point.y() < targetImage->mBounds.bottom() &&
!compareColor(targetImage->constScanLine(xTemp, point.y() + 1), oldColor, tolerance, cache.data())) {
spanRight = false;
}
Q_ASSERT(queue.count() < (targetImage->mBounds.width() * targetImage->mBounds.height()));
xTemp++;
}
}
targetImage->paste(replaceImage);
targetImage->modification();
delete replaceImage;
}