Let us understand what exactly is Gupta Sproull algorithm in computer graphics and then let us see how to implement Gupta Sproull line drawing algorithm in C programming for anti aliased lines.
What is Gupta Sproull Algorithm?
The Gupta Sproull’s algorithm is a scan-conversion method and offers an efficient way of drawing antialiased lines.
This algorithm is primarily used to draw pixel-based lines and the output is usually printers and pixel-based display screens.
This algorithm is derived from DDA line drawing algorithm. wherein three pixel wide lines are drawn on the output screen. It requires a calculation of the perpendicular distance from pixel’s centre to the line’s centre.
What is Line antialiasing?
Anti-aliasing is also known as Oversampling. Anti-aliasing is a technique to transform a stair-like line into a smooth line as shown in the image above.
The Bresenham algorithm is extremely simple to implement. Along with this, it also provides speed and efficiency. This makes it applicable in many domains such as:
This technique for line antialiasing is used majorly in computer graphics and in high-end computer games. There could be different reasons for an antialiased line to occur on your screen or the output device.
One of them could be because of the screen resolution incompatibility with the programmed graphical format. The pixels get deformed when you convert bitmap images.
Here, anti-aliasing technique is of help which can be achieved through many computer graphics algorithms such as DDA algorithm, Gupta Sproull’s line algorithm and much more. The effect of these hazy or blurred lines can be reduced by these anti-aliasing line algorithms.
If you face any issues while compiling this Gupta Sproull Anti aliasing Algorithm code, you may Install graphics.h in your operating system.
Note: This C program for Anti-aliased line algorithm is compiled with Turbo C compiler on Microsoft Windows 10 operating system.
C Program To Implement Gupta Sproull Algorithm For Anti Aliased Line
void gupta_sproull_algorithm(int x0, int x1, int y0, int y1);
void pixel_brightness(int x, int y, double length);
int graphics_driver = DETECT, graphics_mode;
int x0, x1, y0, y1;
initgraph(&graphics_driver, &graphics_mode, "c:\\turboc3\\bgi");
printf("Enter X-axis coordinate of the initial point:\t");
printf("Enter X-axis coordinate of the final point:\t");
printf("Enter Y-axis coordinate of the initial point:\t");
printf("Enter Y-axis coordinate of the final point:\t");
gupta_sproull_algorithm(x0, x1, y0, y1);
void gupta_sproull_algorithm(int x0, int x1, int y0, int y1)
int dx = x1 - x0;
int dy = y1 - y0;
int d = 2 * dy - dx;
int increment_E = 2 * dy;
int increment_NE = 2 * (dy - dx);
int 2dx = 0;
int x = x0;
int y = y0;
double inv_denominator = 1.0 / (2.0 * sqrt(dx * dx + dy * dy));
double inv_denominator_2dx = 2.0 * dx * inv_denominator;
pixel_brightness(x, y, 0);
pixel_brightness(x, y + 1, inv_denominator_2dx);
pixel_brightness(x, y - 1, inv_denominator_2dx);
for(;x < x1;)
if(d < 0)
2dx = d + dx;
d = d + increment_E;
2dx = d - dx;
d = d + increment_NE;
y = y + 1;
x = x + 1;
pixel_brightness(x, y, 2dx * inv_denominator);
pixel_brightness(x, y + 1, inv_denominator_2dx - 2dx * inv_denominator);
pixel_brightness(x, y - 1, inv_denominator_2dx - 2dx * inv_denominator);
void pixel_brightness(int x, int y, double length)
unsigned long brightness;
brightness = filter ((floor(fabs (length)) + 0.5), color);
*( *(grid + y) + x) = brightness;