PageRenderTime 221ms CodeModel.GetById 27ms RepoModel.GetById 13ms app.codeStats 0ms

/t/gfx_rotozoom.t

http://github.com/PerlGameDev/SDL
Perl | 155 lines | 131 code | 21 blank | 3 comment | 9 complexity | 96343149ed883401fbddffd1b304d59a MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. #!perl
  2. use strict;
  3. use warnings;
  4. use SDL;
  5. use SDL::Rect;
  6. use SDL::Config;
  7. use SDL::Video;
  8. use SDL::Version;
  9. use SDL::Surface;
  10. use SDL::PixelFormat;
  11. use SDL::GFX;
  12. use SDL::GFX::Rotozoom;
  13. use Test::More;
  14. use lib 't/lib';
  15. use SDL::TestTool;
  16. my $videodriver = $ENV{SDL_VIDEODRIVER};
  17. $ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
  18. if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
  19. plan( skip_all => 'Failed to init video' );
  20. } elsif ( !SDL::Config->has('SDL_gfx_rotozoom') ) {
  21. plan( skip_all => 'SDL_gfx_rotozoom support not compiled' );
  22. } else {
  23. plan( tests => 23 );
  24. }
  25. my $v = SDL::GFX::linked_version();
  26. isa_ok( $v, 'SDL::Version', '[linked_version]' );
  27. printf( "got version: %d.%d.%d\n", $v->major, $v->minor, $v->patch );
  28. is( SMOOTHING_OFF, 0, 'SMOOTHING_OFF should be imported' );
  29. is( SMOOTHING_OFF(), 0, 'SMOOTHING_OFF() should also be available' );
  30. is( SMOOTHING_ON, 1, 'SMOOTHING_ON should be imported' );
  31. is( SMOOTHING_ON(), 1, 'SMOOTHING_ON() should also be available' );
  32. my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_ANYFORMAT );
  33. my $pixel = SDL::Video::map_RGB( $display->format, 0, 0, 0 );
  34. SDL::Video::fill_rect(
  35. $display,
  36. SDL::Rect->new( 0, 0, $display->w, $display->h ), $pixel
  37. );
  38. if ( !$display ) {
  39. plan skip_all => 'Couldn\'t set video mode: ' . SDL::get_error();
  40. }
  41. my $src = SDL::Video::load_BMP('test/data/picture.bmp');
  42. draw();
  43. # Note: new surface should be less than 16384 in width and height
  44. isa_ok(
  45. SDL::GFX::Rotozoom::surface( $src, 0, 1, 0 ),
  46. 'SDL::Surface', 'surface'
  47. );
  48. draw();
  49. my ( $dest_w, $dest_h ) = @{ SDL::GFX::Rotozoom::surface_size( 100, 200, 45, 1 ) };
  50. is( $dest_w > 100, 1, 'surface_size, resulting width raises at angle is 45' );
  51. is( $dest_h > 200, 1, 'surface_size, resulting height raises at angle is 45' );
  52. ( $dest_w, $dest_h ) = @{ SDL::GFX::Rotozoom::surface_size( 100, 200, 45, 0.3 ) };
  53. is( $dest_w < 100, 1, 'surface_size, resulting width decreases at zoom 0.3' );
  54. is( $dest_h < 200, 1, 'surface_size, resulting height decreases at zoom 0.3' );
  55. SKIP:
  56. {
  57. skip( 'Version 2.0.13 needed', 1 ) if $v < 2.0.13;
  58. isa_ok(
  59. SDL::GFX::Rotozoom::surface_xy( $src, 1, 1, 1, 1 ),
  60. 'SDL::Surface', 'surface_xy'
  61. );
  62. draw();
  63. }
  64. ( $dest_w, $dest_h ) = @{ SDL::GFX::Rotozoom::surface_size_xy( 100, 200, 45, 1.3, 1.7 ) };
  65. is( $dest_w > 100,
  66. 1, 'surface_size_xy, resulting width raises at zoom 1.3 and angle 45'
  67. );
  68. is( $dest_h > 200,
  69. 1, 'surface_size_xy, resulting height raises at zoom 1.7 ans angle 45'
  70. );
  71. ( $dest_w, $dest_h ) = @{ SDL::GFX::Rotozoom::surface_size_xy( 100, 200, 45, 0.3, 0.2 ) };
  72. is( $dest_w < 100,
  73. 1, 'surface_size_xy, resulting width decreases at zoom 0.3 and angle 45'
  74. );
  75. is( $dest_h < 200,
  76. 1, 'surface_size_xy, resulting height decreases at zoom 0.2 ans angle 45'
  77. );
  78. isa_ok(
  79. SDL::GFX::Rotozoom::zoom_surface( $src, 1, 1, 1 ),
  80. 'SDL::Surface', 'zoom_surface'
  81. );
  82. draw();
  83. ( $dest_w, $dest_h ) = @{ SDL::GFX::Rotozoom::zoom_surface_size( 100, 200, 0.5, 0.7 ) };
  84. is( $dest_w < 100,
  85. 1, 'zoom_surface_size, resulting width decreases at zoom 0.5'
  86. );
  87. is( $dest_h < 200,
  88. 1, 'zoom_surface_size, resulting height decreases at zoom 0.7'
  89. );
  90. ( $dest_w, $dest_h ) = @{ SDL::GFX::Rotozoom::zoom_surface_size( 100, 200, 1.2, 7.7 ) };
  91. is( $dest_w > 100, 1, 'zoom_surface_size, resulting width raises at zoom 1.2' );
  92. is( $dest_h > 200, 1,
  93. 'zoom_surface_size, resulting height raises at zoom 7.7'
  94. );
  95. SKIP:
  96. {
  97. skip( 'Version 2.0.14 needed', 1 ) if $v < 2.0.14;
  98. isa_ok(
  99. SDL::GFX::Rotozoom::shrink_surface( $src, 1, 1 ),
  100. 'SDL::Surface', 'shrink_surface'
  101. );
  102. draw();
  103. }
  104. $src = SDL::Surface->new( SDL_SWSURFACE, 100, 200, 32, 0, 0, 0, 0 );
  105. SKIP:
  106. {
  107. skip( 'Version 2.0.17 needed', 1 ) if $v < 2.0.17;
  108. isa_ok(
  109. SDL::GFX::Rotozoom::rotate_surface_90_degrees( $src, 1 ),
  110. 'SDL::Surface', 'rotate_surface_90_degrees'
  111. );
  112. }
  113. # Note: everything but 32bit surface will crash
  114. for ( 1 .. 5 ) {
  115. draw();
  116. }
  117. sub draw {
  118. my $surface = $src;
  119. SDL::Video::blit_surface(
  120. $surface,
  121. SDL::Rect->new( 0, 0, $surface->w, $surface->h ),
  122. $display,
  123. SDL::Rect->new( 50 * 20, 100, $surface->w + 50 + 20, $surface->h + 100 )
  124. );
  125. SDL::Video::update_rect( $display, 0, 0, 640, 480 );
  126. }
  127. SDL::delay(1000);
  128. if ($videodriver) {
  129. $ENV{SDL_VIDEODRIVER} = $videodriver;
  130. } else {
  131. delete $ENV{SDL_VIDEODRIVER};
  132. }
  133. pass 'Are we still alive? Checking for segfaults';
  134. done_testing;