Index: [thread] [date] [subject] [author]
  From: Jim Meier <fatjim@home.com>
  To  : ggi-develop@eskimo.com
  Date: Thu, 13 May 1999 12:13:31 -0600

Re: Semi-Snag in PyGGI...

Marcus Sundberg wrote:

> Jim Meier wrote:
> > Would it be a reasonable course of action to do something like the following:
> > int block_size=(number_of_pixels*actual_pixel_size_in_bytes);
> > ggi_pixel p=ggiMapColor(vis, &color);
> > ggi_pixel *pixel_buffer=(ggi_pixel*)malloc(block_size);
> > ggi_pixel *p=pixel_buffer
> > for(i=0;i<number_of_pixels;i++){
> >     *pixel_buffer=p;
> >     p+=actual_pixel_size_in_bytes;
> > }
> >
> > I'm thinking there's something wrong with my pointer arithmetic there.. but that's
> > a small detail to iron out.
>
> That code won't even compile because you have two declarations of 'p'.
> If you tell my exactly what you're trying to achieve I can give you a
> working code example.

Sorry about that - just quick pseudocode. To make it make sense, the ggi_pixel p should
be renamed this_is_the_pixel_to_copy_many_times and the ggi_pixel*p should be renamed to
this_is_an_index_into_the_pixel_buffer.
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;
}

-Jim, striving to make all example snippets fully compilable demo programs <grin>

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