/* 
 *  call-seq:
 *    convert( other=nil, flags=nil )  ->  Surface
 *
 *  Copies the Surface to a new Surface with the pixel format of another
 *  Surface, for fast blitting. May raise SDLError if a problem occurs.
 *
 *  This method takes these arguments:
 *  - other::  The Surface to match pixel format against. If +nil+, the
 *             display surface (i.e. Screen) is used, if available; if no
 *             display surface is available, raises SDLError.
 *  - flags::  An array of flags to pass when the new Surface is created.
 *             See Surface#new.
 *
 */
VALUE rbgm_surface_convert(int argc, VALUE *argv, VALUE self)
{
        SDL_Surface *surf, *othersurf, *newsurf;
  Uint32 flags = 0;

        Data_Get_Struct(self, SDL_Surface, surf);

        if(argc>0 && argv[0]!=Qnil)
  {
    Data_Get_Struct(argv[0], SDL_Surface, othersurf);
  }
  else
  {
    othersurf = SDL_GetVideoSurface();
    if( othersurf == NULL )
    {
      rb_raise(eSDLError, "Cannot convert Surface with no target given and no Screen made: %s", SDL_GetError());
    }
  }

        if(argc>1 && argv[1]!=Qnil)
  {
    flags = NUM2UINT(argv[1]);
  }

  newsurf = SDL_ConvertSurface( surf, othersurf->format, flags );

  if( newsurf == NULL )
  {
    rb_raise(eSDLError,\
             "Could not convert the Surface: %s",\
             SDL_GetError());
  }

  return Data_Wrap_Struct( cSurface,0,SDL_FreeSurface,newsurf );  
}