/* * 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; VALUE vother, vflags; Data_Get_Struct(self, SDL_Surface, surf); rb_scan_args(argc, argv, "02", &vother, &vflags ); if( !NIL_P(vother) ) { Data_Get_Struct(vother, 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()); } } flags = collapse_flags(vflags); /* in rubygame_shared.c */ if( init_video_system() == 0 ) { newsurf = SDL_ConvertSurface( surf, othersurf->format, flags ); } else { newsurf = NULL; } if( newsurf == NULL ) { rb_raise(eSDLError,\ "Could not convert the Surface: %s",\ SDL_GetError()); } return Data_Wrap_Struct( cSurface,0,SDL_FreeSurface,newsurf ); }