Docsity

Notes on Frame Buffer in Computer Graphics | CSC 413, Study notes of Computer Graphics

Toggle sidebar
bg1
// frameBuffer.cpp
// T. Hain, Feb 2009
#include "frameBuffer.h"
//----------------------------------------------------------------------------
// Fill 4-connected area completely surrounded by boundaryColor pixels, and
// containing no pixels having fillColor color, with fillColor.
void FrameBuffer::fill4(int x, int y, const int boundaryColor, const int fillColor)
{
int saveX = x;
// Fill span containing seed
while (pixNeedsColor(--x, y, boundaryColor,fillColor))
setPixel(x, y, fillColor);
int left = ++x;
x = --saveX;
while (pixNeedsColor(++x, y, boundaryColor,fillColor))
setPixel(x, y, fillColor);
// now get spans above and below current span
getSpans( left, --x, y, TOP, boundaryColor, fillColor);
getSpans( left, x, y, BOTT, boundaryColor, fillColor);
}
//----------------------------------------------------------------------------
// Get and fill any spans immediately above/below and connected to input span.
void FrameBuffer::getSpans(int left, int right, int y, int side, int boundaryColor, int fillColor)
{
y += side;
int x = right, curr_right;
if (pixNeedsColor(right, y, boundaryColor, fillColor))
{
setPixel(right,y,fillColor);
// Check for overhang on the right
while (pixNeedsColor(++x, y, boundaryColor, fillColor))
setPixel(x, y, fillColor);
curr_right = x-1;
if (curr_right > right+1)
getSpans (right+2, curr_right, y, -side, boundaryColor, fillColor);
x = right;
}
else
{
// Skip pixels along span that don't need to be colored
while (--x >= left && !pixNeedsColor(x, y, boundaryColor, fillColor));
if (x < left)
return;
setPixel(x, y, fillColor); // color first pixel that needs to be colored
curr_right = x;
}
while (true)
{
// Color pixels that need to be colored, and that touch span or overhang on the left
while (pixNeedsColor(--x, y, boundaryColor, fillColor))
setPixel(x, y, fillColor);
getSpans (x+1, curr_right, y, side, boundaryColor, fillColor);
if (x <= left) // handle overhang on left of current span
{
if (x < left-2)
getSpans (x+1, left-2, y, -side, boundaryColor, fillColor);
return;
}
// Skip pixels along span that don't need to be colored
while (--x >= left && !pixNeedsColor(x, y, boundaryColor, fillColor));
if (x < left)
return;
setPixel(x, y, fillColor); // color first pixel that needs to be colored
curr_right = x;
}
}

Partial preview of the text

Download Notes on Frame Buffer in Computer Graphics | CSC 413 and more Study notes Computer Graphics in PDF only on Docsity!

// frameBuffer.cpp // T. Hain, Feb 2009 #include "frameBuffer.h" //---------------------------------------------------------------------------- // Fill 4-connected area completely surrounded by boundaryColor pixels, and // containing no pixels having fillColor color, with fillColor. void FrameBuffer::fill4(int x, int y, const int boundaryColor, const int fillColor) { int saveX = x; // Fill span containing seed while (pixNeedsColor(--x, y, boundaryColor,fillColor)) setPixel(x, y, fillColor); int left = ++x; x = --saveX; while (pixNeedsColor(++x, y, boundaryColor,fillColor)) setPixel(x, y, fillColor); // now get spans above and below current span getSpans( left, --x, y, TOP, boundaryColor, fillColor); getSpans( left, x, y, BOTT, boundaryColor, fillColor); } //---------------------------------------------------------------------------- // Get and fill any spans immediately above/below and connected to input span. void FrameBuffer::getSpans(int left, int right, int y, int side, int boundaryColor, int fillColor) { y += side; int x = right, curr_right; if (pixNeedsColor(right, y, boundaryColor, fillColor)) { setPixel(right,y,fillColor); // Check for overhang on the right while (pixNeedsColor(++x, y, boundaryColor, fillColor)) setPixel(x, y, fillColor); curr_right = x-1; if (curr_right > right+1) getSpans (right+2, curr_right, y, -side, boundaryColor, fillColor); x = right; } else { // Skip pixels along span that don't need to be colored while (--x >= left && !pixNeedsColor(x, y, boundaryColor, fillColor)); if (x < left) return; setPixel(x, y, fillColor); // color first pixel that needs to be colored curr_right = x; } while (true) { // Color pixels that need to be colored, and that touch span or overhang on the left while (pixNeedsColor(--x, y, boundaryColor, fillColor)) setPixel(x, y, fillColor); getSpans (x+1, curr_right, y, side, boundaryColor, fillColor); if (x <= left) // handle overhang on left of current span { if (x < left-2) getSpans (x+1, left-2, y, -side, boundaryColor, fillColor); return; } // Skip pixels along span that don't need to be colored while (--x >= left && !pixNeedsColor(x, y, boundaryColor, fillColor)); if (x < left) return; setPixel(x, y, fillColor); // color first pixel that needs to be colored curr_right = x; } }