2 # SDL::GraphicTool - zooming and rotating graphic tool
4 # Copyright (C) 2002 Russell E. Valentine
5 # Copyright (C) 2002 David J. Goehrig
7 package SDL::Tool::Graphic;
18 my $class = ref($proto) || $proto;
31 my ( $self, $surface, $zoomx, $zoomy, $smooth) = @_;
32 croak "SDL::Tool::Graphic::zoom requires an SDL::Surface\n"
33 unless ( ref($surface) && $surface->isa('SDL::Surface'));
35 $$surface = SDL::GFXZoom($$surface, $zoomx, $zoomy, $smooth);
36 SDL::FreeSurface($tmp);
41 my ( $self, $surface, $angle, $zoom, $smooth) = @_;
42 croak "SDL::Tool::Graphic::rotoZoom requires an SDL::Surface\n"
43 unless ( ref($surface) && $surface->isa('SDL::Surface'));
45 $$surface = SDL::GFXRotoZoom($$surface, $angle, $zoom, $smooth);
46 SDL::FreeSurface($tmp);
51 my ( $self, $surface ) = @_;
53 if($surface->isa('SDL::Surface')) {
54 $workingSurface = $$surface;
56 $workingSurface = $surface;
59 my $width = SDL::SurfaceW($workingSurface);
60 my $height = SDL::SurfaceH($workingSurface);
61 for(my $x = 0; $x < $width; $x++){
62 for(my $y = 0; $y < $height; $y++){
63 my $origValue = SDL::SurfacePixel($workingSurface, $x, $y);
64 my $newValue = int(0.3*SDL::ColorR($origValue) + 0.59 * SDL::ColorG($origValue) + 0.11*SDL::ColorB($origValue));
65 SDL::SurfacePixel($workingSurface, $x, $y, SDL::NewColor($newValue, $newValue, $newValue));
69 if($surface->isa('SDL::Surface')) {
70 $surface = \$workingSurface;
72 $surface = $workingSurface;
77 my ( $self, $surface ) = @_;
79 if($surface->isa('SDL::Surface')) {
80 $workingSurface = $$surface;
82 $workingSurface = $surface;
84 my $width = SDL::SurfaceW($workingSurface);
85 my $height = SDL::SurfaceH($workingSurface);
86 for(my $x = 0; $x < $width; $x++){
87 for(my $y = 0; $y < $height; $y++){
88 my $origValue = SDL::SurfacePixel($workingSurface, $x, $y);
89 my $newValue = int(0.3*SDL::ColorR($origValue) + 0.59 * SDL::ColorG($origValue) + 0.11*SDL::ColorB($origValue));
90 SDL::SurfacePixel($workingSurface, $x, $y, SDL::NewColor(255-SDL::ColorR($origValue), 255 - SDL::ColorG($origValue), 255 - SDL::ColorB($origValue)));
94 if($surface->isa('SDL::Surface')) {
95 $$surface = $workingSurface;
97 $surface = $workingSurface;
101 croak "SDL::Tool::Graphic requires SDL_gfx support\n"
102 unless SDL::Config->has('SDL_gfx');
119 L<SDL::Tool::Graphic> is a module for zooming and rotating L<SDL::Surface> objects.
123 =head2 zoom ( surface, xzoom, yzoom, smooth )
125 C<SDL::Tool::Graphic::zoom> scales a L<SDL::Surface> along the two axis independently.
127 =head2 rotoZoom ( surface, angle, zoom, smooth )
129 C<SDL::Tool::Graphic::rotoZoom> rotates and fixed axis zooms a L<SDL::Surface>.
131 =head2 grayScale ( surface )
133 C<SDL::Tool::Graphic::grayScale> rotates and fixed axis zooms a L<SDL::Surface>.
135 =head2 invertColor ( surface )
137 C<SDL::Tool::Graphic::invertColor> inverts the color of a <SDL::Surface>.
146 L<perl> L<SDL::Surface>