//http://dsqiu.iteye.com/blog/1689130
//Recursive 4-way floodfill, crashes if recursion stack is full 
void floodFill4(int x, int y, int newColor, int oldColor) 
{ 
    if(x >= 0 && x < w && y >= 0 && y < h && screenBuffer[x][y] == oldColor && screenBuffer[x][y] != newColor) 
    { 
        screenBuffer[x][y] = newColor; //set color before starting recursion
        
        floodFill4(x + 1, y,     newColor, oldColor);
        floodFill4(x - 1, y,     newColor, oldColor);
        floodFill4(x,     y + 1, newColor, oldColor);
        floodFill4(x,     y - 1, newColor, oldColor);
    }     
}
예제 #2
0
void floodFill4 (int x, int y, int fillColor, int interiorColor)
{
int color;

/* Set current color to fillColor, then perform following operations. */
	getPixel (x, y, color);
	if (color = interiorColor) 
	{
		setPixel (x, y);    			// Set color of pixel to fillColor.
		floodFill4 (x + 1, y, fillColor, interiorColor);
		floodFill4 (x - 1, y, fillColor, interiorColor);
		floodFill4 (x, y + 1, fillColor, interiorColor);
		floodFill4 (x, y - 1, fillColor, interiorColor)
	}
예제 #3
0
파일: qgldessin.cpp 프로젝트: csun92/QImage
void QGLDessin::floodFill4(int x, int y, QImage* image, QPainter* painter)
{
    int w = image->width();
    int h = image->height();

    QRgb currentColor = image->pixel(x, y);
    QRgb bgrColor = qRgb(0, 0, 0);
    QRgb newColor = qRgb(255, 255, 255);

    if(x >= 0 && x < w && y >= 0 && y < h && currentColor == bgrColor && currentColor != newColor)
    {
        painter->drawPoint(x, y);
        draw_pixel(x, y);

        floodFill4(x + 1, y,     image, painter);
        floodFill4(x - 1, y,     image, painter);
        floodFill4(x,     y + 1, image, painter);
        floodFill4(x,     y - 1, image, painter);
    }
}
예제 #4
0
파일: qgldessin.cpp 프로젝트: csun92/QImage
void QGLDessin::Coloriage()
{
    QPixmap qPix(ui->widget->grab());
    QImage* image = new QImage(qPix.toImage());
//    image->save("image.png");

//    QImage double_image = this->grabFramebuffer();
//    double_image.save("_image.png");
//    QImage image = double_image.scaled(this->width(), this->height(), Qt::IgnoreAspectRatio);
    QPainter* painter = new QPainter(image);

    painter->setPen(Qt::white);

    if(coloriageMode == DessinMode::sfr)
        floodFill4(mouse_x, mouse_y, image, painter);
    else if(coloriageMode == DessinMode::sfd)
        floodFill4Stack(mouse_x, mouse_y, image, painter);

    this->update();

    delete painter;
}