Access pixels , parachute deploy

Hi,

Just a quick question. I can’t figure out why it gives me a parachute deployed when I try to access the pixel data as follow (src is rgb24 pixel buffer)

uchar *dest = (unsigned char *)screen->pixels;

for(int i=0; i<n; i++) {
       dest[i*3  ] = src[i*3+2];
       dest[i*3+1] = src[i*3+1];
       dest[i*3+2] = src[i*3  ];
    }

Any idea ??? original code is below------------------------------------------------------

    int w =176;
int h =144;
n     =176*144;

uchar *rgb24buffer = pVideo->grabImage();

    if(SDL_Init(SDL_INIT_VIDEO)==-1)
    {
       cout<<SDL_GetError()<<endl;
    }

  screen = SDL_SetVideoMode(w,h,24,SDL_SWSURFACE);

    if(screen == NULL)
    {
       cout<<SDL_GetError()<<endl;
       exit -1;
}

    if(SDL_MUSTLOCK(screen)) {
        if(SDL_LockSurface(screen) < 0 ){
          cout<<SDL_GetError()<<endl;
          return;
        }
    }

   uchar *dest = (unsigned char *)screen->pixels;

for(int i=0; i<n; i++) {
       dest[i*3  ] = src[i*3+2];
       dest[i*3+1] = src[i*3+1];
       dest[i*3+2] = src[i*3  ];
    }
    
    if(SDL_MUSTLOCK(screen)) {
      SDL_UnlockSurface(screen);
    }
    
    SDL_UpdateRect(screen,0,0,0,0); 

    SDL_Quit();

I couldn’t find where you initialized src in the code
below. That might be your problem. It looks like you want
to use rgb24buffer instead of src for the pixels you’re
copying.

Later,

Rafe

zen Genius wrote:>

Hi,

Just a quick question. I can’t figure out why it gives me a parachute deployed when I try to access the pixel data as follow (src is rgb24 pixel buffer)

uchar *dest = (unsigned char *)screen->pixels;

    for(int i=0; i<n; i++) {
       dest[i*3  ] = src[i*3+2];
       dest[i*3+1] = src[i*3+1];
       dest[i*3+2] = src[i*3  ];
    }

Any idea ??? original code is below


    int w =176;
    int h =144;
    n     =176*144;

    uchar *rgb24buffer = pVideo->grabImage();

    if(SDL_Init(SDL_INIT_VIDEO)==-1)
    {
       cout<<SDL_GetError()<<endl;
    }

  screen = SDL_SetVideoMode(w,h,24,SDL_SWSURFACE);

    if(screen == NULL)
    {
       cout<<SDL_GetError()<<endl;
       exit -1;
    }

    if(SDL_MUSTLOCK(screen)) {
        if(SDL_LockSurface(screen) < 0 ){
          cout<<SDL_GetError()<<endl;
          return;
        }
    }

   uchar *dest = (unsigned char *)screen->pixels;

    for(int i=0; i<n; i++) {
       dest[i*3  ] = src[i*3+2];
       dest[i*3+1] = src[i*3+1];
       dest[i*3+2] = src[i*3  ];
    }

    if(SDL_MUSTLOCK(screen)) {
      SDL_UnlockSurface(screen);
    }

    SDL_UpdateRect(screen,0,0,0,0);

    SDL_Quit();

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl