Raw Image Data

Hi all,

I am Dilip. I am very new to SDL … I am developing a Camera
Application where I am planning to display the Raw Data coming from the
Camera using the SDL.

The Image I am displaying is 640*480 and of 8 Bpp… The procedure I
followed in the program was

  1. Create the Buffer based on the Image Width and Height
  2. Use the SDL_CreateRGBSurface() function
  3. Blit the surface
  4. Update the Buffer …

But after running the program I am getting the segmentation fault. Is
there any logical or syntax error in this. So somebody please help me
regarding this …

My Program …

Display()
{
SDL_Surface *screen, *image;

// Allocating the Buffer for the Image frame.

char buffer = malloc(HeightWidth*Bpp);

// Infinite Loop to display the Camera data

while(ChangeParameters)
{
// Copy the RAW image Data to the Buffer, buffer …

if(SDL_Init(SDL_INIT_VIDEO)==-1)
{
printf(“SDL_Init Video Error !!! \n”);
return 1;
}
/* Set the video colormap */
if ( image->format->palette != NULL )
{
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}

/* load the image */
image=SDL_CreateRGBSurfaceFrom(buffer,640,480,8,640,0,0,0,0);
screen=SDL_SetVideoMode(image->w, image->h,
image->format->BitsPerPixel, SDL_ANYFORMAT);
SDL_BlitSurface(image,0,screen,0);
free(buffer);

// Update the Buffer
update(buffer);

SDL_Flip(screen);
SDL_FreeSurface(image);
}
}

Regards

Dilip Vamanan

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

The Image I am displaying is 640*480 and of 8 Bpp… The procedure I
followed in the program was

  1. Create the Buffer based on the Image Width and Height
  2. Use the SDL_CreateRGBSurface() function
  3. Blit the surface
  4. Update the Buffer …

But after running the program I am getting the segmentation fault. Is
there any logical or syntax error in this. So somebody please help me
regarding this …

My Program …

I’ve re-done the indentation. It was impossible to read. :^)

Display()
{
SDL_Surface *screen, *image;

// Allocating the Buffer for the Image frame.

char buffer = malloc(HeightWidth*Bpp);

// Infinite Loop to display the Camera data

while(ChangeParameters)
{
// Copy the RAW image Data to the Buffer, buffer …

if(SDL_Init(SDL_INIT_VIDEO)==-1)
{
  printf("SDL_Init Video Error !!! \n");
  return 1;
}

Do not do this in a loop. Only do it once!

/* Set the video colormap */
if ( image->format->palette != NULL )
{
  SDL_SetColors(screen, image->format->palette->colors, 0,
                image->format->palette->ncolors);
}

You are looking within the contents of “image” before it’s been assigned
any value. You appear to call “SDL_CreateRGBSurfaceFrom()” after
doing the above. That’ll definitely cause a seg fault.

/* load the image */
image=SDL_CreateRGBSurfaceFrom(buffer,640,480,8,640,0,0,0,0);
screen=SDL_SetVideoMode(image->w, image->h,
                        image->format->BitsPerPixel, SDL_ANYFORMAT);

Only set the video mode once in your app (unless you’re changing modes
or size). You should do this OUTSIDE your loop, after you’ve called
SDL_Init().

SDL_BlitSurface(image,0,screen,0);
free(buffer);

It’s also very good to test things for NULL, just in case.
(e.g., “SDL_SetVideoMode()” might fail and return NULL…
SDL_CreateRGBSurface*() might fail and reutrn NULL…)

// Update the Buffer
update(buffer);

SDL_Flip(screen);
SDL_FreeSurface(image);

}
}

Good luck!

-bill!On Sun, Jan 29, 2006 at 06:04:00PM +0530, dilip.vamanan at wipro.com wrote:

Hey Dillip and rest.

You wrote that you were developing a camera app. So will I soon. Do you or
anyone else has some tips to grabbing video from video-grabbers in windows
or in linux? Librarys, howtos etc…
I would like to use SDL for this project.

I have looked at the docs for dx video grabbing. I am an experienced
programmer, but boy that looks complicated!

Tnx
-MartinOn 1/29/06, dilip.vamanan at wipro.com <dilip.vamanan at wipro.com> wrote:

Hi all,

I am Dilip. I am very new to SDL … I am developing a Camera
Application where I am planning to display the Raw Data coming from the
Camera using the SDL.

The Image I am displaying is 640*480 and of 8 Bpp… The procedure I
followed in the program was

  1. Create the Buffer based on the Image Width and Height
  2. Use the SDL_CreateRGBSurface() function
  3. Blit the surface
  4. Update the Buffer …

But after running the program I am getting the segmentation fault. Is
there any logical or syntax error in this. So somebody please help me
regarding this …

My Program …

Display()
{
SDL_Surface *screen, *image;

// Allocating the Buffer for the Image frame.

char buffer = malloc(HeightWidth*Bpp);
// Infinite Loop to display the Camera data

while(ChangeParameters)
{
// Copy the RAW image Data to the Buffer, buffer …

if(SDL_Init(SDL_INIT_VIDEO)==-1)
{
printf(“SDL_Init Video Error !!! \n”);
return 1;
}
/* Set the video colormap */
if ( image->format->palette != NULL )
{
SDL_SetColors(screen, image->format->palette->colors, 0,
image->format->palette->ncolors);
}

/* load the image */
image=SDL_CreateRGBSurfaceFrom(buffer,640,480,8,640,0,0,0,0);
screen=SDL_SetVideoMode(image->w, image->h, image->format->BitsPerPixel,
SDL_ANYFORMAT);
SDL_BlitSurface(image,0,screen,0);
free(buffer);

// Update the Buffer
update(buffer);

SDL_Flip(screen);
SDL_FreeSurface(image);
}
}

Regards

Dilip Vamanan

The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s) and
may contain proprietary, confidential or privileged information. If you are
not the intended recipient, you should not disseminate, distribute or copy
this e-mail. Please notify the sender immediately and destroy all copies of
this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses. The
company accepts no liability for any damage caused by any virus transmitted
by this email.

www.wipro.com


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