Index: [thread] [date] [subject] [author]
  From: Marcus Sundberg <mackan@stacken.kth.se>
  To  : ggi-develop@eskimo.com
  Date: Sun, 16 May 1999 08:52:34 +0000

Re: Semi-Snag in PyGGI...

Evan Martin wrote:
> 
> Marcus Sundberg wrote:
> > > However, incorporating Evan Martin's fix of my broken pointer arithmetic, we end up
> > > with:
> > >
> > > int block_size=(number_of_pixels*actual_pixel_size_in_bytes);
> > > ggi_pixel this_is_the_pixel_to_copy_many_times=ggiMapColor(vis, &color);
> > > ggi_pixel *pixel_buffer=(ggi_pixel*)malloc(block_size);
> > > uint8 *this_is_an_index_into_the_pixel_buffer=pixel_buffer
> > > for(i=0;i<number_of_pixels;i++){
> > >
> > > *(ggi_pixel*)this_is_an_index_into_the_pixel_buffer=this_is_the_pixel_to_copy_many_times;
> > >
> > >     this_is_an_index_into_the_pixel_buffer+=actual_pixel_size_in_bytes;
> > > }
> >
> > Ok that will work in concept, as long as you have one version of the
> > loop for each of 8, 16, 24 and 32 bit/pixel modes, and make
> > this_is_an_index_into_the_pixel_buffer a pointer to the apropriate
> > type.
> 
> I don't see why it wouldn't work for different color depths.
> The pointer (this_is_an_index...) will be advanced the correct number of
> bytes for each depth.
> Could you explain?

Yes, the increment is fine.
But for the assignment you are casting the pointer to ggi_pixel* instead
of to a pointer to the actual pixel size.

> > But there is absolutely _no_ reason to do what you do above because
> > it will be upto one hundred times slower than using ggiDrawHLine/VLine.
> 
> I apologize for giving you code that didn't quite suit the situation.
> The code I pasted
> was written as an example for another person's problem.
> I would have used ggiDrawHLine, but the original code involved some sort
> of palette
> lookup that required an operation on each individual pixel.

Ah, that explains it then. ;)

//Marcus
-- 
-------------------------------+------------------------------------
        Marcus Sundberg        | http://www.stacken.kth.se/~mackan/
 Royal Institute of Technology |       Phone: +46 707 295404
       Stockholm, Sweden       |   E-Mail: mackan@stacken.kth.se

Index: [thread] [date] [subject] [author]