Xenther has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a simple image slideshow using SDL. I can load images, move them around the screen, but I can't seem to scale the images. I'm trying to use the SDL::GFX::Rotozoom module but the surface I get back doesn't seem to have the "w" or "h" methods. Maybe I'm just missing something really simple. Any help would be greatly appreciated! Thanks!!
#!/usr/bin/perl use strict; use warnings; use SDL; use SDL::Video; use SDL::Rect; use SDL::Surface; use SDLx::Sprite; use SDL::GFX::Rotozoom; use SDLx::App; my $disp = SDLx::App->new( title => 'Ken Burns', width => 1024, height => 800, depth => 32, flags => SDL_ANYFORMAT, resizeable => 1, exit_on_quit => 1 ); #$disp->fullscreen(); my $x = 0; my $y = 0; # This photo is larger than the 1024x800 app size my $big_image = SDLx::Sprite->new( image => '/path/to/photo.jpg' ); my $lil_image = SDL::GFX::Rotozoom::surface( $big_image, 0, 0.7, SMOOT +HING_ON ); for $x ( 0 .. ($lil_image->w-$disp->w) ) { $lil_image->draw_xy( $disp, -$x,0 ); SDL::Video::update_rect( $disp, 0, 0, $disp->w, $disp->h ); # SDL::delay(2); } for $y ( 0 .. ($lil_image->h-$disp->h) ) { $lil_image->draw_xy( $disp, -($lil_image->w-$disp->w),-$y ); SDL::Video::update_rect( $disp, 0, 0, $disp->w, $disp->h ); # SDL::delay(2); } for $x ( 0 .. ($lil_image->w-$disp->w) ) { $lil_image->draw_xy( $disp, -($lil_image->w-$disp->w)+$x,-($lil_image->h-$disp->h) ); SDL::Video::update_rect( $disp, 0, 0, $disp->w, $disp->h ); # SDL::delay(2); } for $y ( 0 .. ($lil_image->h-$disp->h) ) { $lil_image->draw_xy( $disp, 0,-($lil_image->h-$disp->h)+$y ); SDL::Video::update_rect( $disp, 0, 0, $disp->w, $disp->h ); # SDL::delay(1); } #SDL::delay(200);

Replies are listed 'Best First'.
Re: SDL Image Slideshow
by zentara (Cardinal) on Jun 12, 2012 at 12:33 UTC
    Hi, I'm not sure what you are trying to do in your code, but there is 1 glaring error right from the start.
    # This photo is larger than the 1024x800 app size my $big_image = SDLx::Sprite->new( image => '/path/to/photo.jpg' ); my $lil_image = SDL::GFX::Rotozoom::surface( $big_image, 0, 0.7, SMOOTHING_ON );
    If you read perldoc SDL::GFX::Rotozoom you will see that SDL::GFX::Rotozoom::surface requires a surface as input, NOT a SDLx::Sprite as you do in your code.

    From the perldoc:

    my $picture = SDL::Video::load_BMP('test.bmp'); my $rotated = SDL::GFX::Rotozoom::surface( $picture, 45, .8, SMOOTHING_ON +);
    Furthermore, from looking thru the SDL perldocs, it seems you can only load BMP files at this time. Have a look at the example script at /examples/GFX/script_roto.pl in the SDL module distribution.

    Upon further investigation, it looks like you can load a jpg into an SDL::Surface with SDL::Image

    use SDL::Image; SDL::Image::init(IMG_INIT_JPG); #loads JPG support SDL::Image::load("file.png"); #loads PNG support SDL::Image::quit(); #unloads everything

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: SDL Image Slideshow
by zentara (Cardinal) on Jun 12, 2012 at 13:11 UTC
    Just in case you are still scratching your head, here is a script that will load a jpg and scale it down. I cobbled it together from the perldocs.
    #!/usr/bin/perl use strict; use warnings; use SDL; use SDL::Video; use SDL::Rect; use SDL::Surface; use SDLx::Sprite; use SDL::GFX::Rotozoom; use SDLx::App; use SDL::Image; SDL::Image::init(IMG_INIT_JPG); #loads JPG support my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE +); my $pixel = SDL::Video::map_RGB( $display->format, 0, 0, 0 ); SDL::Video::fill_rect( $display, SDL::Rect->new( 0, 0, $display->w, $display->h ), $pixel ); Carp::confess SDL::get_error if !$display; my $disp = SDLx::App->new( title => 'Ken Burns', width => 1024, height => 800, depth => 32, flags => SDL_ANYFORMAT, resizeable => 1, exit_on_quit => 1 ); #$disp->fullscreen(); my $big_image = SDL::Image::load('1Zen16.jpg'); #loads jpg print "$big_image\n"; my $lil_image = SDL::GFX::Rotozoom::surface( $big_image, 0, 0.7, SMOOT +HING_ON ); print "$lil_image\n"; draw($lil_image); #my $temp_surf = SDL::GFX::Rotozoom::shrink_surface( $big_image, .7, . +7); # shrink dos'nt work for me... gives floatingpoint errors #Carp::confess SDL::get_error if !$temp_surf; #draw( $temp_surf ); sub draw { SDL::Video::fill_rect( $display, SDL::Rect->new( 0, 0, $display->w, $display->h ), $pixel ); my $surface = $_[0]; SDL::Video::blit_surface( $surface, SDL::Rect->new( 0, 0, $surface->w, $surface->h ), $display, SDL::Rect->new( 0, 0, $display->w, $display->w ) ); SDL::Video::update_rect( $display, 0, 0, 640, 480 ); } $disp->run();

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      #my $temp_surf = SDL::GFX::Rotozoom::shrink_surface( $big_image, .7, . +7); # shrink dos'nt work for me... gives floatingpoint errors #Carp::confess SDL::get_error if !$temp_surf; #draw( $temp_surf );
      i think you get an floatingpoint error cause shrink needs a shrinkingfactor and 0.7 < 1. try something like
      my $temp_surf = SDL::GFX::Rotozoom::shrink_surface( $big_image, 7, 7);
      or
      my $temp_surf = SDL::GFX::Rotozoom::shrink_surface( $big_image, 1.3, 1 +.3);
      this should work