PageRenderTime 71ms CodeModel.GetById 24ms app.highlight 40ms RepoModel.GetById 1ms app.codeStats 0ms

/t/gfx_imagefilter.t

http://github.com/PerlGameDev/SDL
Perl | 168 lines | 111 code | 16 blank | 41 comment | 11 complexity | 868a33dd47f2a9b5385fdd76cd25a9aa MD5 | raw file
  1#!perl
  2use strict;
  3use warnings;
  4use SDL;
  5use SDL::Rect;
  6use SDL::Config;
  7use SDL::Video;
  8use SDL::Version;
  9use SDL::Surface;
 10use SDL::PixelFormat;
 11use SDL::GFX;
 12use SDL::GFX::ImageFilter;
 13use Test::More;
 14
 15use lib 't/lib';
 16use SDL::TestTool;
 17
 18my $videodriver = $ENV{SDL_VIDEODRIVER};
 19$ENV{SDL_VIDEODRIVER} = 'dummy' unless $ENV{SDL_RELEASE_TESTING};
 20
 21if ( !SDL::TestTool->init(SDL_INIT_VIDEO) ) {
 22	plan( skip_all => 'Failed to init video' );
 23} elsif ( !SDL::Config->has('SDL_gfx_imagefilter') ) {
 24	plan( skip_all => 'SDL_gfx_imagefilter support not compiled' );
 25} else {
 26	plan( tests => 8 );
 27}
 28
 29my $v = SDL::GFX::linked_version();
 30isa_ok( $v, 'SDL::Version', '[linked_version]' );
 31printf( "got version: %d.%d.%d\n", $v->major, $v->minor, $v->patch );
 32
 33my @done = qw/
 34	MMX_detect
 35	/;
 36
 37my $display = SDL::Video::set_video_mode( 640, 480, 32, SDL_SWSURFACE );
 38my $pixel = SDL::Video::map_RGB( $display->format, 0, 0, 0 );
 39SDL::Video::fill_rect(
 40	$display,
 41	SDL::Rect->new( 0, 0, $display->w, $display->h ), $pixel
 42);
 43
 44if ( !$display ) {
 45	plan skip_all => 'Couldn\'t set video mode: ' . SDL::get_error();
 46}
 47
 48my $mmx_before = SDL::GFX::ImageFilter::MMX_detect();
 49is( $mmx_before == 1 || $mmx_before == 0, 1, "MMX_detect == $mmx_before" );
 50is( SDL::GFX::ImageFilter::MMX_off(),    undef, 'MMX_off' );
 51is( SDL::GFX::ImageFilter::MMX_detect(), 0,     "MMX_detect (MMX is off now)" );
 52is( SDL::GFX::ImageFilter::MMX_on(),     undef, 'MMX_on' );
 53is( SDL::GFX::ImageFilter::MMX_detect(),
 54	$mmx_before, "MMX_detect (MMX is same as at start)"
 55);
 56
 57#add(Src1, Src2, Dest, length)
 58#mean(Src1, Src2, Dest, length)
 59#sub(Src1, Src2, Dest, length)
 60#abs_diff(Src1, Src2, Dest, length)
 61#mult(Src1, Src2, Dest, length)
 62#mult_nor(Src1, Src2, Dest, length)
 63#mult_div_by_2(Src1, Src2, Dest, length)
 64#mult_div_by_4(Src1, Src2, Dest, length)
 65#bit_and(Src1, Src2, Dest, length)
 66#bit_or(Src1, Src2, Dest, length)
 67#div(Src1, Src2, Dest, length)
 68#bit_negation(Src1, Dest, length)
 69#add_byte(Src1, Dest, length, C)
 70#add_uint(Src1, Dest, length, C)
 71#add_byte_to_half(Src1, Dest, length, C)
 72#sub_byte(Src1, Dest, length, C)
 73#sub_uint(Src1, Dest, length, C)
 74#shift_right(Src1, Dest, length, N)
 75#shift_right_uint(Src1, Dest, length, N)
 76#mult_by_byte(Src1, Dest, length, C)
 77#shift_right_and_mult_by_byte(Src1, Dest, length, N, C)
 78#shift_left_byte(Src1, Dest, length, N)
 79#shift_left_uint(Src1, Dest, length, N)
 80#shift_left(Src1, Dest, length, N)
 81#binarize_using_threshold(Src1, Dest, length, T)
 82#clip_to_range(Src1, Dest, length, Tmin, Tmax)
 83#normalize_linear(Src1, Dest, length, Cmin, Cmax, Nmin, Nmax)
 84#convolve_kernel_3x3_divide(Src, Dest, rows, columns, Kernel, Divisor)
 85#convolve_kernel_5x5_divide(Src, Dest, rows, columns, Kernel, Divisor)
 86#convolve_kernel_7x7_divide(Src, Dest, rows, columns, Kernel, Divisor)
 87#convolve_kernel_9x9_divide(Src, Dest, rows, columns, Kernel, Divisor)
 88#convolve_kernel_3x3_shift_right(Src, Dest, rows, columns, Kernel, NRightShift)
 89#convolve_kernel_5x5_shift_right(Src, Dest, rows, columns, Kernel, NRightShift)
 90#convolve_kernel_7x7_shift_right(Src, Dest, rows, columns, Kernel, NRightShift)
 91#convolve_kernel_9x9_shift_right(Src, Dest, rows, columns, Kernel, NRightShift)
 92#sobel_x(Src, Dest, rows, columns)
 93#sobel_x_shift_right(Src, Dest, rows, columns, NRightShift)
 94#align_stack()
 95#restore_stack()
 96
 97SDL::Video::update_rect( $display, 0, 0, 640, 480 );
 98
 99#SDL::delay(1000);
100
101my @left = qw/
102	MMX_detect
103	MMX_off
104	MMX_on
105	add
106	mean
107	sub
108	abs_diff
109	mult
110	mult_nor
111	mult_div_by_2
112	mult_div_by_4
113	bit_and
114	bit_or
115	div
116	bit_negation
117	add_byte
118	add_uint
119	add_byte_to_half
120	sub_byte
121	sub_uint
122	shift_right
123	shift_right_uint
124	mult_by_byte
125	shift_right_and_mult_by_byte
126	shift_left_byte
127	shift_left_uint
128	shift_left
129	binarize_using_threshold
130	clip_to_range
131	normalize_linear
132	convolve_kernel_3x3_divide
133	convolve_kernel_5x5_divide
134	convolve_kernel_7x7_divide
135	convolve_kernel_9x9_divide
136	convolve_kernel_3x3_shift_right
137	convolve_kernel_5x5_shift_right
138	convolve_kernel_7x7_shift_right
139	convolve_kernel_9x9_shift_right
140	sobel_x
141	sobel_x_shift_right
142	align_stack
143	restore_stack
144	/;
145
146my $why =
147	  '[Percentage Completion] '
148	. int( 100 * ( $#done + 1 ) / ( $#done + $#left + 2 ) )
149	. '% implementation. '
150	. ( $#done + 1 ) . '/'
151	. ( $#done + $#left + 2 );
152TODO:
153{
154	local $TODO = $why;
155	pass "\nThe following functions:\n" . join ",", @left;
156}
157if   ( $done[0] eq 'none' ) { print '0% done 0/' . $#left . "\n" }
158else                        { print "$why\n" }
159
160if ($videodriver) {
161	$ENV{SDL_VIDEODRIVER} = $videodriver;
162} else {
163	delete $ENV{SDL_VIDEODRIVER};
164}
165
166pass 'Are we still alive? Checking for segfaults';
167
168done_testing;