Type : A slow, ugly, and unoptimized but short method to perform antialiased lines in a framebuffer
References : Posted by arguru[AT]smartelectronix[DOT]com
Simple code to perform antialiased lines in a 32-bit RGBA (1 byte/component) framebuffer.
pframebuffer <- unsigned char* to framebuffer bytes (important: Y flipped line order! [like in the way Win32 CreateDIBSection works...])
client_height=framebuffer height in lines
client_width=framebuffer width in pixels (not in bytes)
This doesnt perform any clip checl so it fails if coordinates are set out of bounds.
sorry for the engrish
// By Arguru
void PutTransPixel(int const x,int const y,UCHAR const r,UCHAR const g,UCHAR const b,UCHAR const a)
unsigned char* ppix=pframebuffer+(x+(client_height-(y+1))*client_width)*4;
void LineAntialiased(int const x1,int const y1,int const x2,int const y2,UCHAR const r,UCHAR const g,UCHAR const b)
// some useful constants first
double const dw=x2-x1;
double const dh=y2-y1;
double const slx=dh/dw;
double const sly=dw/dh;
// determine wichever raster scanning behaviour to use
// x scan
int const ri=int(raster);
double const in_y0=1.0-(raster-ri);
double const in_y1=1.0-(ri+1-raster);
// y scan
int const ri=int(raster);
double const in_x0=1.0-(raster-ri);
double const in_x1=1.0-(ri+1-raster);
Added on : 11/02/04 by Gog
Sorry, but what does this have to do with music DSP ??
Added on : 14/02/04 by pav_101[ AT ]hotmail[ DOT ]com
well, for drawing envelopes, waveforms, etc on screen in your DSP app....
Added on : 15/02/04 by Gog
But... there are TONS of graphic toolkits to do just that. No reason to "roll your own". One f.i. is GDI+ (works darn well to be honest), or if you want non-M$ (and better!) go with AGG at (http://www.antigrain.com). And there are even open-source cross-platform toolkits (if you want to do Unix and Mac without coding).
Graphics and GUIs is a very time-consuming task to do from scratch, therefore I think using libraries such as the above is the way to go, liberating energy to do the DSP stuff... ;-)
Added on : 10/03/04 by Rich
I don't want a toolkit, I want antialiased line drawing and nothing more. Everything else is fine.
Added on : 11/03/04 by Justin
Anyone know how to get the pointer to the framebuffer? Perhaps there is a different answer for different platforms?
Added on : 12/09/04 by daniel[ DOT ]schaack [ at ] basementarts[ DOT ]de
you can also draw everything in a 2x (vertically and horizontally) higher resolution and then reduce the size again by always taking the average of 4 pixels. that works well.
Added on : 20/11/08 by aliloko[ AT ]gmail[ DOT ]com
I think it can be useful to those designing graphical synths.
But the Wu line algorithm is considerably more fast and works only with integers.
|Add your own comment|
Comments are displayed in fixed width, no HTML code allowed!