Putpixel routine, aa-line

--------------235911F8B36D92EECDCA852A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi there,

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be. Currently I am using SDL_FillRect on a 1x1
rectangle. But that seems to me might not be the best solution - any
ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives -
will post, when done!)

CU
Andreas–
| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

--------------235911F8B36D92EECDCA852A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

Hi there,

I wanted to know what the best way to implement a putpixel routine that works on a surface would be. Currently I am using SDL_FillRect on a 1x1 rectangle. But that seems to me might not be the best solution - any ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives - will post, when done!)

CU
Andreas
 

-- 
|  Andreas Schiffler                    aschiffler at home.com  |
|  Senior Systems Engineer    -    Deskplayer Inc., Buffalo  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada  |
|  +1-905-371-3652 (private)  -  +1-905-371-8834 (work/fax)  |
 

--------------235911F8B36D92EECDCA852A–

Andreas Schiffler wrote:

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be. Currently I am using SDL_FillRect on a 1x1
rectangle. But that seems to me might not be the best solution - any
ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives -
will post, when done!)

There have been several implementations of putpixel and primitive drawing. Just start looking through all the libraries on the SDL libraries page. My personal favorite
is sge.

    -- David Snopek

Hi,

You can try this:

void
SetPixel( SDL_Surface * pSurface,Uint16 nX,Uint16 nY,Uint32 lColor )
{
Uint8 pDst;
Uint16 nPitch,nSrcBytePP;

nSrcBytePP = pSurface->format->BytesPerPixel;

if ( !pSurface->pitch )
    nPitch = pSurface->w*nSrcBytePP;
else
    nPitch = pSurface->pitch;

if ( SDL_LockSurface( pSurface )>=0 )
{
	pDst  = (Uint8 *)pSurface->pixels;
	pDst += ((Uint32)nPitch)*nY+nX*nSrcBytePP;

	switch( nSrcBytePP )
	{
        	case 1:
            		*pDst = (Uint8)lColor;
            		break;

        	case 2:
            		*((Uint16 *)pDst) = (Uint16)lColor;
            		break;

        	case 4:
            		*((Uint32 *)pDst) = lColor;
            		break;
    	}
	SDL_UnlockSurface( pSurface );
}

}

Hope it helps.

  • Ken Rogoway> ----- Original Message -----

From: owner-sdl@lokigames.com [mailto:owner-sdl at lokigames.com]On Behalf
Of Andreas Schiffler
Sent: Sunday, January 14, 2001 4:27 PM
To: sdl at lokigames.com
Subject: [SDL] putpixel routine, aa-line

--------------235911F8B36D92EECDCA852A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi there,

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be. Currently I am using SDL_FillRect on a 1x1
rectangle. But that seems to me might not be the best solution - any
ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives -
will post, when done!)

CU
Andreas


| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

--------------235911F8B36D92EECDCA852A
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

Hi there,

I wanted to know what the best way to implement a putpixel routine that works on a surface would be. Currently I am using SDL_FillRect on a 1x1 rectangle. But that seems to me might not be the best solution - any ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives - will post, when done!)

CU
Andreas
 

-- 
|  Andreas
Schiffler           &
nbsp;        aschiffler at home.com  |
|  Senior Systems Engineer    -   
Deskplayer Inc., Buffalo  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada 
|
|  +1-905-371-3652 (private)  -  +1-905-371-8834
(work/fax)  |
 

--------------235911F8B36D92EECDCA852A–

Andreas Schiffler wrote:

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be. Currently I am using SDL_FillRect on a 1x1
rectangle. But that seems to me might not be the best solution - any
ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives -
will post, when done!)

There have been several implementations of putpixel and primitive
drawing. Just start looking through all the libraries on the SDL
libraries page. My personal favorite is sge.

I have a few primitives already available, mostly based on Mike Abrash’s
discussions of how to create graphical primitives. Already I have
antialiased lines (Wu antialiasing), filled polygons, and Bezier curves.
I’m kinda busy to actually get this code into a working package (I wrote
these as part of a non-OpenGL 3D rendering package back when I was still
in college), but if the originator of this post is interested in my code,
I’m willing to contribute it if the licensing is appropriate (i.e. LGPL or
GPL).On Sun, 14 Jan 2001, David Snopek wrote:


Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
ICSM-F Development Team, UP Diliman +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481

I’ve wrote a little library with pixels, lines, circles (filled or not), rects (same). It’s GPL.
The rest is “left as an exercise” :wink:

Herve PARISSI
"You assume too much" (The Menace Phantom)> ----- Original Message -----

From: dido@pacific.net.ph (Rafael R. Sevilla)
To:
Sent: Monday, January 15, 2001 8:35 AM
Subject: Re: [SDL] putpixel routine, aa-line

On Sun, 14 Jan 2001, David Snopek wrote:

Andreas Schiffler wrote:

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be. Currently I am using SDL_FillRect on a 1x1
rectangle. But that seems to me might not be the best solution - any
ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives -
will post, when done!)

There have been several implementations of putpixel and primitive
drawing. Just start looking through all the libraries on the SDL
libraries page. My personal favorite is sge.

I have a few primitives already available, mostly based on Mike Abrash’s
discussions of how to create graphical primitives. Already I have
antialiased lines (Wu antialiasing), filled polygons, and Bezier curves.
I’m kinda busy to actually get this code into a working package (I wrote
these as part of a non-OpenGL 3D rendering package back when I was still
in college), but if the originator of this post is interested in my code,
I’m willing to contribute it if the licensing is appropriate (i.e. LGPL or
GPL).


Rafael R. Sevilla +63 (2) 4342217
ICSM-F Development Team, UP Diliman +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481

-------------- next part --------------
A non-text attachment was scrubbed…
Name: primdemo-0.01.tar.gz
Type: application/x-gzip
Size: 11384 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010115/1891ec48/attachment.bin

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be.

/* This must be called with the surface locked! */
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}

Also, does anyone have a anti-aliased line drawing algorithm?

Wu has. Check any good graphics text

(skip the html when posting here please)

--------------AA66BB2EA7006FE364681BD2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Rafael,

I’ve got a good collection of code together … buf I’d like any AA stuff that
you have.

The final outcome would be LGPL released.

Ciao
Andreas

“Rafael R. Sevilla” wrote:> On Sun, 14 Jan 2001, David Snopek wrote:

Andreas Schiffler wrote:

I wanted to know what the best way to implement a putpixel routine that
works on a surface would be. Currently I am using SDL_FillRect on a 1x1
rectangle. But that seems to me might not be the best solution - any
ideas? Or does anyone have implementations?

Also, does anyone have a anti-aliased line drawing algorithm?

(I am just working on a small lib basic set of SDL graphics primitives -
will post, when done!)

There have been several implementations of putpixel and primitive
drawing. Just start looking through all the libraries on the SDL
libraries page. My personal favorite is sge.

I have a few primitives already available, mostly based on Mike Abrash’s
discussions of how to create graphical primitives. Already I have
antialiased lines (Wu antialiasing), filled polygons, and Bezier curves.
I’m kinda busy to actually get this code into a working package (I wrote
these as part of a non-OpenGL 3D rendering package back when I was still
in college), but if the originator of this post is interested in my code,
I’m willing to contribute it if the licensing is appropriate (i.e. LGPL or
GPL).


Rafael R. Sevilla +63 (2) 4342217
ICSM-F Development Team, UP Diliman +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481


| Andreas Schiffler aschiffler at home.com |
| Senior Systems Engineer - Deskplayer Inc., Buffalo |
| 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
| +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |

--------------AA66BB2EA7006FE364681BD2
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>

Rafael,

I've got a good collection of code together ... buf I'd like any AA stuff that you have.

The final outcome would be LGPL released.

Ciao
Andreas

"Rafael R. Sevilla" wrote:

On Sun, 14 Jan 2001, David Snopek wrote:

> Andreas Schiffler wrote:
>
> > I wanted to know what the best way to implement a putpixel routine that
> > works on a surface would be. Currently I am using SDL_FillRect on a 1x1
> > rectangle. But that seems to me might not be the best solution - any
> > ideas? Or does anyone have implementations?
> >
> > Also, does anyone have a anti-aliased line drawing algorithm?
> >
> > (I am just working on a small lib basic set of SDL graphics primitives -
> > will post, when done!)
>
> There have been several implementations of putpixel and primitive
> drawing.  Just start looking through all the libraries on the SDL
> libraries page.  My personal favorite is sge.
>

I have a few primitives already available, mostly based on Mike Abrash's
discussions of how to create graphical primitives.  Already I have
antialiased lines (Wu antialiasing), filled polygons, and Bezier curves.
I'm kinda busy to actually get this code into a working package (I wrote
these as part of a non-OpenGL 3D rendering package back when I was still
in college), but if the originator of this post is interested in my code,
I'm willing to contribute it if the licensing is appropriate (i.e. LGPL or
GPL).

--
Rafael R. Sevilla <dido at pacific.net.ph>         +63 (2)   4342217
ICSM-F Development Team, UP Diliman             +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481

-- 
|  Andreas Schiffler                    aschiffler at home.com  |
|  Senior Systems Engineer    -    Deskplayer Inc., Buffalo  |
|  4707 Eastwood Cres., Niagara Falls, Ont  L2E 1B4, Canada  |
|  +1-905-371-3652 (private)  -  +1-905-371-8834 (work/fax)  |

 

--------------AA66BB2EA7006FE364681BD2–

What sounds really strange is that most implementation i’ve seen to pixels
routines around the SDL projects are not systeme dependant so I still wonder
why SDL team doesn’t include them as a part of the lib…

Mattias Engdegard a ?crit:> >I wanted to know what the best way to implement a putpixel routine that

works on a surface would be.

/* This must be called with the surface locked! */
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
} else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}

Also, does anyone have a anti-aliased line drawing algorithm?

Wu has. Check any good graphics text

(skip the html when posting here please)

What sounds really strange is that most implementation i’ve seen to pixels
routines around the SDL projects are not systeme dependant so I still wonder
why SDL team doesn’t include them as a part of the lib…

that is precisely the reason

While a putpixel function may be useful for drawing one dot on the screen, its
pretty darn useless for everything else. In a tight loop the two MUL’s just to
find the pixel offset is a waste, nevermind the overhead of the function call
if its not inlined. If you want to draw lines, or perform any kind of
drawing/filtering operation that requires pixel-level access, then design your
pixel access code on a per-algorithm basis and place it directly into your
inner loop.On Mon, Jan 15, 2001 at 05:54:31AM -0800, Sylvain Hellegouarch wrote:

What sounds really strange is that most implementation i’ve seen to pixels
routines around the SDL projects are not systeme dependant so I still wonder
why SDL team doesn’t include them as a part of the lib…

Martin

Bother, said Pooh, as his starship disintegrated.

Martin Donlon wrote:> On Mon, Jan 15, 2001 at 05:54:31AM -0800, Sylvain Hellegouarch wrote:

What sounds really strange is that most implementation i’ve seen to pixels
routines around the SDL projects are not systeme dependant so I still wonder
why SDL team doesn’t include them as a part of the lib…
While a putpixel function may be useful for drawing one dot on the screen, its
pretty darn useless for everything else. In a tight loop the two MUL’s just to
find the pixel offset is a waste, nevermind the overhead of the function call
if its not inlined. If you want to draw lines, or perform any kind of
drawing/filtering operation that requires pixel-level access, then design your
pixel access code on a per-algorithm basis and place it directly into your
inner loop.

My solution to this was to use pre-processor macros for pixel setting and
incrementing a pixel pointer so I wouldn’t have to write it so many bleeding
times!! Martin is right though, there is no easy way. My methods is a little
wasteful… But I do have the rest of my life to refine it!

    -- David Snopek

While a putpixel function may be useful for drawing one dot on the
screen, its pretty darn useless for everything else. In a tight loop
the two MUL’s just to find the pixel offset is a waste, nevermind the
overhead of the function call if its not inlined. If you want to draw
lines, or perform any kind of drawing/filtering operation that
requires pixel-level access, then design your pixel access code on a
per-algorithm basis and place it directly into your inner loop.

My implementation of Wu antialiased lines does this, and the speed
difference between doing putpixels and incrementally computing pixel
offsets directly in the frame buffer is astounding. I nearly tripled the
speed of the antialiased line drawing function, which made it nearly as
fast as the unantialiased Bresenham line drawing function I wrote which
made use of putpixel!On Mon, 15 Jan 2001, Martin Donlon wrote:


Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
ICSM-F Development Team, UP Diliman +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481