5 # Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
7 # ------------------------------------------------------------------------------
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # ------------------------------------------------------------------------------
25 # Please feel free to send questions, suggestions or improvements to:
31 package SDL::Tool::Graphic;
42 my $class = ref($proto) || $proto;
55 my ( $self, $surface, $zoomx, $zoomy, $smooth) = @_;
56 croak "SDL::Tool::Graphic::zoom requires an SDL::Surface\n"
57 unless ( ref($surface) && $surface->isa('SDL::Surface'));
59 $$surface = SDL::GFXZoom($$surface, $zoomx, $zoomy, $smooth);
60 SDL::FreeSurface($tmp);
65 my ( $self, $surface, $angle, $zoom, $smooth) = @_;
66 croak "SDL::Tool::Graphic::rotoZoom requires an SDL::Surface\n"
67 unless ( ref($surface) && $surface->isa('SDL::Surface'));
69 $$surface = SDL::GFXRotoZoom($$surface, $angle, $zoom, $smooth);
70 SDL::FreeSurface($tmp);
75 my ( $self, $surface ) = @_;
77 if($surface->isa('SDL::Surface')) {
78 $workingSurface = $$surface;
80 $workingSurface = $surface;
83 my $width = SDL::SurfaceW($workingSurface);
84 my $height = SDL::SurfaceH($workingSurface);
85 for(my $x = 0; $x < $width; $x++){
86 for(my $y = 0; $y < $height; $y++){
87 my $origValue = SDL::SurfacePixel($workingSurface, $x, $y);
88 my $newValue = int(0.3*SDL::ColorR($origValue) + 0.59 * SDL::ColorG($origValue) + 0.11*SDL::ColorB($origValue));
89 SDL::SurfacePixel($workingSurface, $x, $y, SDL::NewColor($newValue, $newValue, $newValue));
93 if($surface->isa('SDL::Surface')) {
94 $surface = \$workingSurface;
96 $surface = $workingSurface;
101 my ( $self, $surface ) = @_;
102 #Added because of strict if we needed global
103 #do $workingSurface init outside subs.
105 if($surface->isa('SDL::Surface')) {
106 $workingSurface = $$surface;
108 $workingSurface = $surface;
110 my $width = SDL::SurfaceW($workingSurface);
111 my $height = SDL::SurfaceH($workingSurface);
112 for(my $x = 0; $x < $width; $x++){
113 for(my $y = 0; $y < $height; $y++){
114 my $origValue = SDL::SurfacePixel($workingSurface, $x, $y);
115 my $newValue = int(0.3*SDL::ColorR($origValue) + 0.59 * SDL::ColorG($origValue) + 0.11*SDL::ColorB($origValue));
116 SDL::SurfacePixel($workingSurface, $x, $y, SDL::NewColor(255-SDL::ColorR($origValue), 255 - SDL::ColorG($origValue), 255 - SDL::ColorB($origValue)));
120 if($surface->isa('SDL::Surface')) {
121 $$surface = $workingSurface;
123 $surface = $workingSurface;
127 croak "SDL::Tool::Graphic requires SDL_gfx support\n"
128 unless SDL::Config->has('SDL_gfx');
145 L<SDL::Tool::Graphic> is a module for zooming and rotating L<SDL::Surface> objects.
149 =head2 zoom ( surface, xzoom, yzoom, smooth )
151 C<SDL::Tool::Graphic::zoom> scales a L<SDL::Surface> along the two axis independently.
153 =head2 rotoZoom ( surface, angle, zoom, smooth )
155 C<SDL::Tool::Graphic::rotoZoom> rotates and fixed axis zooms a L<SDL::Surface>.
157 =head2 grayScale ( surface )
159 C<SDL::Tool::Graphic::grayScale> rotates and fixed axis zooms a L<SDL::Surface>.
161 =head2 invertColor ( surface )
163 C<SDL::Tool::Graphic::invertColor> inverts the color of a <SDL::Surface>.
172 L<perl> L<SDL::Surface>