mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-15 04:40:37 +02:00
Performance Update
This commit is contained in:
@@ -78,6 +78,6 @@ void IntelliImage::drawPlain(const QColor& color){
|
|||||||
imageData.fill(color);
|
imageData.fill(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor IntelliImage::getPixelColor(int x, int y){
|
QColor IntelliImage::getPixelColor(QPoint& point){
|
||||||
return imageData.pixelColor(x,y);
|
return imageData.pixelColor(point);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
//loads an image to the ColorBuffer
|
//loads an image to the ColorBuffer
|
||||||
virtual bool loadImage(const QString &fileName);
|
virtual bool loadImage(const QString &fileName);
|
||||||
|
|
||||||
virtual QColor getPixelColor(int x, int y);
|
virtual QColor getPixelColor(QPoint& point);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,58 +24,43 @@ void IntelliToolFloodFill::onMouseRightReleased(int x, int y){
|
|||||||
|
|
||||||
void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
|
void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
|
||||||
IntelliTool::onMouseLeftPressed(x,y);
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
QColor oldColor = this->Active->image->getPixelColor(x,y);
|
|
||||||
|
QPoint start(x,y);
|
||||||
std::queue<QPoint> Q;
|
std::queue<QPoint> Q;
|
||||||
Q.push(QPoint(x,y));
|
Q.push(start);
|
||||||
|
|
||||||
|
QColor oldColor = this->Active->image->getPixelColor(start);
|
||||||
QColor newColor = this->colorPicker->getFirstColor();
|
QColor newColor = this->colorPicker->getFirstColor();
|
||||||
Canvas->image->drawPixel(QPoint(x,y),newColor);
|
Canvas->image->drawPixel(start,newColor);
|
||||||
|
|
||||||
|
QPoint left, right, top, down;
|
||||||
while(!Q.empty()){
|
while(!Q.empty()){
|
||||||
QPoint Front = Q.front();
|
QPoint Current = Q.front();
|
||||||
Q.pop();
|
Q.pop();
|
||||||
if((Front.x()+1 < Canvas->width)&&
|
|
||||||
(Active->image->getPixelColor(Front.x()+1,Front.y()) == oldColor)&&
|
left = QPoint(Current.x()-1,Current.y() );
|
||||||
(Canvas->image->getPixelColor(Front.x()+1,Front.y()) != newColor)){
|
right = QPoint(Current.x()+1,Current.y() );
|
||||||
Canvas->image->drawPixel(QPoint(Front.x()+1, Front.y()),newColor);
|
top = QPoint(Current.x() ,Current.y()-1);
|
||||||
Q.push(QPoint(Front.x()+1,Front.y()));
|
down = QPoint(Current.x() ,Current.y()+1);
|
||||||
|
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)){
|
||||||
|
Canvas->image->drawPixel(right,newColor);
|
||||||
|
Q.push(right);
|
||||||
}
|
}
|
||||||
if((Front.x()-1 >= 0)&&
|
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)){
|
||||||
(Active->image->getPixelColor(Front.x()-1,Front.y()) == oldColor)&&
|
Canvas->image->drawPixel(left,newColor);
|
||||||
(Canvas->image->getPixelColor(Front.x()-1,Front.y()) != newColor)){
|
Q.push(left);
|
||||||
Canvas->image->drawPixel(QPoint(Front.x()-1, Front.y()),newColor);
|
|
||||||
Q.push(QPoint(Front.x()-1,Front.y()));
|
|
||||||
}
|
}
|
||||||
if((Front.y()+1 < Canvas->hight)&&
|
if((top.y() < Canvas->hight) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)){
|
||||||
(Active->image->getPixelColor(Front.x(),Front.y()+1) == oldColor)&&
|
Canvas->image->drawPixel(top,newColor);
|
||||||
(Canvas->image->getPixelColor(Front.x(),Front.y()+1) != newColor)){
|
Q.push(top);
|
||||||
Canvas->image->drawPixel(QPoint(Front.x(), Front.y()+1),newColor);
|
|
||||||
Q.push(QPoint(Front.x(),Front.y()+1));
|
|
||||||
}
|
}
|
||||||
if((Front.y()-1 >= 0)&&
|
if((down.y() >= 0) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)){
|
||||||
(Active->image->getPixelColor(Front.x(),Front.y()-1) == oldColor)&&
|
Canvas->image->drawPixel(down,newColor);
|
||||||
(Canvas->image->getPixelColor(Front.x(),Front.y()-1) != newColor)){
|
Q.push(down);
|
||||||
Canvas->image->drawPixel(QPoint(Front.x(), Front.y()-1),newColor);
|
|
||||||
Q.push(QPoint(Front.x(),Front.y()-1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* std::function<void(int,int, LayerObject*, LayerObject*, QColor, QColor)> depthsearch =
|
|
||||||
[&depthsearch](int x, int y,LayerObject* Active, LayerObject* Canvas, QColor oldColor, QColor newColor){
|
|
||||||
if((x >= 0) && (y >= 0) && (x < Canvas->width) && (y < Canvas->hight)){
|
|
||||||
if(Active->image->getPixelColor(x,y) == oldColor){
|
|
||||||
Canvas->image->drawPoint(QPoint(x,y),newColor,1);
|
|
||||||
depthsearch(x-1,y,Active,Canvas,oldColor,newColor);
|
|
||||||
depthsearch(x,y+1,Active,Canvas,oldColor,newColor);
|
|
||||||
depthsearch(x+1,y,Active,Canvas,oldColor,newColor);
|
|
||||||
depthsearch(x,y-1,Active,Canvas,oldColor,newColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
depthsearch(x,y,Active,Canvas,oldColor,this->colorPicker->getFirstColor());
|
|
||||||
*/
|
|
||||||
Canvas->image->calculateVisiblity();
|
Canvas->image->calculateVisiblity();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){
|
void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){
|
||||||
|
|||||||
Reference in New Issue
Block a user