Commit | Line | Data |
8fde61e3 |
1 | # |
2 | # SDL::GraphicTool - zooming and rotating graphic tool |
3 | # |
4 | # Copyright (C) 2002 Russell E. Valentine |
5 | # Copyright (C) 2002 David J. Goehrig |
6 | |
7 | package SDL::Tool::Graphic; |
8 | |
084b921f |
9 | use strict; |
10 | use warnings; |
11 | use Carp; |
8fde61e3 |
12 | use SDL; |
13 | use SDL::Config; |
14 | require SDL::Surface; |
15 | |
16 | sub new { |
17 | my $proto = shift; |
18 | my $class = ref($proto) || $proto; |
084b921f |
19 | my $self = {}; |
8fde61e3 |
20 | bless $self, $class; |
21 | $self; |
22 | } |
23 | |
24 | |
25 | sub DESTROY { |
26 | # nothing to do |
27 | } |
28 | |
29 | |
30 | sub zoom { |
31 | my ( $self, $surface, $zoomx, $zoomy, $smooth) = @_; |
084b921f |
32 | croak "SDL::Tool::Graphic::zoom requires an SDL::Surface\n" |
8fde61e3 |
33 | unless ( ref($surface) && $surface->isa('SDL::Surface')); |
34 | my $tmp = $$surface; |
35 | $$surface = SDL::GFXZoom($$surface, $zoomx, $zoomy, $smooth); |
36 | SDL::FreeSurface($tmp); |
37 | $surface; |
38 | } |
39 | |
40 | sub rotoZoom { |
41 | my ( $self, $surface, $angle, $zoom, $smooth) = @_; |
084b921f |
42 | croak "SDL::Tool::Graphic::rotoZoom requires an SDL::Surface\n" |
8fde61e3 |
43 | unless ( ref($surface) && $surface->isa('SDL::Surface')); |
44 | my $tmp = $$surface; |
45 | $$surface = SDL::GFXRotoZoom($$surface, $angle, $zoom, $smooth); |
46 | SDL::FreeSurface($tmp); |
47 | $surface; |
48 | } |
49 | |
50 | sub grayScale { |
51 | my ( $self, $surface ) = @_; |
084b921f |
52 | my $workingSurface; |
8fde61e3 |
53 | if($surface->isa('SDL::Surface')) { |
084b921f |
54 | $workingSurface = $$surface; |
8fde61e3 |
55 | } else { |
56 | $workingSurface = $surface; |
57 | } |
58 | my $color; |
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)); |
66 | } |
67 | } |
68 | |
69 | if($surface->isa('SDL::Surface')) { |
70 | $surface = \$workingSurface; |
71 | } else { |
72 | $surface = $workingSurface; |
73 | } |
74 | } |
75 | |
76 | sub invertColor { |
77 | my ( $self, $surface ) = @_; |
084b921f |
78 | my $workingSurface; |
8fde61e3 |
79 | if($surface->isa('SDL::Surface')) { |
80 | $workingSurface = $$surface; |
81 | } else { |
82 | $workingSurface = $surface; |
83 | } |
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))); |
91 | } |
92 | } |
93 | |
94 | if($surface->isa('SDL::Surface')) { |
95 | $$surface = $workingSurface; |
96 | } else { |
97 | $surface = $workingSurface; |
98 | } |
99 | } |
100 | |
084b921f |
101 | croak "SDL::Tool::Graphic requires SDL_gfx support\n" |
8fde61e3 |
102 | unless SDL::Config->has('SDL_gfx'); |
103 | |
104 | |
105 | 1; |
106 | |
107 | __END__; |
108 | |
109 | =pod |
110 | |
111 | |
112 | |
113 | =head1 NAME |
114 | |
115 | SDL::Tool::Graphic |
116 | |
117 | =head1 DESCRIPTION |
118 | |
119 | L<SDL::Tool::Graphic> is a module for zooming and rotating L<SDL::Surface> objects. |
120 | |
121 | =head1 METHODS |
122 | |
123 | =head2 zoom ( surface, xzoom, yzoom, smooth ) |
124 | |
125 | C<SDL::Tool::Graphic::zoom> scales a L<SDL::Surface> along the two axis independently. |
126 | |
127 | =head2 rotoZoom ( surface, angle, zoom, smooth ) |
128 | |
129 | C<SDL::Tool::Graphic::rotoZoom> rotates and fixed axis zooms a L<SDL::Surface>. |
130 | |
131 | =head2 grayScale ( surface ) |
132 | |
133 | C<SDL::Tool::Graphic::grayScale> rotates and fixed axis zooms a L<SDL::Surface>. |
134 | |
135 | =head2 invertColor ( surface ) |
136 | |
137 | C<SDL::Tool::Graphic::invertColor> inverts the color of a <SDL::Surface>. |
138 | |
139 | |
140 | =head1 AUTHOR |
141 | |
142 | Russell E. Valentine |
143 | |
144 | =head1 SEE ALSO |
145 | |
146 | L<perl> L<SDL::Surface> |
147 | |
148 | =cut |